| @@ -8,8 +8,13 @@ | ||
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | 10 | namespace MainWP\Dashboard; |
| 11 | 11 | |
| 12 | +// Exit if accessed directly. | |
| 13 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 14 | + exit; | |
| 15 | +} | |
| 16 | + | |
| 12 | 17 | /** |
| 13 | 18 | * Class MainWP_Common_Handler |
| 14 | 19 | * |
| 15 | 20 | * @package MainWP\Dashboard |
| @@ -42,11 +47,25 @@ | ||
| 42 | 47 | * Method sites_available_updates_count() |
| 43 | 48 | * |
| 44 | 49 | * Returns the number of available udpates for sites. |
| 45 | 50 | * |
| 46 | - * @return object $response An object that contains the return data and status of the API request. | |
| 51 | + * @return mixed $response An object that contains the return data and status of the API request. | |
| 47 | 52 | */ |
| 48 | 53 | public function sites_available_updates_count() { // phpcs:ignore -- NOSONAR - complex function. |
| 54 | + | |
| 55 | + $cache_group = MainWP_Cache_Helper::CGR_UPDATES; | |
| 56 | + | |
| 57 | + $cache_key = MainWP_Cache_Helper::get_cache_key( 'updates_count', $cache_group ); | |
| 58 | + | |
| 59 | + $cache_values = MainWP_Cache_Helper::instance()->get_cache( | |
| 60 | + $cache_key, | |
| 61 | + $cache_group | |
| 62 | + ); | |
| 63 | + | |
| 64 | + if ( is_array( $cache_values ) ) { | |
| 65 | + return $cache_values; | |
| 66 | + } | |
| 67 | + | |
| 49 | 68 | $is_staging = 'no'; |
| 50 | 69 | |
| 51 | 70 | $db_updater_count = false; |
| 52 | 71 | $total_plugin_db_upgrades = 0; |
| @@ -51,9 +70,9 @@ | ||
| 51 | 70 | $db_updater_count = false; |
| 52 | 71 | $total_plugin_db_upgrades = 0; |
| 53 | 72 | $supported_db_updater_plugins = array(); |
| 54 | 73 | |
| 55 | - $get_fields = array( 'premium_upgrades', 'favi_icon', 'ignored_wp_upgrades' ); | |
| 74 | + $get_fields = array( 'premium_upgrades', 'favi_icon', 'ignored_wp_upgrades', 'ignored_trans_updates' ); | |
| 56 | 75 | $custom_fields = apply_filters( 'mainwp_available_updates_count_custom_fields_data', array(), 'updates_count' ); |
| 57 | 76 | |
| 58 | 77 | if ( is_array( $custom_fields ) && 1 === count( $custom_fields ) && in_array( 'plugin_db_upgrades', $custom_fields ) ) { |
| 59 | 78 | $get_fields = array_merge( $get_fields, $custom_fields ); |
| @@ -60,9 +79,9 @@ | ||
| 60 | 79 | $db_updater_count = true; |
| 61 | 80 | $supported_db_updater_plugins = apply_filters( 'mainwp_database_updater_supported_plugins', array() ); |
| 62 | 81 | } |
| 63 | 82 | |
| 64 | - $sql = MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, false, $get_fields, $is_staging ); | |
| 83 | + $sql = MainWP_DB::instance()->get_sql_websites_for_current_user( false, null, 'wp.url', false, false, null, false, $get_fields, $is_staging, array( 'connected' => 'yes' ) ); | |
| 65 | 84 | |
| 66 | 85 | $userExtension = MainWP_DB_Common::instance()->get_user_extension(); |
| 67 | 86 | |
| 68 | 87 | $decodedIgnoredCores = ! empty( $userExtension->ignored_wp_upgrades ) ? json_decode( $userExtension->ignored_wp_upgrades, true ) : array(); |
| @@ -94,8 +113,12 @@ | ||
| 94 | 113 | } |
| 95 | 114 | |
| 96 | 115 | $translation_upgrades = json_decode( $website->translation_upgrades, true ); |
| 97 | 116 | |
| 117 | + if ( ! empty( $website->ignored_trans_updates ) ) { | |
| 118 | + $translation_upgrades = array(); | |
| 119 | + } | |
| 120 | + | |
| 98 | 121 | $plugin_upgrades = json_decode( $website->plugin_upgrades, true ); |
| 99 | 122 | if ( $website->is_ignorePluginUpdates ) { |
| 100 | 123 | $plugin_upgrades = array(); |
| 101 | 124 | } |
| @@ -119,9 +142,9 @@ | ||
| 119 | 142 | if ( ! $website->is_ignorePluginUpdates ) { |
| 120 | 143 | |
| 121 | 144 | $premiumUpgrade = array_filter( $premiumUpgrade ); |
| 122 | 145 | if ( ! isset( $plugin_upgrades[ $crrSlug ] ) ) { |
| 123 | - $plugin_upgrades[ $crrSlug ] = array(); | |
| 146 | + continue; | |
| 124 | 147 | } |
| 125 | 148 | |
| 126 | 149 | $plugin_upgrades[ $crrSlug ] = array_merge( $plugin_upgrades[ $crrSlug ], $premiumUpgrade ); |
| 127 | 150 | } |
| @@ -177,14 +200,14 @@ | ||
| 177 | 200 | |
| 178 | 201 | if ( is_array( $plugin_db_upgrades ) && ! $website->is_ignorePluginUpdates ) { |
| 179 | 202 | $_ignored_plugins = ! empty( $website->ignored_plugins ) ? json_decode( $website->ignored_plugins, true ) : array(); |
| 180 | 203 | if ( is_array( $_ignored_plugins ) ) { |
| 181 | - $plugin_db_upgrades = array_diff_key( $plugin_db_upgrades, $_ignored_plugins ); | |
| 204 | + $plugin_db_upgrades = $this->get_not_ignored_updates_plugins_db( $plugin_db_upgrades, $_ignored_plugins ); | |
| 182 | 205 | } |
| 183 | 206 | |
| 184 | 207 | $_ignored_plugins = ! empty( $userExtension->ignored_plugins ) ? json_decode( $userExtension->ignored_plugins, true ) : array(); |
| 185 | 208 | if ( is_array( $_ignored_plugins ) ) { |
| 186 | - $plugin_db_upgrades = array_diff_key( $plugin_db_upgrades, $_ignored_plugins ); | |
| 209 | + $plugin_db_upgrades = $this->get_not_ignored_updates_plugins_db( $plugin_db_upgrades, $_ignored_plugins ); | |
| 187 | 210 | } |
| 188 | 211 | |
| 189 | 212 | // supported the WC plugin. |
| 190 | 213 | if ( is_array( $plugin_db_upgrades ) ) { |
| @@ -226,9 +249,49 @@ | ||
| 226 | 249 | $data['total'] += $total_plugin_db_upgrades; |
| 227 | 250 | } |
| 228 | 251 | MainWP_DB::free_result( $websites ); |
| 229 | 252 | |
| 253 | + // set cache. | |
| 254 | + MainWP_Cache_Helper::add_cache( $cache_key, $cache_group, $data ); | |
| 255 | + | |
| 230 | 256 | return $data; |
| 257 | + } | |
| 258 | + | |
| 259 | + | |
| 260 | + /** | |
| 261 | + * Method get_not_ignored_updates_plugins_db(). | |
| 262 | + * | |
| 263 | + * To compatible with new ignored update info. | |
| 264 | + * | |
| 265 | + * @param array $updates Update info. | |
| 266 | + * @param array $ignored Ignored update info. | |
| 267 | + * @param int $count_ignored Count ignored updates. | |
| 268 | + * | |
| 269 | + * @return array $updates Not ignored updates info. | |
| 270 | + */ | |
| 271 | + public function get_not_ignored_updates_plugins_db( $updates, $ignored, &$count_ignored = 0 ) { //phpcs:ignore -- NOSONAR - complexity. | |
| 272 | + if ( ! is_array( $updates ) || ! is_array( $ignored ) ) { | |
| 273 | + return $updates; | |
| 274 | + } | |
| 275 | + $new_updates = array(); | |
| 276 | + foreach ( $updates as $slug => $dbup_info ) { | |
| 277 | + if ( isset( $ignored[ $slug ] ) ) { | |
| 278 | + if ( is_string( $ignored[ $slug ] ) ) { | |
| 279 | + ++$count_ignored; | |
| 280 | + // old ignored info. | |
| 281 | + continue; // ignored update. | |
| 282 | + } elseif ( is_array( $ignored[ $slug ] ) && ! empty( $ignored[ $slug ]['ignored_versions'] ) ) { | |
| 283 | + $ignored_vers = is_array( $ignored[ $slug ]['ignored_versions'] ) ? $ignored[ $slug ]['ignored_versions'] : array(); | |
| 284 | + $cur_version = is_array( $dbup_info ) && isset( $dbup_info['version'] ) ? $dbup_info['version'] : ''; | |
| 285 | + if ( in_array( 'all_versions', $ignored_vers ) || ( ! empty( $cur_version ) && in_array( $cur_version, $ignored_vers ) ) ) { | |
| 286 | + ++$count_ignored; | |
| 287 | + continue; // ignored update. | |
| 288 | + } | |
| 289 | + } | |
| 290 | + } | |
| 291 | + $new_updates[ $slug ] = $dbup_info; | |
| 292 | + } | |
| 293 | + return $new_updates; | |
| 231 | 294 | } |
| 232 | 295 | } |
| 233 | 296 | |
| 234 | 297 | // End of class. |