Create a gist now

Instantly share code, notes, and snippets.

@mbabker /README.md Secret
Last active Dec 7, 2016

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.

<?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');
// 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_COMPONENT_ADMINISTRATOR . '/models', 'JoomlaupdateModel');
/** @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('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
if ($model->finaliseUpgrade() === false)
{
echo 'Failed to finalize the upgrade, please check the logs for additional details.' . PHP_EOL;
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');
JLog::add('Finished manual update using postupdate', JLog::INFO, 'Update');
echo 'Update to ' . JVERSION . ' completed successfully.' . PHP_EOL;
@sovainfo

Suggest to mark start/end manual update to separate it from the standard log.

@ghazal
ghazal commented Jun 7, 2016

The postupdate script does what is is supposed to do.
Except this Notice:

Notice: Use of undefined constant JPATH_COMPONENT_ADMINISTRATOR - assumed 'JPATH_COMPONENT_ADMINISTRATOR' in /administrator/components/com_joomlaupdate/models/default.php on line 764
Update to 3.5.1 completed successfully. 

Updated from joomla 3.4.4
PHP 5.6.10

@sharphosting

Worked perfectly, Joomla 3.2.7 to 3.6.4. Thanks, really useful to have this. The updater was insisting it was already on the new version.

@alexandar-penkin

Thank you for the script! Works as expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment