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 / BackupServiceProvider.php
wp-staging / Backup Last commit date
Ajax 1 day ago BackgroundProcessing 1 day ago Dto 1 day ago Entity 1 day ago Exceptions 1 day ago FileHeader 1 day ago Interfaces 1 day ago Job 1 day ago Request 1 day ago Service 1 day ago Storage 1 day ago Task 1 day ago Traits 1 day ago Utils 1 day ago AfterRestore.php 1 day ago BackupDeleter.php 1 day ago BackupDownload.php 1 day ago BackupFileIndex.php 1 day ago BackupGlitchReason.php 1 day ago BackupHeader.php 1 day ago BackupNextOffer.php 1 day ago BackupRepairer.php 1 day ago BackupRetentionHandler.php 1 day ago BackupScheduler.php 1 day ago BackupServiceProvider.php 1 day ago BackupValidator.php 1 day ago BeforeUpdateRowStatus.php 1 day ago FileHeader.php 1 day ago FileHeaderAttribute.php 1 day ago UpdateProtectionPausedNotice.php 1 day ago WithBackupIdentifier.php 1 day ago
BackupServiceProvider.php
161 lines
1 <?php
2
3 namespace WPStaging\Backup;
4
5 use WPStaging\Backup\Ajax\Backup;
6 use WPStaging\Backup\Ajax\Delete;
7 use WPStaging\Backup\Ajax\Edit;
8 use WPStaging\Backup\Ajax\FileInfo;
9 use WPStaging\Backup\Ajax\Parts;
10 use WPStaging\Backup\Ajax\BackupSizeCalculator;
11 use WPStaging\Backup\Ajax\Restore;
12 use WPStaging\Backup\Ajax\ScheduleList;
13 use WPStaging\Backup\Ajax\Upload;
14 use WPStaging\Backup\Ajax\Backup\PrepareBackup;
15 use WPStaging\Backup\Ajax\Backup\BackupBeforeUpdateHandler;
16 use WPStaging\Backup\Ajax\BackupDownloader;
17 use WPStaging\Backup\Ajax\Restore\PrepareRestore;
18 use WPStaging\Backup\Ajax\Restore\ReadBackupMetadata;
19 use WPStaging\Backup\Request\Logs;
20 use WPStaging\Backup\Service\BackupAssets;
21 use WPStaging\Backup\Service\BackupsFinder;
22 use WPStaging\Backup\BeforeUpdateRowStatus;
23 use WPStaging\Backup\UpdateProtectionPausedNotice;
24 use WPStaging\Backup\Service\BeforeUpdateBackupRequest;
25 use WPStaging\Backup\Service\UpdateProtectionHealth;
26 use WPStaging\Backup\Task\Tasks\JobBackup\FinishBackupTask;
27 use WPStaging\Backup\Service\Database\Importer\Insert\ExtendedInserterWithoutTransaction;
28 use WPStaging\Backup\Service\Database\Importer\Insert\QueryInserter;
29 use WPStaging\Backup\Ajax\BackupSpeedIndex;
30 use WPStaging\Backup\Ajax\Explore;
31 use WPStaging\Core\Cron\Cron;
32 use WPStaging\Framework\Adapter\Directory;
33 use WPStaging\Framework\Adapter\DirectoryInterface;
34 use WPStaging\Framework\DI\FeatureServiceProvider;
35 use WPStaging\Framework\Filesystem\Filesystem;
36 use WPStaging\Framework\Filesystem\FilesystemScanner;
37 use WPStaging\Framework\Filesystem\PathIdentifier;
38 use WPStaging\Framework\Job\Task\AbstractTask;
39 use WPStaging\Framework\Queue\FileSeekableQueue;
40 use WPStaging\Framework\Queue\SeekableQueueInterface;
41 use WPStaging\Framework\BackgroundProcessing\Job\PrepareJob;
42 use WPStaging\Framework\Facades\Hooks;
43 use WPStaging\Framework\Security\Otp\OtpSender;
44
45 class BackupServiceProvider extends FeatureServiceProvider
46 {
47
48 const ACTION_BACKUP_ENQUEUE_SCRIPTS = 'wpstg.backup.enqueue_scripts';
49
50 public function createBackupsDirectory()
51 {
52 $backupsDirectory = $this->container->make(BackupsFinder::class)->getBackupsDirectory();
53 $this->container->make(Filesystem::class)->mkdir($backupsDirectory, true);
54 }
55
56 protected function registerClasses()
57 {
58 $this->container->bind(SeekableQueueInterface::class, function () {
59 return $this->container->make(FileSeekableQueue::class);
60 });
61
62 $this->container->when(AbstractTask::class)
63 ->needs(SeekableQueueInterface::class)
64 ->give(FileSeekableQueue::class);
65
66 $this->container->when(PathIdentifier::class)
67 ->needs(DirectoryInterface::class)
68 ->give(Directory::class);
69
70 $this->container->when(FilesystemScanner::class)
71 ->needs(SeekableQueueInterface::class)
72 ->give(FileSeekableQueue::class);
73
74 $this->hookDatabaseImporterQueryInserter();
75 }
76
77 protected function addHooks()
78 {
79 $this->enqueueAjaxListeners();
80
81 $this->enqueueBackupScripts();
82
83 add_action(Cron::ACTION_WEEKLY_EVENT, [$this, 'createBackupsDirectory'], 25, 0);
84
85 add_action('wp_login', $this->container->callback(AfterRestore::class, 'loginAfterRestore'), 10, 0);
86
87 Hooks::registerInternalHook(PrepareJob::ACTION_JOB_FAILURE, $this->container->callback(BackupScheduler::class, 'onBackgroundJobFailure'));
88 }
89
90 protected function enqueueAjaxListeners()
91 {
92 add_action('wp_ajax_wpstg--backup-before-update--save-mode', $this->container->callback(BackupBeforeUpdateHandler::class, 'save')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
93 add_action('wp_ajax_wpstg--backup-before-update--plugin-versions', $this->container->callback(BackupBeforeUpdateHandler::class, 'getPluginUpdateVersionInfo')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
94 add_action('wp_ajax_wpstg--backup-before-update--intro-seen', $this->container->callback(BackupBeforeUpdateHandler::class, 'markIntroSeen')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
95 add_action('wp_ajax_wpstg--backup-before-update--set-enabled', $this->container->callback(BackupBeforeUpdateHandler::class, 'setFeatureEnabled')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
96 add_action('wp_ajax_wpstg--backup-before-update--resume', $this->container->callback(BackupBeforeUpdateHandler::class, 'resumeProtection')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
97 add_action('wp_ajax_wpstg--backup-before-update--reusable-backup', $this->container->callback(BackupBeforeUpdateHandler::class, 'getReusableBackup')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
98 add_action('wp_ajax_wpstg--backup-before-update--start', $this->container->callback(BackupBeforeUpdateHandler::class, 'startBackup')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
99 add_action('wp_ajax_wpstg--backup-before-update--progress', $this->container->callback(BackupBeforeUpdateHandler::class, 'getBackupProgress')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
100
101
102
103 add_action(FinishBackupTask::ACTION_BACKUP_CREATED, $this->container->callback(BeforeUpdateBackupRequest::class, 'markCompleted'));
104
105
106
107 add_action(FinishBackupTask::ACTION_BACKUP_CREATED, $this->container->callback(UpdateProtectionHealth::class, 'recordSuccess'));
108 add_action(PrepareJob::ACTION_JOB_FAILURE, $this->container->callback(BeforeUpdateBackupRequest::class, 'onBackgroundJobFailure'));
109
110 add_action('load-plugins.php', $this->container->callback(BeforeUpdateRowStatus::class, 'registerRowMessages'));
111 add_action('admin_notices', $this->container->callback(UpdateProtectionPausedNotice::class, 'render'));
112 add_action('wp_ajax_wpstg--backups--prepare-backup', $this->container->callback(PrepareBackup::class, 'ajaxPrepare')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
113 add_action('wp_ajax_wpstg--backups--create', $this->container->callback(Backup::class, 'render')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
114
115 add_action('wp_ajax_wpstg--backups--prepare-restore', $this->container->callback(PrepareRestore::class, 'ajaxPrepare')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
116 add_action('wp_ajax_wpstg--backups--restore', $this->container->callback(Restore::class, 'render')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
117
118 add_action('wp_ajax_wpstg--backups--read-backup-metadata', $this->container->callback(ReadBackupMetadata::class, 'ajaxPrepare')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
119 add_action('wp_ajax_wpstg--backups--delete', $this->container->callback(Delete::class, 'render')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
120 add_action('wp_ajax_wpstg--backups--edit', $this->container->callback(Edit::class, 'render')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
121 add_action('wp_ajax_wpstg--backups--parts', $this->container->callback(Parts::class, 'render')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
122 add_action('wp_ajax_wpstg--backups--restore--file-info', $this->container->callback(FileInfo::class, 'render')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
123 add_action('wp_ajax_wpstg--backups--prepare-upload', $this->container->callback(Upload::class, 'ajaxPrepareUpload')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
124 add_action('wp_ajax_wpstg--backups--restore--file-upload', $this->container->callback(Upload::class, 'render')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
125 add_action('wp_ajax_wpstg--backups--prepare-url-upload', $this->container->callback(BackupDownloader::class, 'ajaxPrepareUpload')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
126 add_action('wp_ajax_wpstg--backups--url-file-upload', $this->container->callback(BackupDownloader::class, 'ajaxDownloadBackupFromRemoteServer'), 10, 0); // phpcs:ignore WPStaging.Security.AuthorizationChecked
127 add_action('wp_ajax_wpstg--backups--uploads-delete-unfinished', $this->container->callback(Upload::class, 'ajaxDeleteIncompleteUploads')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
128 add_action('wp_ajax_wpstg--backups--explore-list', $this->container->callback(Explore::class, 'listFiles')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
129 add_action('wp_ajax_wpstg--backups--explore-tree', $this->container->callback(Explore::class, 'listTree')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
130 add_action('wp_ajax_wpstg--backups--explore-browse', $this->container->callback(Explore::class, 'browse')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
131 add_action('wp_ajax_wpstg--backups--explore-select-directory', $this->container->callback(Explore::class, 'listDirectoryFiles')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
132 add_action('wp_ajax_wpstg_calculate_backup_speed_index', $this->container->callback(BackupSpeedIndex::class, 'ajaxMaybeShowModal')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
133
134
135 add_action('wp_ajax_wpstg--send--otp', $this->container->callback(OtpSender::class, 'ajaxSendOtp')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
136
137
138 add_action('wp_ajax_nopriv_wpstg--backups--restore', $this->container->callback(Restore::class, 'render')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
139
140 add_action(Cron::ACTION_CREATE_CRON_BACKUP, $this->container->callback(BackupScheduler::class, 'createCronBackup'), 10, 1);
141 add_action('wp_ajax_wpstg--backups-dismiss-schedule', $this->container->callback(BackupScheduler::class, 'dismissSchedule'), 10, 1); // phpcs:ignore WPStaging.Security.AuthorizationChecked
142 add_action('wp_ajax_wpstg--backups-fetch-schedules', $this->container->callback(ScheduleList::class, 'renderScheduleList'), 10, 1); // phpcs:ignore WPStaging.Security.AuthorizationChecked
143
144 add_action("admin_post_wpstg--backups--logs", $this->container->callback(Logs::class, 'download')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
145
146
147 add_action(Cron::ACTION_DAILY_EVENT, $this->container->callback(BackupScheduler::class, 'reCreateCron'), 10, 0);
148 add_action('wp_ajax_wpstg--backups--calculate-backup-size', $this->container->callback(BackupSizeCalculator::class, 'ajaxCalculateBackupPartsSize')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
149 }
150
151 protected function hookDatabaseImporterQueryInserter()
152 {
153 $this->container->bind(QueryInserter::class, ExtendedInserterWithoutTransaction::class);
154 }
155
156 protected function enqueueBackupScripts()
157 {
158 add_action(self::ACTION_BACKUP_ENQUEUE_SCRIPTS, $this->container->callback(BackupAssets::class, 'register')); // phpcs:ignore
159 }
160 }
161