/**
  * 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));
 }
 /**
  * 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);
         }
     }
 }
 public function deployAfterUninstall(PackageEvent $event)
 {
     /** @var  $operation UninstallOperation */
     $operation = $event->getOperation();
     $package = $operation->getPackage();
     $uninstallDeployment = DeploymentFactory::createUninstallDeployment($package);
     $uninstallDeployment->execute();
 }
 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());
 }
 /**
  * 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;
     }
 }
示例#7
0
 /**
  * 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);
 }
示例#9
0
 public static function postPackageUpdate(PackageEvent $event)
 {
     $packageName = $event->getOperation()->getInitialPackage()->getName();
     switch ($packageName) {
         case 'almasaeed2010/adminlte':
             copyAdminLTEFiles();
             break;
         case 'twbs/bootstrap':
             copyBootstrapFiles();
             break;
     }
 }
示例#10
0
 /**
  * @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);
 }
 /**
  * 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);
     }
 }
示例#12
0
 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);
 }
示例#13
0
 /**
  * Mirror a directory if the two directories don't match.
  *
  * @param string       $source
  * @param string       $dest
  * @param PackageEvent $event
  */
 public static function mirror($source, $dest, PackageEvent $event)
 {
     if (realpath($source) === realpath($dest)) {
         return;
     }
     $fs = new Filesystem();
     try {
         $fs->mirror($source, $dest);
     } catch (IOException $e) {
         $event->getIO()->writeError(sprintf('Mirroring %s to %s failed:', $source, $dest));
         $event->getIO()->writeError($e->getMessage());
     }
 }
示例#14
0
 /**
  * @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);
 }
示例#15
0
 /**
  * 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;
     }
 }
示例#16
0
 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());
     }
 }
示例#17
0
 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);
 }
示例#18
0
    /**
     * 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);
    }
示例#19
0
 /**
  * @dataProvider getDataFromRegistrPackageUndefinedType
  *
  * @param string $method
  */
 public function testRegistrPackageUndefinedType($method)
 {
     $operation = $this->getMock('\\Composer\\DependencyResolver\\Operation\\OperationInterface');
     $this->event_package->expects($this->atLeastOnce())->method('getOperation')->will($this->returnValue($operation));
     $operation->expects($this->once())->method('getJobType')->will($this->returnValue('undefined'));
     $operation->expects($this->never())->method('getPackage');
     $operation->expects($this->never())->method('getTargetPackage');
     call_user_func(['\\AnimeDb\\Bundle\\AnimeDbBundle\\Composer\\ScriptHandler', $method], $this->event_package);
 }
示例#20
0
文件: Composer.php 项目: 318io/318-io
 /**
  * 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("");
         }
     }
 }
 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
  * @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));
     }
 }
示例#23
0
 /**
  * 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()));
                 }
             }
         }
     }
 }
 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";
 }
 /**
  * @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);
     }
 }
 /**
  * @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));
 }
 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;
     }
 }
示例#28
0
 /**
  * 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));
     }
 }
示例#29
0
 /**
  * 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());
     }
 }