use Cli\Services\AppLocator;
use Cli\Services\ArtisanRunner;
use Cli\Services\BackupZip;
+use Cli\Services\Directories;
use Cli\Services\EnvironmentLoader;
use Cli\Services\InteractiveConsole;
use Cli\Services\MySqlRunner;
$artisan->run(['view:clear']);
$output->writeln("<info>Cleaning up extract directory...</info>");
- $this->deleteDirectoryAndContents($extractDir);
+ Directories::delete($extractDir);
$output->writeln("<success>\nRestore operation complete!</success>");
$output->writeln("<info>You may need to fix file/folder permissions so that the webserver has</info>");
protected function restoreFolder(string $folderSubPath, string $appDir, string $extractDir): void
{
$fullAppFolderPath = Paths::real(Paths::join($appDir, $folderSubPath));
- $this->deleteDirectoryAndContents($fullAppFolderPath);
- rename(Paths::join($extractDir, $folderSubPath), $fullAppFolderPath);
- }
-
- protected function deleteDirectoryAndContents(string $dir): void
- {
- $files = new RecursiveIteratorIterator(
- new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS),
- RecursiveIteratorIterator::CHILD_FIRST
- );
-
- foreach ($files as $fileinfo) {
- $path = $fileinfo->getRealPath();
- $fileinfo->isDir() ? rmdir($path) : unlink($path);
- }
-
- rmdir($dir);
+ Directories::delete($fullAppFolderPath);
+ Directories::move(Paths::join($extractDir, $folderSubPath), $fullAppFolderPath);
}
protected function restoreDatabase(string $appDir, string $extractDir): void
--- /dev/null
+<?php
+
+namespace Cli\Services;
+use RecursiveDirectoryIterator;
+use RecursiveIteratorIterator;
+
+class Directories
+{
+
+ public static function move(string $src, string $target): void
+ {
+ static::copy($src, $target);
+ static::delete($src);
+ }
+
+ public static function copy(string $src, string $target): void
+ {
+ mkdir($target);
+
+ /** @var RecursiveDirectoryIterator $files */
+ $files = new RecursiveIteratorIterator(
+ new RecursiveDirectoryIterator($src, RecursiveDirectoryIterator::SKIP_DOTS),
+ RecursiveIteratorIterator::SELF_FIRST
+ );
+
+ /** @var \SplFileInfo $fileinfo */
+ foreach ($files as $fileinfo) {
+ $srcPath = $fileinfo->getRealPath();
+ $subPath = $files->getSubPathName();
+ $destPath = Paths::join($target, $subPath);
+ if ($fileinfo->isDir()) {
+ $result = mkdir($destPath);
+ } else {
+ $result = copy($srcPath, $destPath);
+ }
+
+ if ($result === false) {
+ throw new \Exception("Failed to copy file or directory from {$srcPath} to {$destPath}");
+ }
+ }
+ }
+
+ public static function delete(string $dir): void
+ {
+ $files = new RecursiveIteratorIterator(
+ new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS),
+ RecursiveIteratorIterator::CHILD_FIRST
+ );
+
+ foreach ($files as $fileinfo) {
+ $path = $fileinfo->getRealPath();
+ if ($fileinfo->isDir()) {
+ $result = rmdir($path);
+ } else {
+ $result = unlink($path);
+ }
+
+ if ($result === false) {
+ throw new \Exception("Failed to delete file or directory at {$path}");
+ }
+ }
+
+ rmdir($dir);
+ }
+}
\ No newline at end of file