Back to PackageAdapter class

Method copyBaseFiles

protected void
copyBaseFiles
()
Method to copy the extension's base files from the `<files>` tag(s) and the manifest file
Returns
  • void
Since
  • 3.4
-
  • \RuntimeException

Method copyBaseFiles - Source code

/**
 * Method to copy the extension's base files from the `<files>` tag(s) and the manifest file
 *
 * @return  void
 *
 * @since   3.4
 * @throws  \RuntimeException
 */
protected function copyBaseFiles()
{
    $folder = (string) $this->getManifest()->files->attributes()->folder;
    $source = $this->parent->getPath('source');
    if ($folder) {
        $source .= '/' . $folder;
    }
    // Install all necessary files
    if (!\count($this->getManifest()->files->children())) {
        throw new \RuntimeException(Text::sprintf('JLIB_INSTALLER_ABORT_PACK_INSTALL_NO_FILES', Text::_('JLIB_INSTALLER_' . strtoupper($this->route))));
    }
    $dispatcher = Factory::getApplication()->getDispatcher();
    // Add a callback for the `onExtensionAfterInstall` event so we can receive the installed extension ID
    if (!$dispatcher->hasListener([$this, 'onExtensionAfterInstall'], 'onExtensionAfterInstall')) {
        $dispatcher->addListener('onExtensionAfterInstall', [$this, 'onExtensionAfterInstall']);
    }
    foreach ($this->getManifest()->files->children() as $child) {
        $file = $source . '/' . (string) $child;
        if (is_dir($file)) {
            // If it's actually a directory then fill it up
            $package = array();
            $package['dir'] = $file;
            $package['type'] = InstallerHelper::detectType($file);
        } else {
            // If it's an archive
            $package = InstallerHelper::unpack($file);
        }
        $tmpInstaller = new Installer();
        $installResult = $tmpInstaller->install($package['dir']);
        if (!$installResult) {
            throw new \RuntimeException(Text::sprintf('JLIB_INSTALLER_ABORT_PACK_INSTALL_ERROR_EXTENSION', Text::_('JLIB_INSTALLER_' . strtoupper($this->route)), basename($file)));
        }
        $this->results[] = array('name' => (string) $tmpInstaller->manifest->name, 'result' => $installResult);
    }
}