Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sergeytolkachyov/159591d312950f896de781200819ec7a to your computer and use it in GitHub Desktop.
Save sergeytolkachyov/159591d312950f896de781200819ec7a to your computer and use it in GitHub Desktop.
Disable non core Joomla 3 extensions for future safe update to Joomla 5+
<?php
/**
* Put this file into your administrator folder
* and go to your-site.com/administrator/disable_non_joomla3_extensions.php
*
* @package Non Joomla 3 extensions disable
* @version 1.0.0
* @author Sergey Tolkachyov
* @copyright Copyright (c) 2024 Sergey Tolkachyov. All rights reserved.
* @license GNU/GPL 3 license
* @link https://web-tolk.ru
*/
define('_JEXEC', 1);
error_reporting(E_ALL);
ini_set('display_errors', 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';
use Joomla\CMS\Factory;
$j3_extensions = ['actionlogs', 'article', 'beez3', 'blog', 'cache', 'calendar', 'categories', 'checkboxes', 'codemirror', 'color', 'com_actionlogs', 'com_admin', 'com_ajax', 'com_associations', 'com_banners', 'com_cache', 'com_categories', 'com_checkin', 'com_config', 'com_contact', 'com_content', 'com_contenthistory', 'com_cpanel', 'com_fields', 'com_finder', 'com_installer', 'com_joomlaupdate', 'com_languages', 'com_login', 'com_mailto', 'com_media', 'com_menus', 'com_messages', 'com_modules', 'com_newsfeeds', 'com_plugins', 'com_postinstall', 'com_privacy', 'com_redirect', 'com_search', 'com_tags', 'com_templates', 'com_users', 'com_wrapper', 'confirmconsent', 'consents', 'contact', 'contactcreator', 'contacts', 'content', 'cookie', 'debug', 'editor', 'emailcloak', 'en-GB','ru-RU', 'eos310', 'extensionupdate', 'fields', 'finder', 'fof', 'folderinstaller', 'gmail', 'hathor', 'highlight', 'idna_convert', 'image', 'imagelist', 'integer', 'isis', 'joomla', 'joomlaupdate', 'languagecode', 'languagefilter', 'ldap', 'list', 'loadmodule', 'log', 'logout', 'logrotation', 'media', 'menu', 'message', 'mod_articles_archive', 'mod_articles_categories', 'mod_articles_category', 'mod_articles_latest', 'mod_articles_news', 'mod_articles_popular', 'mod_banners', 'mod_breadcrumbs', 'mod_custom', 'mod_feed', 'mod_finder', 'mod_footer', 'mod_languages', 'mod_latest', 'mod_latestactions', 'mod_logged', 'mod_login', 'mod_menu', 'mod_multilangstatus', 'mod_popular', 'mod_privacy_dashboard', 'mod_quickicon', 'mod_random_image', 'mod_related_items', 'mod_sampledata', 'mod_search', 'mod_stats', 'mod_stats_admin', 'mod_status', 'mod_submenu', 'mod_syndicate', 'mod_tags_popular', 'mod_tags_similar', 'mod_title', 'mod_toolbar', 'mod_users_latest', 'mod_version', 'mod_whosonline', 'mod_wrapper', 'module', 'newsfeeds', 'none', 'p3p', 'packageinstaller', 'pagebreak', 'pagenavigation', 'phpass', 'phputf8', 'phpversioncheck', 'pkg_en-GB','pkg_ru-RU', 'privacycheck', 'privacyconsent', 'profile', 'protostar', 'radio', 'readmore', 'recaptcha', 'recaptcha_invisible', 'redirect', 'remember', 'repeatable', 'sef', 'sessiongc', 'sql', 'stats', 'tags', 'terms', 'text', 'textarea', 'tinymce', 'totp', 'updatenotification', 'url', 'urlinstaller', 'user', 'usergrouplist', 'vote', 'yubikey'];
$db = Factory::getDbo();
// Disable extensions
$query = $db->getQuery(true)
->select('*')
->update($db->quoteName('#__extensions'))
->set('enabled = 0')
->where($db->quoteName('element') . ' NOT IN (' . implode(',', $db->quote($j3_extensions)) . ')');
if (!$db->setQuery($query)->execute())
{
throw new \Exception('Disable extensions error');
} else {
$query = $db->getQuery(true)
->select('*')->from($db->quoteName('#__extensions'))
->where($db->quoteName('element') . ' NOT IN (' . implode(',', $db->quote($j3_extensions)) . ')')
->where($db->quoteName('enabled') . ' = '.$db->quote('0'));
$result = $db->setQuery($query)->loadObjectList();
if(count($result))
{
echo count($result).' extensions that are not included in the Joomla 3 core have been detected and disabled.<br>
Make sure that they are disabled in the Site Admin Panel: Extensions - Extension Manager - Management.';
} else {
echo 'No extensions were found that are not included in the Joomla 3 core.';
}
}
@sergeytolkachyov
Copy link
Author

Инструкция на русском https://t.me/webtolkru/287

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