| @@ -1,674 +1,327 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * MainWP Sync Handler | |
| 4 | - * | |
| 5 | - * Handle all syncing between MainWP & Child Site Network. | |
| 6 | - * | |
| 7 | - * @package MainWP/Dashboard | |
| 8 | - */ | |
| 9 | 2 | |
| 10 | -namespace MainWP\Dashboard; | |
| 3 | +class MainWP_Sync { | |
| 11 | 4 | |
| 12 | -/** | |
| 13 | - * Class MainWP_Sync | |
| 14 | - * | |
| 15 | - * @package MainWP\Dashboard | |
| 16 | - */ | |
| 17 | -class MainWP_Sync { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR. | |
| 5 | + public static function syncSite( &$pWebsite = null, $pForceFetch = false, $pAllowDisconnect = true ) { | |
| 6 | + if ( $pWebsite == null ) { | |
| 7 | + return false; | |
| 8 | + } | |
| 9 | + $userExtension = MainWP_DB::Instance()->getUserExtensionByUserId( $pWebsite->userid ); | |
| 10 | + if ( $userExtension == null ) { | |
| 11 | + return false; | |
| 12 | + } | |
| 18 | 13 | |
| 14 | + MainWP_Utility::endSession(); | |
| 19 | 15 | |
| 20 | - /** | |
| 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 static::sync_site( $website, false, true, $clear_session ); | |
| 36 | - } | |
| 16 | + try { | |
| 37 | 17 | |
| 38 | - /** | |
| 39 | - * Method sync_site() | |
| 40 | - * | |
| 41 | - * @param mixed $pWebsite Null|userid. | |
| 42 | - * @param bool $pForceFetch Check if a fourced Sync. | |
| 43 | - * @param bool $pAllowDisconnect Check if allowed to disconect. | |
| 44 | - * @param bool $clear_session to run the ending session or not. | |
| 45 | - * | |
| 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() | |
| 56 | - */ | |
| 57 | - public static function sync_site( &$pWebsite = null, $pForceFetch = false, $pAllowDisconnect = true, $clear_session = true ) { // phpcs:ignore -- NOSONAR - complexity method. | |
| 18 | + $cloneEnabled = apply_filters( 'mainwp_clone_enabled', false ); | |
| 19 | + $cloneSites = array(); | |
| 20 | + if ( $cloneEnabled ) { | |
| 21 | + $disallowedCloneSites = get_option( 'mainwp_clone_disallowedsites' ); | |
| 22 | + if ( $disallowedCloneSites === false ) { | |
| 23 | + $disallowedCloneSites = array(); | |
| 24 | + } | |
| 25 | + $websites = MainWP_DB::Instance()->query( MainWP_DB::Instance()->getSQLWebsitesForCurrentUser() ); | |
| 26 | + if ( $websites ) { | |
| 27 | + while ( $websites && ( $website = @MainWP_DB::fetch_object( $websites ) ) ) { | |
| 28 | + if ( in_array( $website->id, $disallowedCloneSites ) ) { | |
| 29 | + continue; | |
| 30 | + } | |
| 31 | + if ( $website->id == $pWebsite->id ) { | |
| 32 | + continue; | |
| 33 | + } | |
| 58 | 34 | |
| 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 | - } | |
| 35 | + $cloneSites[ $website->id ] = array( | |
| 36 | + 'name' => $website->name, | |
| 37 | + 'url' => $website->url, | |
| 38 | + 'extauth' => $website->extauth, | |
| 39 | + 'size' => $website->totalsize, | |
| 40 | + ); | |
| 41 | + } | |
| 42 | + @MainWP_DB::free_result( $websites ); | |
| 43 | + } | |
| 44 | + } | |
| 63 | 45 | |
| 64 | - if ( null === $pWebsite ) { | |
| 65 | - return false; | |
| 66 | - } | |
| 67 | - $userExtension = MainWP_DB_Common::instance()->get_user_extension_by_user_id( $pWebsite->userid ); | |
| 68 | - if ( null === $userExtension ) { | |
| 69 | - return false; | |
| 70 | - } | |
| 46 | + $primaryBackup = MainWP_Utility::get_primary_backup(); | |
| 71 | 47 | |
| 72 | - if ( $clear_session ) { | |
| 73 | - MainWP_Utility::end_session(); | |
| 74 | - } | |
| 48 | + $othersData = apply_filters( 'mainwp-sync-others-data', array(), $pWebsite ); | |
| 49 | + $information = MainWP_Utility::fetchUrlAuthed( $pWebsite, 'stats', array( | |
| 50 | + 'optimize' => ( ( get_option( 'mainwp_optimize' ) == 1 ) ? 1 : 0 ), | |
| 51 | + 'heatMap' => 0, | |
| 52 | + 'cloneSites' => (!$cloneEnabled ? 0 : urlencode( json_encode( $cloneSites ) ) ), | |
| 53 | + 'othersData' => json_encode( $othersData ), | |
| 54 | + 'server' => get_admin_url(), | |
| 55 | + 'numberdaysOutdatePluginTheme' => get_option( 'mainwp_numberdays_Outdate_Plugin_Theme', 365 ), | |
| 56 | + 'primaryBackup' => $primaryBackup | |
| 57 | + ), true, $pForceFetch | |
| 58 | + ); | |
| 59 | + MainWP_DB::Instance()->updateWebsiteOption( $pWebsite, 'primary_lasttime_backup', isset( $information[ 'primaryLasttimeBackup' ] ) ? $information[ 'primaryLasttimeBackup' ] : 0 ); | |
| 60 | + $return = self::syncInformationArray( $pWebsite, $information, '', 1, false, $pAllowDisconnect ); | |
| 75 | 61 | |
| 76 | - try { | |
| 62 | + return $return; | |
| 63 | + } catch ( MainWP_Exception $e ) { | |
| 64 | + $sync_errors = ''; | |
| 65 | + $offline_check_result = 1; | |
| 77 | 66 | |
| 78 | - /** | |
| 79 | - * Filter: mainwp_clone_enabled | |
| 80 | - * | |
| 81 | - * Filters whether the Clone feature is enabled or disabled. | |
| 82 | - * | |
| 83 | - * @since Unknown | |
| 84 | - */ | |
| 85 | - $cloneEnabled = apply_filters( 'mainwp_clone_enabled', false ); | |
| 86 | - $cloneSites = array(); | |
| 67 | + if ( $e->getMessage() == 'HTTPERROR' ) { | |
| 68 | + $sync_errors = __( 'HTTP error', 'mainwp' ) . ( $e->getMessageExtra() != null ? ' - ' . $e->getMessageExtra() : '' ); | |
| 69 | + $offline_check_result = - 1; | |
| 70 | + } else if ( $e->getMessage() == 'NOMAINWP' ) { | |
| 71 | + $sync_errors = __( 'MainWP Child plugin not detected', 'mainwp' ); | |
| 72 | + $offline_check_result = 1; | |
| 73 | + } | |
| 87 | 74 | |
| 88 | - $disallowed_current_site = false; | |
| 75 | + return self::syncInformationArray( $pWebsite, $information, $sync_errors, $offline_check_result, true, $pAllowDisconnect ); | |
| 76 | + } | |
| 77 | + } | |
| 89 | 78 | |
| 90 | - if ( $cloneEnabled ) { | |
| 91 | - $disallowedCloneSites = get_option( 'mainwp_clone_disallowedsites' ); | |
| 92 | - if ( false === $disallowedCloneSites ) { | |
| 93 | - $disallowedCloneSites = array(); | |
| 94 | - } | |
| 95 | - $websites = MainWP_DB::instance()->query( MainWP_DB::instance()->get_sql_websites_for_current_user() ); | |
| 96 | - if ( $websites ) { | |
| 97 | - while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) { | |
| 98 | - if ( in_array( $website->id, $disallowedCloneSites ) ) { | |
| 99 | - continue; | |
| 100 | - } | |
| 101 | - if ( (int) $website->id === (int) $pWebsite->id ) { | |
| 102 | - continue; | |
| 103 | - } | |
| 79 | + public static function syncInformationArray( &$pWebsite, &$information, $sync_errors = '', $offline_check_result = 1, | |
| 80 | + $error = false, $pAllowDisconnect = true ) { | |
| 81 | + $emptyArray = json_encode( array() ); | |
| 82 | + $websiteValues = array( | |
| 83 | + 'directories' => $emptyArray, | |
| 84 | + 'plugin_upgrades' => $emptyArray, | |
| 85 | + 'theme_upgrades' => $emptyArray, | |
| 86 | + 'translation_upgrades' => $emptyArray, | |
| 87 | + 'securityIssues' => $emptyArray, | |
| 88 | + 'themes' => $emptyArray, | |
| 89 | + 'plugins' => $emptyArray, | |
| 90 | + 'users' => $emptyArray, | |
| 91 | + 'categories' => $emptyArray, | |
| 92 | + 'offline_check_result' => $offline_check_result, | |
| 93 | + ); | |
| 94 | + $websiteSyncValues = array( | |
| 95 | + 'uptodate' => 0, | |
| 96 | + 'sync_errors' => $sync_errors, | |
| 97 | + 'version' => 0, | |
| 98 | + ); | |
| 104 | 99 | |
| 105 | - $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, | |
| 111 | - ); | |
| 112 | - } | |
| 113 | - MainWP_DB::free_result( $websites ); | |
| 114 | - } | |
| 115 | - $disallowed_current_site = in_array( $pWebsite->id, $disallowedCloneSites ) ? true : false; | |
| 116 | - } | |
| 100 | + $done = false; | |
| 117 | 101 | |
| 118 | - $primaryBackup = MainWP_System_Utility::get_primary_backup(); | |
| 102 | + $information = apply_filters( 'mainwp_before_save_sync_result', $information, $pWebsite ); | |
| 119 | 103 | |
| 120 | - $othersData = apply_filters_deprecated( 'mainwp-sync-others-data', array( array(), $pWebsite ), '4.0.7.2', 'mainwp_sync_others_data' ); // @deprecated Use 'mainwp_sync_others_data' instead. NOSONAR - not IP. | |
| 104 | + if ( isset( $information[ 'siteurl' ] ) ) { | |
| 105 | + $websiteValues[ 'siteurl' ] = $information[ 'siteurl' ]; | |
| 106 | + $done = true; | |
| 107 | + } | |
| 121 | 108 | |
| 122 | - /** | |
| 123 | - * Filter: mainwp_sync_others_data | |
| 124 | - * | |
| 125 | - * Filters additional data in the sync request. Allows extensions or 3rd party plugins to hook data to the sync request. | |
| 126 | - * | |
| 127 | - * @param object $pWebsite Object contaning child site data. | |
| 128 | - * | |
| 129 | - * @since Unknown | |
| 130 | - * | |
| 131 | - * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed() | |
| 132 | - */ | |
| 133 | - $othersData = apply_filters( 'mainwp_sync_others_data', $othersData, $pWebsite ); | |
| 109 | + if ( isset( $information[ 'version' ] ) ) { | |
| 110 | + $websiteSyncValues[ 'version' ] = $information[ 'version' ]; | |
| 111 | + $done = true; | |
| 112 | + } | |
| 134 | 113 | |
| 135 | - $saved_days_number = apply_filters( 'mainwp_site_actions_saved_days_number', 30 ); | |
| 136 | 114 | |
| 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 | - ); | |
| 115 | + $phpversion = ''; | |
| 116 | + if ( isset( $information[ 'site_info' ] ) && $information[ 'site_info' ] != null ) { | |
| 117 | + if ( is_array( $information[ 'site_info' ] ) && isset( $information[ 'site_info' ][ 'phpversion' ] ) ) { | |
| 118 | + $phpversion = $information[ 'site_info' ][ 'phpversion' ]; | |
| 119 | + } | |
| 120 | + MainWP_DB::Instance()->updateWebsiteOption( $pWebsite, 'site_info', @json_encode( $information[ 'site_info' ] ) ); | |
| 121 | + $done = true; | |
| 122 | + } else { | |
| 123 | + MainWP_DB::Instance()->updateWebsiteOption( $pWebsite, 'site_info', $emptyArray ); | |
| 124 | + } | |
| 125 | + MainWP_DB::Instance()->updateWebsiteOption( $pWebsite, 'phpversion', $phpversion ); | |
| 148 | 126 | |
| 149 | - $information = MainWP_Connect::fetch_url_authed( | |
| 150 | - $pWebsite, | |
| 151 | - 'stats', | |
| 152 | - $postdata, | |
| 153 | - true, | |
| 154 | - $pForceFetch | |
| 155 | - ); | |
| 156 | - $return = static::sync_information_array( $pWebsite, $information, '', 1, false, $pAllowDisconnect ); | |
| 157 | - MainWP_Logger::instance()->log_execution_time( 'sync :: [siteid=' . $pWebsite->id . ']' ); | |
| 158 | - return $return; | |
| 159 | - } catch ( MainWP_Exception $e ) { | |
| 160 | - $sync_errors = ''; | |
| 161 | - $check_result = 1; | |
| 162 | 127 | |
| 163 | - if ( $e->getMessage() === 'HTTPERROR' ) { | |
| 164 | - $sync_errors = esc_html__( 'HTTP error', 'mainwp' ) . ( ! empty( $e->get_message_extra() ) ? ' - ' . $e->get_message_extra() : '' ); | |
| 165 | - $check_result = - 1; | |
| 166 | - } elseif ( $e->getMessage() === 'NOMAINWP' ) { | |
| 167 | - $sync_errors = MainWP_Error_Helper::get_error_not_detected_connect(); | |
| 168 | - $check_result = 1; | |
| 169 | - } | |
| 128 | + if ( isset( $information[ 'directories' ] ) && is_array( $information[ 'directories' ] ) ) { | |
| 129 | + $websiteValues[ 'directories' ] = @json_encode( $information[ 'directories' ] ); | |
| 130 | + $done = true; | |
| 131 | + } else if ( isset( $information[ 'directories' ] ) ) { | |
| 132 | + $websiteValues[ 'directories' ] = $information[ 'directories' ]; | |
| 133 | + $done = true; | |
| 134 | + } | |
| 170 | 135 | |
| 171 | - MainWP_Logger::instance()->log_execution_time( 'sync :: [siteid=' . $pWebsite->id . ']' ); | |
| 172 | - return static::sync_information_array( $pWebsite, $information, $sync_errors, $check_result, true, $pAllowDisconnect ); | |
| 173 | - } | |
| 174 | - } | |
| 136 | + if ( isset( $information[ 'wp_updates' ] ) && $information[ 'wp_updates' ] != null ) { | |
| 137 | + MainWP_DB::Instance()->updateWebsiteOption( $pWebsite, 'wp_upgrades', @json_encode( array( | |
| 138 | + 'current' => $information[ 'wpversion' ], | |
| 139 | + 'new' => $information[ 'wp_updates' ], | |
| 140 | + ) ) ); | |
| 141 | + $done = true; | |
| 142 | + } else { | |
| 143 | + MainWP_DB::Instance()->updateWebsiteOption( $pWebsite, 'wp_upgrades', $emptyArray ); | |
| 144 | + } | |
| 175 | 145 | |
| 176 | - /** | |
| 177 | - * Method sync_information_array() | |
| 178 | - * | |
| 179 | - * Grab all Child Site Information. | |
| 180 | - * | |
| 181 | - * @param object $pWebsite The website object. | |
| 182 | - * @param array $information Array contaning information returned from child site. | |
| 183 | - * @param string $sync_errors Check for Sync Errors. | |
| 184 | - * @param int $check_result Check if offline. | |
| 185 | - * @param bool $error True|False. | |
| 186 | - * @param bool $pAllowDisconnect True|False. | |
| 187 | - * | |
| 188 | - * @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 | - */ | |
| 198 | - public static function sync_information_array( &$pWebsite, &$information, $sync_errors = '', $check_result = 1, $error = false, $pAllowDisconnect = true ) { // phpcs:ignore -- NOSONAR -Current complexity is the only way to achieve desired results, pull request solutions appreciated. | |
| 199 | - $emptyArray = wp_json_encode( array() ); | |
| 200 | - $websiteValues = array( | |
| 201 | - 'directories' => $emptyArray, | |
| 202 | - 'plugin_upgrades' => $emptyArray, | |
| 203 | - 'theme_upgrades' => $emptyArray, | |
| 204 | - 'translation_upgrades' => $emptyArray, | |
| 205 | - 'securityIssues' => $emptyArray, | |
| 206 | - 'themes' => $emptyArray, | |
| 207 | - 'plugins' => $emptyArray, | |
| 208 | - 'users' => $emptyArray, | |
| 209 | - 'categories' => $emptyArray, | |
| 210 | - 'offline_check_result' => $check_result, | |
| 211 | - ); | |
| 212 | - $websiteSyncValues = array( | |
| 213 | - 'sync_errors' => $sync_errors, | |
| 214 | - 'version' => 0, | |
| 215 | - ); | |
| 146 | + if ( isset( $information[ 'plugin_updates' ] ) ) { | |
| 147 | + $websiteValues[ 'plugin_upgrades' ] = @json_encode( $information[ 'plugin_updates' ] ); | |
| 148 | + $done = true; | |
| 149 | + } | |
| 216 | 150 | |
| 217 | - $_error = $sync_errors; | |
| 151 | + if ( isset( $information[ 'theme_updates' ] ) ) { | |
| 152 | + $websiteValues[ 'theme_upgrades' ] = @json_encode( $information[ 'theme_updates' ] ); | |
| 153 | + $done = true; | |
| 154 | + } | |
| 218 | 155 | |
| 219 | - $done = false; | |
| 156 | + if ( isset( $information[ 'translation_updates' ] ) ) { | |
| 157 | + $websiteValues[ 'translation_upgrades' ] = @json_encode( $information[ 'translation_updates' ] ); | |
| 158 | + $done = true; | |
| 159 | + } | |
| 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 | - } | |
| 161 | + if ( isset( $information[ 'premium_updates' ] ) ) { | |
| 162 | + MainWP_DB::Instance()->updateWebsiteOption( $pWebsite, 'premium_upgrades', @json_encode( $information[ 'premium_updates' ] ) ); | |
| 163 | + $done = true; | |
| 164 | + } else { | |
| 165 | + MainWP_DB::Instance()->updateWebsiteOption( $pWebsite, 'premium_upgrades', $emptyArray ); | |
| 166 | + } | |
| 227 | 167 | |
| 228 | - // to get full data. | |
| 229 | - if ( $current_siteid ) { | |
| 230 | - $pWebsite = MainWP_DB::instance()->get_website_by_id( $current_siteid ); | |
| 231 | - } | |
| 168 | + if ( isset( $information[ 'securityIssues' ] ) && MainWP_Utility::ctype_digit( $information[ 'securityIssues' ] ) && $information[ 'securityIssues' ] >= 0 ) { | |
| 169 | + $websiteValues[ 'securityIssues' ] = $information[ 'securityIssues' ]; | |
| 170 | + $done = true; | |
| 171 | + } | |
| 232 | 172 | |
| 233 | - /** | |
| 234 | - * Filter: mainwp_before_save_sync_result | |
| 235 | - * | |
| 236 | - * Filters data returned from child site before saving to the database. | |
| 237 | - * | |
| 238 | - * @param object $pWebsite Object containing child site data. | |
| 239 | - * | |
| 240 | - * @since 3.4 | |
| 241 | - */ | |
| 242 | - $information = apply_filters( 'mainwp_before_save_sync_result', $information, $pWebsite ); | |
| 173 | + if ( isset( $information[ 'recent_comments' ] ) ) { | |
| 174 | + MainWP_DB::Instance()->updateWebsiteOption( $pWebsite, 'recent_comments', @json_encode( $information[ 'recent_comments' ] ) ); | |
| 175 | + $done = true; | |
| 176 | + } else { | |
| 177 | + MainWP_DB::Instance()->updateWebsiteOption( $pWebsite, 'recent_comments', $emptyArray ); | |
| 178 | + } | |
| 243 | 179 | |
| 244 | - if ( isset( $information['siteurl'] ) ) { | |
| 245 | - $websiteValues['siteurl'] = $information['siteurl']; | |
| 246 | - $done = true; | |
| 247 | - } | |
| 180 | + if ( isset( $information[ 'recent_posts' ] ) ) { | |
| 181 | + MainWP_DB::Instance()->updateWebsiteOption( $pWebsite, 'recent_posts', @json_encode( $information[ 'recent_posts' ] ) ); | |
| 182 | + $done = true; | |
| 183 | + } else { | |
| 184 | + MainWP_DB::Instance()->updateWebsiteOption( $pWebsite, 'recent_posts', $emptyArray ); | |
| 185 | + } | |
| 248 | 186 | |
| 249 | - if ( isset( $information['version'] ) ) { | |
| 250 | - $websiteSyncValues['version'] = $information['version']; | |
| 251 | - $done = true; | |
| 252 | - } | |
| 187 | + if ( isset( $information[ 'recent_pages' ] ) ) { | |
| 188 | + MainWP_DB::Instance()->updateWebsiteOption( $pWebsite, 'recent_pages', @json_encode( $information[ 'recent_pages' ] ) ); | |
| 189 | + $done = true; | |
| 190 | + } else { | |
| 191 | + MainWP_DB::Instance()->updateWebsiteOption( $pWebsite, 'recent_pages', $emptyArray ); | |
| 192 | + } | |
| 253 | 193 | |
| 254 | - $phpversion = ''; | |
| 255 | - if ( isset( $information['site_info'] ) && ! empty( $information['site_info'] ) ) { | |
| 256 | - if ( is_array( $information['site_info'] ) && isset( $information['site_info']['phpversion'] ) ) { | |
| 257 | - $phpversion = $information['site_info']['phpversion']; | |
| 258 | - } | |
| 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 | - MainWP_DB::instance()->update_website_option( $pWebsite, 'site_info', wp_json_encode( $information['site_info'] ) ); | |
| 263 | - $done = true; | |
| 264 | - } else { | |
| 265 | - MainWP_DB::instance()->update_website_option( $pWebsite, 'site_info', $emptyArray ); | |
| 266 | - } | |
| 267 | - if ( ! empty( $phpversion ) ) { | |
| 268 | - MainWP_DB::instance()->update_website_option( $pWebsite, 'phpversion', $phpversion ); | |
| 269 | - } | |
| 270 | - if ( isset( $information['directories'] ) && is_array( $information['directories'] ) ) { | |
| 271 | - $websiteValues['directories'] = wp_json_encode( $information['directories'] ); | |
| 272 | - $done = true; | |
| 273 | - } elseif ( isset( $information['directories'] ) ) { | |
| 274 | - $websiteValues['directories'] = $information['directories']; | |
| 275 | - $done = true; | |
| 276 | - } | |
| 194 | + if ( isset( $information[ 'themes' ] ) ) { | |
| 195 | + $websiteValues[ 'themes' ] = @json_encode( $information[ 'themes' ] ); | |
| 196 | + $done = true; | |
| 197 | + } | |
| 277 | 198 | |
| 278 | - if ( isset( $information['wp_updates'] ) && ! empty( $information['wp_updates'] ) ) { | |
| 279 | - MainWP_DB::instance()->update_website_option( | |
| 280 | - $pWebsite, | |
| 281 | - 'wp_upgrades', | |
| 282 | - wp_json_encode( | |
| 283 | - array( | |
| 284 | - 'current' => $information['wpversion'], | |
| 285 | - 'new' => $information['wp_updates'], | |
| 286 | - ) | |
| 287 | - ) | |
| 288 | - ); | |
| 289 | - $done = true; | |
| 290 | - } else { | |
| 291 | - MainWP_DB::instance()->update_website_option( $pWebsite, 'wp_upgrades', $emptyArray ); | |
| 292 | - } | |
| 293 | - | |
| 294 | - 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 ); | |
| 302 | - $done = true; | |
| 303 | - } | |
| 304 | - | |
| 305 | - 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 ); | |
| 313 | - $done = true; | |
| 314 | - } | |
| 315 | - | |
| 316 | - if ( isset( $information['translation_updates'] ) ) { | |
| 317 | - $websiteValues['translation_upgrades'] = wp_json_encode( $information['translation_updates'] ); | |
| 318 | - $done = true; | |
| 319 | - } | |
| 320 | - | |
| 321 | - if ( isset( $information['premium_updates'] ) ) { | |
| 322 | - MainWP_DB::instance()->update_website_option( $pWebsite, 'premium_upgrades', wp_json_encode( $information['premium_updates'] ) ); | |
| 323 | - $done = true; | |
| 324 | - } else { | |
| 325 | - MainWP_DB::instance()->update_website_option( $pWebsite, 'premium_upgrades', $emptyArray ); | |
| 326 | - } | |
| 327 | - | |
| 328 | - if ( isset( $information['securityStats'] ) ) { | |
| 329 | - $total_securityIssues = 0; | |
| 330 | - $securityStats = $information['securityStats']; | |
| 331 | - if ( is_array( $securityStats ) ) { | |
| 332 | - /** This filter is documented in ../pages/page-mainwp-security-issues.php */ | |
| 333 | - $filterStats = apply_filters( 'mainwp_security_issues_stats', false, $securityStats, $pWebsite ); | |
| 334 | - if ( false !== $filterStats && is_array( $filterStats ) ) { | |
| 335 | - $securityStats = array_merge( $securityStats, $filterStats ); | |
| 336 | - } | |
| 337 | - | |
| 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 | - $tmp_issues = array_filter( | |
| 349 | - $securityStats, | |
| 350 | - function ( $v ) { | |
| 351 | - return 'N' === $v; | |
| 352 | - }, | |
| 353 | - ARRAY_FILTER_USE_BOTH | |
| 354 | - ); | |
| 355 | - $total_securityIssues = count( $tmp_issues ); | |
| 356 | - $securityStats = wp_json_encode( $securityStats ); | |
| 357 | - } else { | |
| 358 | - $securityStats = $emptyArray; | |
| 359 | - } | |
| 360 | - $websiteValues['securityIssues'] = $total_securityIssues; | |
| 361 | - MainWP_DB::instance()->update_website_option( $pWebsite, 'security_stats', $securityStats ); | |
| 362 | - $done = true; | |
| 363 | - } elseif ( isset( $information['securityIssues'] ) && MainWP_Utility::ctype_digit( $information['securityIssues'] ) && $information['securityIssues'] >= 0 ) { | |
| 364 | - $websiteValues['securityIssues'] = $information['securityIssues']; | |
| 365 | - $done = true; | |
| 366 | - } | |
| 367 | - | |
| 368 | - if ( isset( $information['recent_comments'] ) ) { | |
| 369 | - MainWP_DB::instance()->update_website_option( $pWebsite, 'recent_comments', wp_json_encode( $information['recent_comments'] ) ); | |
| 370 | - $done = true; | |
| 371 | - } else { | |
| 372 | - MainWP_DB::instance()->update_website_option( $pWebsite, 'recent_comments', $emptyArray ); | |
| 373 | - } | |
| 374 | - | |
| 375 | - if ( isset( $information['recent_posts'] ) ) { | |
| 376 | - MainWP_DB::instance()->update_website_option( $pWebsite, 'recent_posts', wp_json_encode( $information['recent_posts'] ) ); | |
| 377 | - $done = true; | |
| 378 | - } else { | |
| 379 | - MainWP_DB::instance()->update_website_option( $pWebsite, 'recent_posts', $emptyArray ); | |
| 380 | - } | |
| 381 | - | |
| 382 | - if ( isset( $information['recent_pages'] ) ) { | |
| 383 | - MainWP_DB::instance()->update_website_option( $pWebsite, 'recent_pages', wp_json_encode( $information['recent_pages'] ) ); | |
| 384 | - $done = true; | |
| 385 | - } else { | |
| 386 | - MainWP_DB::instance()->update_website_option( $pWebsite, 'recent_pages', $emptyArray ); | |
| 387 | - } | |
| 388 | - | |
| 389 | - if ( isset( $information['themes'] ) ) { | |
| 390 | - $websiteValues['themes'] = wp_json_encode( $information['themes'] ); | |
| 391 | - $done = true; | |
| 392 | - } | |
| 393 | - | |
| 394 | 199 | if ( isset( $information['plugins'] ) ) { |
| 395 | - $websiteValues['plugins'] = wp_json_encode( $information['plugins'] ); | |
| 200 | + $websiteValues['plugins'] = MainWP_Utility::safe_json_encode($information['plugins']); | |
| 396 | 201 | $done = true; |
| 397 | 202 | } |
| 398 | 203 | |
| 399 | - if ( isset( $information['users'] ) ) { | |
| 400 | - $websiteValues['users'] = wp_json_encode( $information['users'] ); | |
| 401 | - $done = true; | |
| 402 | - } | |
| 204 | + if ( isset( $information[ 'users' ] ) ) { | |
| 205 | + $websiteValues[ 'users' ] = @json_encode( $information[ 'users' ] ); | |
| 206 | + $done = true; | |
| 207 | + } | |
| 403 | 208 | |
| 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. | |
| 408 | - $websiteValues['categories'] = wp_json_encode( $information['categories'] ); | |
| 409 | - $done = true; | |
| 410 | - } | |
| 209 | + if ( isset( $information[ 'categories' ] ) ) { | |
| 210 | + $websiteValues[ 'categories' ] = @json_encode( $information[ 'categories' ] ); | |
| 211 | + $done = true; | |
| 212 | + } | |
| 411 | 213 | |
| 412 | - if ( isset( $information['totalsize'] ) ) { | |
| 413 | - $websiteSyncValues['totalsize'] = $information['totalsize']; | |
| 414 | - $done = true; | |
| 415 | - } | |
| 214 | + if ( isset( $information[ 'totalsize' ] ) ) { | |
| 215 | + $websiteSyncValues[ 'totalsize' ] = $information[ 'totalsize' ]; | |
| 216 | + $done = true; | |
| 217 | + } | |
| 416 | 218 | |
| 417 | - if ( isset( $information['dbsize'] ) ) { | |
| 418 | - $websiteSyncValues['dbsize'] = $information['dbsize']; | |
| 419 | - $done = true; | |
| 420 | - } | |
| 219 | + if ( isset( $information[ 'dbsize' ] ) ) { | |
| 220 | + $websiteSyncValues[ 'dbsize' ] = $information[ 'dbsize' ]; | |
| 221 | + $done = true; | |
| 222 | + } | |
| 421 | 223 | |
| 422 | - if ( isset( $information['extauth'] ) ) { | |
| 423 | - $websiteSyncValues['extauth'] = $information['extauth']; | |
| 424 | - $done = true; | |
| 425 | - } | |
| 224 | + if ( isset( $information[ 'extauth' ] ) ) { | |
| 225 | + $websiteSyncValues[ 'extauth' ] = $information[ 'extauth' ]; | |
| 226 | + $done = true; | |
| 227 | + } | |
| 426 | 228 | |
| 427 | - if ( isset( $information['wpe'] ) ) { | |
| 428 | - $websiteValues['wpe'] = $information['wpe']; | |
| 429 | - $done = true; | |
| 430 | - } | |
| 229 | + if ( isset( $information[ 'nossl' ] ) ) { | |
| 230 | + $websiteValues[ 'nossl' ] = $information[ 'nossl' ]; | |
| 231 | + $done = true; | |
| 232 | + } | |
| 431 | 233 | |
| 432 | - if ( isset( $information['wphost'] ) ) { | |
| 433 | - MainWP_DB::instance()->update_website_option( $pWebsite, 'wphost', $information['wphost'] ); | |
| 434 | - } | |
| 234 | + if ( isset( $information[ 'wpe' ] ) ) { | |
| 235 | + $websiteValues[ 'wpe' ] = $information[ 'wpe' ]; | |
| 236 | + $done = true; | |
| 237 | + } | |
| 435 | 238 | |
| 436 | - if ( isset( $information['last_post_gmt'] ) ) { | |
| 437 | - $websiteSyncValues['last_post_gmt'] = $information['last_post_gmt']; | |
| 438 | - $done = true; | |
| 439 | - } | |
| 239 | + if ( isset( $information[ 'last_post_gmt' ] ) ) { | |
| 240 | + $websiteSyncValues[ 'last_post_gmt' ] = $information[ 'last_post_gmt' ]; | |
| 241 | + $done = true; | |
| 242 | + } | |
| 440 | 243 | |
| 441 | - if ( isset( $information['health_site_status'] ) ) { | |
| 442 | - $health_status = $information['health_site_status']; | |
| 443 | - $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; | |
| 446 | - $done = true; | |
| 447 | - 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 ); | |
| 449 | - if ( null !== $new_noticed ) { | |
| 450 | - MainWP_DB::instance()->update_website_sync_values( | |
| 451 | - $pWebsite->id, | |
| 452 | - array( | |
| 453 | - 'health_site_noticed' => $new_noticed, | |
| 454 | - ) | |
| 455 | - ); | |
| 456 | - } | |
| 244 | + if ( isset( $information[ 'mainwpdir' ] ) ) { | |
| 245 | + $websiteValues[ 'mainwpdir' ] = $information[ 'mainwpdir' ]; | |
| 246 | + $done = true; | |
| 247 | + } | |
| 457 | 248 | |
| 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 | - } else { | |
| 468 | - MainWP_DB::instance()->update_website_option( $pWebsite, 'health_site_status', $emptyArray ); | |
| 469 | - } | |
| 249 | + if ( isset( $information[ 'uniqueId' ] ) ) { | |
| 250 | + $websiteValues[ 'uniqueId' ] = $information[ 'uniqueId' ]; | |
| 251 | + $done = true; | |
| 252 | + } | |
| 470 | 253 | |
| 471 | - if ( isset( $information['mainwpdir'] ) ) { | |
| 472 | - $websiteValues['mainwpdir'] = $information['mainwpdir']; | |
| 473 | - $done = true; | |
| 474 | - } | |
| 475 | - | |
| 476 | - if ( isset( $information['uniqueId'] ) ) { | |
| 477 | - $websiteValues['uniqueId'] = $information['uniqueId']; | |
| 478 | - $done = true; | |
| 479 | - } | |
| 480 | - | |
| 481 | - if ( isset( $information['clone_adminname'] ) ) { | |
| 482 | - $websiteValues['adminname'] = $information['clone_adminname']; | |
| 483 | - $done = true; | |
| 484 | - } | |
| 485 | - | |
| 486 | 254 | if ( isset( $information['admin_nicename'] ) ) { |
| 487 | - MainWP_DB::instance()->update_website_option( $pWebsite, 'admin_nicename', trim( $information['admin_nicename'] ) ); | |
| 488 | - $done = true; | |
| 489 | - } | |
| 255 | + MainWP_DB::Instance()->updateWebsiteOption( $pWebsite, 'admin_nicename', trim( $information['admin_nicename'] ) ); | |
| 256 | + $done = true; | |
| 257 | + } | |
| 490 | 258 | |
| 491 | 259 | if ( isset( $information['admin_useremail'] ) ) { |
| 492 | - MainWP_DB::instance()->update_website_option( $pWebsite, 'admin_useremail', trim( $information['admin_useremail'] ) ); | |
| 493 | - $done = true; | |
| 494 | - } | |
| 260 | + MainWP_DB::Instance()->updateWebsiteOption( $pWebsite, 'admin_useremail', trim( $information['admin_useremail'] ) ); | |
| 261 | + $done = true; | |
| 262 | + } | |
| 495 | 263 | |
| 496 | - if ( isset( $information['plugins_outdate_info'] ) ) { | |
| 497 | - MainWP_DB::instance()->update_website_option( $pWebsite, 'plugins_outdate_info', wp_json_encode( $information['plugins_outdate_info'] ) ); | |
| 498 | - $done = true; | |
| 499 | - } else { | |
| 500 | - MainWP_DB::instance()->update_website_option( $pWebsite, 'plugins_outdate_info', $emptyArray ); | |
| 501 | - } | |
| 264 | + if ( isset( $information[ 'plugins_outdate_info' ] ) ) { | |
| 265 | + MainWP_DB::Instance()->updateWebsiteOption( $pWebsite, 'plugins_outdate_info', @json_encode( $information[ 'plugins_outdate_info' ] ) ); | |
| 266 | + $done = true; | |
| 267 | + } else { | |
| 268 | + MainWP_DB::Instance()->updateWebsiteOption( $pWebsite, 'plugins_outdate_info', $emptyArray ); | |
| 269 | + } | |
| 502 | 270 | |
| 503 | - if ( isset( $information['themes_outdate_info'] ) ) { | |
| 504 | - MainWP_DB::instance()->update_website_option( $pWebsite, 'themes_outdate_info', wp_json_encode( $information['themes_outdate_info'] ) ); | |
| 505 | - $done = true; | |
| 506 | - } else { | |
| 507 | - MainWP_DB::instance()->update_website_option( $pWebsite, 'themes_outdate_info', $emptyArray ); | |
| 508 | - } | |
| 271 | + if ( isset( $information[ 'themes_outdate_info' ] ) ) { | |
| 272 | + MainWP_DB::Instance()->updateWebsiteOption( $pWebsite, 'themes_outdate_info', @json_encode( $information[ 'themes_outdate_info' ] ) ); | |
| 273 | + $done = true; | |
| 274 | + } else { | |
| 275 | + MainWP_DB::Instance()->updateWebsiteOption( $pWebsite, 'themes_outdate_info', $emptyArray ); | |
| 276 | + } | |
| 509 | 277 | |
| 510 | - if ( isset( $information['primaryLasttimeBackup'] ) ) { | |
| 511 | - MainWP_DB::instance()->update_website_option( $pWebsite, 'primary_lasttime_backup', $information['primaryLasttimeBackup'] ); | |
| 512 | - $done = true; | |
| 513 | - } | |
| 278 | + if ( !$done ) { | |
| 279 | + if ( isset( $information[ 'wpversion' ] ) ) { | |
| 280 | + $websiteSyncValues[ 'uptodate' ] = 1; | |
| 281 | + $done = true; | |
| 282 | + } else if ( isset( $information[ 'error' ] ) ) { | |
| 283 | + MainWP_Logger::Instance()->warningForWebsite( $pWebsite, 'SYNC ERROR', '[' . $information[ 'error' ] . ']' ); | |
| 284 | + $error = true; | |
| 285 | + $done = true; | |
| 286 | + $websiteSyncValues[ 'sync_errors' ] = __( 'ERROR: ', 'mainwp' ) . $information[ 'error' ]; | |
| 287 | + } else if ( !empty( $sync_errors ) ) { | |
| 288 | + MainWP_Logger::Instance()->warningForWebsite( $pWebsite, 'SYNC ERROR', '[' . $sync_errors . ']' ); | |
| 514 | 289 | |
| 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 | - } | |
| 290 | + $error = true; | |
| 291 | + if ( !$pAllowDisconnect ) { | |
| 292 | + $sync_errors = ''; | |
| 293 | + } | |
| 522 | 294 | |
| 523 | - if ( ! $done ) { | |
| 524 | - if ( isset( $information['wpversion'] ) ) { | |
| 525 | - $done = true; | |
| 526 | - } elseif ( isset( $information['error'] ) ) { | |
| 527 | - MainWP_Logger::instance()->warning_for_website( $pWebsite, 'SYNC ERROR', '[' . esc_html( $information['error'] ) . ']' ); | |
| 528 | - $error = true; | |
| 529 | - $done = true; | |
| 530 | - $_error = esc_html__( 'ERROR: ', 'mainwp' ) . esc_html( $information['error'] ); | |
| 531 | - $websiteSyncValues['sync_errors'] = $_error; | |
| 532 | - } elseif ( ! empty( $sync_errors ) ) { | |
| 533 | - MainWP_Logger::instance()->warning_for_website( $pWebsite, 'SYNC ERROR', '[' . $sync_errors . ']' ); | |
| 534 | - $_error = $sync_errors; | |
| 535 | - $error = true; | |
| 536 | - if ( ! $pAllowDisconnect ) { | |
| 537 | - $sync_errors = ''; | |
| 538 | - } | |
| 295 | + $websiteSyncValues[ 'sync_errors' ] = $sync_errors; | |
| 296 | + } else { | |
| 297 | + MainWP_Logger::Instance()->warningForWebsite( $pWebsite, 'SYNC ERROR', '[Undefined error]' ); | |
| 298 | + $error = true; | |
| 299 | + if ( $pAllowDisconnect ) { | |
| 300 | + $websiteSyncValues[ 'sync_errors' ] = __( 'Undefined error! Please, reinstall the MainWP Child plugin on the child site.', 'mainwp' ); | |
| 301 | + } | |
| 302 | + } | |
| 303 | + } | |
| 539 | 304 | |
| 540 | - $websiteSyncValues['sync_errors'] = $sync_errors; | |
| 541 | - } else { | |
| 542 | - MainWP_Logger::instance()->warning_for_website( $pWebsite, 'SYNC ERROR', '[Undefined error]' ); | |
| 543 | - $error = true; | |
| 544 | - 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; | |
| 548 | - } | |
| 549 | - } | |
| 550 | - } | |
| 305 | + if ( $done ) { | |
| 306 | + $websiteSyncValues[ 'dtsSync' ] = time(); | |
| 307 | + } | |
| 308 | + MainWP_DB::Instance()->updateWebsiteSyncValues( $pWebsite->id, $websiteSyncValues ); | |
| 309 | + MainWP_DB::Instance()->updateWebsiteValues( $pWebsite->id, $websiteValues ); | |
| 551 | 310 | |
| 552 | - $act_success = false; | |
| 553 | - if ( $done ) { | |
| 554 | - $act_success = true; | |
| 555 | - $websiteSyncValues['dtsSync'] = time(); | |
| 556 | - } | |
| 557 | - MainWP_DB::instance()->update_website_sync_values( $pWebsite->id, $websiteSyncValues ); | |
| 558 | - MainWP_DB::instance()->update_website_values( $pWebsite->id, $websiteValues ); | |
| 311 | + //Sync action | |
| 312 | + if ( !$error ) { | |
| 313 | + do_action( 'mainwp-site-synced', $pWebsite, $information ); | |
| 314 | + } | |
| 559 | 315 | |
| 560 | - // Sync action. | |
| 561 | - if ( ! $error ) { | |
| 562 | - do_action_deprecated( 'mainwp-site-synced', array( $pWebsite, $information ), '4.0.7.2', 'mainwp_site_synced' ); // @deprecated Use 'mainwp_site_synced' instead. NOSONAR - not IP. | |
| 316 | + return (!$error ); | |
| 317 | + } | |
| 563 | 318 | |
| 564 | - /** | |
| 565 | - * Action: mainwp_site_synced | |
| 566 | - * | |
| 567 | - * Fires upon successful site synchronization. | |
| 568 | - * | |
| 569 | - * @param object $pWebsite Object containing child site info. | |
| 570 | - * @param array $information Array containing information returned from child site. | |
| 571 | - * | |
| 572 | - * @since 3.4 | |
| 573 | - */ | |
| 574 | - do_action( 'mainwp_site_synced', $pWebsite, $information ); | |
| 575 | - } | |
| 319 | + public static function statsUpdate( $pSite = null ) { | |
| 320 | + //todo: implement | |
| 321 | + } | |
| 576 | 322 | |
| 577 | - $post_data = array(); | |
| 323 | + public static function offlineCheck( $pSite = null ) { | |
| 324 | + //todo: implement | |
| 325 | + } | |
| 578 | 326 | |
| 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 | - return ! $error; | |
| 595 | - } | |
| 596 | - | |
| 597 | - /** | |
| 598 | - * Method get_wp_icon() | |
| 599 | - * | |
| 600 | - * Get site's icon. | |
| 601 | - * | |
| 602 | - * @param mixed $siteId site's id. | |
| 603 | - * | |
| 604 | - * @return array result error or success | |
| 605 | - * @throws \MainWP_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 | - */ | |
| 618 | - public static function get_wp_icon( $siteId = null ) { // phpcs:ignore -- NOSONAR - complex. | |
| 619 | - if ( MainWP_Utility::ctype_digit( $siteId ) ) { | |
| 620 | - $website = MainWP_DB::instance()->get_website_by_id( $siteId ); | |
| 621 | - if ( MainWP_System_Utility::can_edit_website( $website ) ) { | |
| 622 | - $error = ''; | |
| 623 | - try { | |
| 624 | - $information = MainWP_Connect::fetch_url_authed( $website, 'get_site_icon' ); | |
| 625 | - } catch ( MainWP_Exception $e ) { | |
| 626 | - $error = $e->getMessage(); | |
| 627 | - } | |
| 628 | - | |
| 629 | - if ( ! empty( $error ) ) { | |
| 630 | - return array( 'error' => $error ); | |
| 631 | - } elseif ( isset( $information['faviIconUrl'] ) && ! empty( $information['faviIconUrl'] ) ) { | |
| 632 | - MainWP_Logger::instance()->debug( 'Downloading icon :: ' . esc_html( $information['faviIconUrl'] ) ); | |
| 633 | - $content = MainWP_Connect::get_file_content( $information['faviIconUrl'] ); | |
| 634 | - if ( ! empty( $content ) ) { | |
| 635 | - | |
| 636 | - MainWP_System_Utility::get_wp_file_system(); | |
| 637 | - | |
| 638 | - /** | |
| 639 | - * WordPress files system object. | |
| 640 | - * | |
| 641 | - * @global object | |
| 642 | - */ | |
| 643 | - global $wp_filesystem; | |
| 644 | - | |
| 645 | - $dirs = MainWP_System_Utility::get_mainwp_dir( 'icons', true ); | |
| 646 | - $iconsDir = $dirs[0]; | |
| 647 | - $filename = basename( $information['faviIconUrl'] ); | |
| 648 | - $filename = strtok( $filename, '?' ); | |
| 649 | - if ( $filename ) { | |
| 650 | - $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 | - } | |
| 655 | - if ( $size ) { | |
| 656 | - MainWP_Logger::instance()->debug( 'Icon size :: ' . $size ); | |
| 657 | - MainWP_DB::instance()->update_website_option( $website, 'favi_icon', $filename ); | |
| 658 | - return array( 'result' => 'success' ); | |
| 659 | - } else { | |
| 660 | - return array( 'error' => 'Save icon file failed.' ); | |
| 661 | - } | |
| 662 | - } | |
| 663 | - return array( 'undefined_error' => true ); | |
| 664 | - } else { | |
| 665 | - return array( 'error' => esc_html__( 'Download icon file failed', 'mainwp' ) ); | |
| 666 | - } | |
| 667 | - } else { | |
| 668 | - return array( 'undefined_error' => true ); | |
| 669 | - } | |
| 670 | - } | |
| 671 | - } | |
| 672 | - return array( 'result' => 'NOSITE' ); | |
| 673 | - } | |
| 674 | 327 | } |