FOF30\Utils\InstallScript::postflight PHP Méthode

postflight() public méthode

Runs after install, update or discover_update. In other words, it executes after Joomla! has finished installing or updating your component. This is the last chance you've got to perform any additional installations, clean-up, database updates and similar housekeeping functions.
public postflight ( string $type, JInstallerAdapterComponent $parent )
$type string install, update or discover_update
$parent JInstallerAdapterComponent Parent object
    public function postflight($type, $parent)
    {
        // Add ourselves to the list of extensions depending on FOF30
        $this->addDependency('fof30', $this->componentName);
        // Install or update database
        // Uninstall database
        $dbInstaller = new Installer(JFactory::getDbo(), ($this->schemaXmlPathRelative ? JPATH_ADMINISTRATOR . '/components/' . $this->componentName : '') . '/' . $this->schemaXmlPath);
        $dbInstaller->updateSchema();
        // Make sure menu items are installed
        $this->_createAdminMenus($parent);
        // Make sure menu items are published (surprise goal in the 92' by JInstaller wins the cup for "most screwed up
        // bug in the history of Joomla!")
        $this->_reallyPublishAdminMenuItems($parent);
        // Which files should I remove?
        if ($this->isPaid) {
            // This is the paid version, only remove the removeFilesAllVersions files
            $removeFiles = $this->removeFilesAllVersions;
        } else {
            // This is the free version, remove the removeFilesAllVersions and removeFilesFree files
            $removeFiles = array('files' => array(), 'folders' => array());
            if (isset($this->removeFilesAllVersions['files'])) {
                if (isset($this->removeFilesFree['files'])) {
                    $removeFiles['files'] = array_merge($this->removeFilesAllVersions['files'], $this->removeFilesFree['files']);
                } else {
                    $removeFiles['files'] = $this->removeFilesAllVersions['files'];
                }
            } elseif (isset($this->removeFilesFree['files'])) {
                $removeFiles['files'] = $this->removeFilesFree['files'];
            }
            if (isset($this->removeFilesAllVersions['folders'])) {
                if (isset($this->removeFilesFree['folders'])) {
                    $removeFiles['folders'] = array_merge($this->removeFilesAllVersions['folders'], $this->removeFilesFree['folders']);
                } else {
                    $removeFiles['folders'] = $this->removeFilesAllVersions['folders'];
                }
            } elseif (isset($this->removeFilesFree['folders'])) {
                $removeFiles['folders'] = $this->removeFilesFree['folders'];
            }
        }
        // Remove obsolete files and folders
        $this->removeFilesAndFolders($removeFiles);
        // Copy the CLI files (if any)
        $this->copyCliFiles($parent);
        // Show the post-installation page
        $this->renderPostInstallation($parent);
        // Uninstall obsolete subextensions
        $this->uninstallObsoleteSubextensions($parent);
        // Clear the FOF cache
        $false = false;
        $cache = \JFactory::getCache('fof', '');
        $cache->store($false, 'cache', 'fof');
        // Make sure the Joomla! menu structure is correct
        $this->_rebuildMenu();
        // Add post-installation messages on Joomla! 3.2 and later
        $this->_applyPostInstallationMessages();
    }

Usage Example

 /**
  * Runs after install, update or discover_update. In other words, it executes after Joomla! has finished installing
  * or updating your component. This is the last chance you've got to perform any additional installations, clean-up,
  * database updates and similar housekeeping functions.
  *
  * @param   string                     $type   install, update or discover_update
  * @param   JInstallerAdapterComponent $parent Parent object
  */
 function postflight($type, $parent)
 {
     // Let's install common tables
     $container = null;
     $model = null;
     if (class_exists('FOF30\\Container\\Container')) {
         try {
             $container = \FOF30\Container\Container::getInstance('com_akeeba');
         } catch (\Exception $e) {
             $container = null;
         }
     }
     if (is_object($container) && class_exists('FOF30\\Container\\Container') && $container instanceof \FOF30\Container\Container) {
         /** @var \Akeeba\Backup\Admin\Model\UsageStatistics $model */
         try {
             $model = $container->factory->model('UsageStatistics')->tmpInstance();
         } catch (\Exception $e) {
             $model = null;
         }
     }
     if (is_object($model) && class_exists('Akeeba\\Backup\\Admin\\Model\\UsageStatistics') && $model instanceof Akeeba\Backup\Admin\Model\UsageStatistics && method_exists($model, 'checkAndFixCommonTables')) {
         try {
             $model->checkAndFixCommonTables();
         } catch (Exception $e) {
             // Do nothing if that failed.
         }
     }
     // Parent method
     parent::postflight($type, $parent);
     // Uninstall post-installation messages we are no longer using
     $this->uninstallObsoletePostinstallMessages();
     // Remove the update sites for this component on installation. The update sites are now handled at the package
     // level.
     $this->removeObsoleteUpdateSites($parent);
     // Remove the FOF 2.x update sites (annoying leftovers)
     $this->removeFOFUpdateSites();
     // If this is a new installation tell it to NOT mark the backup profiles as configured.
     if (defined('AKEEBA_THIS_IS_INSTALLATION_FROM_SCRATCH')) {
         $this->markProfilesAsNotConfiguredYet();
     }
     // This is an update of an existing installation
     if (!defined('AKEEBA_THIS_IS_INSTALLATION_FROM_SCRATCH')) {
         // Migrate profiles if necessary
         $this->migrateProfiles();
     }
 }