| @@ -5,9 +5,9 @@ | ||
| 5 | 5 | use WPIDE\App\Services\Storage\LocalFileSystem; |
| 6 | 6 | use WPIDE\App\Utils\Exception; |
| 7 | 7 | use const WPIDE\Constants\BACKUPS_DIR; |
| 8 | 8 | use const WPIDE\Constants\BACKUPS_TODAY_DIR; |
| 9 | -use const WPIDE\Constants\CONTENT_DIR; | |
| 9 | +use const WPIDE\Constants\WP_PATH; | |
| 10 | 10 | |
| 11 | 11 | class FileBackup |
| 12 | 12 | { |
| 13 | 13 | |
| @@ -21,15 +21,17 @@ | ||
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | 23 | * @throws \Exception |
| 24 | 24 | */ |
| 25 | - public static function backup($item, $newContent): bool | |
| 25 | + public static function backup($item, $newContent, $root = false): bool | |
| 26 | 26 | { |
| 27 | 27 | $dir = $item->dir; |
| 28 | 28 | $path = $item->path; |
| 29 | 29 | $name = $item->name; |
| 30 | 30 | |
| 31 | - $storage = LocalFileSystem::load(); | |
| 31 | + $root_dir = $root ? '/' : LocalFileSystem::getRootDir(); | |
| 32 | + | |
| 33 | + $storage = LocalFileSystem::load($root_dir); | |
| 32 | 34 | $oldStream = $storage->readStream($path); |
| 33 | 35 | |
| 34 | 36 | if ($oldStream['stream']) { |
| 35 | 37 | |
| @@ -34,10 +36,10 @@ | ||
| 34 | 36 | if ($oldStream['stream']) { |
| 35 | 37 | |
| 36 | 38 | $backupStorage = LocalFileSystem::load(BACKUPS_TODAY_DIR); |
| 37 | 39 | |
| 38 | - $originalFileDir = CONTENT_DIR . AppConfig::get('file.root') . ltrim($dir, '/'); | |
| 39 | - $originalFileDir = str_replace(ABSPATH, "", $originalFileDir); | |
| 40 | + $originalFileDir = wp_normalize_path(WP_PATH . $root_dir . '/'. ltrim($dir, '/')); | |
| 41 | + $originalFileDir = str_replace(wp_normalize_path(WP_PATH), "", $originalFileDir); | |
| 40 | 42 | $backupFilePath = BACKUPS_TODAY_DIR . "/" .$originalFileDir; |
| 41 | 43 | $ext = '.'.pathinfo($name, PATHINFO_EXTENSION); |
| 42 | 44 | |
| 43 | 45 | if (!is_dir($backupFilePath)) { |