Plugin Directory

Changeset 3400945


Ignore:
Timestamp:
11/22/2025 01:06:05 PM (4 months ago)
Author:
aaron13100
Message:
  • FIX: Table creation issues on multisite. (Thanks to debug file participants!)
Location:
404-solution
Files:
14 edited
1 copied

Legend:

Unmodified
Added
Removed
  • 404-solution/tags/3.0.2/404-solution.php

    r3400707 r3400945  
    88    Author URI:  https://www.ajexperience.com/404-solution/
    99
    10     Version: 3.0.1
     10    Version: 3.0.2
    1111    Requires at least: 5.0
    1212    Requires PHP: 7.4
     
    222222    $abj404dao->deleteOldRedirectsCron();
    223223
    224     // Ngram cache maintenance: sync missing entries and cleanup orphaned ones
    225224    $dbUpgrades = ABJ_404_Solution_DatabaseUpgradesEtc::getInstance();
    226     $dbUpgrades->syncMissingNGrams();
    227     $dbUpgrades->cleanupOrphanedNGrams();
    228 
    229     // Clean up expired rate limit transients to prevent wp_options bloat
    230     $dbUpgrades->cleanupExpiredRateLimitTransients();
     225    $dbUpgrades->runDatabaseMaintenanceTasks();
    231226}
    232227function abj404_updateLogsHitsTableListener() {
  • 404-solution/tags/3.0.2/CHANGELOG.md

    r3400707 r3400945  
    11# Changelog #
     2
     3## Version 3.0.2 (Nov 22, 2025) ##
     4* FIX: Table creation issues on multisite. (Thanks to debug file participants!)
    25
    36## Version 3.0.1 (Nov 20, 2025) ##
  • 404-solution/tags/3.0.2/README.md

    r3400707 r3400945  
    8181## Changelog ##
    8282
     83## Version 3.0.2 (Nov 22, 2025) ##
     84* FIX: Table creation issues on multisite. (Thanks to debug file participants!)
     85
    8386## Version 3.0.1 (Nov 20, 2025) ##
    8487* Improvement: Use accordions on the settings screen instead of chips.
  • 404-solution/tags/3.0.2/includes/DatabaseUpgradesEtc.php

    r3400707 r3400945  
    19421942
    19431943    /**
     1944     * Daily insurance check: verify tables exist and repair if needed.
     1945     *
     1946     * This is a safety net that runs during daily maintenance to catch:
     1947     * - Failed table creation during activation/upgrade
     1948     * - Database corruption or manual table deletions
     1949     * - Edge cases we haven't anticipated
     1950     *
     1951     * Behavior:
     1952     * - Verifies CURRENT site only (per-site cron execution)
     1953     * - In multisite networks, each site's cron verifies its own tables
     1954     * - This avoids O(N²) performance when N sites each loop through N sites
     1955     *
     1956     * The check is lightweight (6 SHOW TABLES queries) and the repair
     1957     * reuses the same idempotent table creation logic used during activation.
     1958     *
     1959     * @return void
     1960     */
     1961    public function runDailyInsuranceCheck() {
     1962        // Always verify current site only
     1963        // Per-site cron execution ensures network coverage without O(N²) duplication
     1964        $this->verifyAndRepairCurrentSite();
     1965    }
     1966
     1967    /**
     1968     * Verify and repair tables for the current site only.
     1969     *
     1970     * Checks all 6 required tables for the plugin:
     1971     * - abj404_redirects (redirect rules)
     1972     * - abj404_logsv2 (404 hits and redirect logs)
     1973     * - abj404_lookup (user/location lookups)
     1974     * - abj404_permalink_cache (performance cache)
     1975     * - abj404_spelling_cache (spell-check results cache)
     1976     * - abj404_ngram_cache (n-gram search cache)
     1977     *
     1978     * If ANY table is missing, triggers full table creation/repair.
     1979     *
     1980     * @return void
     1981     */
     1982    private function verifyAndRepairCurrentSite() {
     1983        global $wpdb;
     1984
     1985        // Define all required tables
     1986        $requiredTables = [
     1987            'abj404_redirects',
     1988            'abj404_logsv2',
     1989            'abj404_lookup',
     1990            'abj404_permalink_cache',
     1991            'abj404_spelling_cache',
     1992            'abj404_ngram_cache',
     1993        ];
     1994
     1995        $missingTables = [];
     1996
     1997        // Check each required table
     1998        foreach ($requiredTables as $tableName) {
     1999            $fullTableName = $wpdb->prefix . $tableName;
     2000            $tableExists = $wpdb->get_var("SHOW TABLES LIKE '{$fullTableName}'");
     2001
     2002            if (!$tableExists) {
     2003                $missingTables[] = $tableName;
     2004            }
     2005        }
     2006
     2007        // If any tables are missing, run repair
     2008        if (!empty($missingTables)) {
     2009            $this->logger->infoMessage(sprintf(
     2010                "Site %d (prefix: %s) is missing %d table(s): %s. Running repair...",
     2011                get_current_blog_id(),
     2012                $wpdb->prefix,
     2013                count($missingTables),
     2014                implode(', ', $missingTables)
     2015            ));
     2016
     2017            // Repair: call the same idempotent routine activation uses
     2018            // This is safe because createDatabaseTables() is idempotent
     2019            $this->createDatabaseTables(false);  // false = not updating to new version
     2020
     2021            $this->logger->infoMessage("Table repair complete for site " . get_current_blog_id());
     2022        }
     2023    }
     2024
     2025    /**
    19442026     * Clean up expired rate limit transients from wp_options table.
    19452027     *
     
    20092091
    20102092    /**
     2093     * Run all database maintenance tasks.
     2094     *
     2095     * This is the main orchestrator method called by the daily maintenance cron job.
     2096     * It coordinates all database-related maintenance tasks in the proper order.
     2097     *
     2098     * Called by: abj404_dailyMaintenanceCronJobListener() in 404-solution.php
     2099     *
     2100     * @return void
     2101     */
     2102    public function runDatabaseMaintenanceTasks() {
     2103        // Insurance: Verify tables exist (per-site or network-wide based on activation mode)
     2104        // This catches failed activations, database corruption, and edge cases
     2105        $this->runDailyInsuranceCheck();
     2106
     2107        // Ngram cache maintenance: sync missing entries and cleanup orphaned ones
     2108        $this->syncMissingNGrams();
     2109        $this->cleanupOrphanedNGrams();
     2110
     2111        // Clean up expired rate limit transients to prevent wp_options bloat
     2112        $this->cleanupExpiredRateLimitTransients();
     2113    }
     2114
     2115    /**
    20112116     * Build ngrams for all categories.
    20122117     * Should be called during initial setup or manual rebuild.
  • 404-solution/tags/3.0.2/includes/Loader.php

    r3400707 r3400945  
    1111    basename(dirname(ABJ404_FILE)) . '/' . basename(ABJ404_FILE));
    1212
    13 define( 'ABJ404_VERSION', '3.0.1' );
     13define( 'ABJ404_VERSION', '3.0.2' );
    1414define( 'URL_TRACKING_SUFFIX', '?utm_source=404SolutionPlugin&utm_medium=WordPress');
    1515define( 'ABJ404_HOME_URL', 'https://www.ajexperience.com/404-solution/' . URL_TRACKING_SUFFIX);
  • 404-solution/tags/3.0.2/includes/Uninstaller.php

    r3400707 r3400945  
    225225        $message .= "WordPress Version: " . get_bloginfo('version') . "\n";
    226226        $message .= "PHP Version: " . PHP_VERSION . "\n";
    227         $message .= "Plugin Version: 3.0.1\n";
     227        $message .= "Plugin Version: 3.0.2\n";
    228228        $message .= "Site URL: " . get_site_url() . "\n";
    229229        $message .= "Site Language: " . get_locale() . "\n";
  • 404-solution/tags/3.0.2/readme.txt

    r3400707 r3400945  
    66Requires PHP: 7.4
    77Tested up to: 6.8
    8 Stable tag: 3.0.1
     8Stable tag: 3.0.2
    99License: GPL-3.0-or-later
    1010License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    240240== Changelog ==
    241241
     242= Version 3.0.2 (Nov 22, 2025) =
     243* FIX: Table creation issues on multisite. (Thanks to debug file participants!)
     244
    242245= Version 3.0.1 (Nov 20, 2025) =
    243246* Improvement: Use accordions on the settings screen instead of chips.
  • 404-solution/trunk/404-solution.php

    r3400707 r3400945  
    88    Author URI:  https://www.ajexperience.com/404-solution/
    99
    10     Version: 3.0.1
     10    Version: 3.0.2
    1111    Requires at least: 5.0
    1212    Requires PHP: 7.4
     
    222222    $abj404dao->deleteOldRedirectsCron();
    223223
    224     // Ngram cache maintenance: sync missing entries and cleanup orphaned ones
    225224    $dbUpgrades = ABJ_404_Solution_DatabaseUpgradesEtc::getInstance();
    226     $dbUpgrades->syncMissingNGrams();
    227     $dbUpgrades->cleanupOrphanedNGrams();
    228 
    229     // Clean up expired rate limit transients to prevent wp_options bloat
    230     $dbUpgrades->cleanupExpiredRateLimitTransients();
     225    $dbUpgrades->runDatabaseMaintenanceTasks();
    231226}
    232227function abj404_updateLogsHitsTableListener() {
  • 404-solution/trunk/CHANGELOG.md

    r3400707 r3400945  
    11# Changelog #
     2
     3## Version 3.0.2 (Nov 22, 2025) ##
     4* FIX: Table creation issues on multisite. (Thanks to debug file participants!)
    25
    36## Version 3.0.1 (Nov 20, 2025) ##
  • 404-solution/trunk/README.md

    r3400707 r3400945  
    8181## Changelog ##
    8282
     83## Version 3.0.2 (Nov 22, 2025) ##
     84* FIX: Table creation issues on multisite. (Thanks to debug file participants!)
     85
    8386## Version 3.0.1 (Nov 20, 2025) ##
    8487* Improvement: Use accordions on the settings screen instead of chips.
  • 404-solution/trunk/includes/DatabaseUpgradesEtc.php

    r3400707 r3400945  
    19421942
    19431943    /**
     1944     * Daily insurance check: verify tables exist and repair if needed.
     1945     *
     1946     * This is a safety net that runs during daily maintenance to catch:
     1947     * - Failed table creation during activation/upgrade
     1948     * - Database corruption or manual table deletions
     1949     * - Edge cases we haven't anticipated
     1950     *
     1951     * Behavior:
     1952     * - Verifies CURRENT site only (per-site cron execution)
     1953     * - In multisite networks, each site's cron verifies its own tables
     1954     * - This avoids O(N²) performance when N sites each loop through N sites
     1955     *
     1956     * The check is lightweight (6 SHOW TABLES queries) and the repair
     1957     * reuses the same idempotent table creation logic used during activation.
     1958     *
     1959     * @return void
     1960     */
     1961    public function runDailyInsuranceCheck() {
     1962        // Always verify current site only
     1963        // Per-site cron execution ensures network coverage without O(N²) duplication
     1964        $this->verifyAndRepairCurrentSite();
     1965    }
     1966
     1967    /**
     1968     * Verify and repair tables for the current site only.
     1969     *
     1970     * Checks all 6 required tables for the plugin:
     1971     * - abj404_redirects (redirect rules)
     1972     * - abj404_logsv2 (404 hits and redirect logs)
     1973     * - abj404_lookup (user/location lookups)
     1974     * - abj404_permalink_cache (performance cache)
     1975     * - abj404_spelling_cache (spell-check results cache)
     1976     * - abj404_ngram_cache (n-gram search cache)
     1977     *
     1978     * If ANY table is missing, triggers full table creation/repair.
     1979     *
     1980     * @return void
     1981     */
     1982    private function verifyAndRepairCurrentSite() {
     1983        global $wpdb;
     1984
     1985        // Define all required tables
     1986        $requiredTables = [
     1987            'abj404_redirects',
     1988            'abj404_logsv2',
     1989            'abj404_lookup',
     1990            'abj404_permalink_cache',
     1991            'abj404_spelling_cache',
     1992            'abj404_ngram_cache',
     1993        ];
     1994
     1995        $missingTables = [];
     1996
     1997        // Check each required table
     1998        foreach ($requiredTables as $tableName) {
     1999            $fullTableName = $wpdb->prefix . $tableName;
     2000            $tableExists = $wpdb->get_var("SHOW TABLES LIKE '{$fullTableName}'");
     2001
     2002            if (!$tableExists) {
     2003                $missingTables[] = $tableName;
     2004            }
     2005        }
     2006
     2007        // If any tables are missing, run repair
     2008        if (!empty($missingTables)) {
     2009            $this->logger->infoMessage(sprintf(
     2010                "Site %d (prefix: %s) is missing %d table(s): %s. Running repair...",
     2011                get_current_blog_id(),
     2012                $wpdb->prefix,
     2013                count($missingTables),
     2014                implode(', ', $missingTables)
     2015            ));
     2016
     2017            // Repair: call the same idempotent routine activation uses
     2018            // This is safe because createDatabaseTables() is idempotent
     2019            $this->createDatabaseTables(false);  // false = not updating to new version
     2020
     2021            $this->logger->infoMessage("Table repair complete for site " . get_current_blog_id());
     2022        }
     2023    }
     2024
     2025    /**
    19442026     * Clean up expired rate limit transients from wp_options table.
    19452027     *
     
    20092091
    20102092    /**
     2093     * Run all database maintenance tasks.
     2094     *
     2095     * This is the main orchestrator method called by the daily maintenance cron job.
     2096     * It coordinates all database-related maintenance tasks in the proper order.
     2097     *
     2098     * Called by: abj404_dailyMaintenanceCronJobListener() in 404-solution.php
     2099     *
     2100     * @return void
     2101     */
     2102    public function runDatabaseMaintenanceTasks() {
     2103        // Insurance: Verify tables exist (per-site or network-wide based on activation mode)
     2104        // This catches failed activations, database corruption, and edge cases
     2105        $this->runDailyInsuranceCheck();
     2106
     2107        // Ngram cache maintenance: sync missing entries and cleanup orphaned ones
     2108        $this->syncMissingNGrams();
     2109        $this->cleanupOrphanedNGrams();
     2110
     2111        // Clean up expired rate limit transients to prevent wp_options bloat
     2112        $this->cleanupExpiredRateLimitTransients();
     2113    }
     2114
     2115    /**
    20112116     * Build ngrams for all categories.
    20122117     * Should be called during initial setup or manual rebuild.
  • 404-solution/trunk/includes/Loader.php

    r3400707 r3400945  
    1111    basename(dirname(ABJ404_FILE)) . '/' . basename(ABJ404_FILE));
    1212
    13 define( 'ABJ404_VERSION', '3.0.1' );
     13define( 'ABJ404_VERSION', '3.0.2' );
    1414define( 'URL_TRACKING_SUFFIX', '?utm_source=404SolutionPlugin&utm_medium=WordPress');
    1515define( 'ABJ404_HOME_URL', 'https://www.ajexperience.com/404-solution/' . URL_TRACKING_SUFFIX);
  • 404-solution/trunk/includes/Uninstaller.php

    r3400707 r3400945  
    225225        $message .= "WordPress Version: " . get_bloginfo('version') . "\n";
    226226        $message .= "PHP Version: " . PHP_VERSION . "\n";
    227         $message .= "Plugin Version: 3.0.1\n";
     227        $message .= "Plugin Version: 3.0.2\n";
    228228        $message .= "Site URL: " . get_site_url() . "\n";
    229229        $message .= "Site Language: " . get_locale() . "\n";
  • 404-solution/trunk/readme.txt

    r3400707 r3400945  
    66Requires PHP: 7.4
    77Tested up to: 6.8
    8 Stable tag: 3.0.1
     8Stable tag: 3.0.2
    99License: GPL-3.0-or-later
    1010License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    240240== Changelog ==
    241241
     242= Version 3.0.2 (Nov 22, 2025) =
     243* FIX: Table creation issues on multisite. (Thanks to debug file participants!)
     244
    242245= Version 3.0.1 (Nov 20, 2025) =
    243246* Improvement: Use accordions on the settings screen instead of chips.
Note: See TracChangeset for help on using the changeset viewer.