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