(
StorageAdapterInterface $srcStorage,
StorageAdapterInterface $dstStorage,
string $srcRoot,
string $dstRoot,
string $sourceFolder,
string $targetFolder
| 1346 | } |
| 1347 | |
| 1348 | private static function copyFolderTreeInternal( |
| 1349 | StorageAdapterInterface $srcStorage, |
| 1350 | StorageAdapterInterface $dstStorage, |
| 1351 | string $srcRoot, |
| 1352 | string $dstRoot, |
| 1353 | string $sourceFolder, |
| 1354 | string $targetFolder, |
| 1355 | callable $copyFilesFn |
| 1356 | ): array { |
| 1357 | $sourceFolder = trim((string)$sourceFolder, "/\\ "); |
| 1358 | $targetFolder = trim((string)$targetFolder, "/\\ "); |
| 1359 | if ($sourceFolder === '' || strtolower($sourceFolder) === 'root') { |
| 1360 | return ['error' => 'Invalid source folder.']; |
| 1361 | } |
| 1362 | if ($targetFolder === '' || strtolower($targetFolder) === 'root') { |
| 1363 | return ['error' => 'Invalid destination folder.']; |
| 1364 | } |
| 1365 | |
| 1366 | [$srcAbs, , $err] = self::resolveFolderPathForAdapter($srcStorage, $srcRoot, $sourceFolder, false); |
| 1367 | if ($err) { |
| 1368 | return ['error' => $err]; |
| 1369 | } |
| 1370 | |
| 1371 | $normalizedTarget = str_replace('\\', '/', $targetFolder); |
| 1372 | $targetName = basename($normalizedTarget); |
| 1373 | if ($targetName === '' || !preg_match(REGEX_FOLDER_NAME, $targetName)) { |
| 1374 | return ['error' => 'Invalid destination folder name.']; |
| 1375 | } |
| 1376 | $parentKey = dirname($normalizedTarget); |
| 1377 | if ($parentKey === '.' || $parentKey === '') { |
| 1378 | $parentKey = 'root'; |
| 1379 | } else { |
| 1380 | $parentKey = trim($parentKey, '/'); |
| 1381 | if ($parentKey === '') { |
| 1382 | $parentKey = 'root'; |
| 1383 | } |
| 1384 | } |
| 1385 | |
| 1386 | [$dstParentAbs, , $err] = self::resolveFolderPathForAdapter($dstStorage, $dstRoot, $parentKey, false); |
| 1387 | if ($err) { |
| 1388 | return ['error' => $err]; |
| 1389 | } |
| 1390 | |
| 1391 | $targetAbs = rtrim($dstParentAbs, "/\\") . DIRECTORY_SEPARATOR . $targetName; |
| 1392 | if ($dstStorage->stat($targetAbs) !== null) { |
| 1393 | return ['error' => 'Destination folder already exists.']; |
| 1394 | } |
| 1395 | if (!$dstStorage->mkdir($targetAbs, 0775, true)) { |
| 1396 | return ['error' => 'Failed to create destination folder.']; |
| 1397 | } |
| 1398 | |
| 1399 | [$maxFiles, $maxBytes, $maxDepth] = self::getCopyTreeLimits(); |
| 1400 | $scan = self::scanFolderTreeForCopy($srcStorage, $srcAbs, $maxFiles, $maxBytes, $maxDepth); |
| 1401 | if (isset($scan['error'])) { |
| 1402 | return ['error' => $scan['error']]; |
| 1403 | } |
| 1404 | |
| 1405 | $folders = $scan['folders'] ?? ['']; |
no test coverage detected