Create a gist now

Instantly share code, notes, and snippets.

@mbabker /README.md Secret
Last active Oct 6, 2017

What would you like to do?

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;

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

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

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.

Thank you for the script! Works as expected

This worked perfectly well. Thanks again!

WooDzu commented Sep 21, 2017 edited

Joomla 3.7.5 => 3.8 update from CLI: Application Instantiation Error: DirectoryIterator::__construct(/var/www/html/libraries/cms/installer/adapter): failed to open dir: No such file or directory

Edit: All works after re-running it again.

WooDzu commented Sep 21, 2017 edited

Please consider including this script in the CMS as cli script

pentik commented Sep 22, 2017

This helped, Thanks a lot!

Thank you and I am not one to leave comments. Again Thanks.

Joomla sorted, followed the instructions above and all is well with the world again.

Just one thing though I was not aware of this postupdate.php until now, my Joomla upgrade component has never worked for me and I have always unzipped the update inside the cpanel. Just a wee bit miffed I had never heard of this requirement.

The ajax error upon update has vexed me for ages, I have tried all of the online solutions but it still will not work !!!!, I am assuming there would be no need for this file if the update could be done from the component

williz commented Sep 29, 2017

Excellent and wonderful solution. It worked perfectly. No problem. Tks, my friend, mbabker. @mbabker

Excellent and wonderful solution. It worked perfectly.

AFlorencia commented Sep 30, 2017 edited

Worked super for me.
Updated from 3.5.1 to 3.6 Succesfully
Updated from 3.6.0 to 3.8 Succesfully
Everything works as expected.
Thank you!

Birdy65 commented Oct 4, 2017

Updated from Joomla 3.7.5 => 3.8. After I had a white window. I bumped into theis script, but had the folowing error: Failed to finalize the upgrade, please check the logs for additional details. What went wrong?

Im a flower shop owner but these script came from Gods. Thank you a lot these worket super for me.

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