I'm attempting to write a Joomla CLI-script that automatically upgrades the site to the current version. In Joomla this appears to be done through *com_joomlaupdate*. The idea is to be able to upgrade any Joomla site on a server from an admin frontend.
I have written the following for testing, attempting to mimic the controller in com_joomlaupdate by directly accessing methods in its model. I'm unfamiliar with the joomla framework so I may be doing some silly things here.
<?php
const _JEXEC = 1;
error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', 1);
define('JPATH_BASE', dirname(__DIR__));
require_once JPATH_BASE . '/includes/defines.php';
require_once JPATH_BASE . '/includes/framework.php';
require_once JPATH_LIBRARIES . '/import.legacy.php';
require_once JPATH_LIBRARIES . '/cms.php';
// Load the configuration
require_once JPATH_CONFIGURATION . '/configuration.php';
define('JPATH_COMPONENT_ADMINISTRATOR', JPATH_ADMINISTRATOR . '/components/com_joomlaupdate');
require_once JPATH_COMPONENT_ADMINISTRATOR . '/models/default.php';
class Upgradejoomla extends JApplicationCli
{
public function doExecute()
{
$app = JFactory::getApplication('administrator');
$app->initialise();
$app->input->set('method', 'direct');
$this->out('Fetching updates...');
$updater = JModelLegacy::getInstance('JoomlaupdateModelDefault');
$updater->refreshUpdates();
$updater->applyUpdateSite();
$basename = $updater->download();
$app->setUserState('com_joomlaupdate.file', $basename);
$updater->createRestorationFile($basename);
echo ($updater->finaliseUpgrade());
$updater->cleanUp();
}
}
JApplicationCli::getInstance('Upgradejoomla')->execute();
download()
works fine, I do get the latest file, and its placed in the tmp directory. createRestorationFile()
appears to work too, i get a restoration.php file inside the com_joomlaupdate directory.
The issue seems to be with finaliseUpgrade()
. It calls setupInstall()
in Installer, which attempts to look for a manifest file. What I'm missing (among other things) I suppose is the step where that file (or the entire contents of the update) is unpacked somewhere. The issue is I can't find any code that does that in com_joomlaupdate?
I have attempted to manually unpack the updatefile inside /tmp. When I do this, finaliseUpgrade()
actually returns true, but the site remains at its old version still.