PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 4.11.0
WP STAGING – WordPress Backups, Restore, Migration & Clone v4.11.0
4.11.0 4.10.0 4.9.5 4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 4.8.1 trunk 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.10.0 3.2.0 3.3.1 3.3.2 3.3.3 3.4.1 3.4.3 3.5.0 3.6.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.8.0
wp-staging / Backup / Ajax / FileInfo.php
wp-staging / Backup / Ajax Last commit date
Backup 1 day ago FileList 1 day ago Restore 1 day ago Backup.php 1 day ago BackupDownloader.php 1 day ago BackupSizeCalculator.php 1 day ago BackupSpeedIndex.php 1 day ago BaseFileList.php 1 day ago BaseListing.php 1 day ago Delete.php 1 day ago Edit.php 1 day ago Explore.php 1 day ago ExploreCache.php 1 day ago FileInfo.php 1 day ago FileList.php 1 day ago Listing.php 1 day ago Parts.php 1 day ago Restore.php 1 day ago ScheduleList.php 1 day ago Upload.php 1 day ago
FileInfo.php
116 lines
1 <?php
2
3 namespace WPStaging\Backup\Ajax;
4
5 use Exception;
6 use WPStaging\Backup\Entity\BackupMetadata;
7 use WPStaging\Backup\Task\RestoreTask;
8 use WPStaging\Backup\Task\Tasks\JobRestore\CleanExistingMediaTask;
9 use WPStaging\Backup\Task\Tasks\JobRestore\RestoreMuPluginsTask;
10 use WPStaging\Backup\Task\Tasks\JobRestore\RestoreOtherFilesInWpContentTask;
11 use WPStaging\Backup\Task\Tasks\JobRestore\RestorePluginsTask;
12 use WPStaging\Backup\Task\Tasks\JobRestore\RestoreThemesTask;
13 use WPStaging\Framework\Component\AbstractTemplateComponent;
14 use WPStaging\Framework\TemplateEngine\TemplateEngine;
15 use WPStaging\Framework\Facades\Hooks;
16 use WPStaging\Framework\Filesystem\PartIdentifier;
17 use WPStaging\Backup\Utils\BackupPathResolver;
18
19 class FileInfo extends AbstractTemplateComponent
20 {
21
22 private $backupPathResolver;
23
24
25 private $excludedBackupParts;
26
27 public function __construct(TemplateEngine $templateEngine, BackupPathResolver $backupPathResolver)
28 {
29 parent::__construct($templateEngine);
30 $this->backupPathResolver = $backupPathResolver;
31 }
32
33
34
35
36 public function render()
37 {
38 if (!$this->canRenderAjax()) {
39 return;
40 }
41
42 $filePath = isset($_POST['filePath']) ? sanitize_text_field($_POST['filePath']) : '';
43 $file = $this->backupPathResolver->resolveBackupPath($filePath);
44 if ($file === '') {
45 wp_send_json([
46 'error' => true,
47 'message' => 'Invalid backup file path!',
48 ]);
49 }
50
51 try {
52 $info = (new BackupMetadata())->hydrateByFilePath($file);
53 } catch (Exception $e) {
54 wp_send_json([
55 'error' => true,
56 'message' => $e->getMessage(),
57 ]);
58 }
59
60 $this->excludedBackupParts = Hooks::applyFilters(RestoreTask::FILTER_EXCLUDE_BACKUP_PARTS, []);
61
62 $excluded = [
63 'database' => $this->isBackupPartExcluded(PartIdentifier::DATABASE_PART_IDENTIFIER),
64 'plugins' => $this->isBackupPartExcluded(PartIdentifier::PLUGIN_PART_IDENTIFIER),
65 'themes' => $this->isBackupPartExcluded(PartIdentifier::THEME_PART_IDENTIFIER),
66 'muPlugins' => $this->isBackupPartExcluded(PartIdentifier::MU_PLUGIN_PART_IDENTIFIER),
67 'uploads' => $this->isBackupPartExcluded(PartIdentifier::UPLOAD_PART_IDENTIFIER),
68 'wpContent' => $this->isBackupPartExcluded(PartIdentifier::WP_CONTENT_PART_IDENTIFIER),
69 'wpRoot' => $this->isBackupPartExcluded(PartIdentifier::WP_ROOT_PART_IDENTIFIER),
70 ];
71
72 $replaced = [
73 'plugins' => $this->isBackupPartReplaced(RestorePluginsTask::FILTER_KEEP_EXISTING_PLUGINS, $info),
74 'themes' => $this->isBackupPartReplaced(RestoreThemesTask::FILTER_KEEP_EXISTING_THEMES, $info),
75 'muPlugins' => $this->isBackupPartReplaced(RestoreMuPluginsTask::FILTER_KEEP_EXISTING_MUPLUGINS, $info),
76 'wpContent' => $this->isBackupPartReplaced(RestoreOtherFilesInWpContentTask::FILTER_KEEP_EXISTING_OTHER_FILES, $info),
77 'wpRoot' => false,
78
79 'uploads' => !Hooks::applyFilters(CleanExistingMediaTask::FILTER_KEEP_EXISTING_MEDIA, false),
80 ];
81
82 $viewData = [
83 'info' => $info,
84 'excluded' => $excluded,
85 'replaced' => $replaced,
86 ];
87
88 $result = $this->templateEngine->render(
89 'backup/modal/confirm-restore.php',
90 $viewData
91 );
92
93 wp_send_json($result);
94 }
95
96 protected function isBackupPartExcluded(string $partName): bool
97 {
98 if (empty($this->excludedBackupParts)) {
99 return false;
100 }
101
102 return in_array($partName, $this->excludedBackupParts);
103 }
104
105 protected function isBackupPartReplaced(string $filter, BackupMetadata $metadata): bool
106 {
107
108 if (!is_multisite() || $metadata->getBackupType() === BackupMetadata::BACKUP_TYPE_MULTISITE) {
109
110 return !Hooks::applyFilters($filter, false);
111 }
112
113 return false;
114 }
115 }
116