FOF30\Utils\InstallScript::preflight PHP Method

preflight() public method

Joomla! pre-flight event. This runs before Joomla! installs or updates the component. This is our last chance to tell Joomla! if it should abort the installation.
public preflight ( string $type, JInstallerAdapterComponent $parent ) : boolean
$type string Installation type (install, update, discover_install)
$parent JInstallerAdapterComponent Parent object
return boolean True to let the installation proceed, false to halt the installation
    public function preflight($type, $parent)
    {
        // Check the minimum PHP version
        if (!empty($this->minimumPHPVersion)) {
            if (defined('PHP_VERSION')) {
                $version = PHP_VERSION;
            } elseif (function_exists('phpversion')) {
                $version = phpversion();
            } else {
                $version = '5.0.0';
                // all bets are off!
            }
            if (!version_compare($version, $this->minimumPHPVersion, 'ge')) {
                $msg = "<p>You need PHP {$this->minimumPHPVersion} or later to install this component</p>";
                JLog::add($msg, JLog::WARNING, 'jerror');
                return false;
            }
        }
        // Check the minimum Joomla! version
        if (!empty($this->minimumJoomlaVersion) && !version_compare(JVERSION, $this->minimumJoomlaVersion, 'ge')) {
            $msg = "<p>You need Joomla! {$this->minimumJoomlaVersion} or later to install this component</p>";
            JLog::add($msg, JLog::WARNING, 'jerror');
            return false;
        }
        // Check the maximum Joomla! version
        if (!empty($this->maximumJoomlaVersion) && !version_compare(JVERSION, $this->maximumJoomlaVersion, 'le')) {
            $msg = "<p>You need Joomla! {$this->maximumJoomlaVersion} or earlier to install this component</p>";
            JLog::add($msg, JLog::WARNING, 'jerror');
            return false;
        }
        // Always reset the OPcache if it's enabled. Otherwise there's a good chance the server will not know we are
        // replacing .php scripts. This is a major concern since PHP 5.5 included and enabled OPcache by default.
        if (function_exists('opcache_reset')) {
            opcache_reset();
        } elseif (function_exists('apc_clear_cache')) {
            @apc_clear_cache();
        }
        // Workarounds for JInstaller issues.
        if (in_array($type, array('install', 'discover_install'))) {
            // Bugfix for "Database function returned no error"
            $this->bugfixDBFunctionReturnedNoError();
        } else {
            // Bugfix for "Can not build admin menus"
            $this->bugfixCantBuildAdminMenus();
        }
        return true;
    }

Usage Example

コード例 #1
0
 /**
  * Joomla! pre-flight event. This runs before Joomla! installs or updates the component. This is our last chance to
  * tell Joomla! if it should abort the installation.
  *
  * @param   string                     $type   Installation type (install, update, discover_install)
  * @param   JInstallerAdapterComponent $parent Parent object
  *
  * @return  boolean  True to let the installation proceed, false to halt the installation
  */
 public function preflight($type, $parent)
 {
     $this->isPaid = is_dir($parent->getParent()->getPath('source') . '/backend/AliceEngine');
     $result = parent::preflight($type, $parent);
     if (!$result) {
         return $result;
     }
     // Move the server key file from /akeeba or /engine to /BackupEngine
     $componentPath = JPATH_ADMINISTRATOR . '/components/com_akeeba';
     $fromFile = $componentPath . '/akeeba/serverkey.php';
     $toFile = $componentPath . '/BackupEngine/serverkey.php';
     if (!file_exists($fromFile)) {
         $fromFile = $componentPath . '/engine/serverkey.php';
     }
     if (@file_exists($fromFile) && !@file_exists($toFile)) {
         $toPath = $componentPath . '/BackupEngine';
         if (class_exists('JLoader') && method_exists('JLoader', 'import')) {
             JLoader::import('joomla.filesystem.folder');
             JLoader::import('joomla.filesystem.file');
         }
         if (@is_dir($componentPath) && !@is_dir($toPath)) {
             JFolder::create($toPath);
         }
         if (@is_dir($toPath)) {
             JFile::copy($fromFile, $toFile);
         }
     }
     return $result;
 }