Skip to content

Instantly share code, notes, and snippets.

@dgrammatiko
Last active February 21, 2022 06:12
Show Gist options
  • Save dgrammatiko/6889cbf2a2cc68627fdbf968bd7d9b43 to your computer and use it in GitHub Desktop.
Save dgrammatiko/6889cbf2a2cc68627fdbf968bd7d9b43 to your computer and use it in GitHub Desktop.
Fix broken 4.1 update
<?php
define('JOOMLA_MINIMUM_PHP', '7.2.5');
if (version_compare(PHP_VERSION, JOOMLA_MINIMUM_PHP, '<')) {
die(str_replace(
'{{phpversion}}',
JOOMLA_MINIMUM_PHP,
file_get_contents(dirname(__FILE__) . '/templates/system/incompatible.html')
));
}
// Constant that is checked in included files to prevent direct access.
define('_JEXEC', 1);
define('JPATH_BASE', __DIR__);
if (file_exists(__DIR__ . '/includes/defines.php')) {
require_once __DIR__ . '/includes/defines.php';
}
if (!defined('_JDEFINES')) {
require_once JPATH_BASE . '/includes/defines.php';
}
// Check for presence of vendor dependencies not included in the git repository
if (!file_exists(JPATH_LIBRARIES . '/vendor/autoload.php') || !is_dir(JPATH_ROOT . '/media/vendor')) {
echo file_get_contents(JPATH_ROOT . '/templates/system/build_incomplete.html');
exit;
}
// Add the JLoader, etc...
require_once JPATH_BASE . '/includes/framework.php';
// Boot the DI container
$container = \Joomla\CMS\Factory::getContainer();
$db = \Joomla\CMS\Factory::getContainer()->get('DatabaseDriver');
$msg = [];
foreach(['atum', 'cassiopeia'] as $template) {
$clientId = $template === 'atum' ? 1 : 0;
$query = $db->getQuery(true)
->update($db->quoteName('#__template_styles'))
->set($db->quoteName('inheritable') . ' = 1')
->where($db->quoteName('template') . ' = ' . $db->quote($template))
->where($db->quoteName('client_id') . ' = ' . $clientId);
try {
$db->setQuery($query)->execute();
} catch (Exception $e) {
$msg[] = \Joomla\CMS\Language\Text::sprintf('JLIB_DATABASE_ERROR_FUNCTION_FAILED', $e->getCode(), $e->getMessage()) . '<br>';
}
}
echo implode('<br>', count($msg) ? $msg : ['Successfully updated the template styles']);
die;
  • Upload the file fix.php in your server at the root folder (where the .htaccess and the index.php are)
  • Temporarily rename .htaccess to .htaccess.bak (needed only for sites with AdminTools)
  • Visit your site's /fix.php (eg https://mydonain.tld/fix.php)
  • Delete the fix.php file
  • Restore .htaccess.bak to .htaccess (needed only for sites with AdminTools)
@rbuelund
Copy link

This is not fixing my problem - both templates are still gone!

@dgrammatiko
Copy link
Author

This is not fixing my problem - both templates are still gone!

Then you have another problem, probably your update was unsuccessful and you're missing files.

@rbuelund
Copy link

Hmm.. but the update went through without errors.. How do I reinstall core files in joomla 4.1 ? Is that not possible anymore like in 3.x ?

@rbuelund
Copy link

And the problem only arose after doing the database repair !? It worked before the repair.

@kitepascal
Copy link

Top, thx! 👍🏼

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