/** * Revert patches on/from packages that are going to be removed * * @param PackageEvent $event * @throws Exception * * @return void */ public function restore(PackageEvent $event) { $operation = $event->getOperation(); if ($operation instanceof UpdateOperation) { $initialPackage = $operation->getInitialPackage(); } elseif ($operation instanceof UninstallOperation) { $initialPackage = $operation->getPackage(); } else { throw new Exception('Unexpected operation ' . get_class($operation)); } static $history = array(); foreach ($this->getPatches($initialPackage, $history) as $patchesAndPackage) { list($patches, $package) = $patchesAndPackage; $packagePath = $this->getPackagePath($package); foreach (array_reverse($patches) as $patch) { /* @var $patch Patch */ try { $patch->revert($packagePath, true); } catch (PatchCommandException $e) { $this->writePatchNotice('revert', $patch, $package, $e); continue; } $this->writePatchNotice('revert', $patch, $package); $patch->revert($packagePath); } } }
/** * 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/'); } }
/** * @param PackageEvent $event */ public function __invoke(PackageEvent $event) { $publicPath = sprintf('%s/public', $this->projectPath); if (!is_dir($publicPath)) { // No public path in the project; nothing to remove return; } $gitignoreFile = sprintf('%s/.gitignore', $publicPath); if (!file_exists($gitignoreFile)) { // No .gitignore rules; nothing to remove return; } $package = $event->getOperation()->getPackage(); $installer = $this->composer->getInstallationManager(); $packagePath = $installer->getInstallPath($package); $packageConfigPath = sprintf('%s/config/module.config.php', $packagePath); if (!file_exists($packageConfigPath)) { // No module configuration defined; nothing to remove return; } $packageConfig = (include $packageConfigPath); if (!is_array($packageConfig) || !isset($packageConfig['asset_manager']['resolver_configs']['paths']) || !is_array($packageConfig['asset_manager']['resolver_configs']['paths'])) { // No assets defined; nothing to remove return; } $this->gitignore = $this->fetchIgnoreRules($gitignoreFile); $paths = $packageConfig['asset_manager']['resolver_configs']['paths']; foreach ($paths as $path) { $this->removeAssets($path, $publicPath); } file_put_contents($gitignoreFile, implode("\n", $this->gitignore)); }
public function deployAfterUninstall(PackageEvent $event) { /** @var $operation UninstallOperation */ $operation = $event->getOperation(); $package = $operation->getPackage(); $uninstallDeployment = DeploymentFactory::createUninstallDeployment($package); $uninstallDeployment->execute(); }
/** * @param PackageEvent $event */ public static function postPackageInstall(PackageEvent $event) { /** @type InstallOperation $operation */ $operation = $event->getOperation(); /** @var PackageInterface $package */ $package = $operation->getPackage(); self::installAssets($event, $package); }
/** * 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(); }
/** * Marks scaffolding to be processed after an install or update command. * * @param \Composer\Installer\PackageEvent $event */ public function onPostPackageEvent(\Composer\Installer\PackageEvent $event) { $package = $this->getCorePackage($event->getOperation()); if ($package) { // By explicitly setting the core package, the onPostCmdEvent() will // process the scaffolding automatically. $this->drupalCorePackage = $package; } }
public function onPackageUninstall(PackageEvent $event) { // note to myself: the package files are still there at this step $removedPackage = $event->getOperation()->getPackage(); if ($removedPackage->getType() !== 'jelix-module' && $removedPackage->getName() !== 'jelix/jelix' && $removedPackage->getName() !== 'jelix/for-classic-package') { return; } $this->jelixParameters->removePackage($removedPackage->getName()); }
/** * 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); }
/** * Updates assets provided by the package, if any. * * Uninstalls any previously installed assets for the package, and then * runs an install for the package. * * @param PackageEvent $event */ public function onPostPackageUpdate(PackageEvent $event) { $operation = $event->getOperation(); $initialPackage = $operation->getInitialPackage(); $targetPackage = $operation->getTargetPackage(); // Uninstall any previously installed assets $uninstall = new AssetUninstaller($this->composer, $this->io); $uninstall($this->createPackageEventWithOperation($event, new UninstallOperation($initialPackage, $operation->getReason()))); // Install new assets $installer = new AssetInstaller($this->composer, $this->io); $installer($this->createPackageEventWithOperation($event, new InstallOperation($targetPackage, $operation->getReason()))); }
/** * @param PackageEvent $event * * @throws \Exception * * @quality:method [C] */ public function handlePackageEvent(PackageEvent $event) { $operation = $event->getOperation(); if ($operation instanceof InstallOperation) { $package = $operation->getPackage(); } elseif ($operation instanceof UpdateOperation) { $package = $operation->getTargetPackage(); } else { return; } $this->handlePackage($package); }
public static function postPackageUpdate(PackageEvent $event) { $packageName = $event->getOperation()->getInitialPackage()->getName(); switch ($packageName) { case 'almasaeed2010/adminlte': copyAdminLTEFiles(); break; case 'twbs/bootstrap': copyBootstrapFiles(); break; } }
/** * Prints a links to package changelog on the post-package-update event. * * @param PackageEvent $event */ public function onPostPackageUpdate(PackageEvent $event) { $operation = $event->getOperation(); if ($operation instanceof UpdateOperation) { try { $changelog = self::getChangelog($operation->getInitialPackage(), $operation->getTargetPackage()); } catch (Exception\CouldNotCalculateChangelog $e) { $changelog = $e->getMessage(); } $this->io->write(self::PAD_STR . 'CHANGELOG: ' . $changelog); } }
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); }
public static function postPackageUpdate(PackageEvent $event) { $initial_package = $event->getOperation()->getInitialPackage(); $initial_package_type = $initial_package->getType(); $initial_package_name = $initial_package->getName(); $initial_package_extra = $initial_package->getExtra(); $target_package = $event->getOperation()->getTargetPackage(); $target_package_type = $target_package->getType(); $target_package_name = $target_package->getName(); $target_package_extra = $target_package->getExtra(); if (!in_array($initial_package_type, self::$known_types) and !in_array($target_package_type, self::$known_types)) { return; } self::ascii(); try { self::packageUninstall($initial_package_type, $initial_package_name, $initial_package_extra); self::packageInstall($target_package_type, $target_package_name, $target_package_extra); } catch (Exception $e) { throw $e; } echo "* ExtenderInstaller update task completed\n\n"; }
/** * @return void */ public static function install(PackageEvent $event) { global $app; $composer_json_filename = getenv('COMPOSER'); $app_root_dir = empty($composer_json_filename) ? getcwd() : dirname($composer_json_filename); $app = (require "{$app_root_dir}/bootstrap.php"); $composer_pkg = $event->getOperation()->getPackage(); $vendor_dir = getenv('COMPOSER_VENDOR_DIR'); $vendor_dir_abs = empty($vendor_dir) ? "{$app_root_dir}/vendor" : "{$app_root_dir}/{$vendor_dir}"; $composer_pkg_dir = $vendor_dir_abs . DIRECTORY_SEPARATOR . $composer_pkg->getName(); $app->addExtension($composer_pkg_dir); $ext_install_event = Event\Type\System\ExtensionInstall::create($composer_pkg); $app->dispatch($ext_install_event); }
public function downloadPackages(\Composer\Installer\PackageEvent $event) { // exit early, if no downloader was found if ($this->tool === false) { $this->io->write('Skipping downloading, because Composer couldn\'t find a suitable download tool.'); $this->io->write('You might install one of the following tools: aria2'); //, wget, curl. return; } $installedPackage = $event->getOperation()->getPackage(); if ('jakoch/composer-fastfetch' === $installedPackage->getPrettyName()) { $this->downloader->downloadPackages($event->getOperations()); } }
/** * Marks scaffolding to be processed after an install or update command. * * @param \Composer\Installer\PackageEvent $event */ public function onPostPackageEvent(\Composer\Installer\PackageEvent $event) { $operation = $event->getOperation(); if ($operation instanceof InstallOperation) { $package = $operation->getPackage(); } elseif ($operation instanceof UpdateOperation) { $package = $operation->getTargetPackage(); } if (isset($package) && $package instanceof PackageInterface && $package->getName() == 'drupal/core') { // By explicitiley setting the core package, the onPostCmdEvent() will // process the scaffolding automatically. $this->drupalCorePackage = $package; } }
public function onPackageUnistall(\Composer\Installer\PackageEvent $event) { $ds = DIRECTORY_SEPARATOR; $package = $event->getOperation()->getPackage(); list($vendor, $packageName) = explode('/', $package->getPrettyName()); $packageName = trim(str_replace('module-', '', $packageName)); $packageInstallationPath = $packageInstallationPath = $this->installer->getTargetDir(); $packagePath = ucfirst($vendor) . $ds . str_replace(' ', '', ucwords(str_replace('-', ' ', $packageName))); $this->io->write("Removing {$packagePath}"); $libPath = 'lib' . $ds . 'internal' . $ds . $packagePath; $magentoPackagePath = 'app' . $ds . 'code' . $ds . $packagePath; $deployStrategy = $this->installer->getDeployStrategy($package); $deployStrategy->rmdirRecursive($packageInstallationPath . $ds . $libPath); $deployStrategy->rmdirRecursive($packageInstallationPath . $ds . $magentoPackagePath); }
/** * 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 */ public function __invoke(PackageEvent $event) { $publicPath = sprintf('%s/public', $this->projectPath); if (!is_dir($publicPath)) { return; } $package = $event->getOperation()->getPackage(); $installer = $this->composer->getInstallationManager(); $packagePath = $installer->getInstallPath($package); $packageConfigPath = sprintf('%s/config/module.config.php', $packagePath); if (!file_exists($packageConfigPath)) { return; } $packageConfig = (include $packageConfigPath); if (!is_array($packageConfig) || !isset($packageConfig['asset_manager']['resolver_configs']['paths']) || !is_array($packageConfig['asset_manager']['resolver_configs']['paths'])) { return; } $paths = $packageConfig['asset_manager']['resolver_configs']['paths']; foreach ($paths as $path) { $this->copyAssets($path, $publicPath); } }
public function onPostPackageInstall(PackageEvent $event) { if (!in_array($event->getOperation()->getPackage()->getType(), ['heroku-sys-php', 'heroku-sys-hhvm', 'heroku-sys-php-extension', 'heroku-sys-hhvm-extension', 'heroku-sys-webserver'])) { return; } $this->initAllPlatformRequirements($event->getOperations()); try { $this->configurePackage($event->getOperation()->getPackage()); $this->enableReplaces($event->getOperation()->getPackage()); $this->writeProfile($event->getOperation()->getPackage()); $this->writeExport($event->getOperation()->getPackage()); } catch (\Exception $e) { $this->io->writeError(sprintf('<error>Failed to activate package %s</error>', $event->getOperation()->getPackage()->getName())); $this->io->writeError(''); throw $e; } }
/** * @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)); }
/** * 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 * * Can be added as post-install-cmd in composer.json */ public static function registerBundle(PackageEvent $event) { $package = $event->getOperation()->getPackage(); if ('symfony-bundle' === $package->getType()) { self::registerWithPackage($package, $output = $event->getIo()); } }
/** * Add the version to the package url * * The version needs to be added in the PRE_PACKAGE_INSTALL/UPDATE * event to make sure that different version save different urls * in composer.lock. Composer would load any available version from cache * although the version numbers might differ (because they have the same * url). * * @access public * @param PackageEvent $event The event that called the method * @throws UnexpectedValueException */ public function addVersion(PackageEvent $event) { $package = $this->getPackageFromOperation($event->getOperation()); if (in_array($package->getName(), self::WPM_PRO_PACKAGE_NAMES())) { $version = $this->validateVersion($package->getPrettyVersion(), $package->getName()); $package->setDistUrl($this->addParameterToUrl($package->getDistUrl(), 'v', $version)); } }
/** * When this package is uninstalled, the generated git hooks need to be removed * * @param PackageEvent $event */ public function prePackageUninstall(PackageEvent $event) { /** @var UninstallOperation $operation */ $operation = $event->getOperation(); $package = $operation->getPackage(); if (!$this->guardIsGrumPhpPackage($package)) { return; } // First remove the hook, before everything is deleted! $this->deInitGitHook(); }
/** * @param PackageEvent $event */ public function postPackageOperation(PackageEvent $event) { $operation = $event->getOperation(); $this->outputter->addOperation($operation); }