itorTable . "` LIKE 'AString'"); if ($result > 0) { $this->wpdb->query("ALTER TABLE `" . $visitorTable . "` DROP `AString`"); } // Add index ip $result = $this->wpdb->query("SHOW INDEX FROM `" . $visitorTable . "` WHERE Key_name = 'ip'"); if (!$result) { $this->wpdb->query("ALTER TABLE `" . $visitorTable . "` ADD index (ip)"); } } /** * Update options */ if (Option::get('privacy_audit') === false && version_compare($this->latestVersion, '14.7', '>=')) { Option::update('privacy_audit', true); } if (Option::get('share_anonymous_data') === false && version_compare($this->latestVersion, '14.12', '>')) { Option::update('share_anonymous_data', false); } if (Option::get('display_notifications') === false && version_compare($this->latestVersion, '14.12', '>')) { Option::update('display_notifications', true); } if (Option::get('show_privacy_issues_in_report') === false && version_compare($this->latestVersion, '14.12', '>')) { Option::update('show_privacy_issues_in_report', false); } /** * Update GeoIP schedule from daily to monthly */ if (Option::get('schedule_geoip') && version_compare($this->currentVersion, '14.11', '<')) { Event::reschedule('wp_statistics_geoip_hook', 'monthly'); } /** * Remove wp_statistics_marketing_campaign_hook, wp_statistics_notification_hook from schedule */ if (version_compare($this->latestVersion, '14.15', '>=')) { Event::unschedule('wp_statistics_marketing_campaign_hook'); Event::unschedule('wp_statistics_notification_hook'); } /** * Remove wp_statistics_add_visit_hook from schedule */ if (version_compare($this->latestVersion, '14.15', '>=')) { Event::unschedule('wp_statistics_add_visit_hook'); } /** * Remove all wp statistics transients */ if (version_compare($this->latestVersion, '14.15.1', '>=')) { SystemCleaner::clearAllTransients(); } /** * Remove wp_statistics_referrerspam_hook from schedule */ if (version_compare($this->latestVersion, '14.16', '>=')) { Event::unschedule('wp_statistics_referrerspam_hook'); } /** * The Tracker Debugger no longer stores PHP errors raised during hits, so drop * the log it kept. */ if (version_compare($this->currentVersion, '14.16.19', '<')) { delete_option('wp_statistics_tracker_js_errors'); } /** * Update consent integration to WP Consent API for backward compatibility */ $integration = Option::get('consent_integration'); $isWpConsentApiActive = IntegrationHelper::getIntegration('wp_consent_api')->isActive(); if ($isWpConsentApiActive && empty($integration)) { Option::update('consent_integration', 'wp_consent_api'); } /** * Removes duplicate entries from the visitor_relationships table. * * @version 14.4 */ //self::delete_duplicate_data(); // todo to move in background cronjob /** * Remove old hash format assets * * @version 14.8.1 */ if (Option::get('bypass_ad_blockers', false) && $this->currentVersion == '14.8' && class_exists('WP_Statistics\Components\AssetNameObfuscator')) { $assetNameObfuscator = new AssetNameObfuscator(); $assetNameObfuscator->deleteAllHashedFiles(); $assetNameObfuscator->deleteDatabaseOption(); } // Enable Top Metrics in Advanced Reporting Add-on By Default $advancedReportingOptions = Option::getAddonOptions('advanced_reporting'); if ($advancedReportingOptions !== false && Option::getByAddon('email_top_metrics', 'advanced_reporting') === false) { Option::saveByAddon(array_merge(['email_top_metrics' => 1], $advancedReportingOptions), 'advanced_reporting'); } /** * Update old DataPlus options. * * @version 14.10 */ if (version_compare($this->currentVersion, '14.10', '<') && (Option::get('link_tracker') || Option::get('download_tracker'))) { Option::saveByAddon([ 'link_tracker' => Option::get('link_tracker'), 'download_tracker' => Option::get('download_tracker'), 'latest_visitors_metabox' => '1', ], 'data_plus'); } // Clear not used scheduled. if (function_exists('wp_clear_scheduled_hook')) { // Remove unused cron job for purging high hit count visitors daily wp_clear_scheduled_hook('wp_statistics_dbmaint_visitor_hook'); // Remove referral db update cron wp_clear_scheduled_hook('wp_statistics_referrals_db_hook'); } /** * Update old excluded URLs to the new structure with explicit wildcards. * * @version 14.10.3 */ if (version_compare($this->currentVersion, '14.10.3', '<') && Option::get('excluded_urls')) { $updatedExcludedUrls = $this->updateOldExcludedUrls(); if (!empty($updatedExcludedUrls)) { Option::update('excluded_urls', implode("\n", $updatedExcludedUrls)); } } if (!Option::get('schedule_dbmaint') && version_compare($this->currentVersion, '14.15.5', '<')) { Option::update('schedule_dbmaint_days', '0'); } if (Option::get('schedule_dbmaint') && version_compare($this->currentVersion, '14.15.5', '<')) { Event::reschedule('wp_statistics_dbmaint_hook', 'daily', DateTime::get('tomorrow midnight', 'U')); } } /** * Updates old excluded URLs to the new structure with explicit wildcards. * * @return array updated URLs. */ private function updateOldExcludedUrls() { $updatedUrls = []; foreach (explode("\n", Option::get('excluded_urls')) as $url) { $url = wp_make_link_relative($url); $url = trim($url); // If the URL contains a query string, strip it $url = explode('?', $url)[0]; // Trim leading/trailing slashes $url = trim($url, '/\\'); // If the URL doesn't end with an asterisk (*), add one and make it a wildcard if (substr($url, -1) !== '*') { $url .= '*'; } // Add the URL to the new list if it's not similar to others if (!in_array($url, $updatedUrls)) { $updatedUrls[] = $url; } } return $updatedUrls; } }