PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / trunk
MainWP Dashboard: Self-hosted WordPress Management for Agencies vtrunk
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 trunk, at class/class-mainwp-post-backup-handler.php

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