diff --git a/src/HordeInstaller.php b/src/HordeInstaller.php index 8126b31..66ccd20 100644 --- a/src/HordeInstaller.php +++ b/src/HordeInstaller.php @@ -1,9 +1,14 @@ projectRoot = realpath(dirname(\Composer\Factory::getComposerFile())); + $this->projectRoot = realpath(dirname(Factory::getComposerFile())); $this->webDir = $this->projectRoot . '/web'; $this->hordeDir = $this->webDir . '/horde'; $this->hordeRegistryDir = $this->hordeDir . '/config/registry.d/'; @@ -53,12 +61,14 @@ protected function _setupDirs(PackageInterface $package) $this->packageDocRegistryDir = $this->packageDir . '/doc/registry.d/'; $this->presetDir = $this->projectRoot . '/presets/' . $this->packageName; } + /** * {@inheritDoc} */ public function getInstallPath(PackageInterface $package) { $this->_setupDirs($package); + return $this->packageDir; } @@ -68,6 +78,7 @@ public function getInstallPath(PackageInterface $package) public function install(InstalledRepositoryInterface $repo, PackageInterface $package) { parent::install($repo, $package); + $this->postinstall($repo, $package); } @@ -77,60 +88,63 @@ public function install(InstalledRepositoryInterface $repo, PackageInterface $pa public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target) { parent::update($repo, $initial, $target); + $this->postinstall($repo, $target); } /** * Handle horde-specific install/upgrade tasks * - * @param \Composer\Repository\InstalledRepositoryInterface $repo The repository - * @param \Composer\Package\PackageInterface $package The package installed or updated + * @param InstalledRepositoryInterface $repo The repository + * @param PackageInterface $package The package installed or updated */ protected function postinstall(InstalledRepositoryInterface $repo, PackageInterface $package) { $this->_setupDirs($package); $app = $this->packageName; + // Type horde-application needs a config/horde.local.php pointing to horde dir // If a horde-application has a registry snippet in doc-dir, fetch it and put it into config/registry.d if (is_dir($this->packageDocRegistryDir)) { - $dir = new \DirectoryIterator($this->packageDocRegistryDir); + $dir = new DirectoryIterator($this->packageDocRegistryDir); foreach ($dir as $entry) { if ($dir->isFile()) { copy($dir->getPathName(), $this->hordeRegistryDir . $entry); } } } + // If a deployment has a preset dir for this app, copy files from preset if (is_dir($this->presetDir)) { - $dir = new \DirectoryIterator($this->presetDir); + $dir = new DirectoryIterator($this->presetDir); foreach ($dir as $entry) { if ($dir->isFile() && !file_exists($this->packageDir . '/config/' . $entry)) { copy($dir->getPathName(), $this->packageDir . '/config/' . $entry); } } } + // horde-library needs to check for js/ to copy or link - if ($package->getType() == 'horde-application') - { + if ($package->getType() == 'horde-application') { $this->linkJavaScript($package, $this->packageName); $hordeLocalFilePath = $this->packageDir . '/config/horde.local.php'; $hordeLocalFileContent = sprintf("hordeDir )); - // special case horde/horde needs to require the composer autoloader if ($package->getName() == 'horde/components') { // special case - a horde app which does not need horde. // Do we need to generalize this for other standalone cases? return; } + + // special case horde/horde needs to require the composer autoloader if ($package->getName() == 'horde/horde') { $hordeLocalFileContent .= $this->_legacyWorkaround(realpath($this->vendorDir)); $hordeLocalFileContent .= 'require_once(\'' . $this->vendorDir .'/autoload.php\');'; // ensure a registry snippet for base exists. If not, create one containing only fileroot $registryLocalFilePath = $this->hordeDir . '/config/registry.d/00-horde.php'; - if (!file_exists($registryLocalFilePath)) - { + if (!file_exists($registryLocalFilePath)) { $registryLocalFileContent = sprintf( "getType() == 'horde-library') - { + if ($package->getType() == 'horde-library') { $this->linkJavaScript($package); } } public function linkJavaScript($package, $app = 'horde') { - $packageJsDir = $this->getInstallPath($package) . '/js/'; // TODO: Error handling + $packageJsDir = $this->getInstallPath($package) . '/js/'; if (!is_dir($packageJsDir)) { return; } + try { $jsDirHandle = opendir($packageJsDir); } catch (ErrorException $e) { return; } + $targetDir = $this->jsDir . '/' . $app; $this->filesystem->ensureDirectoryExists($targetDir); while (false !== ($sourceItem = readdir($jsDirHandle))) { - if ($sourceItem == '.' || $sourceItem == '..') - { + if ($sourceItem == '.' || $sourceItem == '..') { continue; } + $this->filesystem->relativeSymlink(realpath("$packageJsDir/$sourceItem"), "$targetDir/$sourceItem"); } + closedir($jsDirHandle); } @@ -211,12 +229,12 @@ protected function _legacyWorkaround($path) */ public function supports($packageType) { - switch ($packageType) - { + switch ($packageType) { case 'horde-application': case 'horde-library': case 'horde-theme': - return true; + return true; + default: return false; }