| @@ -15,64 +15,27 @@ | ||
| 15 | 15 | * @package MainWP\Dashboard |
| 16 | 16 | */ |
| 17 | 17 | class MainWP_Sync { |
| 18 | 18 | |
| 19 | - | |
| 20 | 19 | /** |
| 21 | - * Method sync_website() | |
| 22 | - * | |
| 23 | - * Sync Child Site. | |
| 24 | - * | |
| 25 | - * @param object $website object. | |
| 26 | - * @param bool $clear_session to run the ending session or not. | |
| 27 | - * | |
| 28 | - * @return bool sync result. | |
| 29 | - */ | |
| 30 | - public static function sync_website( $website, $clear_session = true ) { | |
| 31 | - if ( ! is_object( $website ) ) { | |
| 32 | - return false; | |
| 33 | - } | |
| 34 | - MainWP_DB::instance()->update_website_sync_values( $website->id, array( 'dtsSyncStart' => time() ) ); | |
| 35 | - return self::sync_site( $website, false, true, $clear_session ); | |
| 36 | - } | |
| 37 | - | |
| 38 | - /** | |
| 39 | 20 | * Method sync_site() |
| 40 | 21 | * |
| 41 | - * @param mixed $pWebsite Null|userid. | |
| 42 | - * @param bool $pForceFetch Check if a fourced Sync. | |
| 22 | + * @param mixed $pWebsite Null|userid. | |
| 23 | + * @param bool $pForceFetch Check if a fourced Sync. | |
| 43 | 24 | * @param bool $pAllowDisconnect Check if allowed to disconect. |
| 44 | - * @param bool $clear_session to run the ending session or not. | |
| 45 | 25 | * |
| 46 | - * @return bool sync_information_array | |
| 47 | - * | |
| 48 | - * @uses \MainWP\Dashboard\MainWP_DB_Common::get_user_extension_by_user_id() | |
| 49 | - * @uses \MainWP\Dashboard\MainWP_DB::query() | |
| 50 | - * @uses \MainWP\Dashboard\MainWP_DB::update_website_option() | |
| 51 | - * @uses \MainWP\Dashboard\MainWP_DB::fetch_object() | |
| 52 | - * @uses \MainWP\Dashboard\MainWP_DB::free_result() | |
| 53 | - * @uses \MainWP\Dashboard\MainWP_Exception | |
| 54 | - * @uses \MainWP\Dashboard\MainWP_System_Utility::get_primary_backup() | |
| 55 | - * @uses \MainWP\Dashboard\MainWP_Utility::end_session() | |
| 26 | + * @return array sync_information_array | |
| 56 | 27 | */ |
| 57 | - public static function sync_site( &$pWebsite = null, $pForceFetch = false, $pAllowDisconnect = true, $clear_session = true ) { // phpcs:ignore -- complexity method. | |
| 58 | - | |
| 59 | - // to support demo data. | |
| 60 | - if ( MainWP_Demo_Handle::get_instance()->is_demo_website( $pWebsite ) ) { | |
| 61 | - return MainWP_Demo_Handle::get_instance()->handle_action_demo( $pWebsite, 'sync_site' ); | |
| 62 | - } | |
| 63 | - | |
| 64 | - if ( null === $pWebsite ) { | |
| 28 | + public static function sync_site( &$pWebsite = null, $pForceFetch = false, $pAllowDisconnect = true ) { | |
| 29 | + if ( null == $pWebsite ) { | |
| 65 | 30 | return false; |
| 66 | 31 | } |
| 67 | 32 | $userExtension = MainWP_DB_Common::instance()->get_user_extension_by_user_id( $pWebsite->userid ); |
| 68 | - if ( null === $userExtension ) { | |
| 33 | + if ( null == $userExtension ) { | |
| 69 | 34 | return false; |
| 70 | 35 | } |
| 71 | 36 | |
| 72 | - if ( $clear_session ) { | |
| 73 | - MainWP_Utility::end_session(); | |
| 74 | - } | |
| 37 | + MainWP_Utility::end_session(); | |
| 75 | 38 | |
| 76 | 39 | try { |
| 77 | 40 | |
| 78 | 41 | /** |
| @@ -83,11 +46,8 @@ | ||
| 83 | 46 | * @since Unknown |
| 84 | 47 | */ |
| 85 | 48 | $cloneEnabled = apply_filters( 'mainwp_clone_enabled', false ); |
| 86 | 49 | $cloneSites = array(); |
| 87 | - | |
| 88 | - $disallowed_current_site = false; | |
| 89 | - | |
| 90 | 50 | if ( $cloneEnabled ) { |
| 91 | 51 | $disallowedCloneSites = get_option( 'mainwp_clone_disallowedsites' ); |
| 92 | 52 | if ( false === $disallowedCloneSites ) { |
| 93 | 53 | $disallowedCloneSites = array(); |
| @@ -97,23 +57,21 @@ | ||
| 97 | 57 | while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) { |
| 98 | 58 | if ( in_array( $website->id, $disallowedCloneSites ) ) { |
| 99 | 59 | continue; |
| 100 | 60 | } |
| 101 | - if ( (int) $website->id === (int) $pWebsite->id ) { | |
| 61 | + if ( $website->id == $pWebsite->id ) { | |
| 102 | 62 | continue; |
| 103 | 63 | } |
| 104 | 64 | |
| 105 | 65 | $cloneSites[ $website->id ] = array( |
| 106 | - 'name' => $website->name, | |
| 107 | - 'url' => $website->url, | |
| 108 | - 'extauth' => $website->extauth, | |
| 109 | - 'size' => $website->totalsize, | |
| 110 | - 'connect_admin' => $website->adminname, | |
| 66 | + 'name' => $website->name, | |
| 67 | + 'url' => $website->url, | |
| 68 | + 'extauth' => $website->extauth, | |
| 69 | + 'size' => $website->totalsize, | |
| 111 | 70 | ); |
| 112 | 71 | } |
| 113 | 72 | MainWP_DB::free_result( $websites ); |
| 114 | 73 | } |
| 115 | - $disallowed_current_site = in_array( $pWebsite->id, $disallowedCloneSites ) ? true : false; | |
| 116 | 74 | } |
| 117 | 75 | |
| 118 | 76 | $primaryBackup = MainWP_System_Utility::get_primary_backup(); |
| 119 | 77 | |
| @@ -126,50 +84,42 @@ | ||
| 126 | 84 | * |
| 127 | 85 | * @param object $pWebsite Object contaning child site data. |
| 128 | 86 | * |
| 129 | 87 | * @since Unknown |
| 130 | - * | |
| 131 | - * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed() | |
| 132 | 88 | */ |
| 133 | 89 | $othersData = apply_filters( 'mainwp_sync_others_data', $othersData, $pWebsite ); |
| 134 | 90 | |
| 135 | - $saved_days_number = apply_filters( 'mainwp_site_actions_saved_days_number', 30 ); | |
| 136 | - | |
| 137 | - $postdata = array( | |
| 138 | - 'optimize' => 1 === (int) get_option( 'mainwp_optimize', 1 ) ? 1 : 0, | |
| 139 | - 'cloneSites' => ( ! $cloneEnabled || $disallowed_current_site ? 0 : rawurlencode( wp_json_encode( $cloneSites ) ) ), | |
| 140 | - 'othersData' => wp_json_encode( $othersData ), | |
| 141 | - 'server' => get_admin_url(), | |
| 142 | - 'numberdaysOutdatePluginTheme' => get_option( 'mainwp_numberdays_Outdate_Plugin_Theme', 365 ), | |
| 143 | - 'primaryBackup' => $primaryBackup, | |
| 144 | - 'siteId' => $pWebsite->id, | |
| 145 | - 'child_actions_saved_days_number' => intval( $saved_days_number ), | |
| 146 | - 'pingnonce' => MainWP_Utility::instance()->create_site_nonce( 'pingnonce', $pWebsite->id ), | |
| 147 | - ); | |
| 148 | - | |
| 149 | 91 | $information = MainWP_Connect::fetch_url_authed( |
| 150 | 92 | $pWebsite, |
| 151 | 93 | 'stats', |
| 152 | - $postdata, | |
| 94 | + array( | |
| 95 | + 'optimize' => ( ( get_option( 'mainwp_optimize' ) == 1 ) ? 1 : 0 ), | |
| 96 | + 'cloneSites' => ( ! $cloneEnabled ? 0 : rawurlencode( wp_json_encode( $cloneSites ) ) ), | |
| 97 | + 'othersData' => wp_json_encode( $othersData ), | |
| 98 | + 'server' => get_admin_url(), | |
| 99 | + 'numberdaysOutdatePluginTheme' => get_option( 'mainwp_numberdays_Outdate_Plugin_Theme', 365 ), | |
| 100 | + 'primaryBackup' => $primaryBackup, | |
| 101 | + 'siteId' => $pWebsite->id, | |
| 102 | + ), | |
| 153 | 103 | true, |
| 154 | 104 | $pForceFetch |
| 155 | 105 | ); |
| 156 | - $return = self::sync_information_array( $pWebsite, $information, '', 1, false, $pAllowDisconnect ); | |
| 157 | - MainWP_Logger::instance()->log_execution_time( 'sync :: [siteid=' . $pWebsite->id . ']' ); | |
| 106 | + MainWP_DB::instance()->update_website_option( $pWebsite, 'primary_lasttime_backup', isset( $information['primaryLasttimeBackup'] ) ? $information['primaryLasttimeBackup'] : 0 ); | |
| 107 | + $return = self::sync_information_array( $pWebsite, $information, '', 1, false, $pAllowDisconnect ); | |
| 108 | + | |
| 158 | 109 | return $return; |
| 159 | 110 | } catch ( MainWP_Exception $e ) { |
| 160 | 111 | $sync_errors = ''; |
| 161 | 112 | $check_result = 1; |
| 162 | 113 | |
| 163 | - if ( $e->getMessage() === 'HTTPERROR' ) { | |
| 164 | - $sync_errors = esc_html__( 'HTTP error', 'mainwp' ) . ( ! empty( $e->get_message_extra() ) ? ' - ' . $e->get_message_extra() : '' ); | |
| 114 | + if ( $e->getMessage() == 'HTTPERROR' ) { | |
| 115 | + $sync_errors = __( 'HTTP error', 'mainwp' ) . ( $e->get_message_extra() != null ? ' - ' . $e->get_message_extra() : '' ); | |
| 165 | 116 | $check_result = - 1; |
| 166 | - } elseif ( $e->getMessage() === 'NOMAINWP' ) { | |
| 167 | - $sync_errors = MainWP_Error_Helper::get_error_not_detected_connect(); | |
| 117 | + } elseif ( $e->getMessage() == 'NOMAINWP' ) { | |
| 118 | + $sync_errors = __( 'MainWP Child plugin not detected', 'mainwp' ); | |
| 168 | 119 | $check_result = 1; |
| 169 | 120 | } |
| 170 | 121 | |
| 171 | - MainWP_Logger::instance()->log_execution_time( 'sync :: [siteid=' . $pWebsite->id . ']' ); | |
| 172 | 122 | return self::sync_information_array( $pWebsite, $information, $sync_errors, $check_result, true, $pAllowDisconnect ); |
| 173 | 123 | } |
| 174 | 124 | } |
| 175 | 125 | |
| @@ -185,16 +135,8 @@ | ||
| 185 | 135 | * @param bool $error True|False. |
| 186 | 136 | * @param bool $pAllowDisconnect True|False. |
| 187 | 137 | * |
| 188 | 138 | * @return bool true|false True on success, false on failure. |
| 189 | - * | |
| 190 | - * @uses \MainWP\Dashboard\MainWP_DB::update_website_option() | |
| 191 | - * @uses \MainWP\Dashboard\MainWP_DB::update_website_sync_values() | |
| 192 | - * @uses \MainWP\Dashboard\MainWP_DB::update_website_values() | |
| 193 | - * @uses \MainWP\Dashboard\MainWP_Logger::warning_for_website() | |
| 194 | - * @uses \MainWP\Dashboard\MainWP_Monitoring_Handler::get_health_noticed_status_value() | |
| 195 | - * @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit() | |
| 196 | - * @uses \MainWP\Dashboard\MainWP_Utility::get_site_health() | |
| 197 | 139 | */ |
| 198 | 140 | public static function sync_information_array( &$pWebsite, &$information, $sync_errors = '', $check_result = 1, $error = false, $pAllowDisconnect = true ) { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated. |
| 199 | 141 | $emptyArray = wp_json_encode( array() ); |
| 200 | 142 | $websiteValues = array( |
| @@ -213,30 +155,16 @@ | ||
| 213 | 155 | 'sync_errors' => $sync_errors, |
| 214 | 156 | 'version' => 0, |
| 215 | 157 | ); |
| 216 | 158 | |
| 217 | - $_error = $sync_errors; | |
| 218 | - | |
| 219 | 159 | $done = false; |
| 220 | 160 | |
| 221 | - $current_siteid = 0; | |
| 222 | - if ( is_string( $pWebsite ) || is_int( $pWebsite ) ) { | |
| 223 | - $current_siteid = intval( $pWebsite ); | |
| 224 | - } elseif ( is_object( $pWebsite ) && ( ! property_exists( $pWebsite, 'plugin_updates' ) || ! property_exists( $pWebsite, 'theme_updates' ) ) ) { | |
| 225 | - $current_siteid = $pWebsite->id; | |
| 226 | - } | |
| 227 | - | |
| 228 | - // to get full data. | |
| 229 | - if ( $current_siteid ) { | |
| 230 | - $pWebsite = MainWP_DB::instance()->get_website_by_id( $current_siteid ); | |
| 231 | - } | |
| 232 | - | |
| 233 | 161 | /** |
| 234 | 162 | * Filter: mainwp_before_save_sync_result |
| 235 | 163 | * |
| 236 | - * Filters data returned from child site before saving to the database. | |
| 164 | + * Filters data returned from child site before sasving to the database. | |
| 237 | 165 | * |
| 238 | - * @param object $pWebsite Object containing child site data. | |
| 166 | + * @param object $pWebsite Object contaning child site data. | |
| 239 | 167 | * |
| 240 | 168 | * @since 3.4 |
| 241 | 169 | */ |
| 242 | 170 | $information = apply_filters( 'mainwp_before_save_sync_result', $information, $pWebsite ); |
| @@ -251,23 +179,19 @@ | ||
| 251 | 179 | $done = true; |
| 252 | 180 | } |
| 253 | 181 | |
| 254 | 182 | $phpversion = ''; |
| 255 | - if ( isset( $information['site_info'] ) && ! empty( $information['site_info'] ) ) { | |
| 183 | + if ( isset( $information['site_info'] ) && null != $information['site_info'] ) { | |
| 256 | 184 | if ( is_array( $information['site_info'] ) && isset( $information['site_info']['phpversion'] ) ) { |
| 257 | 185 | $phpversion = $information['site_info']['phpversion']; |
| 258 | 186 | } |
| 259 | - if ( is_array( $information['site_info'] ) && isset( $information['site_info']['ip'] ) ) { | |
| 260 | - $websiteValues['ip'] = sanitize_text_field( wp_unslash( $information['site_info']['ip'] ) ); | |
| 261 | - } | |
| 262 | 187 | MainWP_DB::instance()->update_website_option( $pWebsite, 'site_info', wp_json_encode( $information['site_info'] ) ); |
| 263 | 188 | $done = true; |
| 264 | 189 | } else { |
| 265 | 190 | MainWP_DB::instance()->update_website_option( $pWebsite, 'site_info', $emptyArray ); |
| 266 | 191 | } |
| 267 | - if ( ! empty( $phpversion ) ) { | |
| 268 | - MainWP_DB::instance()->update_website_option( $pWebsite, 'phpversion', $phpversion ); | |
| 269 | - } | |
| 192 | + MainWP_DB::instance()->update_website_option( $pWebsite, 'phpversion', $phpversion ); | |
| 193 | + | |
| 270 | 194 | if ( isset( $information['directories'] ) && is_array( $information['directories'] ) ) { |
| 271 | 195 | $websiteValues['directories'] = wp_json_encode( $information['directories'] ); |
| 272 | 196 | $done = true; |
| 273 | 197 | } elseif ( isset( $information['directories'] ) ) { |
| @@ -274,9 +198,9 @@ | ||
| 274 | 198 | $websiteValues['directories'] = $information['directories']; |
| 275 | 199 | $done = true; |
| 276 | 200 | } |
| 277 | 201 | |
| 278 | - if ( isset( $information['wp_updates'] ) && ! empty( $information['wp_updates'] ) ) { | |
| 202 | + if ( isset( $information['wp_updates'] ) && null != $information['wp_updates'] ) { | |
| 279 | 203 | MainWP_DB::instance()->update_website_option( |
| 280 | 204 | $pWebsite, |
| 281 | 205 | 'wp_upgrades', |
| 282 | 206 | wp_json_encode( |
| @@ -291,26 +215,14 @@ | ||
| 291 | 215 | MainWP_DB::instance()->update_website_option( $pWebsite, 'wp_upgrades', $emptyArray ); |
| 292 | 216 | } |
| 293 | 217 | |
| 294 | 218 | if ( isset( $information['plugin_updates'] ) ) { |
| 295 | - $update_values = array(); | |
| 296 | - if ( is_array( $information['plugin_updates'] ) ) { | |
| 297 | - foreach ( $information['plugin_updates'] as $file => $update ) { | |
| 298 | - $update_values[ $file ] = $update; | |
| 299 | - } | |
| 300 | - } | |
| 301 | - $websiteValues['plugin_upgrades'] = wp_json_encode( $update_values ); | |
| 219 | + $websiteValues['plugin_upgrades'] = wp_json_encode( $information['plugin_updates'] ); | |
| 302 | 220 | $done = true; |
| 303 | 221 | } |
| 304 | 222 | |
| 305 | 223 | if ( isset( $information['theme_updates'] ) ) { |
| 306 | - $update_values = array(); | |
| 307 | - if ( is_array( $information['theme_updates'] ) ) { | |
| 308 | - foreach ( $information['theme_updates'] as $file => $update ) { | |
| 309 | - $update_values[ $file ] = $update; | |
| 310 | - } | |
| 311 | - } | |
| 312 | - $websiteValues['theme_upgrades'] = wp_json_encode( $update_values ); | |
| 224 | + $websiteValues['theme_upgrades'] = wp_json_encode( $information['theme_updates'] ); | |
| 313 | 225 | $done = true; |
| 314 | 226 | } |
| 315 | 227 | |
| 316 | 228 | if ( isset( $information['translation_updates'] ) ) { |
| @@ -334,22 +246,12 @@ | ||
| 334 | 246 | if ( false !== $filterStats && is_array( $filterStats ) ) { |
| 335 | 247 | $securityStats = array_merge( $securityStats, $filterStats ); |
| 336 | 248 | } |
| 337 | 249 | |
| 338 | - $unset_scripts = apply_filters( 'mainwp_unset_security_scripts_stylesheets', true ); | |
| 339 | - if ( $unset_scripts ) { | |
| 340 | - if ( isset( $securityStats['versions'] ) ) { | |
| 341 | - unset( $securityStats['versions'] ); | |
| 342 | - } | |
| 343 | - if ( isset( $securityStats['registered_versions'] ) ) { | |
| 344 | - unset( $securityStats['registered_versions'] ); | |
| 345 | - } | |
| 346 | - } | |
| 347 | - | |
| 348 | 250 | $tmp_issues = array_filter( |
| 349 | 251 | $securityStats, |
| 350 | - function ( $v ) { | |
| 351 | - return 'N' === $v; | |
| 252 | + function( $v, $k ) { | |
| 253 | + return 'N' == $v; | |
| 352 | 254 | }, |
| 353 | 255 | ARRAY_FILTER_USE_BOTH |
| 354 | 256 | ); |
| 355 | 257 | $total_securityIssues = count( $tmp_issues ); |
| @@ -357,10 +259,9 @@ | ||
| 357 | 259 | } else { |
| 358 | 260 | $securityStats = $emptyArray; |
| 359 | 261 | } |
| 360 | 262 | $websiteValues['securityIssues'] = $total_securityIssues; |
| 361 | - MainWP_DB::instance()->update_website_option( $pWebsite, 'security_stats', $securityStats ); | |
| 362 | - $done = true; | |
| 263 | + $done = true; | |
| 363 | 264 | } elseif ( isset( $information['securityIssues'] ) && MainWP_Utility::ctype_digit( $information['securityIssues'] ) && $information['securityIssues'] >= 0 ) { |
| 364 | 265 | $websiteValues['securityIssues'] = $information['securityIssues']; |
| 365 | 266 | $done = true; |
| 366 | 267 | } |
| @@ -400,12 +301,9 @@ | ||
| 400 | 301 | $websiteValues['users'] = wp_json_encode( $information['users'] ); |
| 401 | 302 | $done = true; |
| 402 | 303 | } |
| 403 | 304 | |
| 404 | - if ( isset( $information['categories_list'] ) ) { | |
| 405 | - $websiteValues['categories'] = wp_json_encode( $information['categories_list'] ); | |
| 406 | - $done = true; | |
| 407 | - } elseif ( isset( $information['categories'] ) ) { // support old child version. | |
| 305 | + if ( isset( $information['categories'] ) ) { | |
| 408 | 306 | $websiteValues['categories'] = wp_json_encode( $information['categories'] ); |
| 409 | 307 | $done = true; |
| 410 | 308 | } |
| 411 | 309 | |
| @@ -423,17 +321,18 @@ | ||
| 423 | 321 | $websiteSyncValues['extauth'] = $information['extauth']; |
| 424 | 322 | $done = true; |
| 425 | 323 | } |
| 426 | 324 | |
| 325 | + if ( isset( $information['nossl'] ) ) { | |
| 326 | + $websiteValues['nossl'] = $information['nossl']; | |
| 327 | + $done = true; | |
| 328 | + } | |
| 329 | + | |
| 427 | 330 | if ( isset( $information['wpe'] ) ) { |
| 428 | 331 | $websiteValues['wpe'] = $information['wpe']; |
| 429 | 332 | $done = true; |
| 430 | 333 | } |
| 431 | 334 | |
| 432 | - if ( isset( $information['wphost'] ) ) { | |
| 433 | - MainWP_DB::instance()->update_website_option( $pWebsite, 'wphost', $information['wphost'] ); | |
| 434 | - } | |
| 435 | - | |
| 436 | 335 | if ( isset( $information['last_post_gmt'] ) ) { |
| 437 | 336 | $websiteSyncValues['last_post_gmt'] = $information['last_post_gmt']; |
| 438 | 337 | $done = true; |
| 439 | 338 | } |
| @@ -440,13 +339,13 @@ | ||
| 440 | 339 | |
| 441 | 340 | if ( isset( $information['health_site_status'] ) ) { |
| 442 | 341 | $health_status = $information['health_site_status']; |
| 443 | 342 | $hstatus = MainWP_Utility::get_site_health( $health_status ); |
| 444 | - $custom_health_value = $hstatus['val'] - $hstatus['critical'] * 100; // computes custom health value to support sorting by sites health and sites health threshold. | |
| 445 | - $websiteSyncValues['health_value'] = $custom_health_value; | |
| 343 | + $new_health_value = $hstatus['val'] - $hstatus['critical'] * 100; // computes custom health value to support sorting by sites health and sites health threshold. | |
| 344 | + $websiteSyncValues['health_value'] = $new_health_value; | |
| 446 | 345 | $done = true; |
| 447 | 346 | MainWP_DB::instance()->update_website_option( $pWebsite, 'health_site_status', wp_json_encode( $health_status ) ); |
| 448 | - $new_noticed = MainWP_Monitoring_Handler::get_health_noticed_status_value( $pWebsite, $custom_health_value ); | |
| 347 | + $new_noticed = MainWP_Monitoring_Handler::get_health_noticed_status_value( $pWebsite, $new_health_value ); | |
| 449 | 348 | if ( null !== $new_noticed ) { |
| 450 | 349 | MainWP_DB::instance()->update_website_sync_values( |
| 451 | 350 | $pWebsite->id, |
| 452 | 351 | array( |
| @@ -453,18 +352,8 @@ | ||
| 453 | 352 | 'health_site_noticed' => $new_noticed, |
| 454 | 353 | ) |
| 455 | 354 | ); |
| 456 | 355 | } |
| 457 | - | |
| 458 | - $hval = $hstatus['val']; | |
| 459 | - $critical = $hstatus['critical']; | |
| 460 | - $health_status = 0; | |
| 461 | - if ( 80 <= $hval && empty( $critical ) ) { | |
| 462 | - $health_status = 0; // Good. | |
| 463 | - } else { | |
| 464 | - $health_status = 1; // Should be improved'. | |
| 465 | - } | |
| 466 | - $websiteSyncValues['health_status'] = $health_status; | |
| 467 | 356 | } else { |
| 468 | 357 | MainWP_DB::instance()->update_website_option( $pWebsite, 'health_site_status', $emptyArray ); |
| 469 | 358 | } |
| 470 | 359 | |
| @@ -477,13 +366,8 @@ | ||
| 477 | 366 | $websiteValues['uniqueId'] = $information['uniqueId']; |
| 478 | 367 | $done = true; |
| 479 | 368 | } |
| 480 | 369 | |
| 481 | - if ( isset( $information['clone_adminname'] ) ) { | |
| 482 | - $websiteValues['adminname'] = $information['clone_adminname']; | |
| 483 | - $done = true; | |
| 484 | - } | |
| 485 | - | |
| 486 | 370 | if ( isset( $information['admin_nicename'] ) ) { |
| 487 | 371 | MainWP_DB::instance()->update_website_option( $pWebsite, 'admin_nicename', trim( $information['admin_nicename'] ) ); |
| 488 | 372 | $done = true; |
| 489 | 373 | } |
| @@ -506,34 +390,20 @@ | ||
| 506 | 390 | } else { |
| 507 | 391 | MainWP_DB::instance()->update_website_option( $pWebsite, 'themes_outdate_info', $emptyArray ); |
| 508 | 392 | } |
| 509 | 393 | |
| 510 | - if ( isset( $information['primaryLasttimeBackup'] ) ) { | |
| 511 | - MainWP_DB::instance()->update_website_option( $pWebsite, 'primary_lasttime_backup', $information['primaryLasttimeBackup'] ); | |
| 512 | - $done = true; | |
| 513 | - } | |
| 514 | - | |
| 515 | - if ( isset( $information['child_site_actions_data'] ) ) { | |
| 516 | - if ( is_array( $information['child_site_actions_data'] ) && isset( $information['child_site_actions_data']['connected_admin'] ) ) { | |
| 517 | - unset( $information['child_site_actions_data']['connected_admin'] ); | |
| 518 | - } | |
| 519 | - MainWP_DB_Site_Actions::instance()->sync_site_actions( $pWebsite->id, $information['child_site_actions_data'] ); | |
| 520 | - $done = true; | |
| 521 | - } | |
| 522 | - | |
| 523 | 394 | if ( ! $done ) { |
| 524 | 395 | if ( isset( $information['wpversion'] ) ) { |
| 525 | 396 | $done = true; |
| 526 | 397 | } elseif ( isset( $information['error'] ) ) { |
| 527 | - MainWP_Logger::instance()->warning_for_website( $pWebsite, 'SYNC ERROR', '[' . esc_html( $information['error'] ) . ']' ); | |
| 398 | + MainWP_Logger::instance()->warning_for_website( $pWebsite, 'SYNC ERROR', '[' . $information['error'] . ']' ); | |
| 528 | 399 | $error = true; |
| 529 | 400 | $done = true; |
| 530 | - $_error = esc_html__( 'ERROR: ', 'mainwp' ) . esc_html( $information['error'] ); | |
| 531 | - $websiteSyncValues['sync_errors'] = $_error; | |
| 401 | + $websiteSyncValues['sync_errors'] = __( 'ERROR: ', 'mainwp' ) . $information['error']; | |
| 532 | 402 | } elseif ( ! empty( $sync_errors ) ) { |
| 533 | 403 | MainWP_Logger::instance()->warning_for_website( $pWebsite, 'SYNC ERROR', '[' . $sync_errors . ']' ); |
| 534 | - $_error = $sync_errors; | |
| 535 | - $error = true; | |
| 404 | + | |
| 405 | + $error = true; | |
| 536 | 406 | if ( ! $pAllowDisconnect ) { |
| 537 | 407 | $sync_errors = ''; |
| 538 | 408 | } |
| 539 | 409 | |
| @@ -541,18 +411,14 @@ | ||
| 541 | 411 | } else { |
| 542 | 412 | MainWP_Logger::instance()->warning_for_website( $pWebsite, 'SYNC ERROR', '[Undefined error]' ); |
| 543 | 413 | $error = true; |
| 544 | 414 | if ( $pAllowDisconnect ) { |
| 545 | - $sync_errors = esc_html__( 'Undefined error! Please, reinstall the MainWP Child plugin on the child site.', 'mainwp' ); | |
| 546 | - $websiteSyncValues['sync_errors'] = $sync_errors; | |
| 547 | - $_error = $sync_errors; | |
| 415 | + $websiteSyncValues['sync_errors'] = __( 'Undefined error! Please, reinstall the MainWP Child plugin on the child site.', 'mainwp' ); | |
| 548 | 416 | } |
| 549 | 417 | } |
| 550 | 418 | } |
| 551 | 419 | |
| 552 | - $act_success = false; | |
| 553 | 420 | if ( $done ) { |
| 554 | - $act_success = true; | |
| 555 | 421 | $websiteSyncValues['dtsSync'] = time(); |
| 556 | 422 | } |
| 557 | 423 | MainWP_DB::instance()->update_website_sync_values( $pWebsite->id, $websiteSyncValues ); |
| 558 | 424 | MainWP_DB::instance()->update_website_values( $pWebsite->id, $websiteValues ); |
| @@ -563,12 +429,12 @@ | ||
| 563 | 429 | |
| 564 | 430 | /** |
| 565 | 431 | * Action: mainwp_site_synced |
| 566 | 432 | * |
| 567 | - * Fires upon successful site synchronization. | |
| 433 | + * Fires upon successfull site sinchronization. | |
| 568 | 434 | * |
| 569 | - * @param object $pWebsite Object containing child site info. | |
| 570 | - * @param array $information Array containing information returned from child site. | |
| 435 | + * @param object $pWebsite Object contaning child site info. | |
| 436 | + * @param array $information Array contaning information returned from child site. | |
| 571 | 437 | * |
| 572 | 438 | * @since 3.4 |
| 573 | 439 | */ |
| 574 | 440 | do_action( 'mainwp_site_synced', $pWebsite, $information ); |
| @@ -573,50 +439,20 @@ | ||
| 573 | 439 | */ |
| 574 | 440 | do_action( 'mainwp_site_synced', $pWebsite, $information ); |
| 575 | 441 | } |
| 576 | 442 | |
| 577 | - $post_data = array(); | |
| 578 | - | |
| 579 | - /** | |
| 580 | - * Action: mainwp_site_sync | |
| 581 | - * | |
| 582 | - * Fires upon successful site synchronization. | |
| 583 | - * | |
| 584 | - * @param object $pWebsite Object containing child site info. | |
| 585 | - * @param array $information Array containing information returned from child site. | |
| 586 | - * @param bool $act_success action success or failed. | |
| 587 | - * @param string $_error Sync error message if existed. | |
| 588 | - * @param array $post_data Addition post data. | |
| 589 | - * | |
| 590 | - * @since 3.4 | |
| 591 | - */ | |
| 592 | - do_action( 'mainwp_site_sync', $pWebsite, $information, $act_success, $_error, $post_data ); | |
| 593 | - | |
| 594 | 443 | return ( ! $error ); |
| 595 | 444 | } |
| 596 | 445 | |
| 597 | 446 | /** |
| 598 | - * Method get_wp_icon() | |
| 447 | + * Method sync_site_icon() | |
| 599 | 448 | * |
| 600 | 449 | * Get site's icon. |
| 601 | 450 | * |
| 602 | 451 | * @param mixed $siteId site's id. |
| 603 | - * | |
| 604 | 452 | * @return array result error or success |
| 605 | - * @throws \Exception Error message. | |
| 606 | - * | |
| 607 | - * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed() | |
| 608 | - * @uses \MainWP\Dashboard\MainWP_Connect::get_file_content() | |
| 609 | - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() | |
| 610 | - * @uses \MainWP\Dashboard\MainWP_DB_Common::update_website_option() | |
| 611 | - * @uses \MainWP\Dashboard\MainWP_Exception | |
| 612 | - * @uses \MainWP\Dashboard\MainWP_Logger::debug() | |
| 613 | - * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website() | |
| 614 | - * @uses \MainWP\Dashboard\MainWP_System_Utility::get_wp_file_system() | |
| 615 | - * @uses \MainWP\Dashboard\MainWP_System_Utility::get_mainwp_dir() | |
| 616 | - * @uses \MainWP\Dashboard\MainWP_Utility::ctype_digit() | |
| 617 | 453 | */ |
| 618 | - public static function get_wp_icon( $siteId = null ) { | |
| 454 | + public static function sync_site_icon( $siteId = null ) { | |
| 619 | 455 | if ( MainWP_Utility::ctype_digit( $siteId ) ) { |
| 620 | 456 | $website = MainWP_DB::instance()->get_website_by_id( $siteId ); |
| 621 | 457 | if ( MainWP_System_Utility::can_edit_website( $website ) ) { |
| 622 | 458 | $error = ''; |
| @@ -625,12 +461,12 @@ | ||
| 625 | 461 | } catch ( MainWP_Exception $e ) { |
| 626 | 462 | $error = $e->getMessage(); |
| 627 | 463 | } |
| 628 | 464 | |
| 629 | - if ( ! empty( $error ) ) { | |
| 465 | + if ( '' != $error ) { | |
| 630 | 466 | return array( 'error' => $error ); |
| 631 | 467 | } elseif ( isset( $information['faviIconUrl'] ) && ! empty( $information['faviIconUrl'] ) ) { |
| 632 | - MainWP_Logger::instance()->debug( 'Downloading icon :: ' . esc_html( $information['faviIconUrl'] ) ); | |
| 468 | + MainWP_Logger::instance()->debug( 'Downloading icon :: ' . $information['faviIconUrl'] ); | |
| 633 | 469 | $content = MainWP_Connect::get_file_content( $information['faviIconUrl'] ); |
| 634 | 470 | if ( ! empty( $content ) ) { |
| 635 | 471 | |
| 636 | 472 | $hasWPFileSystem = MainWP_System_Utility::get_wp_file_system(); |
| @@ -647,12 +483,9 @@ | ||
| 647 | 483 | $filename = basename( $information['faviIconUrl'] ); |
| 648 | 484 | $filename = strtok( $filename, '?' ); |
| 649 | 485 | if ( $filename ) { |
| 650 | 486 | $filename = 'favi-' . $siteId . '-' . $filename; |
| 651 | - $size = false; | |
| 652 | - if ( MainWP_Utility::check_image_file_name( $filename ) ) { | |
| 653 | - $size = $wp_filesystem->put_contents( $iconsDir . $filename, $content ); // phpcs:ignore -- | |
| 654 | - } | |
| 487 | + $size = $wp_filesystem->put_contents( $iconsDir . $filename, $content ); // phpcs:ignore -- | |
| 655 | 488 | if ( $size ) { |
| 656 | 489 | MainWP_Logger::instance()->debug( 'Icon size :: ' . $size ); |
| 657 | 490 | MainWP_DB::instance()->update_website_option( $website, 'favi_icon', $filename ); |
| 658 | 491 | return array( 'result' => 'success' ); |
| @@ -670,5 +503,6 @@ | ||
| 670 | 503 | } |
| 671 | 504 | } |
| 672 | 505 | return array( 'result' => 'NOSITE' ); |
| 673 | 506 | } |
| 507 | + | |
| 674 | 508 | } |