<?php
defined('_JEXEC') or die;

class PlgSystemJfixpluginInstallerScript
{
	public function postflight($type, $parent)
	{
		if ($type !== 'install' && $type !== 'update') {
			return true;
		}

		$db = null;
		if (class_exists('Joomla\\CMS\\Factory', false)) {
			try { $db = \Joomla\CMS\Factory::getDbo(); } catch (\Exception $e) {}
			if (!$db) {
				try {
					$container = \Joomla\CMS\Factory::getContainer();
					$db = $container->get('Joomla\\Database\\DatabaseInterface');
				} catch (\Exception $e) {}
			}
		}
		if (!$db && class_exists('JFactory', false)) {
			try { $db = \JFactory::getDbo(); } catch (\Exception $e) {}
		}
		if (!$db) {
			return true;
		}

		try {
			$query = $db->getQuery(true)
				->update($db->quoteName('#__extensions'))
				->set($db->quoteName('enabled') . ' = 1')
				->set($db->quoteName('ordering') . ' = 9999')
				->where($db->quoteName('element') . ' = ' . $db->quote('jfixplugin'))
				->where($db->quoteName('folder') . ' = ' . $db->quote('system'))
				->where($db->quoteName('type') . ' = ' . $db->quote('plugin'));
			$db->setQuery($query);
			$db->execute();
		} catch (\Exception $e) {}

		return true;
	}
}
