PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.2.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.2.1
6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 5.2.2 5.3 All 153 releases
mainwp / class / class-mainwp-post-backup-handler.php

class-mainwp-post-backup-handler.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 5.2.1, at class/class-mainwp-post-backup-handler.php

621 lines 25.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * This class handles the MainWP Post Backups.
4 *
5 * @package MainWP/Dashboard
6 */
7
8 namespace MainWP\Dashboard;
9
10 /**
11 * Class MainWP_Post_Backup_Handler
12 *
13 * Handle Backup Post.
14 *
15 * @package MainWP\Dashboard
16 *
17 * @uses \MainWP\Dashboard\MainWP_Post_Base_Handler
18 */
19 class MainWP_Post_Backup_Handler extends MainWP_Post_Base_Handler { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
20
21 /**
22 * Instance class.
23 *
24 * @var $instance Singleton MainWP_Post_Backup_Handler.
25 */
26 private static $instance = null;
27
28 /**
29 * Create public static instance.
30 *
31 * @static
32 * @return self $instance MainWP_Post_Backup_Handler.
33 */
34 public static function instance() {
35 if ( null === static::$instance ) {
36 static::$instance = new self();
37 }
38 return static::$instance;
39 }
40
41 /**
42 * Init backups actions
43 */
44 public function init() {
45 // Page: ManageBackups.
46 $this->add_action( 'mainwp_addbackup', array( &$this, 'mainwp_addbackup' ) );
47 if ( mainwp_current_user_have_right( 'dashboard', 'edit_backup_tasks' ) ) {
48 $this->add_action( 'mainwp_updatebackup', array( &$this, 'mainwp_updatebackup' ) );
49 }
50 if ( mainwp_current_user_have_right( 'dashboard', 'delete_backup_tasks' ) ) {
51 $this->add_action( 'mainwp_removebackup', array( &$this, 'mainwp_removebackup' ) );
52 }
53 $this->add_action( 'mainwp_pausebackup', array( &$this, 'mainwp_pausebackup' ) );
54 $this->add_action( 'mainwp_resumebackup', array( &$this, 'mainwp_resumebackup' ) );
55
56 $this->add_action( 'mainwp_backuptask_get_sites', array( &$this, 'mainwp_backuptask_get_sites' ) );
57
58 if ( mainwp_current_user_have_right( 'dashboard', 'run_backup_tasks' ) ) {
59 $this->add_action( 'mainwp_backuptask_run_site', array( &$this, 'mainwp_backuptask_run_site' ) );
60 }
61 $this->add_action( 'mainwp_backup_upload_file', array( &$this, 'mainwp_backup_upload_file' ) );
62
63 // Page: backup.
64 if ( mainwp_current_user_have_right( 'dashboard', 'run_backup_tasks' ) ) {
65 $this->add_action( 'mainwp_backup_run_site', array( &$this, 'mainwp_backup_run_site' ) );
66 }
67 if ( mainwp_current_user_have_right( 'dashboard', 'execute_backups' ) ) {
68 $this->add_action( 'mainwp_backup', array( &$this, 'ajax_mainwp_backup' ) );
69 }
70 $this->add_action( 'mainwp_checkbackups', array( &$this, 'mainwp_checkbackups' ) );
71 $this->add_action( 'mainwp_backup_checkpid', array( &$this, 'mainwp_backup_checkpid' ) );
72 $this->add_action( 'mainwp_createbackup_getfilesize', array( &$this, 'mainwp_createbackup_getfilesize' ) );
73 $this->add_action( 'mainwp_backup_download_file', array( &$this, 'ajax_mainwp_backup_download_file' ) );
74 $this->add_action( 'mainwp_backup_delete_file', array( &$this, 'mainwp_backup_delete_file' ) );
75 $this->add_action( 'mainwp_backup_getfilesize', array( &$this, 'mainwp_backup_getfilesize' ) );
76 $this->add_action( 'mainwp_backup_upload_getprogress', array( &$this, 'mainwp_backup_upload_getprogress' ) );
77 $this->add_action( 'mainwp_backup_upload_checkstatus', array( &$this, 'mainwp_backup_upload_checkstatus' ) );
78 }
79
80 /*
81 * Page: Backup
82 */
83
84 /**
85 * Method mainwp_backup_run_site()
86 *
87 * Run backup task of site
88 *
89 * @throws MainWP_Exception On errors.
90 *
91 * @uses \MainWP\Dashboard\MainWP_Backup_Handler::backup()
92 * @uses \MainWP\Dashboard\MainWP_Exception
93 */
94 public function mainwp_backup_run_site() {
95 $this->secure_request( 'mainwp_backup_run_site' );
96 $site_id = isset( $_POST['site_id'] ) ? intval( $_POST['site_id'] ) : false; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
97 try {
98 if ( ! $site_id ) {
99 throw new MainWP_Exception( 'Site ID not found. Please reload the page and try again.', 'mainwp' );
100 }
101
102 $ret = array( 'result' => MainWP_Backup_Handler::backup( $site_id, 'full', '', '', 1, 1, 1, 1 ) );
103 wp_send_json( $ret );
104 } catch ( MainWP_Exception $e ) {
105 die(
106 wp_json_encode(
107 array(
108 'error' => array(
109 'message' => $e->getMessage(),
110 'extra' => $e->get_message_extra(),
111 ),
112 )
113 )
114 );
115 }
116 }
117
118 /**
119 * Method mainwp_backup()
120 *
121 * Run backup task
122 *
123 * @throws MainWP_Exception On errors.
124 *
125 * @uses \MainWP\Dashboard\MainWP_Backup_Handler::backup()
126 * @uses \MainWP\Dashboard\MainWP_Exception
127 */
128 public function ajax_mainwp_backup() {
129 $this->secure_request( 'mainwp_backup' );
130 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
131 $site_id = isset( $_POST['site_id'] ) ? intval( $_POST['site_id'] ) : false;
132 try {
133 if ( ! $site_id ) {
134 throw new MainWP_Exception( 'Site ID not found. Please reload the page and try again.', 'mainwp' );
135 }
136
137 $excludedFolder = isset( $_POST['exclude'] ) ? trim( wp_unslash( $_POST['exclude'] ), "\n" ) : '';
138 $excludedFolder = explode( "\n", $excludedFolder );
139 $excludedFolder = array_map( array( MainWP_Utility::get_class_name(), 'trim_slashes' ), $excludedFolder );
140 $excludedFolder = array_map( 'htmlentities', $excludedFolder );
141 $excludedFolder = implode( ',', $excludedFolder );
142
143 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
144 $subfolder = isset( $_POST['subfolder'] ) ? sanitize_text_field( wp_unslash( $_POST['subfolder'] ) ) : '';
145 $excludebackup = isset( $_POST['excludebackup'] ) ? sanitize_text_field( wp_unslash( $_POST['excludebackup'] ) ) : '';
146 $excludecache = isset( $_POST['excludecache'] ) ? sanitize_text_field( wp_unslash( $_POST['excludecache'] ) ) : '';
147 $excludenonwp = isset( $_POST['excludenonwp'] ) ? sanitize_text_field( wp_unslash( $_POST['excludenonwp'] ) ) : '';
148 $excludezip = isset( $_POST['excludezip'] ) ? sanitize_text_field( wp_unslash( $_POST['excludezip'] ) ) : '';
149 $filename = isset( $_POST['filename'] ) ? sanitize_text_field( wp_unslash( $_POST['filename'] ) ) : '';
150 $fileNameUID = isset( $_POST['fileNameUID'] ) ? sanitize_text_field( wp_unslash( $_POST['fileNameUID'] ) ) : '';
151 $archiveFormat = isset( $_POST['archiveFormat'] ) ? sanitize_text_field( wp_unslash( $_POST['archiveFormat'] ) ) : '';
152 $maximumFileDescriptorsOverride = isset( $_POST['maximumFileDescriptorsOverride'] ) ? intval( $_POST['maximumFileDescriptorsOverride'] ) : false;
153 $maximumFileDescriptorsAuto = isset( $_POST['maximumFileDescriptorsAuto'] ) ? intval( $_POST['maximumFileDescriptorsAuto'] ) : false;
154 $maximumFileDescriptors = isset( $_POST['maximumFileDescriptors'] ) ? sanitize_text_field( wp_unslash( $_POST['maximumFileDescriptors'] ) ) : '';
155 $loadFilesBeforeZip = isset( $_POST['loadFilesBeforeZip'] ) ? sanitize_text_field( wp_unslash( $_POST['loadFilesBeforeZip'] ) ) : false;
156 $pid = isset( $_POST['pid'] ) ? intval( $_POST['pid'] ) : false;
157 $append = isset( $_POST['append'] ) ? intval( $_POST['append'] ) : false;
158
159 $result = MainWP_Backup_Handler::backup( $site_id, $type, $subfolder, $excludedFolder, $excludebackup, $excludecache, $excludenonwp, $excludezip, $filename, $fileNameUID, $archiveFormat, $maximumFileDescriptorsOverride, $maximumFileDescriptorsAuto, $maximumFileDescriptors, $loadFilesBeforeZip, $pid, $append );
160 wp_send_json( array( 'result' => $result ) );
161 } catch ( MainWP_Exception $e ) {
162 die(
163 wp_json_encode(
164 array(
165 'error' => array(
166 'message' => $e->getMessage(),
167 'extra' => $e->get_message_extra(),
168 ),
169 )
170 )
171 );
172 }
173 // phpcs:enable
174 }
175
176 /**
177 * Method mainwp_backup_checkpid()
178 *
179 * Check backup task
180 *
181 * @throws MainWP_Exception On errors.
182 *
183 * @uses \MainWP\Dashboard\MainWP_Backup_Handler::backup_check_pid()
184 * @uses \MainWP\Dashboard\MainWP_Exception
185 */
186 public function mainwp_backup_checkpid() {
187 $this->secure_request( 'mainwp_backup_checkpid' );
188 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
189 $site_id = isset( $_POST['site_id'] ) ? intval( $_POST['site_id'] ) : false;
190 try {
191 if ( ! $site_id ) {
192 throw new MainWP_Exception( 'Site ID not found. Please reload the page and try again.', 'mainwp' );
193 }
194 $pid = isset( $_POST['pid'] ) ? intval( $_POST['pid'] ) : false;
195 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
196 $subfolder = isset( $_POST['subfolder'] ) ? sanitize_text_field( wp_unslash( $_POST['subfolder'] ) ) : '';
197 $filename = isset( $_POST['filename'] ) ? sanitize_text_field( wp_unslash( $_POST['filename'] ) ) : '';
198 wp_send_json( MainWP_Backup_Handler::backup_check_pid( $site_id, $pid, $type, $subfolder, $filename ) );
199 } catch ( MainWP_Exception $e ) {
200 die(
201 wp_json_encode(
202 array(
203 'error' => array(
204 'message' => $e->getMessage(),
205 'extra' => $e->get_message_extra(),
206 ),
207 )
208 )
209 );
210 }
211 // phpcs:enable
212 }
213
214 /**
215 * Method mainwp_backup_download_file()
216 *
217 * Download backup file
218 *
219 * @throws MainWP_Exception On errors.
220 *
221 * @uses \MainWP\Dashboard\MainWP_Backup_Handler::backup_download_file()
222 * @uses \MainWP\Dashboard\MainWP_Exception
223 */
224 public function ajax_mainwp_backup_download_file() {
225 $this->secure_request( 'mainwp_backup_download_file' );
226 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
227 $site_id = isset( $_POST['site_id'] ) ? intval( $_POST['site_id'] ) : false;
228 try {
229 if ( ! $site_id ) {
230 throw new MainWP_Exception( 'Site ID not found. Please reload the page and try again.', 'mainwp' );
231 }
232 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
233 $url = isset( $_POST['url'] ) ? sanitize_text_field( wp_unslash( $_POST['url'] ) ) : '';
234 $local = isset( $_POST['local'] ) ? sanitize_text_field( wp_unslash( $_POST['local'] ) ) : '';
235 die( wp_json_encode( array( 'result' => MainWP_Backup_Handler::backup_download_file( $site_id, $type, $url, $local ) ) ) );
236 } catch ( MainWP_Exception $e ) {
237 die(
238 wp_json_encode(
239 array(
240 'error' => array(
241 'message' => $e->getMessage(),
242 'extra' => $e->get_message_extra(),
243 ),
244 )
245 )
246 );
247 }
248 // phpcs:enable
249 }
250
251 /**
252 * Method mainwp_backup_delete_file()
253 *
254 * Delete backup file
255 *
256 * @throws MainWP_Exception On errors.
257 *
258 * @uses \MainWP\Dashboard\MainWP_Backup_Handler::backup_delete_file()
259 * @uses \MainWP\Dashboard\MainWP_Exception
260 */
261 public function mainwp_backup_delete_file() {
262 $this->secure_request( 'mainwp_backup_delete_file' );
263 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
264 $site_id = isset( $_POST['site_id'] ) ? intval( $_POST['site_id'] ) : false;
265 try {
266 if ( ! $site_id ) {
267 throw new MainWP_Exception( esc_html__( 'Site ID not found. Please reload the page and try again.', 'mainwp' ) );
268 }
269
270 $site_id = isset( $_POST['site_id'] ) ? intval( $_POST['site_id'] ) : 0;
271 $file = isset( $_POST['file'] ) ? sanitize_text_field( wp_unslash( $_POST['file'] ) ) : '';
272
273 die( wp_json_encode( array( 'result' => MainWP_Backup_Handler::backup_delete_file( $site_id, $file ) ) ) );
274 } catch ( MainWP_Exception $e ) {
275 die(
276 wp_json_encode(
277 array(
278 'error' => array(
279 'message' => $e->getMessage(),
280 'extra' => $e->get_message_extra(),
281 ),
282 )
283 )
284 );
285 }
286 // phpcs:enable
287 }
288
289 /**
290 * Method mainwp_createbackup_getfilesize()
291 *
292 * Get create backup file size.
293 *
294 * @throws \MainWP_Exception On errors.
295 *
296 * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
297 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
298 * @uses \MainWP\Dashboard\MainWP_Utility::end_session()
299 * @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit()
300 */
301 public function mainwp_createbackup_getfilesize() {
302 $this->secure_request( 'mainwp_createbackup_getfilesize' );
303
304 // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
305 try {
306 if ( ! isset( $_POST['siteId'] ) ) {
307 throw new MainWP_Exception( esc_html__( 'No site selected!', 'mainwp' ) );
308 }
309 $siteId = isset( $_POST['siteId'] ) ? intval( $_POST['siteId'] ) : '';
310 $fileName = isset( $_POST['fileName'] ) ? sanitize_text_field( wp_unslash( $_POST['fileName'] ) ) : '';
311 $fileNameUID = isset( $_POST['fileNameUID'] ) ? sanitize_text_field( wp_unslash( $_POST['fileNameUID'] ) ) : '';
312 $type = isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '';
313
314 $website = MainWP_DB::instance()->get_website_by_id( $siteId );
315 if ( ! $website ) {
316 throw new MainWP_Exception( esc_html__( 'No site selected!', 'mainwp' ) );
317 }
318
319 MainWP_Utility::end_session();
320 // Send request to the childsite!
321 $result = MainWP_Connect::fetch_url_authed(
322 $website,
323 'createBackupPoll',
324 array(
325 'fileName' => $fileName,
326 'fileNameUID' => $fileNameUID,
327 'type' => $type,
328 )
329 );
330
331 if ( ! isset( $result['size'] ) ) {
332 throw new MainWP_Exception( esc_html__( 'Invalid response!', 'mainwp' ) );
333 }
334
335 if ( MainWP_Utility::ctype_digit( $result['size'] ) ) {
336 $output = array( 'size' => $result['size'] );
337 } else {
338 $output = array();
339 }
340 } catch ( \Exception $e ) {
341 $output = array( 'error' => $e->getMessage() );
342 }
343 // phpcs:enable
344
345 die( wp_json_encode( $output ) );
346 }
347
348 /**
349 * Method mainwp_backup_getfilesize()
350 *
351 * Get backup file size
352 *
353 * @uses \MainWP\Dashboard\MainWP_Exception
354 * @uses \MainWP\Dashboard\MainWP_Manage_Sites::backup_get_file_size()
355 */
356 public function mainwp_backup_getfilesize() {
357 $this->secure_request( 'mainwp_backup_getfilesize' );
358
359 try {
360 $local = isset( $_POST['local'] ) ? sanitize_text_field( wp_unslash( $_POST['local'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
361 die( wp_json_encode( array( 'result' => MainWP_Backup_Handler::backup_get_file_size( $local ) ) ) );
362 } catch ( MainWP_Exception $e ) {
363 die(
364 wp_json_encode(
365 array(
366 'error' => array(
367 'message' => $e->getMessage(),
368 'extra' => $e->get_message_extra(),
369 ),
370 )
371 )
372 );
373 }
374 }
375
376 /**
377 * Method mainwp_backup_upload_checkstatus()
378 *
379 * Check upload status
380 *
381 * @throws MainWP_Exception On errors.
382 *
383 * @uses \MainWP\Dashboard\MainWP_Exception
384 */
385 public function mainwp_backup_upload_checkstatus() {
386 $this->secure_request( 'mainwp_backup_upload_checkstatus' );
387
388 try {
389 $unique = isset( $_POST['unique'] ) ? sanitize_text_field( wp_unslash( $_POST['unique'] ) ) : false; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
390 $array = get_option( 'mainwp_upload_progress' );
391 $info = apply_filters( 'mainwp_remote_destination_info', array(), ( isset( $_POST['remote_destination'] ) ? sanitize_text_field( wp_unslash( $_POST['remote_destination'] ) ) : '' ) ); // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
392
393 if ( ! is_array( $array ) || empty( $unique ) || empty( $array[ $unique ] ) || empty( $array[ $unique ]['dts'] ) ) {
394 die(
395 wp_json_encode(
396 array(
397 'status' => 'stalled',
398 'info' => $info,
399 )
400 )
401 );
402 } elseif ( isset( $array[ $unique ]['finished'] ) ) {
403 die(
404 wp_json_encode(
405 array(
406 'status' => 'done',
407 'info' => $info,
408 )
409 )
410 );
411 } elseif ( isset( $array[ $unique ]['dts'] ) && intval( $array[ $unique ]['dts'] ) < ( time() - ( 2 * 60 ) ) ) {
412
413 // 2minutes.
414 die(
415 wp_json_encode(
416 array(
417 'status' => 'stalled',
418 'info' => $info,
419 )
420 )
421 );
422 } else {
423 die(
424 wp_json_encode(
425 array(
426 'status' => 'busy',
427 'info' => $info,
428 )
429 )
430 );
431 }
432 } catch ( MainWP_Exception $e ) {
433 die(
434 wp_json_encode(
435 array(
436 'error' => array(
437 'message' => $e->getMessage(),
438 'extra' => $e->get_message_extra(),
439 ),
440 )
441 )
442 );
443 }
444 }
445
446 /**
447 * Method mainwp_backup_upload_getprogress()
448 *
449 * Get progress status.
450 *
451 * @throws MainWP_Exception On finished or errors.
452 *
453 * @uses \MainWP\Dashboard\MainWP_Exception
454 */
455 public function mainwp_backup_upload_getprogress() {
456 $this->secure_request( 'mainwp_backup_upload_getprogress' );
457
458 try {
459 $array = get_option( 'mainwp_upload_progress' );
460 $unique = isset( $_POST['unique'] ) ? sanitize_text_field( wp_unslash( $_POST['unique'] ) ) : false; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
461
462 if ( ! is_array( $array ) || ! isset( $array[ $unique ] ) ) {
463 die( wp_json_encode( array( 'result' => 0 ) ) );
464 } elseif ( isset( $array[ $unique ]['finished'] ) ) {
465 throw new MainWP_Exception( esc_html__( 'finished...', 'maiwnp' ) );
466 } else {
467 wp_send_json( array( 'result' => ( isset( $array[ $unique ]['offset'] ) ? $array[ $unique ]['offset'] : $array[ $unique ] ) ) );
468 }
469 } catch ( MainWP_Exception $e ) {
470 die(
471 wp_json_encode(
472 array(
473 'error' => array(
474 'message' => $e->getMessage(),
475 'extra' => $e->get_message_extra(),
476 ),
477 )
478 )
479 );
480 }
481 }
482
483 /*
484 * Page: ManageBackups
485 */
486
487 /**
488 * Method mainwp_addbackup()
489 *
490 * Add task to the database.
491 *
492 * @uses \MainWP\Dashboard\MainWP_Manage_Backups_Handler::add_backup()
493 */
494 public function mainwp_addbackup() {
495 $this->secure_request( 'mainwp_addbackup' );
496
497 MainWP_Manage_Backups_Handler::add_backup();
498 }
499
500 /**
501 * Method mainwp_updatebackup()
502 *
503 * Update task.
504 *
505 * @uses \MainWP\Dashboard\MainWP_Manage_Backups_Handler::update_backup()
506 */
507 public function mainwp_updatebackup() {
508 $this->secure_request( 'mainwp_updatebackup' );
509
510 MainWP_Manage_Backups_Handler::update_backup();
511 }
512
513 /**
514 * Method mainwp_removebackup()
515 *
516 * Remove a task from MainWP.
517 *
518 * @uses \MainWP\Dashboard\MainWP_Manage_Backups_Handler::remove_backup()
519 */
520 public function mainwp_removebackup() {
521 $this->secure_request( 'mainwp_removebackup' );
522
523 MainWP_Manage_Backups_Handler::remove_backup();
524 }
525
526 /**
527 * Method mainwp_resumebackup()
528 *
529 * Resume backup task.
530 *
531 * @uses \MainWP\Dashboard\MainWP_Manage_Backups_Handler::resume_backup()
532 */
533 public function mainwp_resumebackup() {
534 $this->secure_request( 'mainwp_resumebackup' );
535
536 MainWP_Manage_Backups_Handler::resume_backup();
537 }
538
539 /**
540 * Method mainwp_pausebackup()
541 *
542 * Pause backup task.
543 *
544 * @uses \MainWP\Dashboard\MainWP_Manage_Backups_Handler::pause_backup()
545 */
546 public function mainwp_pausebackup() {
547 $this->secure_request( 'mainwp_pausebackup' );
548
549 MainWP_Manage_Backups_Handler::pause_backup();
550 }
551
552 /**
553 * Method mainwp_backuptask_get_sites()
554 *
555 * Get sites of backup task.
556 *
557 * @uses \MainWP\Dashboard\MainWP_Manage_Backups_Handler::get_backup_task_sites()
558 */
559 public function mainwp_backuptask_get_sites() {
560 $this->secure_request( 'mainwp_backuptask_get_sites' );
561
562 $taskID = isset( $_POST['task_id'] ) ? intval( $_POST['task_id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
563
564 wp_send_json( array( 'result' => MainWP_Manage_Backups_Handler::get_backup_task_sites( $taskID ) ) );
565 }
566
567 /**
568 * Method mainwp_backuptask_run_site()
569 *
570 * Run backup task of site.
571 *
572 * @throws MainWP_Exception On errors.
573 *
574 * @uses \MainWP\Dashboard\MainWP_Exception
575 * @uses \MainWP\Dashboard\MainWP_Manage_Backups_Handler::backup()
576 */
577 public function mainwp_backuptask_run_site() {
578 try {
579 $this->secure_request( 'mainwp_backuptask_run_site' );
580 $site_id = isset( $_POST['site_id'] ) ? intval( $_POST['site_id'] ) : false; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
581 $task_id = isset( $_POST['task_id'] ) ? intval( $_POST['task_id'] ) : false; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
582 if ( ! $site_id || ! $task_id ) {
583 throw new MainWP_Exception( esc_html__( 'Site ID or backup task ID not found. Please reload the page and try again.', 'mainwp' ) );
584 }
585
586 $fileNameUID = isset( $_POST['fileNameUID'] ) ? sanitize_text_field( wp_unslash( $_POST['fileNameUID'] ) ) : false; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
587 wp_send_json( array( 'result' => MainWP_Manage_Backups_Handler::backup( $task_id, $site_id, $fileNameUID ) ) );
588 } catch ( MainWP_Exception $e ) {
589 die(
590 wp_json_encode(
591 array(
592 'error' => array(
593 'message' => $e->getMessage(),
594 'extra' => $e->get_message_extra(),
595 ),
596 )
597 )
598 );
599 }
600 }
601
602 /**
603 * Method mainwp_checkbackups()
604 *
605 * Check backup status.
606 *
607 * @throws \MainWP_Exception On errors.
608 *
609 * @uses \MainWP\Dashboard\MainWP_Updates_Overview::check_backups()
610 */
611 public function mainwp_checkbackups() {
612 $this->secure_request( 'mainwp_checkbackups' );
613
614 try {
615 wp_send_json( array( 'result' => MainWP_Updates_Overview::check_backups() ) );
616 } catch ( \Exception $e ) {
617 die( wp_json_encode( array( 'error' => $e->getMessage() ) ) );
618 }
619 }
620 }
621