PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.2
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.2
6.2.3 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 All 156 releases
← All changes | class/class-mainwp-wp-cli-command.php +762 -753 5.0.3.2 → 6.2.2 View file →
@@ -4,17 +4,22 @@
4 4 *
5 5 * This file extends the WP-CLI and provides a set of SubCommands to Control your
6 6 * Child Sites that are added to the MainWP Dashboard.
7 7 *
8 - * @todo: allow to add or remove child sites
8 + * @devtodo: allow to add or remove child sites
9 9 * @package MainWP/Dashboard
10 10 */
11 11
12 12 namespace MainWP\Dashboard;
13 13
14 +// Exit if accessed directly.
15 +if ( ! defined( 'ABSPATH' ) ) {
16 + exit;
17 +}
18 +
14 19 // Exit if access directly.
15 20 if ( ! defined( 'WP_CLI' ) ) {
16 - return;
21 + return; // NOSONAR - jump to avoid CLI.
17 22 }
18 23
19 24 /**
20 25 * Class MainWP_WP_CLI_Command
@@ -22,838 +27,842 @@
22 27 * Manage all child sites added to the MainWP Dashboard.
23 28 *
24 29 * @package MainWP\Dashboard
25 30 */
26 -class MainWP_WP_CLI_Command extends \WP_CLI_Command {
31 +class MainWP_WP_CLI_Command extends \WP_CLI_Command { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
27 32
28 - /**
29 - * Method init()
30 - *
31 - * Initiate the MainWP CLI after all Plugins have loaded.
32 - */
33 - public static function init() {
34 - add_action( 'plugins_loaded', array( self::class, 'init_wpcli_commands' ), 99999 );
35 - }
33 + /**
34 + * Method init()
35 + *
36 + * Initiate the MainWP CLI after all Plugins have loaded.
37 + */
38 + public static function init() {
39 + add_action( 'plugins_loaded', array( static::class, 'init_wpcli_commands' ), 99999 );
40 + }
36 41
37 - /**
38 - * Method init_wpcli_commands
39 - *
40 - * Adds the MainWP WP CLI Commands via WP_CLI::add_command
41 - */
42 - public static function init_wpcli_commands() {
43 - \WP_CLI::add_command( 'mainwp', self::class );
44 - }
42 + /**
43 + * Method init_wpcli_commands
44 + *
45 + * Adds the MainWP WP CLI Commands via WP_CLI::add_command
46 + */
47 + public static function init_wpcli_commands() {
48 + \WP_CLI::add_command( 'mainwp', static::class );
49 + }
45 50
46 - /**
47 - * List information about added child sites.
48 - *
49 - * ## OPTIONS
50 - *
51 - * [--list]
52 - * : Get a list of all child sites
53 - *
54 - * [--count]
55 - * : If set, count child sites.
56 - *
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 - * @param array $args Function arguments.
66 - * @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 - */
74 - public function sites( $args, $assoc_args ) {
51 + /**
52 + * List information about added child sites.
53 + *
54 + * ## OPTIONS
55 + *
56 + * [--list]
57 + * : Get a list of all child sites
58 + *
59 + * [--count]
60 + * : If set, count child sites.
61 + *
62 + *
63 + * ## EXAMPLES
64 + *
65 + * wp mainwp sites --list
66 + * wp mainwp sites --all-sites-count
67 + *
68 + * ## Synopsis [--list] [--all-sites-count]
69 + *
70 + * @param array $args Function arguments.
71 + * @param array $assoc_args Function associate arguments.
72 + *
73 + * @uses \MainWP\Dashboard\MainWP_DB::query()
74 + * @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_for_current_user()
75 + * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
76 + * @uses \MainWP\Dashboard\MainWP_DB::free_result()
77 + * @uses \MainWP\Dashboard\MainWP_DB::data_seek()
78 + */
79 + public function sites( $args, $assoc_args ) {
75 80
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 - }
81 + // support new mainwp sites cli commands.
82 + $handle = MainWP_WP_CLI_Handle::get_assoc_args_commands( 'sites', $assoc_args );
83 + if ( ! empty( $handle ) ) {
84 + MainWP_WP_CLI_Handle::handle_cli_callback( 'sites', $args, $assoc_args );
85 + return;
86 + }
82 87
83 - $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, true ) );
88 + $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, true ) );
84 89
85 - $idLength = strlen( 'id' );
86 - $nameLength = strlen( 'name' );
87 - $urlLength = strlen( 'url' );
88 - $versionLength = strlen( 'version' );
89 - while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
90 - if ( $idLength < strlen( $website->id ) ) {
91 - $idLength = strlen( $website->id );
92 - }
93 - if ( $nameLength < strlen( $website->name ) ) {
94 - $nameLength = strlen( $website->name );
95 - }
96 - if ( $urlLength < strlen( $website->url ) ) {
97 - $urlLength = strlen( $website->url );
98 - }
99 - if ( $versionLength < strlen( $website->version ) ) {
100 - $versionLength = strlen( $website->version );
101 - }
102 - }
103 - MainWP_DB::data_seek( $websites, 0 );
90 + $idLength = strlen( 'id' );
91 + $nameLength = strlen( 'name' );
92 + $urlLength = strlen( 'url' );
93 + $versionLength = strlen( 'version' );
94 + while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
95 + if ( $idLength < strlen( $website->id ) ) {
96 + $idLength = strlen( $website->id );
97 + }
98 + if ( $nameLength < strlen( $website->name ) ) {
99 + $nameLength = strlen( $website->name );
100 + }
101 + if ( $urlLength < strlen( $website->url ) ) {
102 + $urlLength = strlen( $website->url );
103 + }
104 + if ( $versionLength < strlen( $website->version ) ) {
105 + $versionLength = strlen( $website->version );
106 + }
107 + }
108 + MainWP_DB::data_seek( $websites, 0 );
104 109
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+', '', '', '', '' ) );
110 + \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $urlLength + 2 ) . "s+%'--" . ( $versionLength + 2 ) . 's+', '', '', '', '' ) );
111 + \WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $urlLength . 's | %-' . $versionLength . 's |', 'id', 'name', 'url', 'version' ) );
112 + \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $urlLength + 2 ) . "s+%'--" . ( $versionLength + 2 ) . 's+', '', '', '', '' ) );
108 113
109 - 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 ) );
111 - }
114 + while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
115 + \WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $urlLength . 's | %-' . $versionLength . 's |', $website->id, $website->name, $website->url, $website->version ) );
116 + }
112 117
113 - \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $urlLength + 2 ) . "s+%'--" . ( $versionLength + 2 ) . 's+', '', '', '', '' ) );
114 - MainWP_DB::free_result( $websites );
115 - }
118 + \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $urlLength + 2 ) . "s+%'--" . ( $versionLength + 2 ) . 's+', '', '', '', '' ) );
119 + MainWP_DB::free_result( $websites );
120 + }
116 121
117 - /**
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 - }
122 + /**
123 + * Site commands.
124 + *
125 + * ## OPTIONS
126 + *
127 + * [--site]
128 + * : Get site data
129 + *
130 + * [--site-info]
131 + * : If set, get site info.
132 + *
133 + *
134 + * ## EXAMPLES
135 + *
136 + * wp mainwp site --site [<websiteid>]
137 + * wp mainwp site --site-info [<websiteid>]
138 + *
139 + * ## Synopsis [--site] [--site-info] [...]
140 + *
141 + * @param array $args Function arguments.
142 + * @param array $assoc_args Function associate arguments.
143 + */
144 + public function site( $args, $assoc_args ) {
145 + MainWP_WP_CLI_Handle::handle_cli_callback( 'site', $args, $assoc_args );
146 + }
142 147
143 148
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 - }
149 + /**
150 + * Updates commands.
151 + *
152 + * ## OPTIONS
153 + *
154 + * [--available-updates <websiteid>]
155 + * : Get available updates
156 + *
157 + * [--ignored-plugins-updates <websiteid>]
158 + * : If set, get ignored plugins updates.
159 + *
160 + * [--site-ignored-plugins-updates <websiteid>]
161 + * : If set, get ignored plugins updates of site.
162 + *
163 + * [--ignored-themes-updates <websiteid>]
164 + * : If set, get ignored themes updates.
165 + *
166 + * [--site-ignored-themes-updates <websiteid>]
167 + * : If set, get ignored themes updates of site.
168 + *
169 + * [--ignore-updates --type=[type] --slug=[slug]]
170 + * : If set, ignored updates.
171 + *
172 + * [--ignore-update <websiteid> --type=[type] --slug=[slug]]
173 + * : If set, ignored update.
174 + *
175 + * [--unignore-updates --type=[type] --slug=[slug]]
176 + * : If set, unignore updates.
177 + *
178 + * [--unignore-update <websiteid> --type=[type] --slug=[slug]]
179 + * : If set, unignore update.
180 + *
181 + *
182 + * ## EXAMPLES
183 + *
184 + * wp mainwp updates --available-updates
185 + * wp mainwp updates --ignored-plugins-updates
186 + * wp mainwp updates --site-ignored-plugins-updates 3
187 + *
188 + * ## Synopsis [--available-updates] [--ignored-plugins-updates] [--site-ignored-plugins-updates] [...]
189 + *
190 + * @param array $args Function arguments.
191 + * @param array $assoc_args Function associate arguments.
192 + */
193 + public function updates( $args, $assoc_args ) {
194 + MainWP_WP_CLI_Handle::handle_cli_callback( 'updates', $args, $assoc_args );
195 + }
191 196
192 - /**
193 - * Sync Data with Child Sites
194 - *
195 - * ## OPTIONS
196 - *
197 - * [<websiteid>]
198 - * : The id (or ids, comma separated) of the child sites that need to be synced.
199 - *
200 - * [--all]
201 - * : If set, all child sites will be synced.
202 - *
203 - * ## EXAMPLES
204 - *
205 - * wp mainwp sync 2,5
206 - * wp mainwp sync --all
207 - *
208 - * ## Synopsis [<websiteid>] [--all]
209 - *
210 - * @param array $args Function arguments.
211 - * @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 - */
220 - public function sync( $args, $assoc_args ) {
221 - $sites = array();
222 - if ( count( $args ) > 0 ) {
223 - $args_exploded = explode( ',', $args[0] );
224 - foreach ( $args_exploded as $arg ) {
225 - if ( ! is_numeric( trim( $arg ) ) ) {
226 - \WP_CLI::error( 'Child site ids should be numeric.' );
227 - }
197 + /**
198 + * Sync Data with Child Sites
199 + *
200 + * ## OPTIONS
201 + *
202 + * [<websiteid>]
203 + * : The id (or ids, comma separated) of the child sites that need to be synced.
204 + *
205 + * [--all]
206 + * : If set, all child sites will be synced.
207 + *
208 + * ## EXAMPLES
209 + *
210 + * wp mainwp sync 2,5
211 + * wp mainwp sync --all
212 + *
213 + * ## Synopsis [<websiteid>] [--all]
214 + *
215 + * @param array $args Function arguments.
216 + * @param array $assoc_args Function associate arguments.
217 + *
218 + * @uses \MainWP\Dashboard\MainWP_Error_Helper::get_console_error_message()
219 + * @uses \MainWP\Dashboard\MainWP_DB::query()
220 + * @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_for_current_user()
221 + * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
222 + * @uses \MainWP\Dashboard\MainWP_DB::free_result()
223 + * @uses \MainWP\Dashboard\MainWP_Sync::sync_site()
224 + */
225 + public function sync( $args, $assoc_args ) {
226 + $sites = array();
227 + if ( ! empty( $args ) ) {
228 + $args_exploded = explode( ',', $args[0] );
229 + foreach ( $args_exploded as $arg ) {
230 + if ( ! is_numeric( trim( $arg ) ) ) {
231 + \WP_CLI::error( 'Child site ids should be numeric.' );
232 + }
228 233
229 - $sites[] = trim( $arg );
230 - }
231 - }
234 + $sites[] = trim( $arg );
235 + }
236 + }
232 237
233 - if ( is_array( $assoc_args ) && isset( $assoc_args['all'] ) ) {
234 - update_option( 'mainwp_last_synced_all_sites', time() );
235 - }
238 + if ( is_array( $assoc_args ) && isset( $assoc_args['all'] ) ) {
239 + update_option( 'mainwp_last_synced_all_sites', time() );
240 + }
236 241
237 - if ( 0 === count( $sites ) && ( ! isset( $assoc_args['all'] ) ) ) {
238 - \WP_CLI::error( 'Please specify one or more child sites, or use --all.' );
239 - }
240 - MainWP_WP_CLI_Handle::handle_sync_sites( $args, $assoc_args );
241 - }
242 + if ( empty( $sites ) && ( ! isset( $assoc_args['all'] ) ) ) {
243 + \WP_CLI::error( 'Please specify one or more child sites, or use --all.' );
244 + }
245 + MainWP_WP_CLI_Handle::handle_sync_sites( $args, $assoc_args );
246 + }
242 247
243 - /**
244 - * Reconnect with Child Sites
245 - *
246 - * ## OPTIONS
247 - *
248 - * [<websiteid>]
249 - * : The id (or ids, comma separated) of the child sites that need to be reconnect.
250 - *
251 - * ## EXAMPLES
252 - *
253 - * wp mainwp reconnect 2,5
254 - *
255 - * ## Synopsis [<websiteid>]
256 - *
257 - * @param array $args Function arguments.
258 - * @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 - */
267 - public function reconnect( $args, $assoc_args ) {
268 - $sites = array();
269 - if ( 0 < count( $args ) ) {
270 - $args_exploded = explode( ',', $args[0] );
271 - foreach ( $args_exploded as $arg ) {
272 - if ( ! is_numeric( trim( $arg ) ) ) {
273 - \WP_CLI::error( 'Child site ids should be numeric.' );
274 - }
248 + /**
249 + * Reconnect with Child Sites
250 + *
251 + * ## OPTIONS
252 + *
253 + * [<websiteid>]
254 + * : The id (or ids, comma separated) of the child sites that need to be reconnect.
255 + *
256 + * ## EXAMPLES
257 + *
258 + * wp mainwp reconnect 2,5
259 + *
260 + * ## Synopsis [<websiteid>]
261 + *
262 + * @param array $args Function arguments.
263 + * @param array $assoc_args Function associate arguments.
264 + *
265 + * @uses \MainWP\Dashboard\MainWP_Error_Helper::get_console_error_message()
266 + * @uses \MainWP\Dashboard\MainWP_DB::query()
267 + * @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_for_current_user()
268 + * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
269 + * @uses \MainWP\Dashboard\MainWP_DB::free_result()
270 + * @uses \MainWP\Dashboard\MainWP_Manage_Sites_View::m_reconnect_site()
271 + */
272 + public function reconnect( $args, $assoc_args ) { //phpcs:ignore -- NOSONAR - complex.
273 + $sites = array();
274 + if ( ! empty( $args ) ) {
275 + $args_exploded = explode( ',', $args[0] );
276 + foreach ( $args_exploded as $arg ) {
277 + if ( ! is_numeric( trim( $arg ) ) ) {
278 + \WP_CLI::error( 'Child site ids should be numeric.' );
279 + }
275 280
276 - $sites[] = trim( $arg );
277 - }
278 - }
281 + $sites[] = trim( $arg );
282 + }
283 + }
279 284
280 - if ( 0 === count( $sites ) ) {
281 - \WP_CLI::error( 'Please specify one or more child sites.' );
282 - }
285 + if ( empty( $sites ) ) {
286 + \WP_CLI::error( 'Please specify one or more child sites.' );
287 + }
283 288
284 - $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' );
286 - $warnings = 0;
287 - $errors = 0;
288 - while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
289 - if ( ( 0 < count( $sites ) ) && ( ! in_array( $website->id, $sites, true ) ) ) {
290 - continue;
291 - }
292 - \WP_CLI::line( ' -> ' . $website->name . ' (' . $website->url . ')' );
293 - try {
294 - if ( MainWP_Manage_Sites_View::m_reconnect_site( $website ) ) {
295 - \WP_CLI::success( ' Reconnected successfully' );
296 - } else {
297 - \WP_CLI::warning( ' Reconnect failed' );
298 - ++$warnings;
299 - }
300 - } catch ( \Exception $e ) {
301 - \WP_CLI::error( ' Reconnect failed: ' . MainWP_Error_Helper::get_console_error_message( $e ) );
302 - ++$errors;
303 - }
304 - }
305 - MainWP_DB::free_result( $websites );
306 - if ( 0 < $errors ) {
307 - \WP_CLI::error( 'Reconnect completed with errors' );
308 - } elseif ( 0 < $warnings ) {
309 - \WP_CLI::warning( 'Reconnect completed with warnings' );
310 - } else {
311 - \WP_CLI::success( 'Reconnect completed' );
312 - }
313 - }
289 + $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, true ) );
290 + \WP_CLI::line( 'Reconnect started' );
291 + $warnings = 0;
292 + $errors = 0;
293 + while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
294 + if ( ( ! empty( $sites ) ) && ( ! in_array( $website->id, $sites, true ) ) ) {
295 + continue;
296 + }
297 + \WP_CLI::line( ' -> ' . $website->name . ' (' . $website->url . ')' );
298 + try {
299 + if ( MainWP_Manage_Sites_View::m_reconnect_site( $website ) ) {
300 + \WP_CLI::success( ' Reconnected successfully' );
301 + } else {
302 + \WP_CLI::warning( ' Reconnect failed' );
303 + ++$warnings;
304 + }
305 + } catch ( \Exception $e ) {
306 + \WP_CLI::error( ' Reconnect failed: ' . MainWP_Error_Helper::get_console_error_message( $e ) );
307 + ++$errors;
308 + }
309 + }
310 + MainWP_DB::free_result( $websites );
311 + if ( 0 < $errors ) {
312 + \WP_CLI::error( 'Reconnect completed with errors' );
313 + } elseif ( 0 < $warnings ) {
314 + \WP_CLI::warning( 'Reconnect completed with warnings' );
315 + } else {
316 + \WP_CLI::success( 'Reconnect completed' );
317 + }
318 + }
314 319
315 320
316 - /**
317 - * List information about plugin updates
318 - *
319 - * ## OPTIONS
320 - *
321 - * [<websiteid>]
322 - * : The id (or ids, comma separated) of the child sites that need to be listed/upgraded, when omitted all childsites are used.
323 - *
324 - * [--list]
325 - * : Get a list of plugins with available updates
326 - *
327 - * [--list-all]
328 - * : List all plugins
329 - *
330 - * [--upgrade=<pluginslug>]
331 - * : Update the plugin slugs
332 - *
333 - * [--upgrade-all]
334 - * : Update all plugins
335 - *
336 - * ## EXAMPLES
337 - *
338 - * wp mainwp plugin 2,5 --list
339 - * wp mainwp plugin --list
340 - * wp mainwp plugin 2,5 --list-all
341 - * wp mainwp plugin 2,5 --upgrade-all
342 - * wp mainwp plugin 2,5 --upgrade=mainwpchild
343 - *
344 - * ## Synopsis [<websiteid>] [--list] [--list-all] [--upgrade=<pluginslug>] [--upgrade-all]
345 - *
346 - * @param array $args Function arguments.
347 - * @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 - */
357 - public function plugin( $args, $assoc_args ) { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated.
358 - $sites = array();
359 - if ( 0 < count( $args ) ) {
360 - $args_exploded = explode( ',', $args[0] );
361 - foreach ( $args_exploded as $arg ) {
362 - if ( ! is_numeric( trim( $arg ) ) ) {
363 - \WP_CLI::error( 'Child site IDs should be numeric.' );
364 - }
321 + /**
322 + * List information about plugin updates
323 + *
324 + * ## OPTIONS
325 + *
326 + * [<websiteid>]
327 + * : The id (or ids, comma separated) of the child sites that need to be listed/upgraded, when omitted all childsites are used.
328 + *
329 + * [--list]
330 + * : Get a list of plugins with available updates
331 + *
332 + * [--list-all]
333 + * : List all plugins
334 + *
335 + * [--upgrade=<pluginslug>]
336 + * : Update the plugin slugs
337 + *
338 + * [--upgrade-all]
339 + * : Update all plugins
340 + *
341 + * ## EXAMPLES
342 + *
343 + * wp mainwp plugin 2,5 --list
344 + * wp mainwp plugin --list
345 + * wp mainwp plugin 2,5 --list-all
346 + * wp mainwp plugin 2,5 --upgrade-all
347 + * wp mainwp plugin 2,5 --upgrade=mainwpchild
348 + *
349 + * ## Synopsis [<websiteid>] [--list] [--list-all] [--upgrade=<pluginslug>] [--upgrade-all]
350 + *
351 + * @param array $args Function arguments.
352 + * @param array $assoc_args Function associate arguments.
353 + *
354 + * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension()
355 + * @uses \MainWP\Dashboard\MainWP_Error_Helper::get_console_error_message()
356 + * @uses \MainWP\Dashboard\MainWP_DB::query()
357 + * @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_for_current_user()
358 + * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
359 + * @uses \MainWP\Dashboard\MainWP_Updates_Handler::upgrade_plugin_theme_translation()
360 + * @uses \MainWP\Dashboard\MainWP_Utility::value_to_string()
361 + */
362 + public function plugin( $args, $assoc_args ) { // phpcs:ignore -- NOSONAR -Current complexity is the only way to achieve desired results, pull request solutions appreciated.
363 + $sites = array();
364 + if ( ! empty( $args ) ) {
365 + $args_exploded = explode( ',', $args[0] );
366 + foreach ( $args_exploded as $arg ) {
367 + if ( ! is_numeric( trim( $arg ) ) ) {
368 + \WP_CLI::error( 'Child site IDs should be numeric.' );
369 + }
365 370
366 - $sites[] = trim( $arg );
367 - }
368 - }
371 + $sites[] = trim( $arg );
372 + }
373 + }
369 374
370 - if ( isset( $assoc_args['list'] ) ) {
371 - $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, true ) );
372 - $userExtension = MainWP_DB_Common::instance()->get_user_extension();
373 - $websites_to_upgrade = array();
374 - while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
375 - if ( ( count( $sites ) > 0 ) && ( ! in_array( $website->id, $sites, true ) ) ) {
376 - continue;
377 - }
375 + if ( isset( $assoc_args['list'] ) ) {
376 + $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, true ) );
377 + $userExtension = MainWP_DB_Common::instance()->get_user_extension();
378 + $websites_to_upgrade = array();
379 + while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
380 + if ( ! empty( $sites ) && ( ! in_array( $website->id, $sites, true ) ) ) {
381 + continue;
382 + }
378 383
379 - $plugin_upgrades = json_decode( $website->plugin_upgrades, true );
384 + $plugin_upgrades = json_decode( $website->plugin_upgrades, true );
380 385
381 - if ( is_array( $plugin_upgrades ) ) {
382 - $ignored_plugins = json_decode( $website->ignored_plugins, true );
383 - if ( is_array( $ignored_plugins ) ) {
384 - $plugin_upgrades = array_diff_key( $plugin_upgrades, $ignored_plugins );
385 - }
386 + if ( is_array( $plugin_upgrades ) ) {
387 + $ignored_plugins = json_decode( $website->ignored_plugins, true );
388 + if ( is_array( $ignored_plugins ) ) {
389 + $plugin_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $plugin_upgrades, $ignored_plugins );
386 390
387 - $ignored_plugins = json_decode( $userExtension->ignored_plugins, true );
388 - if ( is_array( $ignored_plugins ) ) {
389 - $plugin_upgrades = array_diff_key( $plugin_upgrades, $ignored_plugins );
390 - }
391 + }
391 392
392 - $tmp = array();
393 - foreach ( $plugin_upgrades as $plugin_upgrade ) {
394 - $tmp[] = array(
395 - 'name' => $plugin_upgrade['update']['slug'],
396 - 'version' => $plugin_upgrade['Version'],
397 - 'new_version' => $plugin_upgrade['update']['new_version'],
398 - );
399 - }
400 - $websites_to_upgrade[] = array(
401 - 'id' => $website->id,
402 - 'name' => $website->name,
403 - 'plugins' => $tmp,
404 - );
405 - }
406 - }
393 + $ignored_plugins = json_decode( $userExtension->ignored_plugins, true );
394 + if ( is_array( $ignored_plugins ) ) {
395 + $plugin_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $plugin_upgrades, $ignored_plugins );
407 396
408 - $idLength = strlen( 'id' );
409 - $nameLength = strlen( 'name' );
410 - $pluginLength = strlen( 'plugin' );
411 - $oldVersionLength = strlen( 'version' );
412 - $newVersionLength = strlen( 'new version' );
413 - foreach ( $websites_to_upgrade as $website_to_upgrade ) {
414 - if ( $idLength < strlen( $website_to_upgrade['id'] ) ) {
415 - $idLength = strlen( $website_to_upgrade['id'] );
416 - }
417 - if ( $nameLength < strlen( $website_to_upgrade['name'] ) ) {
418 - $nameLength = strlen( $website_to_upgrade['name'] );
419 - }
397 + }
420 398
421 - foreach ( $website_to_upgrade['plugins'] as $plugin_to_upgrade ) {
422 - if ( $pluginLength < strlen( $plugin_to_upgrade['name'] ) ) {
423 - $pluginLength = strlen( $plugin_to_upgrade['name'] );
424 - }
425 - if ( $oldVersionLength < strlen( $plugin_to_upgrade['version'] ) ) {
426 - $oldVersionLength = strlen( $plugin_to_upgrade['version'] );
427 - }
428 - if ( $newVersionLength < strlen( $plugin_to_upgrade['new_version'] ) ) {
429 - $newVersionLength = strlen( $plugin_to_upgrade['new_version'] );
430 - }
431 - }
432 - }
399 + $tmp = array();
400 + foreach ( $plugin_upgrades as $plugin_upgrade ) {
401 + $tmp[] = array(
402 + 'name' => $plugin_upgrade['update']['slug'],
403 + 'version' => $plugin_upgrade['Version'],
404 + 'new_version' => $plugin_upgrade['update']['new_version'],
405 + );
406 + }
407 + $websites_to_upgrade[] = array(
408 + 'id' => $website->id,
409 + 'name' => $website->name,
410 + 'plugins' => $tmp,
411 + );
412 + }
413 + }
433 414
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+', '', '', '', '', '' ) );
415 + $idLength = strlen( 'id' );
416 + $nameLength = strlen( 'name' );
417 + $pluginLength = strlen( 'plugin' );
418 + $oldVersionLength = strlen( 'version' );
419 + $newVersionLength = strlen( 'new version' );
420 + foreach ( $websites_to_upgrade as $website_to_upgrade ) {
421 + if ( $idLength < strlen( $website_to_upgrade['id'] ) ) {
422 + $idLength = strlen( $website_to_upgrade['id'] );
423 + }
424 + if ( $nameLength < strlen( $website_to_upgrade['name'] ) ) {
425 + $nameLength = strlen( $website_to_upgrade['name'] );
426 + }
437 427
438 - foreach ( $websites_to_upgrade as $website_to_upgrade ) {
439 - if ( $idLength < strlen( $website_to_upgrade['id'] ) ) {
440 - $idLength = strlen( $website_to_upgrade['id'] );
441 - }
442 - if ( $nameLength < strlen( $website_to_upgrade['name'] ) ) {
443 - $nameLength = strlen( $website_to_upgrade['name'] );
444 - }
428 + foreach ( $website_to_upgrade['plugins'] as $plugin_to_upgrade ) {
429 + if ( $pluginLength < strlen( $plugin_to_upgrade['name'] ) ) {
430 + $pluginLength = strlen( $plugin_to_upgrade['name'] );
431 + }
432 + if ( $oldVersionLength < strlen( $plugin_to_upgrade['version'] ) ) {
433 + $oldVersionLength = strlen( $plugin_to_upgrade['version'] );
434 + }
435 + if ( $newVersionLength < strlen( $plugin_to_upgrade['new_version'] ) ) {
436 + $newVersionLength = strlen( $plugin_to_upgrade['new_version'] );
437 + }
438 + }
439 + }
445 440
446 - $i = 0;
447 - 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'] ) );
450 - } 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'] ) );
452 - }
453 - ++$i;
454 - }
455 - }
441 + \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $pluginLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . "s+%'--" . ( $newVersionLength + 2 ) . 's+', '', '', '', '', '' ) );
442 + \WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $pluginLength . 's | %-' . $oldVersionLength . 's | %-' . $newVersionLength . 's |', 'id', 'name', 'plugin', 'version', 'new version' ) );
443 + \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $pluginLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . "s+%'--" . ( $newVersionLength + 2 ) . 's+', '', '', '', '', '' ) );
456 444
457 - \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $pluginLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . "s+%'--" . ( $newVersionLength + 2 ) . 's+', '', '', '', '', '' ) );
458 - } elseif ( isset( $assoc_args['list-all'] ) ) {
459 - $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, true ) );
460 - $userExtension = MainWP_DB_Common::instance()->get_user_extension();
461 - $websites_to_list = array();
462 - while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
463 - if ( ( 0 < count( $sites ) ) && ( ! in_array( $website->id, $sites, true ) ) ) {
464 - continue;
465 - }
445 + foreach ( $websites_to_upgrade as $website_to_upgrade ) {
446 + if ( $idLength < strlen( $website_to_upgrade['id'] ) ) {
447 + $idLength = strlen( $website_to_upgrade['id'] );
448 + }
449 + if ( $nameLength < strlen( $website_to_upgrade['name'] ) ) {
450 + $nameLength = strlen( $website_to_upgrade['name'] );
451 + }
466 452
467 - $plugins_to_list = json_decode( $website->plugins, true );
468 - if ( is_array( $plugins_to_list ) ) {
469 - $tmp = array();
470 - foreach ( $plugins_to_list as $plugin ) {
471 - $tmp[] = array(
472 - 'name' => $plugin['slug'],
473 - 'version' => $plugin['version'],
474 - );
475 - }
476 - $websites_to_list[] = array(
477 - 'id' => $website->id,
478 - 'name' => $website->name,
479 - 'plugins' => $tmp,
480 - );
481 - }
482 - }
453 + $i = 0;
454 + foreach ( $website_to_upgrade['plugins'] as $plugin_to_upgrade ) {
455 + if ( 0 === $i ) {
456 + \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'] ) );
457 + } else {
458 + \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'] ) );
459 + }
460 + ++$i;
461 + }
462 + }
483 463
484 - $idLength = strlen( 'id' );
485 - $nameLength = strlen( 'name' );
486 - $pluginLength = strlen( 'plugin' );
487 - $oldVersionLength = strlen( 'version' );
488 - foreach ( $websites_to_list as $website_item ) {
489 - if ( $idLength < strlen( $website_item['id'] ) ) {
490 - $idLength = strlen( $website_item['id'] );
491 - }
492 - if ( $nameLength < strlen( $website_item['name'] ) ) {
493 - $nameLength = strlen( $website_item['name'] );
494 - }
464 + \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $pluginLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . "s+%'--" . ( $newVersionLength + 2 ) . 's+', '', '', '', '', '' ) );
465 + } elseif ( isset( $assoc_args['list-all'] ) ) {
466 + $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, true ) );
467 + $userExtension = MainWP_DB_Common::instance()->get_user_extension();
468 + $websites_to_list = array();
469 + while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
470 + if ( ( ! empty( $sites ) ) && ( ! in_array( $website->id, $sites, true ) ) ) {
471 + continue;
472 + }
495 473
496 - foreach ( $website_item['plugins'] as $plugin_item ) {
497 - if ( $pluginLength < strlen( $plugin_item['name'] ) ) {
498 - $pluginLength = strlen( $plugin_item['name'] );
499 - }
500 - if ( $oldVersionLength < strlen( $plugin_item['version'] ) ) {
501 - $oldVersionLength = strlen( $plugin_item['version'] );
502 - }
503 - }
504 - }
474 + $plugins_to_list = json_decode( $website->plugins, true );
475 + if ( is_array( $plugins_to_list ) ) {
476 + $tmp = array();
477 + foreach ( $plugins_to_list as $plugin ) {
478 + $tmp[] = array(
479 + 'name' => $plugin['slug'],
480 + 'version' => $plugin['version'],
481 + );
482 + }
483 + $websites_to_list[] = array(
484 + 'id' => $website->id,
485 + 'name' => $website->name,
486 + 'plugins' => $tmp,
487 + );
488 + }
489 + }
505 490
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+', '', '', '', '' ) );
491 + $idLength = strlen( 'id' );
492 + $nameLength = strlen( 'name' );
493 + $pluginLength = strlen( 'plugin' );
494 + $oldVersionLength = strlen( 'version' );
495 + foreach ( $websites_to_list as $website_item ) {
496 + if ( $idLength < strlen( $website_item['id'] ) ) {
497 + $idLength = strlen( $website_item['id'] );
498 + }
499 + if ( $nameLength < strlen( $website_item['name'] ) ) {
500 + $nameLength = strlen( $website_item['name'] );
501 + }
509 502
510 - foreach ( $websites_to_list as $website_item ) {
511 - if ( $idLength < strlen( $website_item['id'] ) ) {
512 - $idLength = strlen( $website_item['id'] );
513 - }
514 - if ( $nameLength < strlen( $website_item['name'] ) ) {
515 - $nameLength = strlen( $website_item['name'] );
516 - }
503 + foreach ( $website_item['plugins'] as $plugin_item ) {
504 + if ( $pluginLength < strlen( $plugin_item['name'] ) ) {
505 + $pluginLength = strlen( $plugin_item['name'] );
506 + }
507 + if ( $oldVersionLength < strlen( $plugin_item['version'] ) ) {
508 + $oldVersionLength = strlen( $plugin_item['version'] );
509 + }
510 + }
511 + }
517 512
518 - $i = 0;
519 - 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'] ) );
522 - } else {
523 - \WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $pluginLength . 's | %-' . $oldVersionLength . 's |', '', '', $plugin_item['name'], $plugin_item['version'] ) );
524 - }
525 - ++$i;
526 - }
527 - }
513 + \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $pluginLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . 's+', '', '', '', '' ) );
514 + \WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $pluginLength . 's | %-' . $oldVersionLength . 's |', 'id', 'name', 'plugin', 'version' ) );
515 + \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $pluginLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . 's+', '', '', '', '' ) );
528 516
529 - \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $pluginLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . 's+', '', '', '', '' ) );
530 - } elseif ( isset( $assoc_args['upgrade'] ) || isset( $assoc_args['upgrade-all'] ) ) {
517 + foreach ( $websites_to_list as $website_item ) {
518 + if ( $idLength < strlen( $website_item['id'] ) ) {
519 + $idLength = strlen( $website_item['id'] );
520 + }
521 + if ( $nameLength < strlen( $website_item['name'] ) ) {
522 + $nameLength = strlen( $website_item['name'] );
523 + }
531 524
532 - $pluginSlugs = array();
533 - if ( isset( $assoc_args['upgrade'] ) ) {
534 - $pluginSlugs = explode( ',', $assoc_args['upgrade'] );
535 - }
525 + $i = 0;
526 + foreach ( $website_item['plugins'] as $plugin_item ) {
527 + if ( 0 === $i ) {
528 + \WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $pluginLength . 's | %-' . $oldVersionLength . 's |', $website_item['id'], $website_item['name'], $plugin_item['name'], $plugin_item['version'] ) );
529 + } else {
530 + \WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $pluginLength . 's | %-' . $oldVersionLength . 's |', '', '', $plugin_item['name'], $plugin_item['version'] ) );
531 + }
532 + ++$i;
533 + }
534 + }
536 535
537 - $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, true ) );
538 - $userExtension = MainWP_DB_Common::instance()->get_user_extension();
539 - while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
540 - if ( ( count( $sites ) > 0 ) && ( ! in_array( $website->id, $sites, true ) ) ) {
541 - continue;
542 - }
536 + \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $pluginLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . 's+', '', '', '', '' ) );
537 + } elseif ( isset( $assoc_args['upgrade'] ) || isset( $assoc_args['upgrade-all'] ) ) {
543 538
544 - $plugin_upgrades = json_decode( $website->plugin_upgrades, true );
539 + $pluginSlugs = array();
540 + if ( isset( $assoc_args['upgrade'] ) ) {
541 + $pluginSlugs = explode( ',', $assoc_args['upgrade'] );
542 + }
545 543
546 - if ( is_array( $plugin_upgrades ) ) {
547 - $ignored_plugins = json_decode( $website->ignored_plugins, true );
548 - if ( is_array( $ignored_plugins ) ) {
549 - $plugin_upgrades = array_diff_key( $plugin_upgrades, $ignored_plugins );
550 - }
544 + $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, true ) );
545 + $userExtension = MainWP_DB_Common::instance()->get_user_extension();
546 + while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
547 + if ( ! empty( $sites ) && ( ! in_array( $website->id, $sites, true ) ) ) {
548 + continue;
549 + }
551 550
552 - $ignored_plugins = json_decode( $userExtension->ignored_plugins, true );
553 - if ( is_array( $ignored_plugins ) ) {
554 - $plugin_upgrades = array_diff_key( $plugin_upgrades, $ignored_plugins );
555 - }
551 + $plugin_upgrades = json_decode( $website->plugin_upgrades, true );
556 552
557 - $tmp = array();
558 - foreach ( $plugin_upgrades as $key => $plugin_upgrade ) {
559 - if ( ( count( $pluginSlugs ) > 0 ) && ( ! in_array( $plugin_upgrade['update']['slug'], $pluginSlugs, true ) ) ) {
560 - continue;
561 - }
553 + if ( is_array( $plugin_upgrades ) ) {
554 + $ignored_plugins = json_decode( $website->ignored_plugins, true );
555 + if ( is_array( $ignored_plugins ) ) {
556 + $plugin_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $plugin_upgrades, $ignored_plugins );
562 557
563 - $tmp[] = $key;
564 - }
558 + }
565 559
566 - if ( 0 === count( $tmp ) ) {
567 - \WP_CLI::line( 'No available plugin updates for ' . $website->name );
560 + $ignored_plugins = json_decode( $userExtension->ignored_plugins, true );
561 + if ( is_array( $ignored_plugins ) ) {
562 + $plugin_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $plugin_upgrades, $ignored_plugins );
568 563
569 - continue;
570 - }
564 + }
571 565
572 - \WP_CLI::line( 'Updating ' . count( $tmp ) . ' plugins for ' . $website->name );
566 + $tmp = array();
567 + foreach ( $plugin_upgrades as $key => $plugin_upgrade ) {
568 + if ( ! empty( $pluginSlugs ) && ( ! in_array( $plugin_upgrade['update']['slug'], $pluginSlugs, true ) ) ) {
569 + continue;
570 + }
573 571
574 - try {
575 - MainWP_Updates_Handler::upgrade_plugin_theme_translation( $website->id, 'plugin', implode( ',', $tmp ) );
576 - \WP_CLI::success( 'Updates completed' );
577 - } 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 ) );
581 - }
582 - }
583 - }
584 - }
585 - }
586 - }
572 + $tmp[] = $key;
573 + }
587 574
588 - /**
589 - * List information about theme updates
590 - *
591 - * ## OPTIONS
592 - *
593 - * [<websiteid>]
594 - * : The id (or ids, comma separated) of the child sites that need to be listed/upgraded, when omitted all childsites are used.
595 - *
596 - * [--list]
597 - * : Get a list of themes with available updates
598 - *
599 - * [--list-all]
600 - * : list all themes
601 - *
602 - * [--upgrade=<theme>]
603 - * : Update the themes
604 - *
605 - * [--upgrade-all]
606 - * : Update all themes
607 - *
608 - * ## EXAMPLES
609 - *
610 - * wp mainwp theme 2,5 --list
611 - * wp mainwp theme --list
612 - * wp mainwp theme 2,5 --upgrade-all
613 - * wp mainwp theme 2,5 --upgrade=twentysixteen
614 - *
615 - * ## Synopsis [<websiteid>] [--list] [--list-all] [--upgrade=<theme>] [--upgrade-all]
616 - *
617 - * @param array $args Function arguments.
618 - * @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 - */
628 - public function theme( $args, $assoc_args ) { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated.
629 - $sites = array();
630 - if ( count( $args ) > 0 ) {
631 - $args_exploded = explode( ',', $args[0] );
632 - foreach ( $args_exploded as $arg ) {
633 - if ( ! is_numeric( trim( $arg ) ) ) {
634 - \WP_CLI::error( 'Child site IDs should be numeric.' );
635 - }
575 + if ( empty( $tmp ) ) {
576 + \WP_CLI::line( 'No available plugin updates for ' . $website->name );
636 577
637 - $sites[] = trim( $arg );
638 - }
639 - }
578 + continue;
579 + }
640 580
641 - if ( isset( $assoc_args['list'] ) ) {
642 - $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, true ) );
643 - $userExtension = MainWP_DB_Common::instance()->get_user_extension();
644 - $websites_to_upgrade = array();
645 - while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
646 - if ( ( count( $sites ) > 0 ) && ( ! in_array( $website->id, $sites, true ) ) ) {
647 - continue;
648 - }
581 + \WP_CLI::line( 'Updating ' . count( $tmp ) . ' plugins for ' . $website->name );
649 582
650 - $theme_upgrades = json_decode( $website->theme_upgrades, true );
583 + try {
584 + MainWP_Updates_Handler::upgrade_plugin_theme_translation( $website->id, 'plugin', implode( ',', $tmp ) );
585 + \WP_CLI::success( 'Updates completed' );
586 + } catch ( \Exception $e ) {
587 + \WP_CLI::error( 'Updates failed: ' . MainWP_Error_Helper::get_console_error_message( $e ) );
588 + if ( $e->getMesage() === 'WPERROR' ) {
589 + \WP_CLI::debug( 'Error: ' . MainWP_Utility::value_to_string( $e->get_message_extra(), 1 ) );
590 + }
591 + }
592 + }
593 + }
594 + }
595 + }
651 596
652 - if ( is_array( $theme_upgrades ) ) {
653 - $ignored_themes = json_decode( $website->ignored_themes, true );
654 - if ( is_array( $ignored_themes ) ) {
655 - $theme_upgrades = array_diff_key( $theme_upgrades, $ignored_themes );
656 - }
597 + /**
598 + * List information about theme updates
599 + *
600 + * ## OPTIONS
601 + *
602 + * [<websiteid>]
603 + * : The id (or ids, comma separated) of the child sites that need to be listed/upgraded, when omitted all childsites are used.
604 + *
605 + * [--list]
606 + * : Get a list of themes with available updates
607 + *
608 + * [--list-all]
609 + * : list all themes
610 + *
611 + * [--upgrade=<theme>]
612 + * : Update the themes
613 + *
614 + * [--upgrade-all]
615 + * : Update all themes
616 + *
617 + * ## EXAMPLES
618 + *
619 + * wp mainwp theme 2,5 --list
620 + * wp mainwp theme --list
621 + * wp mainwp theme 2,5 --upgrade-all
622 + * wp mainwp theme 2,5 --upgrade=twentysixteen
623 + *
624 + * ## Synopsis [<websiteid>] [--list] [--list-all] [--upgrade=<theme>] [--upgrade-all]
625 + *
626 + * @param array $args Function arguments.
627 + * @param array $assoc_args Function associate arguments.
628 + *
629 + * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension()
630 + * @uses \MainWP\Dashboard\MainWP_Error_Helper::get_console_error_message()
631 + * @uses \MainWP\Dashboard\MainWP_DB::query()
632 + * @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_for_current_user()
633 + * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
634 + * @uses \MainWP\Dashboard\MainWP_Updates_Handler::upgrade_plugin_theme_translation()
635 + * @uses \MainWP\Dashboard\MainWP_Utility::value_to_string()
636 + */
637 + public function theme( $args, $assoc_args ) { // phpcs:ignore -- NOSONAR -Current complexity is the only way to achieve desired results, pull request solutions appreciated.
638 + $sites = array();
639 + if ( ! empty( $args ) ) {
640 + $args_exploded = explode( ',', $args[0] );
641 + foreach ( $args_exploded as $arg ) {
642 + if ( ! is_numeric( trim( $arg ) ) ) {
643 + \WP_CLI::error( 'Child site IDs should be numeric.' );
644 + }
657 645
658 - $ignored_themes = json_decode( $userExtension->ignored_themes, true );
659 - if ( is_array( $ignored_themes ) ) {
660 - $theme_upgrades = array_diff_key( $theme_upgrades, $ignored_themes );
661 - }
646 + $sites[] = trim( $arg );
647 + }
648 + }
662 649
663 - $tmp = array();
664 - foreach ( $theme_upgrades as $theme_upgrade ) {
665 - $tmp[] = array(
666 - 'name' => $theme_upgrade['update']['theme'],
667 - 'version' => $theme_upgrade['Version'],
668 - 'new_version' => $theme_upgrade['update']['new_version'],
669 - );
670 - }
671 - $websites_to_upgrade[] = array(
672 - 'id' => $website->id,
673 - 'name' => $website->name,
674 - 'themes' => $tmp,
675 - );
676 - }
677 - }
650 + if ( isset( $assoc_args['list'] ) ) {
651 + $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, true ) );
652 + $userExtension = MainWP_DB_Common::instance()->get_user_extension();
653 + $websites_to_upgrade = array();
654 + while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
655 + if ( ! empty( $sites ) && ( ! in_array( $website->id, $sites, true ) ) ) {
656 + continue;
657 + }
678 658
679 - $idLength = strlen( 'id' );
680 - $nameLength = strlen( 'name' );
681 - $themeLength = strlen( 'theme' );
682 - $oldVersionLength = strlen( 'version' );
683 - $newVersionLength = strlen( 'new version' );
684 - foreach ( $websites_to_upgrade as $website_to_upgrade ) {
685 - if ( $idLength < strlen( $website_to_upgrade['id'] ) ) {
686 - $idLength = strlen( $website_to_upgrade['id'] );
687 - }
688 - if ( $nameLength < strlen( $website_to_upgrade['name'] ) ) {
689 - $nameLength = strlen( $website_to_upgrade['name'] );
690 - }
659 + $theme_upgrades = json_decode( $website->theme_upgrades, true );
691 660
692 - foreach ( $website_to_upgrade['themes'] as $theme_to_upgrade ) {
693 - if ( $themeLength < strlen( $theme_to_upgrade['name'] ) ) {
694 - $themeLength = strlen( $theme_to_upgrade['name'] );
695 - }
696 - if ( $oldVersionLength < strlen( $theme_to_upgrade['version'] ) ) {
697 - $oldVersionLength = strlen( $theme_to_upgrade['version'] );
698 - }
699 - if ( $newVersionLength < strlen( $theme_to_upgrade['new_version'] ) ) {
700 - $newVersionLength = strlen( $theme_to_upgrade['new_version'] );
701 - }
702 - }
703 - }
661 + if ( is_array( $theme_upgrades ) ) {
662 + $ignored_themes = json_decode( $website->ignored_themes, true );
663 + if ( is_array( $ignored_themes ) ) {
664 + $theme_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $theme_upgrades, $ignored_themes );
665 + }
704 666
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+', '', '', '', '', '' ) );
667 + $ignored_themes = json_decode( $userExtension->ignored_themes, true );
668 + if ( is_array( $ignored_themes ) ) {
669 + $theme_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $theme_upgrades, $ignored_themes );
670 + }
708 671
709 - foreach ( $websites_to_upgrade as $website_to_upgrade ) {
710 - if ( $idLength < strlen( $website_to_upgrade['id'] ) ) {
711 - $idLength = strlen( $website_to_upgrade['id'] );
712 - }
713 - if ( $nameLength < strlen( $website_to_upgrade['name'] ) ) {
714 - $nameLength = strlen( $website_to_upgrade['name'] );
715 - }
672 + $tmp = array();
673 + foreach ( $theme_upgrades as $theme_upgrade ) {
674 + $tmp[] = array(
675 + 'name' => $theme_upgrade['update']['theme'],
676 + 'version' => $theme_upgrade['Version'],
677 + 'new_version' => $theme_upgrade['update']['new_version'],
678 + );
679 + }
680 + $websites_to_upgrade[] = array(
681 + 'id' => $website->id,
682 + 'name' => $website->name,
683 + 'themes' => $tmp,
684 + );
685 + }
686 + }
716 687
717 - $i = 0;
718 - 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'] ) );
721 - } 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'] ) );
723 - }
724 - ++$i;
725 - }
726 - }
688 + $idLength = strlen( 'id' );
689 + $nameLength = strlen( 'name' );
690 + $themeLength = strlen( 'theme' );
691 + $oldVersionLength = strlen( 'version' );
692 + $newVersionLength = strlen( 'new version' );
693 + foreach ( $websites_to_upgrade as $website_to_upgrade ) {
694 + if ( $idLength < strlen( $website_to_upgrade['id'] ) ) {
695 + $idLength = strlen( $website_to_upgrade['id'] );
696 + }
697 + if ( $nameLength < strlen( $website_to_upgrade['name'] ) ) {
698 + $nameLength = strlen( $website_to_upgrade['name'] );
699 + }
727 700
728 - \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $themeLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . "s+%'--" . ( $newVersionLength + 2 ) . 's+', '', '', '', '', '' ) );
729 - } elseif ( isset( $assoc_args['list-all'] ) ) {
730 - $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, true ) );
731 - $userExtension = MainWP_DB_Common::instance()->get_user_extension();
732 - $websites_to_upgrade = array();
733 - while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
734 - if ( ( count( $sites ) > 0 ) && ( ! in_array( $website->id, $sites, true ) ) ) {
735 - continue;
736 - }
737 - $theme_to_list = json_decode( $website->themes, true );
738 - if ( is_array( $theme_to_list ) ) {
739 - $tmp = array();
740 - foreach ( $theme_to_list as $theme ) {
741 - $tmp[] = array(
742 - 'name' => $theme['name'],
743 - 'active' => $theme['active'] ? 'yes' : '',
744 - 'version' => $theme['version'],
745 - );
746 - }
747 - $websites_to_upgrade[] = array(
748 - 'id' => $website->id,
749 - 'name' => $website->name,
750 - 'themes' => $tmp,
751 - );
752 - }
753 - }
701 + foreach ( $website_to_upgrade['themes'] as $theme_to_upgrade ) {
702 + if ( $themeLength < strlen( $theme_to_upgrade['name'] ) ) {
703 + $themeLength = strlen( $theme_to_upgrade['name'] );
704 + }
705 + if ( $oldVersionLength < strlen( $theme_to_upgrade['version'] ) ) {
706 + $oldVersionLength = strlen( $theme_to_upgrade['version'] );
707 + }
708 + if ( $newVersionLength < strlen( $theme_to_upgrade['new_version'] ) ) {
709 + $newVersionLength = strlen( $theme_to_upgrade['new_version'] );
710 + }
711 + }
712 + }
754 713
755 - $idLength = strlen( 'id' );
756 - $nameLength = strlen( 'name' );
757 - $themeLength = strlen( 'theme' );
758 - $oldVersionLength = strlen( 'version' );
759 - $activeLength = strlen( 'active' );
760 - foreach ( $websites_to_upgrade as $website_item ) {
761 - if ( $idLength < strlen( $website_item['id'] ) ) {
762 - $idLength = strlen( $website_item['id'] );
763 - }
764 - if ( $nameLength < strlen( $website_item['name'] ) ) {
765 - $nameLength = strlen( $website_item['name'] );
766 - }
714 + \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $themeLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . "s+%'--" . ( $newVersionLength + 2 ) . 's+', '', '', '', '', '' ) );
715 + \WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $themeLength . 's | %-' . $oldVersionLength . 's | %-' . $newVersionLength . 's |', 'id', 'name', 'theme', 'version', 'new version' ) );
716 + \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $themeLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . "s+%'--" . ( $newVersionLength + 2 ) . 's+', '', '', '', '', '' ) );
767 717
768 - foreach ( $website_item['themes'] as $theme_item ) {
769 - if ( $themeLength < strlen( $theme_item['name'] ) ) {
770 - $themeLength = strlen( $theme_item['name'] );
771 - }
772 - if ( $oldVersionLength < strlen( $theme_item['version'] ) ) {
773 - $oldVersionLength = strlen( $theme_item['version'] );
774 - }
775 - }
776 - }
718 + foreach ( $websites_to_upgrade as $website_to_upgrade ) {
719 + if ( $idLength < strlen( $website_to_upgrade['id'] ) ) {
720 + $idLength = strlen( $website_to_upgrade['id'] );
721 + }
722 + if ( $nameLength < strlen( $website_to_upgrade['name'] ) ) {
723 + $nameLength = strlen( $website_to_upgrade['name'] );
724 + }
777 725
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+', '', '', '', '', '' ) );
726 + $i = 0;
727 + foreach ( $website_to_upgrade['themes'] as $theme_to_upgrade ) {
728 + if ( 0 === $i ) {
729 + \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'] ) );
730 + } else {
731 + \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'] ) );
732 + }
733 + ++$i;
734 + }
735 + }
781 736
782 - foreach ( $websites_to_upgrade as $website_item ) {
783 - if ( $idLength < strlen( $website_item['id'] ) ) {
784 - $idLength = strlen( $website_item['id'] );
785 - }
786 - if ( $nameLength < strlen( $website_item['name'] ) ) {
787 - $nameLength = strlen( $website_item['name'] );
788 - }
737 + \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $themeLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . "s+%'--" . ( $newVersionLength + 2 ) . 's+', '', '', '', '', '' ) );
738 + } elseif ( isset( $assoc_args['list-all'] ) ) {
739 + $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, true ) );
740 + $userExtension = MainWP_DB_Common::instance()->get_user_extension();
741 + $websites_to_upgrade = array();
742 + while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
743 + if ( ! empty( $sites ) && ( ! in_array( $website->id, $sites, true ) ) ) {
744 + continue;
745 + }
746 + $theme_to_list = json_decode( $website->themes, true );
747 + if ( is_array( $theme_to_list ) ) {
748 + $tmp = array();
749 + foreach ( $theme_to_list as $theme ) {
750 + $tmp[] = array(
751 + 'name' => $theme['name'],
752 + 'active' => $theme['active'] ? 'yes' : '',
753 + 'version' => $theme['version'],
754 + );
755 + }
756 + $websites_to_upgrade[] = array(
757 + 'id' => $website->id,
758 + 'name' => $website->name,
759 + 'themes' => $tmp,
760 + );
761 + }
762 + }
789 763
790 - $i = 0;
791 - 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'] ) );
794 - } 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'] ) );
796 - }
797 - ++$i;
798 - }
799 - }
764 + $idLength = strlen( 'id' );
765 + $nameLength = strlen( 'name' );
766 + $themeLength = strlen( 'theme' );
767 + $oldVersionLength = strlen( 'version' );
768 + $activeLength = strlen( 'active' );
769 + foreach ( $websites_to_upgrade as $website_item ) {
770 + if ( $idLength < strlen( $website_item['id'] ) ) {
771 + $idLength = strlen( $website_item['id'] );
772 + }
773 + if ( $nameLength < strlen( $website_item['name'] ) ) {
774 + $nameLength = strlen( $website_item['name'] );
775 + }
800 776
801 - \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $themeLength + 2 ) . "s+%'--" . ( $activeLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . 's+', '', '', '', '', '' ) );
802 - } elseif ( isset( $assoc_args['upgrade'] ) || isset( $assoc_args['upgrade-all'] ) ) {
777 + foreach ( $website_item['themes'] as $theme_item ) {
778 + if ( $themeLength < strlen( $theme_item['name'] ) ) {
779 + $themeLength = strlen( $theme_item['name'] );
780 + }
781 + if ( $oldVersionLength < strlen( $theme_item['version'] ) ) {
782 + $oldVersionLength = strlen( $theme_item['version'] );
783 + }
784 + }
785 + }
803 786
804 - $themeSlugs = array();
805 - if ( isset( $assoc_args['upgrade'] ) ) {
806 - $themeSlugs = explode( ',', $assoc_args['upgrade'] );
807 - }
787 + \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $themeLength + 2 ) . "s+%'--" . ( $activeLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . 's+', '', '', '', '', '' ) );
788 + \WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $themeLength . 's | %-' . $activeLength . 's | %-' . $oldVersionLength . 's |', 'id', 'name', 'theme', 'active', 'version' ) );
789 + \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $themeLength + 2 ) . "s+%'--" . ( $activeLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . 's+', '', '', '', '', '' ) );
808 790
809 - $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, true ) );
810 - $userExtension = MainWP_DB_Common::instance()->get_user_extension();
811 - while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
812 - if ( ( count( $sites ) > 0 ) && ( ! in_array( $website->id, $sites, true ) ) ) {
813 - continue;
814 - }
791 + foreach ( $websites_to_upgrade as $website_item ) {
792 + if ( $idLength < strlen( $website_item['id'] ) ) {
793 + $idLength = strlen( $website_item['id'] );
794 + }
795 + if ( $nameLength < strlen( $website_item['name'] ) ) {
796 + $nameLength = strlen( $website_item['name'] );
797 + }
815 798
816 - $theme_upgrades = json_decode( $website->theme_upgrades, true );
799 + $i = 0;
800 + foreach ( $website_item['themes'] as $theme_item ) {
801 + if ( 0 === $i ) {
802 + \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'] ) );
803 + } else {
804 + \WP_CLI::line( sprintf( '| %-' . $idLength . 's | %-' . $nameLength . 's | %-' . $themeLength . 's | %-' . $activeLength . 's | %-' . $oldVersionLength . 's |', '', '', $theme_item['name'], $theme_item['active'], $theme_item['version'] ) );
805 + }
806 + ++$i;
807 + }
808 + }
817 809
818 - if ( is_array( $theme_upgrades ) ) {
819 - $ignored_themes = json_decode( $website->ignored_themes, true );
820 - if ( is_array( $ignored_themes ) ) {
821 - $theme_upgrades = array_diff_key( $theme_upgrades, $ignored_themes );
822 - }
810 + \WP_CLI::line( sprintf( "+%'--" . ( $idLength + 2 ) . "s+%'--" . ( $nameLength + 2 ) . "s+%'--" . ( $themeLength + 2 ) . "s+%'--" . ( $activeLength + 2 ) . "s+%'--" . ( $oldVersionLength + 2 ) . 's+', '', '', '', '', '' ) );
811 + } elseif ( isset( $assoc_args['upgrade'] ) || isset( $assoc_args['upgrade-all'] ) ) {
823 812
824 - $ignored_themes = json_decode( $userExtension->ignored_themes, true );
825 - if ( is_array( $ignored_themes ) ) {
826 - $theme_upgrades = array_diff_key( $theme_upgrades, $ignored_themes );
827 - }
813 + $themeSlugs = array();
814 + if ( isset( $assoc_args['upgrade'] ) ) {
815 + $themeSlugs = explode( ',', $assoc_args['upgrade'] );
816 + }
828 817
829 - $tmp = array();
830 - foreach ( $theme_upgrades as $key => $theme_upgrade ) {
831 - if ( ( count( $themeSlugs ) > 0 ) && ( ! in_array( $theme_upgrade['update']['slug'], $themeSlugs, true ) ) ) {
832 - continue;
833 - }
818 + $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, true ) );
819 + $userExtension = MainWP_DB_Common::instance()->get_user_extension();
820 + while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
821 + if ( ! empty( $sites ) && ( ! in_array( $website->id, $sites, true ) ) ) {
822 + continue;
823 + }
834 824
835 - $tmp[] = $key;
836 - }
825 + $theme_upgrades = json_decode( $website->theme_upgrades, true );
837 826
838 - if ( 0 === count( $tmp ) ) {
839 - \WP_CLI::line( 'No available theme updates for ' . $website->name );
827 + if ( is_array( $theme_upgrades ) ) {
828 + $ignored_themes = json_decode( $website->ignored_themes, true );
829 + if ( is_array( $ignored_themes ) ) {
830 + $theme_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $theme_upgrades, $ignored_themes );
831 + }
840 832
841 - continue;
842 - }
833 + $ignored_themes = json_decode( $userExtension->ignored_themes, true );
834 + if ( is_array( $ignored_themes ) ) {
835 + $theme_upgrades = MainWP_Common_Functions::instance()->get_not_ignored_updates_themesplugins( $theme_upgrades, $ignored_themes );
836 + }
843 837
844 - \WP_CLI::line( 'Updating ' . count( $tmp ) . ' themes for ' . $website->name );
838 + $tmp = array();
839 + foreach ( $theme_upgrades as $key => $theme_upgrade ) {
840 + if ( ! empty( $themeSlugs ) && ( ! in_array( $theme_upgrade['update']['slug'], $themeSlugs, true ) ) ) {
841 + continue;
842 + }
845 843
846 - try {
847 - MainWP_Updates_Handler::upgrade_plugin_theme_translation( $website->id, 'theme', implode( ',', $tmp ) );
848 - \WP_CLI::success( 'Updates completed' );
849 - } 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 ) );
853 - }
854 - }
855 - }
856 - }
857 - }
858 - }
844 + $tmp[] = $key;
845 + }
846 +
847 + if ( empty( $tmp ) ) {
848 + \WP_CLI::line( 'No available theme updates for ' . $website->name );
849 +
850 + continue;
851 + }
852 +
853 + \WP_CLI::line( 'Updating ' . count( $tmp ) . ' themes for ' . $website->name );
854 +
855 + try {
856 + MainWP_Updates_Handler::upgrade_plugin_theme_translation( $website->id, 'theme', implode( ',', $tmp ) );
857 + \WP_CLI::success( 'Updates completed' );
858 + } catch ( \Exception $e ) {
859 + \WP_CLI::error( 'Updates failed: ' . MainWP_Error_Helper::get_console_error_message( $e ) );
860 + if ( $e->getMesage() === 'WPERROR' ) {
861 + \WP_CLI::debug( 'Error: ' . MainWP_Utility::value_to_string( $e->get_message_extra(), 1 ) );
862 + }
863 + }
864 + }
865 + }
866 + }
867 + }
859 868 }