require_once INCLUDES_DIR.DIR."class".DIR."Config.php"; # File: SQL # See Also: # require INCLUDES_DIR.DIR."class".DIR."SQL.php"; # File: Translation # See Also: # require_once INCLUDES_DIR.DIR."class".DIR."Translation.php"; # Register our autoloader. spl_autoload_register("autoload"); # Boolean: $upgraded # Has Chyrp Lite been upgraded? $upgraded = false; # Load the config settings. $config = Config::current(); # Prepare the SQL interface. $sql = SQL::current(); # Initialize connection to SQL server. $sql->connect(); # Set the locale. set_locale($config->locale); # Load the translation engine. load_translator("chyrp", INCLUDES_DIR.DIR."locale"); /** * Function: alert * Logs an alert message and returns the log to date. */ function alert($message = null): ?array { static $log = array(); if (isset($message)) $log[] = (string) $message; return empty($log) ? null : $log ; } /** * Function: test_directories * Tests whether or not the directories that need write access have it. */ function test_directories(): void { # Test if we can write to MAIN_DIR (needed for the .htaccess file). if (!is_writable(MAIN_DIR)) alert( __("Please CHMOD or CHOWN the installation directory to make it writable.") ); # Test if we can write to INCLUDES_DIR (needed for config.json.php). if (!is_writable(INCLUDES_DIR)) alert( __("Please CHMOD or CHOWN the includes directory to make it writable.") ); # Test if we can write to CACHES_DIR (needed by some extensions). if (!is_writable(CACHES_DIR)) alert( __("Please CHMOD or CHOWN the caches directory to make it writable.") ); # Test if we can write to twig cache. if (!is_writable(CACHES_DIR.DIR."twig")) alert( __("Please CHMOD or CHOWN the twig directory to make it writable.") ); # Test if we can write to thumbs cache. if (!is_writable(CACHES_DIR.DIR."thumbs")) alert( __("Please CHMOD or CHOWN the thumbs directory to make it writable.") ); } /** * Function: update_htaccess * Updates the .htaccess file to ensure all features are supported. * * Versions: 2018.02 => 2018.03 */ function update_htaccess(): void { $config = Config::current(); if (file_exists(MAIN_DIR.DIR.".htaccess")) { $set = htaccess_conf(); if ($set === false) alert(__("Failed to write file to disk.")); } } /** * Function: update_caddyfile * Updates the caddyfile to ensure all features are supported. * * Versions: 2019.03 => 2019.04 */ function update_caddyfile(): void { $config = Config::current(); if (file_exists(MAIN_DIR.DIR."caddyfile")) { $set = caddyfile_conf(); if ($set === false) alert(__("Failed to write file to disk.")); } } /** * Function: update_nginx * Updates the nginx configuration to ensure all features are supported. * * Versions: 2019.03 => 2019.04 */ function update_nginx(): void { $config = Config::current(); if (file_exists(MAIN_DIR.DIR."include.conf")) { $set = nginx_conf(); if ($set === false) alert(__("Failed to write file to disk.")); } } /** * Function: add_markdown * Adds the enable_markdown config setting. * * Versions: 2015.06 => 2015.07 */ function add_markdown(): void { $set = Config::current()->set("enable_markdown", true, true); if ($set === false) error( __("Error"), __("Could not write the configuration file.") ); } /** * Function: add_homepage * Adds the enable_homepage config setting. * * Versions: 2015.06 => 2015.07 */ function add_homepage(): void { $set = Config::current()->set("enable_homepage", false, true); if ($set === false) error( __("Error"), __("Could not write the configuration file.") ); } /** * Function: add_uploads_limit * Adds the uploads_limit config setting. * * Versions: 2015.06 => 2015.07 */ function add_uploads_limit(): void { $set = Config::current()->set("uploads_limit", 10, true); if ($set === false) error( __("Error"), __("Could not write the configuration file.") ); } /** * Function: remove_trackbacking * Removes the enable_trackbacking config setting. * * Versions: 2015.06 => 2015.07 */ function remove_trackbacking(): void { $set = Config::current()->remove("enable_trackbacking"); if ($set === false) error( __("Error"), __("Could not write the configuration file.") ); } /** * Function: add_admin_per_page * Adds the admin_per_page config setting. * * Versions: 2015.07 => 2016.01 */ function add_admin_per_page(): void { $set = Config::current()->set("admin_per_page", 25, true); if ($set === false) error( __("Error"), __("Could not write the configuration file.") ); } /** * Function: disable_importers * Disables the importers module. * * Versions: 2016.03 => 2016.04 */ function disable_importers(): void { $config = Config::current(); $set = $config->set( "enabled_modules", array_diff($config->enabled_modules, array("importers")) ); if ($set === false) error( __("Error"), __("Could not write the configuration file.") ); } /** * Function: add_export_content * Adds the export_content permission. * * Versions: 2016.03 => 2016.04 */ function add_export_content(): void { $sql = SQL::current(); if ( !$sql->count( "permissions", array( "id" => "export_content", "group_id" => 0 ) ) ) $sql->insert( "permissions", array( "id" => "export_content", "name" => "Export Content", "group_id" => 0 ) ); } /** * Function: add_feed_format * Adds the feed_format config setting. * * Versions: 2017.02 => 2017.03 */ function add_feed_format(): void { $set = Config::current()->set("feed_format", "AtomFeed", true); if ($set === false) error( __("Error"), __("Could not write the configuration file.") ); } /** * Function: remove_captcha * Removes the enable_captcha config setting. * * Versions: 2017.03 => 2018.01 */ function remove_captcha(): void { $set = Config::current()->remove("enable_captcha"); if ($set === false) error( __("Error"), __("Could not write the configuration file.") ); } /** * Function: disable_recaptcha * Disables the recaptcha module. * * Versions: 2017.03 => 2018.01 */ function disable_recaptcha(): void { $config = Config::current(); $set = $config->set( "enabled_modules", array_diff($config->enabled_modules, array("recaptcha")) ); if ($set === false) error( __("Error"), __("Could not write the configuration file.") ); } /** * Function: remove_feed_url * Removes the feed_url config setting. * * Versions: 2018.03 => 2018.04 */ function remove_feed_url(): void { $set = Config::current()->remove("feed_url"); if ($set === false) error( __("Error"), __("Could not write the configuration file.") ); } /** * Function: remove_cookies_notification * Removes the cookies_notification config setting. * * Versions: 2019.01 => 2019.02 */ function remove_cookies_notification(): void { $set = Config::current()->remove("cookies_notification"); if ($set === false) error( __("Error"), __("Could not write the configuration file.") ); } /** * Function: remove_ajax * Removes the enable_ajax config setting. * * Versions: 2019.02 => 2019.03 */ function remove_ajax(): void { $set = Config::current()->remove("enable_ajax"); if ($set === false) error( __("Error"), __("Could not write the configuration file.") ); } /** * Function: disable_simplemde * Disables the simplemde module. * * Versions: 2019.03 => 2019.04 */ function disable_simplemde(): void { $config = Config::current(); $set = $config->set( "enabled_modules", array_diff($config->enabled_modules, array("simplemde")) ); if ($set === false) error( __("Error"), __("Could not write the configuration file.") ); } /** * Function: add_search_pages * Adds the search_pages config setting. * * Versions: 2020.03 => 2020.04 */ function add_search_pages(): void { $set = Config::current()->set("search_pages", false, true); if ($set === false) error( __("Error"), __("Could not write the configuration file.") ); } /** * Function: fix_sqlite_post_pinned * Fixes the pinned status of posts created without bool-to-int conversion. * * Versions: 2021.01 => 2021.02 */ function fix_sqlite_post_pinned(): void { $sql = SQL::current(); if ($sql->adapter != "sqlite") return; $results = $sql->select( tables:"posts", fields:"id", conds:array("pinned" => "") )->fetchAll(); foreach ($results as $result) $sql->update( table:"posts", conds:array("id" => $result["id"]), data:array("pinned" => false) ); } /** * Function: fix_post_updated * Normalizes updated_at values to "1000-01-01 00:00:00". * * Versions: 2022.01 => 2022.02, 2024.01 */ function fix_post_updated(): void { $sql = SQL::current(); $values = ($sql->adapter == "pgsql") ? array( "0001-01-01 00:00:00" ) : array( "0000-00-00 00:00:00", "0001-01-01 00:00:00" ) ; $results = $sql->select( tables:"posts", fields:"id", conds:array("updated_at" => $values) )->fetchAll(); foreach ($results as $result) $sql->update( table:"posts", conds:array("id" => $result["id"]), data:array("updated_at" => SQL_DATETIME_ZERO) ); } /** * Function: mysql_utf8mb4 * Upgrades MySQL database tables and columns to utf8mb4. * * Versions: 2022.01 => 2022.02 */ function mysql_utf8mb4(): void { $sql = SQL::current(); if ($sql->adapter != "mysql") return; $tables = $sql->query("SHOW TABLE STATUS")->fetchAll(); foreach ($tables as $table) { if (strpos($table["Collation"], "utf8mb4_") === 0) continue; $sql->query( "ALTER TABLE \"".$table["Name"]. "\" CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci" ); } } /** * Function: add_import_content * Adds the import_content permission. * * Versions: 2022.02 => 2022.03 */ function add_import_content(): void { $sql = SQL::current(); if ( !$sql->count( "permissions", array( "id" => "import_content", "group_id" => 0 ) ) ) $sql->insert( "permissions", array( "id" => "import_content", "name" => "Import Content", "group_id" => 0 ) ); } /** * Function: remove_xmlrpc * Removes the enable_xmlrpc config setting. * * Versions: 2022.03 => 2023.01 */ function remove_xmlrpc(): void { $set = Config::current()->remove("enable_xmlrpc"); if ($set === false) error( __("Error"), __("Could not write the configuration file.") ); } /** * Function: add_monospace_font * Adds the monospace_font config setting. * * Versions: 2023.03 => 2024.01 */ function add_monospace_font(): void { $set = Config::current()->set("monospace_font", false, true); if ($set === false) error( __("Error"), __("Could not write the configuration file.") ); } #--------------------------------------------- # Output Starts #--------------------------------------------- ?> <?php echo __("Chyrp Lite Upgrader"); ?>
enabled_modules as $module) {
            if (file_exists(MAIN_DIR.DIR."modules".DIR.$module.DIR."upgrades.php"))
                require MAIN_DIR.DIR."modules".DIR.$module.DIR."upgrades.php";
        }

        # Perform feather upgrades.
        foreach ($config->enabled_feathers as $feather) {
            if (file_exists(MAIN_DIR.DIR."feathers".DIR.$feather.DIR."upgrades.php"))
                require MAIN_DIR.DIR."feathers".DIR.$feather.DIR."upgrades.php";
        }

        @unlink(INCLUDES_DIR.DIR."upgrading.lock");
        $upgraded = true;
    }

    #---------------------------------------------
    # Upgrading Ends
    #---------------------------------------------

    foreach ((array) alert() as $message)
        echo ''.sanitize_html($message).''."\n";

            ?>

  1. Backup your database before proceeding!"); ?>

  1. upgrade.php once you are finished upgrading."); ?>