Skip to content

Instantly share code, notes, and snippets.

@mbabker
Last active November 11, 2022 20:11

Revisions

  1. mbabker revised this gist Feb 1, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion postupdate.php
    Original file line number Diff line number Diff line change
    @@ -44,7 +44,7 @@
    }
    else
    {
    require_once JPATH_BASE . '/includes/subtoolbar.php'
    require_once JPATH_BASE . '/includes/subtoolbar.php';
    }

    // Boot JApplicationAdministrator so the application references in the factory resolve correctly.
  2. mbabker revised this gist Dec 24, 2018. 1 changed file with 10 additions and 1 deletion.
    11 changes: 10 additions & 1 deletion postupdate.php
    Original file line number Diff line number Diff line change
    @@ -36,7 +36,16 @@

    require_once JPATH_BASE . '/includes/framework.php';
    require_once JPATH_BASE . '/includes/helper.php';
    require_once JPATH_BASE . '/includes/toolbar.php';

    // Account for moved JToolbarHelper class in 3.9
    if (file_exists(JPATH_BASE . '/includes/toolbar.php'))
    {
    require_once JPATH_BASE . '/includes/toolbar.php';
    }
    else
    {
    require_once JPATH_BASE . '/includes/subtoolbar.php'
    }

    // Boot JApplicationAdministrator so the application references in the factory resolve correctly.
    JFactory::getApplication('administrator');
  3. mbabker revised this gist Jun 15, 2016. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion postupdate.php
    Original file line number Diff line number Diff line change
    @@ -41,8 +41,13 @@
    // Boot JApplicationAdministrator so the application references in the factory resolve correctly.
    JFactory::getApplication('administrator');

    // Set the component path (un)constants
    define('JPATH_COMPONENT', JPATH_ADMINISTRATOR . '/components/com_joomlaupdate');
    define('JPATH_COMPONENT_ADMINISTRATOR', JPATH_ADMINISTRATOR . '/components/com_joomlaupdate');
    define('JPATH_COMPONENT_SITE', JPATH_SITE . '/components/com_joomlaupdate');

    // Load the update component's model to run the cleanup methods
    JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_joomlaupdate/models', 'JoomlaupdateModel');
    JModelLegacy::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . '/models', 'JoomlaupdateModel');

    /** @var JoomlaupdateModelDefault $model */
    $model = JModelLegacy::getInstance('default', 'JoomlaupdateModel');
  4. mbabker revised this gist May 12, 2016. 1 changed file with 18 additions and 0 deletions.
    18 changes: 18 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    # Post-Manual Update Script

    If you have found yourself in a scenario where you cannot update Joomla! via the Joomla! Update Component
    and need to perform a manual update for any reason whatsoever, this script will assist with performing all
    necessary steps that would be taken after the update component runs the updates on the filesystem.

    This script assumes that you have manually extracted the update package over your site and are ready to
    finish the update. You should trigger this script immediately after this process and before logging into
    your site's admin to do anything else, including the "database fix" routine.

    To use this script, you should copy the `postupdate.php` file to your site's administrator directory.
    You can either access this script via a web request (`https://www.example.com/administrator/postupdate.php`)
    or from the command line interface (`php /path/to/administrator/postupdate.php`).

    This script will run the "finalise" and "cleanup" steps from the update component, which performs such tasks
    as any database migrations and the removal of old files from your installation.

    Once complete, you should immediately remove this script from your server.
  5. mbabker revised this gist May 12, 2016. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions postupdate.php
    Original file line number Diff line number Diff line change
    @@ -65,6 +65,12 @@
    array('Update', 'databasequery', 'jerror')
    );

    JLog::add('Starting manual update using postupdate', JLog::INFO, 'Update');

    // Load the Joomla library and update component language files
    JFactory::getLanguage()->load('lib_joomla');
    JFactory::getLanguage()->load('com_joomlaupdate');

    JLog::add(JText::_('COM_JOOMLAUPDATE_UPDATE_LOG_FINALISE'), JLog::INFO, 'Update');

    // Finalize the update
    @@ -81,5 +87,6 @@
    $model->cleanUp();

    JLog::add(JText::sprintf('COM_JOOMLAUPDATE_UPDATE_LOG_COMPLETE', JVERSION), JLog::INFO, 'Update');
    JLog::add('Finished manual update using postupdate', JLog::INFO, 'Update');

    echo 'Update to ' . JVERSION . ' completed successfully.' . PHP_EOL;
  6. mbabker revised this gist May 10, 2016. 1 changed file with 24 additions and 0 deletions.
    24 changes: 24 additions & 0 deletions postupdate.php
    Original file line number Diff line number Diff line change
    @@ -47,6 +47,26 @@
    /** @var JoomlaupdateModelDefault $model */
    $model = JModelLegacy::getInstance('default', 'JoomlaupdateModel');

    // Make sure we got the model
    if (!($model instanceof JoomlaupdateModelDefault))
    {
    echo 'Could not load update component model, please check the logs for additional details.' . PHP_EOL;

    exit(1);
    }

    // Load up the logger
    JLog::addLogger(
    array(
    'format' => '{DATE}\t{TIME}\t{LEVEL}\t{CODE}\t{MESSAGE}',
    'text_file' => 'joomla_update.php',
    ),
    JLog::INFO,
    array('Update', 'databasequery', 'jerror')
    );

    JLog::add(JText::_('COM_JOOMLAUPDATE_UPDATE_LOG_FINALISE'), JLog::INFO, 'Update');

    // Finalize the update
    if ($model->finaliseUpgrade() === false)
    {
    @@ -55,7 +75,11 @@
    exit(1);
    }

    JLog::add(JText::_('COM_JOOMLAUPDATE_UPDATE_LOG_CLEANUP'), JLog::INFO, 'Update');

    // Cleanup after the update
    $model->cleanUp();

    JLog::add(JText::sprintf('COM_JOOMLAUPDATE_UPDATE_LOG_COMPLETE', JVERSION), JLog::INFO, 'Update');

    echo 'Update to ' . JVERSION . ' completed successfully.' . PHP_EOL;
  7. mbabker revised this gist May 10, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions postupdate.php
    Original file line number Diff line number Diff line change
    @@ -42,10 +42,10 @@
    JFactory::getApplication('administrator');

    // Load the update component's model to run the cleanup methods
    JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_joomlaupdate/models', 'Joomlaupdate');
    JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_joomlaupdate/models', 'JoomlaupdateModel');

    /** @var JoomlaupdateModelDefault $model */
    $model = JModelLegacy::getInstance('default', 'Joomlaupdate');
    $model = JModelLegacy::getInstance('default', 'JoomlaupdateModel');

    // Finalize the update
    if ($model->finaliseUpgrade() === false)
  8. mbabker created this gist May 10, 2016.
    61 changes: 61 additions & 0 deletions postupdate.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,61 @@
    <?php
    /**
    * @package Joomla.Administrator
    *
    * @copyright Copyright (C) 2016 Open Source Matters, Inc. All rights reserved.
    * @license GNU General Public License version 2 or later; see LICENSE.txt
    */

    /**
    * Define the application's minimum supported PHP version as a constant so it can be referenced within the application.
    */
    define('JOOMLA_MINIMUM_PHP', '5.3.10');

    if (version_compare(PHP_VERSION, JOOMLA_MINIMUM_PHP, '<'))
    {
    die('Your host needs to use PHP ' . JOOMLA_MINIMUM_PHP . ' or higher to run this version of Joomla!');
    }

    /**
    * Constant that is checked in included files to prevent direct access.
    * define() is used in the installation folder rather than "const" to not error for PHP 5.2 and lower
    */
    define('_JEXEC', 1);

    // Load the administrator application's path constants
    if (file_exists(__DIR__ . '/defines.php'))
    {
    include_once __DIR__ . '/defines.php';
    }

    if (!defined('_JDEFINES'))
    {
    define('JPATH_BASE', __DIR__);
    require_once JPATH_BASE . '/includes/defines.php';
    }

    require_once JPATH_BASE . '/includes/framework.php';
    require_once JPATH_BASE . '/includes/helper.php';
    require_once JPATH_BASE . '/includes/toolbar.php';

    // Boot JApplicationAdministrator so the application references in the factory resolve correctly.
    JFactory::getApplication('administrator');

    // Load the update component's model to run the cleanup methods
    JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_joomlaupdate/models', 'Joomlaupdate');

    /** @var JoomlaupdateModelDefault $model */
    $model = JModelLegacy::getInstance('default', 'Joomlaupdate');

    // Finalize the update
    if ($model->finaliseUpgrade() === false)
    {
    echo 'Failed to finalize the upgrade, please check the logs for additional details.' . PHP_EOL;

    exit(1);
    }

    // Cleanup after the update
    $model->cleanUp();

    echo 'Update to ' . JVERSION . ' completed successfully.' . PHP_EOL;