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