Skip to content

Instantly share code, notes, and snippets.

@mbabker
Last active November 11, 2022 20:11
Show Gist options
  • Save mbabker/d7bfb4e1e2fbc6b7815a733607f89281 to your computer and use it in GitHub Desktop.
Save mbabker/d7bfb4e1e2fbc6b7815a733607f89281 to your computer and use it in GitHub Desktop.

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';
// 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');
// 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;
@vale82on
Copy link

vale82on commented Jan 9, 2018

Dear Michael, I found your script because I got an error 1054 (control panel blocked) after running the automatic upgrade from joomla 3.5.1 to 3.6.5.
I downloaded and launched your script, but unfortunately I got the error message: Failed to finalize the upgrade, please check the logs for additional details.
Here are the logs, I wasn't able to get any help from the logs:

#Fields: datetime	priority clientip	category	message
2018-01-09T19:14:51+00:00	INFO 83.86.151.54	update	Update started by user Super User (6306). Old version is 3.5.1.
2018-01-09T19:14:51+00:00	INFO 83.86.151.54	update	Downloading update file from https://downloads.joomla.org/cms/joomla3/3-6-5/Joomla_3.6.5-Stable-Update_Package.zip.
2018-01-09T19:15:04+00:00	INFO 83.86.151.54	update	File Joomla_3.6.5-Stable-Update_Package.zip successfully downloaded.
2018-01-09T19:15:04+00:00	INFO 83.86.151.54	update	Starting installation of new version.
2018-01-09T19:17:12+00:00	INFO 83.86.151.54	update	Finalising installation.
2018-01-09T19:17:12+00:00	INFO 83.86.151.54	update	Cleaning up after installation.
2018-01-09T19:17:12+00:00	INFO 83.86.151.54	update	Update to version 3.6.5 is complete.
2018-01-09T19:18:18+00:00	INFO 83.86.151.54	update	Update started by user Super User (6306). Old version is 3.6.5.
2018-01-09T19:18:18+00:00	INFO 83.86.151.54	update	Downloading update file from https://downloads.joomla.org/cms/joomla3/3-8-3/Joomla_3.8.3-Stable-Update_Package.zip.
2018-01-09T19:18:24+00:00	INFO 83.86.151.54	update	File Joomla_3.8.3-Stable-Update_Package.zip successfully downloaded.
2018-01-09T19:18:24+00:00	INFO 83.86.151.54	update	Starting installation of new version.
2018-01-09T19:19:39+00:00	INFO 83.86.151.54	update	Finalising installation.
2018-01-09T19:19:39+00:00	INFO 83.86.151.54	update	Cleaning up after installation.
2018-01-09T19:19:39+00:00	INFO 83.86.151.54	update	Update to version 3.8.3 is complete.
2018-01-09T19:42:39+00:00	INFO 83.86.151.54	update	Starting manual update using postupdate
2018-01-09T19:42:39+00:00	INFO 83.86.151.54	update	Finalising installation.

I don't know what to do. Should I try a manual upgrade? But how if the control panel is blocked? Thanks!

@Mbocha
Copy link

Mbocha commented Jan 24, 2018

Thanks a Million!! with this I was able to update a client's website from 3.4 to 3.8.3. Be blessed!!

@markic
Copy link

markic commented Jan 25, 2018

Thank you very much. Fixed from 3.8 to 3.8.1 after 2 hours of google work! Awesome!

@Rational-Storm
Copy link

I'm experiencing a failure when attempting to upgrade 3.7.4 to 3.8.5
After running the upgrade via joomla update, attempting to visit the site, I only get "ERROR" in typewriter font and nothing else.
I've tried dumping the upgrade folder into the existing folders but nothing changes at all.
I then ran the above referenced php script and the response is similar to - ...3.7.4 successfully upgraded
Running the upgrade again and repeat "ERROR" message

@rapid1004
Copy link

I was upgrading from 3.7.5 to 3.8.5 and I was receiving a 500 error on the front-end and just a blank admin page. Now it's working fine. Thank you!

@alejoasotelo
Copy link

Works with errors from3.4.x to 3.8.6, but when i login to administrator works 👍 , I fix the db from the administrator and i have my site working right now. Thank you very much!!!

XDebug (short):
Notice: Constant QQ already defined in /home/temaiken/public_html/net/libraries/src/Language/Language.php on line 18
Error: Call to undefined method JApplicationAdministrator::isClient() in /home/temaiken/public_html/net/libraries/src/Helper/ModuleHelper.php on line 411
Fatal error: Uncaught Error: Call to undefined method JApplicationAdministrator::isClient() in /home/temaiken/public_html/net/libraries/src/Helper/ModuleHelper.php on line 411
Error: Call to undefined method JApplicationAdministrator::isClient() in /home/temaiken/public_html/net/libraries/src/Helper/ModuleHelper.php on line 411

@luca7766
Copy link

luca7766 commented Mar 22, 2018

With update to 3.8.6 I get blank page and this error in page title title:
Error: 0 DirectoryIterator::__construct(/web/htdocs/[WEBSITE_FOLDER]/home/libraries/cms/installer/adapter): failed to open dir: No such file or directory

but the website v3.8.6 seems to work correctly, just have to fix DB

@panter011
Copy link

Hello Everyone,
I have made the steps above but my admin joomla is still showing blank page with this error on top:

Error: Unknown column 'a.client_id' in 'where clause': Unknown column 'a.client_id' in 'where clause'

Please help.

@ajrange
Copy link

ajrange commented Apr 23, 2018

This is awesome, thank you so much!!!!!! Huge help!

@verosandri
Copy link

Hey mbabker,

Thank you very much it worked for me also, you save a lot of time :)

Thanks

@nympheastudio
Copy link

Thanks, it worked for me,
first i get the error "adapter/ folder missing", after correct this issue (by copying folder and files),
the script worked for an update to Joomla! 3.8.7 Stable.

@OESternad
Copy link

after running this scriopt I got "Server Failure error 500" Doesn´t work for me . . . what do I wrong

@OESternad
Copy link

update:
I removed htaccess and htpasswd from the admin folder, ran the script again - works. Have some warning, but I guess it is just about cleaning up a bit.
Thank you for the script!

@Chris2508
Copy link

Thank you so much! I had updated from Joomla! 3.7.5 to 3.8.5 and received an "error: 500 failed to start application" on the backend. I ran your script, deleted the file, did the database fix and everything is working fine again. Thank you, thank you, thank you! You saved my day.

@xander182
Copy link

Thanks for this great script! It saved me so much headache and basically my site as well

@oxyzium
Copy link

oxyzium commented Jul 4, 2018

IT WORK'S!!

A big thanks.... really thanks a lot for saving my efforts and time.

I was upgrading Joomla from 3.3 to 3.8.0 all the upgrades worked fine.. but while upgrading the version from 3.7.5 to 3.8.0 both frontend and backend were showing blank pages.. all site was broken... using this script has resolved all the issues.

@invent-studio
Copy link

Thank's you

@invent-studio
Copy link

GOD bless you

@LazarBaruk
Copy link

Very impressive.
Very.
Thanks.

@GrapGat
Copy link

GrapGat commented Nov 28, 2018

I keep getting the HTTP 500 Error no matter what I try, I have tried the automatic update, the manual why described above, and still getting the same error. Am I doing something wrong?

@schultz-it-solutions
Copy link

Line 39 require_once JPATH_BASE . '/includes/toolbar.php';
needs to be changed to
require_once JPATH_BASE . '/includes/subtoolbar.php';

@mbabker
Copy link
Author

mbabker commented Dec 24, 2018

The script has been updated to account for the changes in 3.9.

@Legallity
Copy link

Legallity commented Dec 29, 2018

you forgot a ; at: require_once JPATH_BASE . '/includes/subtoolbar.php'

@Legallity
Copy link

also the script doesnt work for me, it still gives me the following error:
Error displaying the error page: Call to undefined method JLanguageHelper::parseIniFile(): Call to undefined method JLanguageHelper::parseIniFile()

@scoutdubna
Copy link

I have 6 Joomla sites of various ages and now transferring them to a new server running php7 so I need to upgrade. All have been successful using the manual system to upgrade to Joomla 3.9.4 except for one which is being stubborn. On running the postupdate.php script I am getting the following errors. Can anyone point me in the right direction please?

PHP Notice: Undefined index: HTTP_HOST in /var/www/HITACHI/gss/joomla_gss /libraries/joomla/application/web.php on line 869
PHP Notice: Undefined index: HTTP_HOST in /var/www/HITACHI/gss/joomla_gss /libraries/joomla/uri/uri.php on line 96

I am running the script using the command line via PUTTY.

Copy link

ghost commented May 6, 2019

Array to string conversion in /home/vol15_8/byethost11.com/b11_23862066/htdocs/hemi/libraries/joomla/registry/registry.php on line 342

@Mister-A
Copy link

Mister-A commented Aug 8, 2019

I love you 😄 ❤️

Saved my bacon, works a treat!

@schultz-it-solutions
Copy link

Thank you Mike!
I am using this script (since 2016) in a complex multisite environment to automate the update for several dozen websites in one swoop - this saves me a ton of work!!!

Just one suggestion: you should include the "github" link within the sourcecode (as a comment) and maybe even a version number or "date-last-changed").

@gistamelandy
Copy link

where Postupdate. PHP is located? I searched in cpanel, but did not find it. Please help me

@carlitorweb
Copy link

Something similar for J4?

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