/** * Calls actions and install scripts provided by installed packages. * * @param PackageEvent $event * @return void * @throws Exception\UnexpectedOperationException */ public static function postPackageUpdateAndInstall(PackageEvent $event) { $operation = $event->getOperation(); if (!$operation instanceof InstallOperation && !$operation instanceof UpdateOperation) { throw new Exception\UnexpectedOperationException('Handling of operation with type "' . $operation->getJobType() . '" not supported', 1348750840); } $package = $operation->getJobType() === 'install' ? $operation->getPackage() : $operation->getTargetPackage(); $packageExtraConfig = $package->getExtra(); $installPath = $event->getComposer()->getInstallationManager()->getInstallPath($package); $evaluatedInstallerResources = false; if (isset($packageExtraConfig['neos']['installer-resource-folders'])) { foreach ($packageExtraConfig['neos']['installer-resource-folders'] as $installerResourceDirectory) { static::copyDistributionFiles($installPath . $installerResourceDirectory); } $evaluatedInstallerResources = true; } if (isset($packageExtraConfig['typo3/flow']['post-install']) && $operation->getJobType() === 'install') { self::runPackageScripts($packageExtraConfig['typo3/flow']['post-install']); } if (isset($packageExtraConfig['typo3/flow']['post-update']) && $operation->getJobType() === 'update') { self::runPackageScripts($packageExtraConfig['typo3/flow']['post-update']); } // TODO: Deprecated from Flow 3.1 remove three versions after. if (!$evaluatedInstallerResources && isset($packageExtraConfig['typo3/flow']['manage-resources']) && $packageExtraConfig['typo3/flow']['manage-resources'] === true) { static::copyDistributionFiles($installPath . 'Resources/Private/Installer/'); } }
/** * Remove ignored files of the installed package defined in the root * package extra section. * * @param PackageEvent $event */ public static function deleteIgnoredFiles(PackageEvent $event) { if (null === ($package = static::getLibraryPackage($event->getOperation()))) { return; } $section = static::getIgnoreExtraSection(); $manager = IgnoreFactory::create($event->getComposer(), $package, null, $section); $manager->cleanup(); }
/** * Remove plugin install via composer to the .gitignore * * @param PackageEvent $event composer event * * @return bool */ public static function postPackageUninstall(PackageEvent $event) { $package = $event->getOperation()->getPackage(); if (!in_array($package->getType(), array('wordpress-muplugin', 'wordpress-plugin', 'wordpress-theme'))) { return false; } $plugin_name = self::getPluginName($package); $finalPath = self::getGitignoreFile($event->getComposer()); return self::removeWithMarkers($finalPath, $plugin_name); }
public static function prePackageUninstall(PackageEvent $packageEvent) { $uninstalledPackage = $packageEvent->getOperation()->getPackage(); $extra = $uninstalledPackage->getExtra(); // Check if composer package is an Inkstand bundle if (!array_key_exists('bundle_class', $extra)) { return; } $installPath = $packageEvent->getComposer()->getInstallationManager()->getInstallPath($uninstalledPackage); $kernel = self::bootKernel(); $container = $kernel->getContainer(); $container->get('plugin_service')->uninstall($uninstalledPackage, $installPath); }
/** * @param PackageEvent $event */ public function postPackageInstall(PackageEvent $event) { $operation = $event->getOperation(); if (!$operation instanceof InstallOperation) { return; } $package = $operation->getPackage(); if ($package->getName() !== static::$packageName) { return; } $extra = $event->getComposer()->getPackage()->getExtra(); if (!isset($extra['connect-packages']) || !count($extra['connect-packages'])) { return; } //skip if we are installing from lock file if ($event->getComposer()->getLocker()->isLocked()) { return; } $packages = implode('", "', array_keys($extra['connect-packages'])); $message = '<comment>The package(s): "%s" will be installed the next time you run '; $message .= 'composer update</comment>'; $event->getIO()->write(sprintf($message, $packages)); }
/** * Auto registers the "pbj-schema-store" repos with the SchemaStore. * * @param PackageEvent $event */ public static function writePbjSchemaStoresFile(PackageEvent $event) { if (!$event->isDevMode()) { return; } $dirs = []; /** @var PackageInterface $package */ foreach ($event->getInstalledRepo()->getPackages() as $package) { if (!$package instanceof PackageInterface) { continue; } if ('pbj-schema-store' !== $package->getType()) { continue; } $dir = sprintf('$vendorDir.\'/%s/schemas/\'', $package->getName()); // override for current package if ($event->getComposer()->getPackage()->getName() == $package->getName()) { $dir = '__DIR__.\'/schemas/\''; } $dirs[] = sprintf('%s %s', PHP_EOL, $dir); } if (empty($dirs)) { return; } $dirs = implode(',', $dirs); $event->getIO()->write('<info>Writing "pbj-schema-store" locations to "pbj-schema-stores.php"</info>'); $text = <<<TEXT <?php /** * DO NOT EDIT THIS FILE as it will be overwritten by Composer as part of * the installation/update process. * * Registers all directories from all required packages which are of * of the type "pbj-schema-store". * * This file has been auto-generated by the Pbj Compiler. */ \$vendorDir = realpath(__DIR__.'/vendor'); \\Gdbots\\Pbjc\\SchemaStore::addDirs([{$dirs} ]); TEXT; $fs = new Filesystem(); $fs->dumpFile('pbj-schema-stores.php', $text); }
/** * Remove possibly problematic test files from vendored projects. * * @param \Composer\Installer\PackageEvent $event * A PackageEvent object to get the configured composer vendor directories * from. */ public static function vendorTestCodeCleanup(PackageEvent $event) { $vendor_dir = $event->getComposer()->getConfig()->get('vendor-dir'); $io = $event->getIO(); $op = $event->getOperation(); if ($op->getJobType() == 'update') { $package = $op->getTargetPackage(); } else { $package = $op->getPackage(); } $package_key = static::findPackageKey($package->getName()); $message = sprintf(" Processing <comment>%s</comment>", $package->getPrettyName()); if ($io->isVeryVerbose()) { $io->write($message); } if ($package_key) { foreach (static::$packageToCleanup[$package_key] as $path) { $dir_to_remove = $vendor_dir . '/' . $package_key . '/' . $path; $print_message = $io->isVeryVerbose(); if (is_dir($dir_to_remove)) { if (static::deleteRecursive($dir_to_remove)) { $message = sprintf(" <info>Removing directory '%s'</info>", $path); } else { // Always display a message if this fails as it means something has // gone wrong. Therefore the message has to include the package name // as the first informational message might not exist. $print_message = TRUE; $message = sprintf(" <error>Failure removing directory '%s'</error> in package <comment>%s</comment>.", $path, $package->getPrettyName()); } } else { // If the package has changed or the --prefer-dist version does not // include the directory this is not an error. $message = sprintf(" Directory '%s' does not exist", $path); } if ($print_message) { $io->write($message); } } if ($io->isVeryVerbose()) { // Add a new line to separate this output from the next package. $io->write(""); } } }
/** * Event handler for composer package events * * @param PackageEvent $event */ public static function handle(PackageEvent $event) { $operation = $event->getOperation(); if ($operation instanceof InstallOperation) { $package = $operation->getPackage(); } elseif ($operation instanceof UpdateOperation) { $package = $operation->getTargetPackage(); } else { return; } $extra = $package->getExtra(); if ($package->getType() !== 'bolt-extension' || !isset($extra['bolt-assets'])) { return; } $packageAssets = 'vendor/' . $package->getName() . '/' . $extra['bolt-assets']; // Copy package assets to main web path $rootExtra = $event->getComposer()->getPackage()->getExtra(); $dest = $rootExtra['bolt-web-path'] . '/extensions/' . $packageAssets; self::mirror($packageAssets, $dest, $event); }
/** * Remove possibly problematic test files from vendored projects. * * @param \Composer\Installer\PackageEvent $event * A PackageEvent object to get the configured composer vendor directories * from. */ public static function vendorTestCodeCleanup(PackageEvent $event) { $vendor_dir = $event->getComposer()->getConfig()->get('vendor-dir'); $op = $event->getOperation(); if ($op->getJobType() == 'update') { $package = $op->getTargetPackage(); } else { $package = $op->getPackage(); } $package_key = static::findPackageKey($package->getName()); if ($package_key) { foreach (static::$packageToCleanup[$package_key] as $path) { $dir_to_remove = $vendor_dir . '/' . $package_key . '/' . $path; if (is_dir($dir_to_remove)) { if (!static::deleteRecursive($dir_to_remove)) { throw new \RuntimeException(sprintf("Failure removing directory '%s' in package '%s'.", $path, $package->getPrettyName())); } } } } }
/** * @param PackageEvent $event * @param PackageInterface $package */ private static function installAssets(PackageEvent $event, PackageInterface $package) { $composer = $event->getComposer(); /** @type RootPackageInterface $rootPackage */ $rootPackage = $composer->getPackage(); $composerExtra = $rootPackage->getExtra(); $pathConfig = self::$defaultPathConfig; if (!isset($composerExtra['asset-installer'], $composerExtra['asset-installer']['assets'])) { return; } $assetConfig = $composerExtra['asset-installer']['assets']; if (isset($composerExtra['asset-installer']['path-config'])) { $pathConfig = array_merge($pathConfig, $composerExtra['asset-installer']['path-config']); } /** @type InstallationManager $installationManager */ $installationManager = $composer->getInstallationManager(); $packageName = $package->getPrettyName(); if (isset($assetConfig[$packageName])) { self::copyAssets($packageName, $pathConfig, $assetConfig[$packageName], $installationManager->getInstallPath($package)); } }
/** * @param PackageEvent $event * @return bool|void */ public function installBinary(PackageEvent $event) { $binLocation = $event->getComposer()->getConfig()->get('bin-dir'); $binaries = $event->getOperation()->getPackage()->getBinaries(); if (count($binaries) === 0) { return; } $binary = basename(array_values($binaries)[0]); $binaryLocation = sprintf('%s/%s', $binLocation, $binary); $target = $this->getInstallLocation($binary); //if target exists and is symlink then we just remove it if (is_link($target)) { unlink($target); } if (is_writable(dirname($target))) { return symlink($binaryLocation, $target); } $event->getIO()->write(sprintf('<error>The directory: %s is not writeable. The workshop %s cannot be installed.</error>', dirname($target), $binary)); $event->getIO()->write(""); $event->getIO()->write(sprintf('You have two options now:')); $event->getIO()->write(sprintf(' 1. Add the composer global bin dir: <info>%s</info> to your PATH variable', $binLocation)); $event->getIO()->write(sprintf(' 2. Run <info>%s</info> directly with <info>%s</info>', $binary, $binaryLocation)); $event->getIO()->write(""); }
/** * {@inheritdoc} */ public function onPostPackageInstall(PackageEvent $event) { // This is a duplicate of Wikimedia's onPostPackageInstall. $op = $event->getOperation(); if ($op instanceof InstallOperation) { $package = $op->getPackage()->getName(); if ($package === self::PACKAGE_NAME) { $this->logger->info(self::PACKAGE_NAME . ' installed'); $this->state->setFirstInstall(TRUE); $this->state->setLocked($event->getComposer()->getLocker()->isLocked()); } } }
/** * Check if a contao package should be installed. * * This prevents from installing, if contao/core is installed in the parent directory. * * @param PackageEvent $event The event being raised. * * @return void * * @throws DuplicateContaoException When Contao would be installed within an existing Contao installation. */ public function checkContaoPackage(PackageEvent $event) { $operation = $event->getOperation(); if ($operation instanceof InstallOperation) { $package = $operation->getPackage(); } elseif ($operation instanceof UpdateOperation) { $package = $operation->getTargetPackage(); } else { return; } if ($package->getName() === 'contao/core' || in_array($package->getName(), Environment::$bundleNames)) { try { $composer = $event->getComposer(); $contao = $this->getContaoRoot($composer->getPackage()); $vendor = getcwd() . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR; // Contao is already installed in parent directory, prevent installing in vendor! if ($contao && $vendor !== substr($contao, 0, strlen($vendor))) { throw new DuplicateContaoException('Warning: Contao core was about to get installed but has been found in project root, ' . 'to recover from this problem please restart the operation'); } } catch (ConstantsNotFoundException $e) { // Silently ignore the fact that the constants are not found. } $this->contaoRoot = null; $this->contaoVersion = null; $this->contaoBuild = null; $this->contaoUploadPath = null; } }
private static function getRootPath(PackageEvent $event) { $vendorPath = $event->getComposer()->getConfig()->get('vendor-dir'); return realpath($vendorPath . '/..'); }
/** * @param PackageEvent $event * @throws \Exception */ public function postInstall(PackageEvent $event) { // Get the package object for the current operation. $operation = $event->getOperation(); /** @var PackageInterface $package */ $package = $this->getPackageFromOperation($operation); $package_name = $package->getName(); if (!isset($this->patches[$package_name])) { if ($this->io->isVerbose()) { $this->io->write('<info>No patches found for ' . $package_name . '.</info>'); } return; } $this->io->write(' - Applying patches for <info>' . $package_name . '</info>'); // Get the install path from the package object. $manager = $event->getComposer()->getInstallationManager(); $install_path = $manager->getInstaller($package->getType())->getInstallPath($package); // Set up a downloader. $downloader = new RemoteFilesystem($this->io, $this->composer->getConfig()); // Track applied patches in the package info in installed.json $localRepository = $this->composer->getRepositoryManager()->getLocalRepository(); $localPackage = $localRepository->findPackage($package_name, $package->getVersion()); $extra = $localPackage->getExtra(); $extra['patches_applied'] = array(); foreach ($this->patches[$package_name] as $description => $url) { $this->io->write(' <info>' . $url . '</info> (<comment>' . $description . '</comment>)'); try { $this->eventDispatcher->dispatch(NULL, new PatchEvent(PatchEvents::PRE_PATCH_APPLY, $package, $url, $description)); $this->getAndApplyPatch($downloader, $install_path, $url); $this->eventDispatcher->dispatch(NULL, new PatchEvent(PatchEvents::POST_PATCH_APPLY, $package, $url, $description)); $extra['patches_applied'][$description] = $url; } catch (\Exception $e) { $this->io->write(' <error>Could not apply patch! Skipping. The error was: ' . $e->getMessage() . '</error>'); if (getenv('COMPOSER_EXIT_ON_PATCH_FAILURE')) { throw new \Exception("Cannot apply patch {$description} ({$url})!"); } } } $localPackage->setExtra($extra); $this->io->write(''); $this->writePatchReport($this->patches[$package_name], $install_path); }
public function onPreUninstall(PackageEvent $event) { /** @var UninstallOperation $operation */ $operation = $event->getOperation(); $package = $operation->getPackage(); $installer = $event->getComposer()->getInstallationManager()->getInstaller($package->getType()); if (method_exists($installer, 'onUninstall')) { $installer->onUninstall($operation, $this->postprocess); } }
/** * @param PackageEvent $event */ public function __construct(PackageEvent $event) { $this->aliasOf = $event; parent::__construct($event->getName(), $event->getComposer(), $event->getIO(), $event->isDevMode(), $event->getArguments(), $event->getFlags()); }
/** * Handle an event callback following installation of a new package by * checking to see if the package that was installed was our plugin. * * @param PackageEvent $event */ public function onPostPackageInstall(PackageEvent $event) { $op = $event->getOperation(); if ($op instanceof InstallOperation) { $package = $op->getPackage()->getName(); if ($package === self::PACKAGE_NAME) { $this->logger->info('composer-merge-plugin installed'); $this->state->setFirstInstall(true); $this->state->setLocked($event->getComposer()->getLocker()->isLocked()); } } }
/** * @param PackageEvent|Event $event * @return string */ private static function getHtaccessFilePath($event) { $dir = $event->getComposer()->getConfig()->get('vendor-dir') . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR; return $dir . self::HTACCESS_FILENAME; }