Back to InstallerAdapter class

Method install

public bool|int
install
()
Generic install method for extensions
Returns
  • bool|int The extension ID on success, boolean false on failure
Since
  • 3.4

Method install - Source code

/**
 * Generic install method for extensions
 *
 * @return  boolean|integer  The extension ID on success, boolean false on failure
 *
 * @since   3.4
 */
public function install()
{
    // Get the extension's description
    $description = (string) $this->getManifest()->description;
    $this->parent->message = '';
    if ($description) {
        $this->parent->message = Text::_($description);
    }
    // Set the extension's name and element
    $this->name = $this->getName();
    $this->element = $this->getElement();
    $this->changelogurl = (string) $this->getManifest()->changelogurl;
    /*
     * ---------------------------------------------------------------------------------------------
     * Extension Precheck and Setup Section
     * ---------------------------------------------------------------------------------------------
     */
    // Setup the install paths and perform other prechecks as necessary
    try {
        $this->setupInstallPaths();
    } catch (\RuntimeException $e) {
        // Install failed, roll back changes
        $this->parent->abort($e->getMessage());
        return false;
    }
    // Check to see if an extension by the same name is already installed.
    try {
        $this->checkExistingExtension();
    } catch (\RuntimeException $e) {
        // Install failed, roll back changes
        $this->parent->abort($e->getMessage());
        return false;
    }
    // Check if the extension is present in the filesystem
    try {
        $this->checkExtensionInFilesystem();
    } catch (\RuntimeException $e) {
        // Install failed, roll back changes
        $this->parent->abort($e->getMessage());
        return false;
    }
    // If we are on the update route, run any custom setup routines
    if ($this->route === 'update') {
        try {
            $this->setupUpdates();
        } catch (\RuntimeException $e) {
            // Install failed, roll back changes
            $this->parent->abort($e->getMessage());
            return false;
        }
    }
    /*
     * ---------------------------------------------------------------------------------------------
     * Installer Trigger Loading
     * ---------------------------------------------------------------------------------------------
     */
    $this->setupScriptfile();
    try {
        $this->triggerManifestScript('preflight');
    } catch (\RuntimeException $e) {
        // Install failed, roll back changes
        $this->parent->abort($e->getMessage());
        return false;
    }
    /*
     * ---------------------------------------------------------------------------------------------
     * Filesystem Processing Section
     * ---------------------------------------------------------------------------------------------
     */
    // If the extension directory does not exist, lets create it
    try {
        $this->createExtensionRoot();
    } catch (\RuntimeException $e) {
        // Install failed, roll back changes
        $this->parent->abort($e->getMessage());
        return false;
    }
    // Copy all necessary files
    try {
        $this->copyBaseFiles();
    } catch (\RuntimeException $e) {
        // Install failed, roll back changes
        $this->parent->abort($e->getMessage());
        return false;
    }
    // Parse optional tags
    $this->parseOptionalTags();
    /*
     * ---------------------------------------------------------------------------------------------
     * Database Processing Section
     * ---------------------------------------------------------------------------------------------
     */
    try {
        $this->storeExtension();
    } catch (\RuntimeException $e) {
        // Install failed, roll back changes
        $this->parent->abort($e->getMessage());
        return false;
    }
    try {
        $this->parseQueries();
    } catch (\RuntimeException $e) {
        // Install failed, roll back changes
        $this->parent->abort($e->getMessage());
        return false;
    }
    // Run the custom method based on the route
    try {
        $this->triggerManifestScript($this->route);
    } catch (\RuntimeException $e) {
        // Install failed, roll back changes
        $this->parent->abort($e->getMessage());
        return false;
    }
    /*
     * ---------------------------------------------------------------------------------------------
     * Finalization and Cleanup Section
     * ---------------------------------------------------------------------------------------------
     */
    try {
        $this->finaliseInstall();
    } catch (\RuntimeException $e) {
        // Install failed, roll back changes
        $this->parent->abort($e->getMessage());
        return false;
    }
    // And now we run the postflight
    try {
        $this->triggerManifestScript('postflight');
    } catch (\RuntimeException $e) {
        // Install failed, roll back changes
        $this->parent->abort($e->getMessage());
        return false;
    }
    return $this->extension->extension_id;
}