PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 4.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v4.1
6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 5.2.2 5.3 All 153 releases
← All changes | class/class-mainwp-wp-cli-command.php +103 -205 5.0.3.24.1 View file →
@@ -30,9 +30,9 @@
30 30 *
31 31 * Initiate the MainWP CLI after all Plugins have loaded.
32 32 */
33 33 public static function init() {
34 - add_action( 'plugins_loaded', array( self::class, 'init_wpcli_commands' ), 99999 );
34 + add_action( 'plugins_loaded', array( 'MainWP_WP_CLI_Command', 'init_wpcli_commands' ), 99999 );
35 35 }
36 36
37 37 /**
38 38 * Method init_wpcli_commands
@@ -39,9 +39,9 @@
39 39 *
40 40 * Adds the MainWP WP CLI Commands via WP_CLI::add_command
41 41 */
42 42 public static function init_wpcli_commands() {
43 - \WP_CLI::add_command( 'mainwp', self::class );
43 + \WP_CLI::add_command( 'mainwp', 'MainWP_WP_CLI_Command' );
44 44 }
45 45
46 46 /**
47 47 * List information about added child sites.
@@ -50,39 +50,15 @@
50 50 *
51 51 * [--list]
52 52 * : Get a list of all child sites
53 53 *
54 - * [--count]
55 - * : If set, count child sites.
54 + * ## Synopsis [--list]
56 55 *
57 - *
58 - * ## EXAMPLES
59 - *
60 - * wp mainwp sites --list
61 - * wp mainwp sites --all-sites-count
62 - *
63 - * ## Synopsis [--list] [--all-sites-count]
64 - *
65 56 * @param array $args Function arguments.
66 57 * @param array $assoc_args Function associate arguments.
67 - *
68 - * @uses \MainWP\Dashboard\MainWP_DB::query()
69 - * @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_for_current_user()
70 - * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
71 - * @uses \MainWP\Dashboard\MainWP_DB::free_result()
72 - * @uses \MainWP\Dashboard\MainWP_DB::data_seek()
73 58 */
74 59 public function sites( $args, $assoc_args ) {
75 -
76 - // support new mainwp sites cli commands.
77 - $handle = MainWP_WP_CLI_Handle::get_assoc_args_commands( 'sites', $assoc_args );
78 - if ( ! empty( $handle ) ) {
79 - MainWP_WP_CLI_Handle::handle_cli_callback( 'sites', $args, $assoc_args );
80 - return;
81 - }
82 -
83 - $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, true ) );
84 -
60 + $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, true ) );
85 61 $idLength = strlen( 'id' );
86 62 $nameLength = strlen( 'name' );
87 63 $urlLength = strlen( 'url' );
88 64 $versionLength = strlen( 'version' );
@@ -101,96 +77,21 @@
101 77 }
102 78 }
103 79 MainWP_DB::data_seek( $websites, 0 );
104 80
105 - \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $urlLength + 2 ) . "s+%'--" . ( $versionLength + 2 ) . 's+', '', '', '', '' ) );
106 - \WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $urlLength . 's | %-' . $versionLength . 's |', 'id', 'name', 'url', 'version' ) );
107 - \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $urlLength + 2 ) . "s+%'--" . ( $versionLength + 2 ) . 's+', '', '', '', '' ) );
81 + WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $urlLength + 2 ) . "s+%'--" . ( $versionLength + 2 ) . 's+', '', '', '', '' ) );
82 + WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $urlLength . 's | %-' . $versionLength . 's |', 'id', 'name', 'url', 'version' ) );
83 + WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $urlLength + 2 ) . "s+%'--" . ( $versionLength + 2 ) . 's+', '', '', '', '' ) );
108 84
109 85 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
110 - \WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $urlLength . 's | %-' . $versionLength . 's |', $website->id, $website->name, $website->url, $website->version ) );
86 + WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $urlLength . 's | %-' . $versionLength . 's |', $website->id, $website->name, $website->url, $website->version ) );
111 87 }
112 88
113 - \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $urlLength + 2 ) . "s+%'--" . ( $versionLength + 2 ) . 's+', '', '', '', '' ) );
89 + WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $urlLength + 2 ) . "s+%'--" . ( $versionLength + 2 ) . 's+', '', '', '', '' ) );
114 90 MainWP_DB::free_result( $websites );
115 91 }
116 92
117 93 /**
118 - * Site commands.
119 - *
120 - * ## OPTIONS
121 - *
122 - * [--site]
123 - * : Get site data
124 - *
125 - * [--site-info]
126 - * : If set, get site info.
127 - *
128 - *
129 - * ## EXAMPLES
130 - *
131 - * wp mainwp site --site [<websiteid>]
132 - * wp mainwp site --site-info [<websiteid>]
133 - *
134 - * ## Synopsis [--site] [--site-info] [...]
135 - *
136 - * @param array $args Function arguments.
137 - * @param array $assoc_args Function associate arguments.
138 - */
139 - public function site( $args, $assoc_args ) {
140 - MainWP_WP_CLI_Handle::handle_cli_callback( 'site', $args, $assoc_args );
141 - }
142 -
143 -
144 - /**
145 - * Updates commands.
146 - *
147 - * ## OPTIONS
148 - *
149 - * [--available-updates <websiteid>]
150 - * : Get available updates
151 - *
152 - * [--ignored-plugins-updates <websiteid>]
153 - * : If set, get ignored plugins updates.
154 - *
155 - * [--site-ignored-plugins-updates <websiteid>]
156 - * : If set, get ignored plugins updates of site.
157 - *
158 - * [--ignored-themes-updates <websiteid>]
159 - * : If set, get ignored themes updates.
160 - *
161 - * [--site-ignored-themes-updates <websiteid>]
162 - * : If set, get ignored themes updates of site.
163 - *
164 - * [--ignore-updates --type=[type] --slug=[slug]]
165 - * : If set, ignored updates.
166 - *
167 - * [--ignore-update <websiteid> --type=[type] --slug=[slug]]
168 - * : If set, ignored update.
169 - *
170 - * [--unignore-updates --type=[type] --slug=[slug]]
171 - * : If set, unignore updates.
172 - *
173 - * [--unignore-update <websiteid> --type=[type] --slug=[slug]]
174 - * : If set, unignore update.
175 - *
176 - *
177 - * ## EXAMPLES
178 - *
179 - * wp mainwp updates --available-updates
180 - * wp mainwp updates --ignored-plugins-updates
181 - * wp mainwp updates --site-ignored-plugins-updates 3
182 - *
183 - * ## Synopsis [--available-updates] [--ignored-plugins-updates] [--site-ignored-plugins-updates] [...]
184 - *
185 - * @param array $args Function arguments.
186 - * @param array $assoc_args Function associate arguments.
187 - */
188 - public function updates( $args, $assoc_args ) {
189 - MainWP_WP_CLI_Handle::handle_cli_callback( 'updates', $args, $assoc_args );
190 - }
191 -
192 - /**
193 94 * Sync Data with Child Sites
194 95 *
195 96 * ## OPTIONS
196 97 *
@@ -208,15 +109,8 @@
208 109 * ## Synopsis [<websiteid>] [--all]
209 110 *
210 111 * @param array $args Function arguments.
211 112 * @param array $assoc_args Function associate arguments.
212 - *
213 - * @uses \MainWP\Dashboard\MainWP_Error_Helper::get_console_error_message()
214 - * @uses \MainWP\Dashboard\MainWP_DB::query()
215 - * @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_for_current_user()
216 - * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
217 - * @uses \MainWP\Dashboard\MainWP_DB::free_result()
218 - * @uses \MainWP\Dashboard\MainWP_Sync::sync_site()
219 113 */
220 114 public function sync( $args, $assoc_args ) {
221 115 $sites = array();
222 116 if ( count( $args ) > 0 ) {
@@ -222,9 +116,9 @@
222 116 if ( count( $args ) > 0 ) {
223 117 $args_exploded = explode( ',', $args[0] );
224 118 foreach ( $args_exploded as $arg ) {
225 119 if ( ! is_numeric( trim( $arg ) ) ) {
226 - \WP_CLI::error( 'Child site ids should be numeric.' );
120 + WP_CLI::error( 'Child site ids should be numeric.' );
227 121 }
228 122
229 123 $sites[] = trim( $arg );
230 124 }
@@ -229,16 +123,42 @@
229 123 $sites[] = trim( $arg );
230 124 }
231 125 }
232 126
233 - if ( is_array( $assoc_args ) && isset( $assoc_args['all'] ) ) {
234 - update_option( 'mainwp_last_synced_all_sites', time() );
127 + if ( ( count( $sites ) == 0 ) && ( ! isset( $assoc_args['all'] ) ) ) {
128 + WP_CLI::error( 'Please specify one or more child sites, or use --all.' );
235 129 }
236 130
237 - if ( 0 === count( $sites ) && ( ! isset( $assoc_args['all'] ) ) ) {
238 - \WP_CLI::error( 'Please specify one or more child sites, or use --all.' );
131 + $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, true ) );
132 + WP_CLI::line( 'Sync started' );
133 + $warnings = 0;
134 + $errors = 0;
135 + while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
136 + if ( ( count( $sites ) > 0 ) && ( ! in_array( $website->id, $sites, true ) ) ) {
137 + continue;
138 + }
139 +
140 + WP_CLI::line( ' -> ' . $website->name . ' (' . $website->url . ')' );
141 + try {
142 + if ( MainWP_Sync::sync_site( $website ) ) {
143 + WP_CLI::success( ' Sync succeeded' );
144 + } else {
145 + WP_CLI::warning( ' Sync failed' );
146 + $warnings++;
147 + }
148 + } catch ( \Exception $e ) {
149 + WP_CLI::error( ' Sync failed: ' . MainWP_Error_Helper::get_console_error_message( $e ) );
150 + $errors++;
151 + }
239 152 }
240 - MainWP_WP_CLI_Handle::handle_sync_sites( $args, $assoc_args );
153 + MainWP_DB::free_result( $websites );
154 + if ( $errors > 0 ) {
155 + WP_CLI::error( 'Sync completed with errors' );
156 + } elseif ( $warnings > 0 ) {
157 + WP_CLI::warning( 'Sync completed with warnings' );
158 + } else {
159 + WP_CLI::success( 'Sync completed' );
160 + }
241 161 }
242 162
243 163 /**
244 164 * Reconnect with Child Sites
@@ -255,15 +175,8 @@
255 175 * ## Synopsis [<websiteid>]
256 176 *
257 177 * @param array $args Function arguments.
258 178 * @param array $assoc_args Function associate arguments.
259 - *
260 - * @uses \MainWP\Dashboard\MainWP_Error_Helper::get_console_error_message()
261 - * @uses \MainWP\Dashboard\MainWP_DB::query()
262 - * @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_for_current_user()
263 - * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
264 - * @uses \MainWP\Dashboard\MainWP_DB::free_result()
265 - * @uses \MainWP\Dashboard\MainWP_Manage_Sites_View::m_reconnect_site()
266 179 */
267 180 public function reconnect( $args, $assoc_args ) {
268 181 $sites = array();
269 182 if ( 0 < count( $args ) ) {
@@ -269,9 +182,9 @@
269 182 if ( 0 < count( $args ) ) {
270 183 $args_exploded = explode( ',', $args[0] );
271 184 foreach ( $args_exploded as $arg ) {
272 185 if ( ! is_numeric( trim( $arg ) ) ) {
273 - \WP_CLI::error( 'Child site ids should be numeric.' );
186 + WP_CLI::error( 'Child site ids should be numeric.' );
274 187 }
275 188
276 189 $sites[] = trim( $arg );
277 190 }
@@ -276,14 +189,14 @@
276 189 $sites[] = trim( $arg );
277 190 }
278 191 }
279 192
280 - if ( 0 === count( $sites ) ) {
281 - \WP_CLI::error( 'Please specify one or more child sites.' );
193 + if ( count( $sites ) == 0 ) {
194 + WP_CLI::error( 'Please specify one or more child sites.' );
282 195 }
283 196
284 197 $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, true ) );
285 - \WP_CLI::line( 'Reconnect started' );
198 + WP_CLI::line( 'Reconnect started' );
286 199 $warnings = 0;
287 200 $errors = 0;
288 201 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
289 202 if ( ( 0 < count( $sites ) ) && ( ! in_array( $website->id, $sites, true ) ) ) {
@@ -288,28 +201,28 @@
288 201 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
289 202 if ( ( 0 < count( $sites ) ) && ( ! in_array( $website->id, $sites, true ) ) ) {
290 203 continue;
291 204 }
292 - \WP_CLI::line( ' -> ' . $website->name . ' (' . $website->url . ')' );
205 + WP_CLI::line( ' -> ' . $website->name . ' (' . $website->url . ')' );
293 206 try {
294 207 if ( MainWP_Manage_Sites_View::m_reconnect_site( $website ) ) {
295 - \WP_CLI::success( ' Reconnected successfully' );
208 + WP_CLI::success( ' Reconnected successfully' );
296 209 } else {
297 - \WP_CLI::warning( ' Reconnect failed' );
298 - ++$warnings;
210 + WP_CLI::warning( ' Reconnect failed' );
211 + $warnings++;
299 212 }
300 213 } catch ( \Exception $e ) {
301 - \WP_CLI::error( ' Reconnect failed: ' . MainWP_Error_Helper::get_console_error_message( $e ) );
302 - ++$errors;
214 + WP_CLI::error( ' Reconnect failed: ' . MainWP_Error_Helper::get_console_error_message( $e ) );
215 + $errors++;
303 216 }
304 217 }
305 218 MainWP_DB::free_result( $websites );
306 219 if ( 0 < $errors ) {
307 - \WP_CLI::error( 'Reconnect completed with errors' );
220 + WP_CLI::error( 'Reconnect completed with errors' );
308 221 } elseif ( 0 < $warnings ) {
309 - \WP_CLI::warning( 'Reconnect completed with warnings' );
222 + WP_CLI::warning( 'Reconnect completed with warnings' );
310 223 } else {
311 - \WP_CLI::success( 'Reconnect completed' );
224 + WP_CLI::success( 'Reconnect completed' );
312 225 }
313 226 }
314 227
315 228
@@ -344,16 +257,8 @@
344 257 * ## Synopsis [<websiteid>] [--list] [--list-all] [--upgrade=<pluginslug>] [--upgrade-all]
345 258 *
346 259 * @param array $args Function arguments.
347 260 * @param array $assoc_args Function associate arguments.
348 - *
349 - * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension()
350 - * @uses \MainWP\Dashboard\MainWP_Error_Helper::get_console_error_message()
351 - * @uses \MainWP\Dashboard\MainWP_DB::query()
352 - * @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_for_current_user()
353 - * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
354 - * @uses \MainWP\Dashboard\MainWP_Updates_Handler::upgrade_plugin_theme_translation()
355 - * @uses \MainWP\Dashboard\MainWP_Utility::value_to_string()
356 261 */
357 262 public function plugin( $args, $assoc_args ) { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated.
358 263 $sites = array();
359 264 if ( 0 < count( $args ) ) {
@@ -359,9 +264,9 @@
359 264 if ( 0 < count( $args ) ) {
360 265 $args_exploded = explode( ',', $args[0] );
361 266 foreach ( $args_exploded as $arg ) {
362 267 if ( ! is_numeric( trim( $arg ) ) ) {
363 - \WP_CLI::error( 'Child site IDs should be numeric.' );
268 + WP_CLI::error( 'Child site IDs should be numeric.' );
364 269 }
365 270
366 271 $sites[] = trim( $arg );
367 272 }
@@ -430,11 +335,11 @@
430 335 }
431 336 }
432 337 }
433 338
434 - \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $pluginLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . "s+%'--" . ( $newVersionLength + 2 ) . 's+', '', '', '', '', '' ) );
435 - \WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $pluginLength . 's | %-' . $oldVersionLength . 's | %-' . $newVersionLength . 's |', 'id', 'name', 'plugin', 'version', 'new version' ) );
436 - \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $pluginLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . "s+%'--" . ( $newVersionLength + 2 ) . 's+', '', '', '', '', '' ) );
339 + WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $pluginLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . "s+%'--" . ( $newVersionLength + 2 ) . 's+', '', '', '', '', '' ) );
340 + WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $pluginLength . 's | %-' . $oldVersionLength . 's | %-' . $newVersionLength . 's |', 'id', 'name', 'plugin', 'version', 'new version' ) );
341 + WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $pluginLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . "s+%'--" . ( $newVersionLength + 2 ) . 's+', '', '', '', '', '' ) );
437 342
438 343 foreach ( $websites_to_upgrade as $website_to_upgrade ) {
439 344 if ( $idLength < strlen( $website_to_upgrade['id'] ) ) {
440 345 $idLength = strlen( $website_to_upgrade['id'] );
@@ -444,18 +349,18 @@
444 349 }
445 350
446 351 $i = 0;
447 352 foreach ( $website_to_upgrade['plugins'] as $plugin_to_upgrade ) {
448 - if ( 0 === $i ) {
449 - \WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $pluginLength . 's | %-' . $oldVersionLength . 's | %-' . $newVersionLength . 's |', $website_to_upgrade['id'], $website_to_upgrade['name'], $plugin_to_upgrade['name'], $plugin_to_upgrade['version'], $plugin_to_upgrade['new_version'] ) );
353 + if ( 0 == $i ) {
354 + WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $pluginLength . 's | %-' . $oldVersionLength . 's | %-' . $newVersionLength . 's |', $website_to_upgrade['id'], $website_to_upgrade['name'], $plugin_to_upgrade['name'], $plugin_to_upgrade['version'], $plugin_to_upgrade['new_version'] ) );
450 355 } else {
451 - \WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $pluginLength . 's | %-' . $oldVersionLength . 's | %-' . $newVersionLength . 's |', '', '', $plugin_to_upgrade['name'], $plugin_to_upgrade['version'], $plugin_to_upgrade['new_version'] ) );
356 + WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $pluginLength . 's | %-' . $oldVersionLength . 's | %-' . $newVersionLength . 's |', '', '', $plugin_to_upgrade['name'], $plugin_to_upgrade['version'], $plugin_to_upgrade['new_version'] ) );
452 357 }
453 - ++$i;
358 + $i++;
454 359 }
455 360 }
456 361
457 - \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $pluginLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . "s+%'--" . ( $newVersionLength + 2 ) . 's+', '', '', '', '', '' ) );
362 + WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $pluginLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . "s+%'--" . ( $newVersionLength + 2 ) . 's+', '', '', '', '', '' ) );
458 363 } elseif ( isset( $assoc_args['list-all'] ) ) {
459 364 $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, true ) );
460 365 $userExtension = MainWP_DB_Common::instance()->get_user_extension();
461 366 $websites_to_list = array();
@@ -502,11 +407,11 @@
502 407 }
503 408 }
504 409 }
505 410
506 - \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $pluginLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . 's+', '', '', '', '' ) );
507 - \WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $pluginLength . 's | %-' . $oldVersionLength . 's |', 'id', 'name', 'plugin', 'version' ) );
508 - \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $pluginLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . 's+', '', '', '', '' ) );
411 + WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $pluginLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . 's+', '', '', '', '' ) );
412 + WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $pluginLength . 's | %-' . $oldVersionLength . 's |', 'id', 'name', 'plugin', 'version' ) );
413 + WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $pluginLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . 's+', '', '', '', '' ) );
509 414
510 415 foreach ( $websites_to_list as $website_item ) {
511 416 if ( $idLength < strlen( $website_item['id'] ) ) {
512 417 $idLength = strlen( $website_item['id'] );
@@ -516,18 +421,18 @@
516 421 }
517 422
518 423 $i = 0;
519 424 foreach ( $website_item['plugins'] as $plugin_item ) {
520 - if ( 0 === $i ) {
521 - \WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $pluginLength . 's | %-' . $oldVersionLength . 's |', $website_item['id'], $website_item['name'], $plugin_item['name'], $plugin_item['version'] ) );
425 + if ( 0 == $i ) {
426 + WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $pluginLength . 's | %-' . $oldVersionLength . 's |', $website_item['id'], $website_item['name'], $plugin_item['name'], $plugin_item['version'] ) );
522 427 } else {
523 - \WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $pluginLength . 's | %-' . $oldVersionLength . 's |', '', '', $plugin_item['name'], $plugin_item['version'] ) );
428 + WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $pluginLength . 's | %-' . $oldVersionLength . 's |', '', '', $plugin_item['name'], $plugin_item['version'] ) );
524 429 }
525 - ++$i;
430 + $i++;
526 431 }
527 432 }
528 433
529 - \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $pluginLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . 's+', '', '', '', '' ) );
434 + WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $pluginLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . 's+', '', '', '', '' ) );
530 435 } elseif ( isset( $assoc_args['upgrade'] ) || isset( $assoc_args['upgrade-all'] ) ) {
531 436
532 437 $pluginSlugs = array();
533 438 if ( isset( $assoc_args['upgrade'] ) ) {
@@ -562,23 +467,23 @@
562 467
563 468 $tmp[] = $key;
564 469 }
565 470
566 - if ( 0 === count( $tmp ) ) {
567 - \WP_CLI::line( 'No available plugin updates for ' . $website->name );
471 + if ( count( $tmp ) == 0 ) {
472 + WP_CLI::line( 'No available plugin updates for ' . $website->name );
568 473
569 474 continue;
570 475 }
571 476
572 - \WP_CLI::line( 'Updating ' . count( $tmp ) . ' plugins for ' . $website->name );
477 + WP_CLI::line( 'Updating ' . count( $tmp ) . ' plugins for ' . $website->name );
573 478
574 479 try {
575 480 MainWP_Updates_Handler::upgrade_plugin_theme_translation( $website->id, 'plugin', implode( ',', $tmp ) );
576 - \WP_CLI::success( 'Updates completed' );
481 + WP_CLI::success( 'Updates completed' );
577 482 } catch ( \Exception $e ) {
578 - \WP_CLI::error( 'Updates failed: ' . MainWP_Error_Helper::get_console_error_message( $e ) );
579 - if ( $e->getMesage() === 'WPERROR' ) {
580 - \WP_CLI::debug( 'Error: ' . MainWP_Utility::value_to_string( $e->get_message_extra(), 1 ) );
483 + WP_CLI::error( 'Updates failed: ' . MainWP_Error_Helper::get_console_error_message( $e ) );
484 + if ( $e->getMesage() == 'WPERROR' ) {
485 + WP_CLI::debug( 'Error: ' . MainWP_Utility::value_to_string( $e->get_message_extra(), 1 ) );
581 486 }
582 487 }
583 488 }
584 489 }
@@ -615,16 +520,8 @@
615 520 * ## Synopsis [<websiteid>] [--list] [--list-all] [--upgrade=<theme>] [--upgrade-all]
616 521 *
617 522 * @param array $args Function arguments.
618 523 * @param array $assoc_args Function associate arguments.
619 - *
620 - * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension()
621 - * @uses \MainWP\Dashboard\MainWP_Error_Helper::get_console_error_message()
622 - * @uses \MainWP\Dashboard\MainWP_DB::query()
623 - * @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_for_current_user()
624 - * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
625 - * @uses \MainWP\Dashboard\MainWP_Updates_Handler::upgrade_plugin_theme_translation()
626 - * @uses \MainWP\Dashboard\MainWP_Utility::value_to_string()
627 524 */
628 525 public function theme( $args, $assoc_args ) { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated.
629 526 $sites = array();
630 527 if ( count( $args ) > 0 ) {
@@ -630,9 +527,9 @@
630 527 if ( count( $args ) > 0 ) {
631 528 $args_exploded = explode( ',', $args[0] );
632 529 foreach ( $args_exploded as $arg ) {
633 530 if ( ! is_numeric( trim( $arg ) ) ) {
634 - \WP_CLI::error( 'Child site IDs should be numeric.' );
531 + WP_CLI::error( 'Child site IDs should be numeric.' );
635 532 }
636 533
637 534 $sites[] = trim( $arg );
638 535 }
@@ -701,11 +598,11 @@
701 598 }
702 599 }
703 600 }
704 601
705 - \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $themeLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . "s+%'--" . ( $newVersionLength + 2 ) . 's+', '', '', '', '', '' ) );
706 - \WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $themeLength . 's | %-' . $oldVersionLength . 's | %-' . $newVersionLength . 's |', 'id', 'name', 'theme', 'version', 'new version' ) );
707 - \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $themeLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . "s+%'--" . ( $newVersionLength + 2 ) . 's+', '', '', '', '', '' ) );
602 + WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $themeLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . "s+%'--" . ( $newVersionLength + 2 ) . 's+', '', '', '', '', '' ) );
603 + WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $themeLength . 's | %-' . $oldVersionLength . 's | %-' . $newVersionLength . 's |', 'id', 'name', 'theme', 'version', 'new version' ) );
604 + WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $themeLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . "s+%'--" . ( $newVersionLength + 2 ) . 's+', '', '', '', '', '' ) );
708 605
709 606 foreach ( $websites_to_upgrade as $website_to_upgrade ) {
710 607 if ( $idLength < strlen( $website_to_upgrade['id'] ) ) {
711 608 $idLength = strlen( $website_to_upgrade['id'] );
@@ -715,18 +612,18 @@
715 612 }
716 613
717 614 $i = 0;
718 615 foreach ( $website_to_upgrade['themes'] as $theme_to_upgrade ) {
719 - if ( 0 === $i ) {
720 - \WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $themeLength . 's | %-' . $oldVersionLength . 's | %-' . $newVersionLength . 's |', $website_to_upgrade['id'], $website_to_upgrade['name'], $theme_to_upgrade['name'], $theme_to_upgrade['version'], $theme_to_upgrade['new_version'] ) );
616 + if ( 0 == $i ) {
617 + WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $themeLength . 's | %-' . $oldVersionLength . 's | %-' . $newVersionLength . 's |', $website_to_upgrade['id'], $website_to_upgrade['name'], $theme_to_upgrade['name'], $theme_to_upgrade['version'], $theme_to_upgrade['new_version'] ) );
721 618 } else {
722 - \WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $themeLength . 's | %-' . $oldVersionLength . 's | %-' . $newVersionLength . 's |', '', '', $theme_to_upgrade['name'], $theme_to_upgrade['version'], $theme_to_upgrade['new_version'] ) );
619 + WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $themeLength . 's | %-' . $oldVersionLength . 's | %-' . $newVersionLength . 's |', '', '', $theme_to_upgrade['name'], $theme_to_upgrade['version'], $theme_to_upgrade['new_version'] ) );
723 620 }
724 - ++$i;
621 + $i++;
725 622 }
726 623 }
727 624
728 - \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $themeLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . "s+%'--" . ( $newVersionLength + 2 ) . 's+', '', '', '', '', '' ) );
625 + WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $themeLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . "s+%'--" . ( $newVersionLength + 2 ) . 's+', '', '', '', '', '' ) );
729 626 } elseif ( isset( $assoc_args['list-all'] ) ) {
730 627 $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, true ) );
731 628 $userExtension = MainWP_DB_Common::instance()->get_user_extension();
732 629 $websites_to_upgrade = array();
@@ -774,11 +671,11 @@
774 671 }
775 672 }
776 673 }
777 674
778 - \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $themeLength + 2 ) . "s+%'--" . ( $activeLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . 's+', '', '', '', '', '' ) );
779 - \WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $themeLength . 's | %-' . $activeLength . 's | %-' . $oldVersionLength . 's |', 'id', 'name', 'theme', 'active', 'version' ) );
780 - \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $themeLength + 2 ) . "s+%'--" . ( $activeLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . 's+', '', '', '', '', '' ) );
675 + WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $themeLength + 2 ) . "s+%'--" . ( $activeLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . 's+', '', '', '', '', '' ) );
676 + WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $themeLength . 's | %-' . $activeLength . 's | %-' . $oldVersionLength . 's |', 'id', 'name', 'theme', 'active', 'version' ) );
677 + WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $themeLength + 2 ) . "s+%'--" . ( $activeLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . 's+', '', '', '', '', '' ) );
781 678
782 679 foreach ( $websites_to_upgrade as $website_item ) {
783 680 if ( $idLength < strlen( $website_item['id'] ) ) {
784 681 $idLength = strlen( $website_item['id'] );
@@ -788,18 +685,18 @@
788 685 }
789 686
790 687 $i = 0;
791 688 foreach ( $website_item['themes'] as $theme_item ) {
792 - if ( 0 === $i ) {
793 - \WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $themeLength . 's | %-' . $activeLength . 's | %-' . $oldVersionLength . 's |', $website_item['id'], $website_item['name'], $theme_item['name'], $theme_item['active'], $theme_item['version'] ) );
689 + if ( 0 == $i ) {
690 + WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $themeLength . 's | %-' . $activeLength . 's | %-' . $oldVersionLength . 's |', $website_item['id'], $website_item['name'], $theme_item['name'], $theme_item['active'], $theme_item['version'] ) );
794 691 } else {
795 - \WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $themeLength . 's | %-' . $activeLength . 's | %-' . $oldVersionLength . 's |', '', '', $theme_item['name'], $theme_item['active'], $theme_item['version'] ) );
692 + WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $themeLength . 's | %-' . $activeLength . 's | %-' . $oldVersionLength . 's |', '', '', $theme_item['name'], $theme_item['active'], $theme_item['version'] ) );
796 693 }
797 - ++$i;
694 + $i++;
798 695 }
799 696 }
800 697
801 - \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $themeLength + 2 ) . "s+%'--" . ( $activeLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . 's+', '', '', '', '', '' ) );
698 + WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $themeLength + 2 ) . "s+%'--" . ( $activeLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . 's+', '', '', '', '', '' ) );
802 699 } elseif ( isset( $assoc_args['upgrade'] ) || isset( $assoc_args['upgrade-all'] ) ) {
803 700
804 701 $themeSlugs = array();
805 702 if ( isset( $assoc_args['upgrade'] ) ) {
@@ -834,23 +731,23 @@
834 731
835 732 $tmp[] = $key;
836 733 }
837 734
838 - if ( 0 === count( $tmp ) ) {
839 - \WP_CLI::line( 'No available theme updates for ' . $website->name );
735 + if ( count( $tmp ) == 0 ) {
736 + WP_CLI::line( 'No available theme updates for ' . $website->name );
840 737
841 738 continue;
842 739 }
843 740
844 - \WP_CLI::line( 'Updating ' . count( $tmp ) . ' themes for ' . $website->name );
741 + WP_CLI::line( 'Updating ' . count( $tmp ) . ' themes for ' . $website->name );
845 742
846 743 try {
847 744 MainWP_Updates_Handler::upgrade_plugin_theme_translation( $website->id, 'theme', implode( ',', $tmp ) );
848 - \WP_CLI::success( 'Updates completed' );
745 + WP_CLI::success( 'Updates completed' );
849 746 } catch ( \Exception $e ) {
850 - \WP_CLI::error( 'Updates failed: ' . MainWP_Error_Helper::get_console_error_message( $e ) );
851 - if ( $e->getMesage() === 'WPERROR' ) {
852 - \WP_CLI::debug( 'Error: ' . MainWP_Utility::value_to_string( $e->get_message_extra(), 1 ) );
747 + WP_CLI::error( 'Updates failed: ' . MainWP_Error_Helper::get_console_error_message( $e ) );
748 + if ( $e->getMesage() == 'WPERROR' ) {
749 + WP_CLI::debug( 'Error: ' . MainWP_Utility::value_to_string( $e->get_message_extra(), 1 ) );
853 750 }
854 751 }
855 752 }
856 753 }
@@ -855,5 +752,6 @@
855 752 }
856 753 }
857 754 }
858 755 }
756 +
859 757 }