Your IP : 216.73.216.68


Current Path : /home/jeromecohp/www/plugins/system/fs_grid/
Upload File :
Current File : /home/jeromecohp/www/plugins/system/fs_grid/installer.php

<?php
/**
 * @package   Grid 10 element for YOOtheme Pro
 * @author    Flart Studio https://www.flart.studio
 * @copyright Copyright (C) Flart Studio
 * @license   GNU General Public License version 3, or later
 */

// No direct access to this file
defined('_JEXEC') or die();

use Joomla\CMS\Factory;
use Joomla\CMS\Log\Log;

class plgSystemfs_gridInstallerScript
{
    protected $minimumPHPVersion = '8.1.0';
    protected $minimumJoomlaVersion = '4.3.0';
    protected $minimumYOOthemeVersion = '4.1.0';
    protected $parent;

    public function preflight($type, $parent)
    {
        // Check PHP
        if (!version_compare(PHP_VERSION, $this->minimumPHPVersion, '>=')) {
            $error = 'To install Grid 10 element, you need to have PHP version ' . $this->minimumPHPVersion . ' or later. <br />Please ensure that you have the minimum required version of PHP installed on your server before attempting to install the Grid 10 element.';
            Log::add($error, Log::WARNING, 'jerror');

            return false;
        }

        // Check Joomla!
        if (!version_compare(JVERSION, $this->minimumJoomlaVersion, '>=')) {
            $error = 'To install Grid 10, you need to have Joomla! version ' . $this->minimumJoomlaVersion . ' or later. <br />Please ensure that you have the minimum required version of Joomla! installed before attempting to install the Grid 10 element.';
            Log::add($error, Log::WARNING, 'jerror');

            return false;
        }

        // Check YOOtheme Pro
        $yoothemeManifest = simplexml_load_file(JPATH_SITE . '/templates/yootheme/templateDetails.xml');
        if (!$yoothemeManifest or !version_compare((string)$yoothemeManifest->version, $this->minimumYOOthemeVersion, '>=')) {
            $error = 'To install Grid 10 element, it is required to have YOOtheme Pro version ' . $this->minimumYOOthemeVersion . ' or later.<br /> Please ensure that you have the minimum required version of YOOtheme Pro installed before attempting to install the Grid 10 element.';
            Log::add($error, Log::WARNING, 'jerror');

            return false;
        }

        return true;
    }

    public function install($parent)
    {
        // Enable the extension
        $this->enablePlugin();

        return true;
    }

    private function enablePlugin()
    {
        try {
            $db = Factory::getContainer()->get('DatabaseDriver');
            $query = $db->getQuery(true)
                ->update($db->qn('#__extensions'))
                ->set($db->qn('enabled') . ' = ' . $db->q(1))
                ->where('type = ' . $db->q('plugin'))
                ->where('folder = ' . $db->q('system'))
                ->where('element = ' . $db->q('fs_grid'));
            $db->setQuery($query);
            $db->execute();
        } catch (\Exception $e) {
            return;
        }
    }

    public function update($parent)
    {
    }

    public function uninstall($parent)
    {
    }

    public function postflight($type, $parent)
    {

        // Do not run on uninstall.
        if ($type === 'uninstall') {
            return true;
        }

        // Remove obsolete update site
        $this->removeOldUpdateSites();

        return true;

    }

    private function removeOldUpdateSites()
    {
        try {
            $db = Factory::getContainer()->get('DatabaseDriver');
            $query = $db->getQuery(true)
                ->delete($db->qn('#__update_sites'))
                ->where($db->qn('location') . ' = ' . $db->q('https://flart.studio/updates/joomla/grid-pro.xml'));
            $db->setQuery($query);
            $db->execute();
        } catch (\Exception $e) {
            // Do nothing on failure
        }
    }

}