PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 4.0.0
WP STAGING – WordPress Backup, Restore, Migration & Clone v4.0.0
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 year ago BackgroundProcessing 1 year ago Dto 1 year ago Entity 1 year ago Exceptions 1 year ago Interfaces 1 year ago Job 1 year ago Request 2 years ago Service 1 year ago Storage 1 year ago Task 1 year ago AfterRestore.php 1 year ago BackupDeleter.php 1 year ago BackupDownload.php 1 year ago BackupFileIndex.php 1 year ago BackupHeader.php 1 year ago BackupRepairer.php 1 year ago BackupRetentionHandler.php 1 year ago BackupScheduler.php 1 year ago BackupServiceProvider.php 1 year ago BackupValidator.php 1 year ago FileHeader.php 1 year ago FileHeaderAttribute.php 2 years ago WithBackupIdentifier.php 1 year ago
BackupServiceProvider.php
126 lines
1 <?php
2
3 namespace WPStaging\Backup;
4
5 use WPStaging\Backup\Ajax\Backup;
6 use WPStaging\Backup\Ajax\Cancel;
7 use WPStaging\Backup\Ajax\Delete;
8 use WPStaging\Backup\Ajax\Edit;
9 use WPStaging\Backup\Ajax\FileInfo;
10 use WPStaging\Backup\Ajax\Parts;
11 use WPStaging\Backup\Ajax\Restore;
12 use WPStaging\Backup\Ajax\ScheduleList;
13 use WPStaging\Backup\Ajax\Status;
14 use WPStaging\Backup\Ajax\Upload;
15 use WPStaging\Backup\Ajax\Backup\PrepareBackup;
16 use WPStaging\Backup\Ajax\BackupDownloader;
17 use WPStaging\Backup\Ajax\Restore\LoginUrl;
18 use WPStaging\Backup\Ajax\Restore\PrepareRestore;
19 use WPStaging\Backup\Ajax\Restore\ReadBackupMetadata;
20 use WPStaging\Backup\Request\Logs;
21 use WPStaging\Backup\Service\BackupAssets;
22 use WPStaging\Backup\Service\BackupsFinder;
23 use WPStaging\Backup\Service\Database\Importer\Insert\ExtendedInserterWithoutTransaction;
24 use WPStaging\Backup\Service\Database\Importer\Insert\QueryInserter;
25 use WPStaging\Backup\Ajax\BackupSpeedIndex;
26 use WPStaging\Framework\Adapter\Directory;
27 use WPStaging\Framework\Adapter\DirectoryInterface;
28 use WPStaging\Framework\DI\FeatureServiceProvider;
29 use WPStaging\Framework\Filesystem\Filesystem;
30 use WPStaging\Framework\Filesystem\PathIdentifier;
31 use WPStaging\Framework\Job\Task\AbstractTask;
32 use WPStaging\Framework\Queue\FileSeekableQueue;
33 use WPStaging\Framework\Queue\SeekableQueueInterface;
34 use WPStaging\Framework\Security\Otp\OtpSender;
35
36 class BackupServiceProvider extends FeatureServiceProvider
37 {
38 /** @var string */
39 const BACKUP_SCRIPTS_ENQUEUE_ACTION = 'wpstg.backup.enqueue_scripts';
40
41 public function createBackupsDirectory()
42 {
43 $backupsDirectory = $this->container->make(BackupsFinder::class)->getBackupsDirectory();
44 $this->container->make(Filesystem::class)->mkdir($backupsDirectory, true);
45 }
46
47 protected function registerClasses()
48 {
49 $this->container->bind(SeekableQueueInterface::class, function () {
50 return $this->container->make(FileSeekableQueue::class);
51 });
52
53 $this->container->when(AbstractTask::class)
54 ->needs(SeekableQueueInterface::class)
55 ->give(FileSeekableQueue::class);
56
57 $this->container->when(PathIdentifier::class)
58 ->needs(DirectoryInterface::class)
59 ->give(Directory::class);
60
61 $this->hookDatabaseImporterQueryInserter();
62 }
63
64 protected function addHooks()
65 {
66 $this->enqueueAjaxListeners();
67
68 $this->enqueueBackupScripts();
69
70 add_action('wpstg_weekly_event', [$this, 'createBackupsDirectory'], 25, 0);
71
72 add_action('wp_login', $this->container->callback(AfterRestore::class, 'loginAfterRestore'), 10, 0);
73 }
74
75 protected function enqueueAjaxListeners()
76 {
77 add_action('wp_ajax_wpstg--backups--prepare-backup', $this->container->callback(PrepareBackup::class, 'ajaxPrepare')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
78 add_action('wp_ajax_wpstg--backups--create', $this->container->callback(Backup::class, 'render')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
79
80 add_action('wp_ajax_wpstg--backups--prepare-restore', $this->container->callback(PrepareRestore::class, 'ajaxPrepare')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
81 add_action('wp_ajax_wpstg--backups--restore', $this->container->callback(Restore::class, 'render')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
82
83 add_action('wp_ajax_wpstg--backups--read-backup-metadata', $this->container->callback(ReadBackupMetadata::class, 'ajaxPrepare')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
84 add_action('wp_ajax_wpstg--backups--delete', $this->container->callback(Delete::class, 'render')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
85 add_action('wp_ajax_wpstg--backups--cancel', $this->container->callback(Cancel::class, 'render')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
86 add_action('wp_ajax_wpstg--backups--edit', $this->container->callback(Edit::class, 'render')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
87 add_action('wp_ajax_wpstg--backups--parts', $this->container->callback(Parts::class, 'render')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
88 add_action('wp_ajax_wpstg--backups--status', $this->container->callback(Status::class, 'render')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
89 add_action('wp_ajax_wpstg--backups--restore--file-info', $this->container->callback(FileInfo::class, 'render')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
90 add_action('wp_ajax_wpstg--backups--prepare-upload', $this->container->callback(Upload::class, 'ajaxPrepareUpload')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
91 add_action('wp_ajax_wpstg--backups--restore--file-upload', $this->container->callback(Upload::class, 'render')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
92 add_action('wp_ajax_wpstg--backups--prepare-url-upload', $this->container->callback(BackupDownloader::class, 'ajaxPrepareUpload')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
93 add_action('wp_ajax_wpstg--backups--url-file-upload', $this->container->callback(BackupDownloader::class, 'ajaxDownloadBackupFromRemoteServer'), 10, 0); // phpcs:ignore WPStaging.Security.AuthorizationChecked
94 add_action('wp_ajax_wpstg--backups--uploads-delete-unfinished', $this->container->callback(Upload::class, 'ajaxDeleteIncompleteUploads')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
95 add_action('wp_ajax_raw_wpstg--backups--login-url', $this->container->callback(LoginUrl::class, 'getLoginUrl')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
96 add_action('wp_ajax_wpstg_calculate_backup_speed_index', $this->container->callback(BackupSpeedIndex::class, 'ajaxMaybeShowModal')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
97
98 // TODO: move this to JobServiceProvider once the Staging PR: https://github.com/wp-staging/wp-staging-pro/pull/3738 is merged
99 add_action('wp_ajax_wpstg--send--otp', $this->container->callback(OtpSender::class, 'ajaxSendOtp')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
100
101 // Nopriv
102 add_action('wp_ajax_nopriv_wpstg--backups--restore', $this->container->callback(Restore::class, 'render')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
103 add_action('wp_ajax_nopriv_wpstg--backups--status', $this->container->callback(Status::class, 'render')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
104 add_action('wp_ajax_nopriv_raw_wpstg--backups--login-url', $this->container->callback(LoginUrl::class, 'getLoginUrl')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
105
106 add_action('wpstg_create_cron_backup', $this->container->callback(BackupScheduler::class, 'createCronBackup'), 10, 1);
107 add_action('wp_ajax_wpstg--backups-dismiss-schedule', $this->container->callback(BackupScheduler::class, 'dismissSchedule'), 10, 1); // phpcs:ignore WPStaging.Security.AuthorizationChecked
108 add_action('wp_ajax_wpstg--backups-fetch-schedules', $this->container->callback(ScheduleList::class, 'renderScheduleList'), 10, 1); // phpcs:ignore WPStaging.Security.AuthorizationChecked
109
110 add_action("admin_post_wpstg--backups--logs", $this->container->callback(Logs::class, 'download')); // phpcs:ignore WPStaging.Security.AuthorizationChecked
111
112 // Event that we can run on daily basis to repair any corrupted backup create cron jobs
113 add_action('wpstg_daily_event', $this->container->callback(BackupScheduler::class, 'reCreateCron'), 10, 0);
114 }
115
116 protected function hookDatabaseImporterQueryInserter()
117 {
118 $this->container->bind(QueryInserter::class, ExtendedInserterWithoutTransaction::class);
119 }
120
121 protected function enqueueBackupScripts()
122 {
123 add_action(self::BACKUP_SCRIPTS_ENQUEUE_ACTION, $this->container->callback(BackupAssets::class, 'register')); // phpcs:ignore
124 }
125 }
126