본문으로 건너뛰기

상품 복사 시 이미지 폴더 구조 처리 개선

PHP 8 · GODO26
변경 파일 수: 1개
변경 파일 목록
총 1개
Component (1)
Storage.phpStorage/
변경 파일 코드
추가삭제
Component/Storage/Storage.php+22-8
변경 전Storage.php
const PATH_CODE_EVENT_GROUP_TMP = 30;
const PATH_CODE_JOIN_EVENT = 31;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
public static function copy($pathCode, $toStorageName, $toPath, $fromStorageName, $fromPath, $recursive = false)
{
$toStorage = Storage::disk($pathCode, $toStorageName, true);
set_time_limit(1000);
$result = false;
$contents = $manager->listContents('to://' . $toPath, $recursive);
$addRecursive = '';
foreach ($contents as $entry) {
$update = true;
if ($update) {
if ($entry['type'] == 'file') {
$result = $manager->copy('to://' . $entry['path'], 'from://' . $fromStorage->getMountPath($fromPath . $addRecursive . $entry['basename']));
} else {
$addRecursive .= $entry['filename'] . DS;
}
}
 
 
 
 
}
return $result;
 
변경 후Storage.php
const PATH_CODE_EVENT_GROUP_TMP = 30;
const PATH_CODE_JOIN_EVENT = 31;
/**
* 파일 또는 디렉토리를 복사한다.
*
* 디렉토리를 복사할 때 대상 경로는 항상 $fromPath 바로 아래에 평면으로 구성된다.
* 원본의 하위 디렉토리 구조는 보존하지 않는다.
*
* @param int $pathCode
* @param string $toStorageName
* @param string $toPath
* @param string $fromStorageName
* @param string $fromPath
* @param bool $recursive 원본 목록 조회 범위에만 적용된다. 대상 경로 구성에는 영향을 주지 않으므로,
* true 로 호출하면 하위 디렉토리의 파일도 대상 폴더 최상위로 복사된다.
*
* @return bool
*/
public static function copy($pathCode, $toStorageName, $toPath, $fromStorageName, $fromPath, $recursive = false)
{
$toStorage = Storage::disk($pathCode, $toStorageName, true);
set_time_limit(1000);
$result = false;
$contents = $manager->listContents('to://' . $toPath, $recursive);
 
foreach ($contents as $entry) {
if ($entry['type'] !== 'file') {
continue;
 
 
 
 
 
}
// 대상 경로는 항상 $fromPath 바로 아래로 만든다.
// 디렉토리 엔트리 이름을 누적해 두면 그 뒤에 나오는 형제 파일까지 하위 디렉토리로 밀려 들어간다.
$result = $manager->copy('to://' . $entry['path'], 'from://' . $fromStorage->getMountPath($fromPath . $entry['basename']));
}
return $result;