PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.1
6.2.2 6.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 All 155 releases
← All changes | class/class-mainwp-post-backup-handler.php +554 -549 5.0.2 → 6.2.1 View file →
@@ -6,8 +6,13 @@
6 6 */
7 7
8 8 namespace MainWP\Dashboard;
9 9
10 +// Exit if accessed directly.
11 +if ( ! defined( 'ABSPATH' ) ) {
12 + exit;
13 +}
14 +
10 15 /**
11 16 * Class MainWP_Post_Backup_Handler
12 17 *
13 18 * Handle Backup Post.
@@ -15,606 +20,606 @@
15 20 * @package MainWP\Dashboard
16 21 *
17 22 * @uses \MainWP\Dashboard\MainWP_Post_Base_Handler
18 23 */
19 -class MainWP_Post_Backup_Handler extends MainWP_Post_Base_Handler {
24 +class MainWP_Post_Backup_Handler extends MainWP_Post_Base_Handler { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
20 25
21 - /**
22 - * Instance class.
23 - *
24 - * @var $instance Singleton MainWP_Post_Backup_Handler.
25 - */
26 - private static $instance = null;
26 + /**
27 + * Instance class.
28 + *
29 + * @var $instance Singleton MainWP_Post_Backup_Handler.
30 + */
31 + private static $instance = null;
27 32
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 === self::$instance ) {
36 - self::$instance = new self();
37 - }
38 - return self::$instance;
39 - }
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 + }
40 45
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' ) );
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' ) );
55 60
56 - $this->add_action( 'mainwp_backuptask_get_sites', array( &$this, 'mainwp_backuptask_get_sites' ) );
61 + $this->add_action( 'mainwp_backuptask_get_sites', array( &$this, 'mainwp_backuptask_get_sites' ) );
57 62
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' ) );
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' ) );
62 67
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, '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, '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 - }
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 + }
79 84
80 - /*
81 - * Page: Backup
82 - */
85 + /*
86 + * Page: Backup
87 + */
83 88
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 - }
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 + }
101 106
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 - }
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 + }
117 122
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 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 - }
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 + }
136 141
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 + $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 );
142 147
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;
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;
158 163
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 - }
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 + }
175 180
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 - }
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 + }
213 218
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 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 - }
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 + }
250 255
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 - }
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 + }
269 274
270 - $site_id = isset( $_POST['site_id'] ) ? intval( $_POST['site_id'] ) : 0;
271 - $file = isset( $_POST['file'] ) ? sanitize_text_field( wp_unslash( $_POST['file'] ) ) : '';
275 + $site_id = isset( $_POST['site_id'] ) ? intval( $_POST['site_id'] ) : 0;
276 + $file = isset( $_POST['file'] ) ? sanitize_text_field( wp_unslash( $_POST['file'] ) ) : '';
272 277
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 - }
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 + }
288 293
289 - /**
290 - * Method mainwp_createbackup_getfilesize()
291 - *
292 - * Get create backup file size.
293 - *
294 - * @throws \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' );
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' );
303 308
304 - // phpcs:disable WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
305 - try {
306 - if ( ! isset( $_POST['siteId'] ) ) {
307 - throw new \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'] ) ) : '';
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'] ) ) : '';
313 318
314 - $website = MainWP_DB::instance()->get_website_by_id( $siteId );
315 - if ( ! $website ) {
316 - throw new \Exception( esc_html__( 'No site selected!', 'mainwp' ) );
317 - }
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 + }
318 323
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 - );
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 + );
330 335
331 - if ( ! isset( $result['size'] ) ) {
332 - throw new \Exception( esc_html__( 'Invalid response!', 'mainwp' ) );
333 - }
336 + if ( ! isset( $result['size'] ) ) {
337 + throw new MainWP_Exception( esc_html__( 'Invalid response!', 'mainwp' ) );
338 + }
334 339
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
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
344 349
345 - die( wp_json_encode( $output ) );
346 - }
350 + die( wp_json_encode( $output ) );
351 + }
347 352
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' );
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' );
358 363
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 - }
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 + }
375 380
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' );
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' );
387 392
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
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
392 397
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 ) ) ) {
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 ) ) ) {
412 417
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 - }
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 + }
445 450
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' );
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' );
457 462
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
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
461 466
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 - }
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 + }
482 487
483 - /*
484 - * Page: ManageBackups
485 - */
488 + /*
489 + * Page: ManageBackups
490 + */
486 491
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' );
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' );
496 501
497 - MainWP_Manage_Backups_Handler::add_backup();
498 - }
502 + MainWP_Manage_Backups_Handler::add_backup();
503 + }
499 504
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' );
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' );
509 514
510 - MainWP_Manage_Backups_Handler::update_backup();
511 - }
515 + MainWP_Manage_Backups_Handler::update_backup();
516 + }
512 517
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' );
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' );
522 527
523 - MainWP_Manage_Backups_Handler::remove_backup();
524 - }
528 + MainWP_Manage_Backups_Handler::remove_backup();
529 + }
525 530
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' );
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' );
535 540
536 - MainWP_Manage_Backups_Handler::resume_backup();
537 - }
541 + MainWP_Manage_Backups_Handler::resume_backup();
542 + }
538 543
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' );
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' );
548 553
549 - MainWP_Manage_Backups_Handler::pause_backup();
550 - }
554 + MainWP_Manage_Backups_Handler::pause_backup();
555 + }
551 556
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' );
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' );
561 566
562 - $taskID = isset( $_POST['task_id'] ) ? intval( $_POST['task_id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
567 + $taskID = isset( $_POST['task_id'] ) ? intval( $_POST['task_id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
563 568
564 - wp_send_json( array( 'result' => MainWP_Manage_Backups_Handler::get_backup_task_sites( $taskID ) ) );
565 - }
569 + wp_send_json( array( 'result' => MainWP_Manage_Backups_Handler::get_backup_task_sites( $taskID ) ) );
570 + }
566 571
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 - }
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 + }
585 590
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 - }
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 + }
601 606
602 - /**
603 - * Method mainwp_checkbackups()
604 - *
605 - * Check backup status.
606 - *
607 - * @throws \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' );
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' );
613 618
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 - }
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 + }
620 625 }