Exemplo n.º 1
0
 /**
  * Вызов инсталлятора из composer
  * @param PackageEvent $event
  * @return type
  */
 public static function package(PackageEvent $event)
 {
     // консоль
     $io = $event->getIO();
     // устанавливаемый модуль
     $package = $event->getOperation()->getPackage();
     // только для модулей /podvincev-n/
     if (preg_match('#podvincev-n/([^/]+)#', $package->getName(), $match)) {
         $packageName = $match[1];
     } else {
         $io->write("> skip install " . $package->getName() . ": not /podvincev-n/", true);
         return false;
     }
     $composer = $event->getComposer();
     $composerConfig = $composer->getConfig();
     $installationManager = $composer->getInstallationManager();
     $installationPath = $installationManager->getInstallPath($package);
     $installationFile = $installationPath . '/Install.php';
     $basePath = dirname($composerConfig->get('vendor-dir'));
     if (file_exists($installationFile)) {
         $io->write("> installation file: " . $installationFile, true);
         $installerClass = (require_once $installationFile);
         $installer = new $installerClass(array('yiiConsoleApp' => self::getYiiConsoleApp($basePath), 'path' => $installationPath, 'name' => $packageName, 'io' => $io, 'migrationPath' => static::getMigrationPath($basePath), 'configPath' => static::getYiipConfigPath($basePath) . $packageName));
         $installer->install();
         $io->write("---", true);
         $io->write("", true);
     } else {
         $io->write("> no installation file", true);
         $io->write("", true);
     }
     return true;
 }
Exemplo n.º 2
0
 /**
  * Calls actions and install scripts provided by installed packages.
  *
  * @param \Composer\Script\PackageEvent $event
  * @return void
  * @throws Exception\UnexpectedOperationException
  */
 public static function postPackageUpdateAndInstall(PackageEvent $event)
 {
     $operation = $event->getOperation();
     if (!$operation instanceof \Composer\DependencyResolver\Operation\InstallOperation && !$operation instanceof \Composer\DependencyResolver\Operation\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();
     if (isset($packageExtraConfig['typo3/flow'])) {
         if (isset($packageExtraConfig['typo3/flow']['post-install']) && $operation->getJobType() === 'install') {
             self::runPackageScripts($packageExtraConfig['typo3/flow']['post-install']);
         } elseif (isset($packageExtraConfig['typo3/flow']['post-update']) && $operation->getJobType() === 'update') {
             self::runPackageScripts($packageExtraConfig['typo3/flow']['post-update']);
         }
         $installPath = $event->getComposer()->getInstallationManager()->getInstallPath($package);
         $relativeInstallPath = str_replace(getcwd() . '/', '', $installPath);
         if (isset($packageExtraConfig['typo3/flow']['manage-resources']) && $packageExtraConfig['typo3/flow']['manage-resources'] === TRUE) {
             if (is_dir($relativeInstallPath . '/Resources/Private/Installer/Distribution/Essentials')) {
                 Files::copyDirectoryRecursively($relativeInstallPath . '/Resources/Private/Installer/Distribution/Essentials', './', FALSE, TRUE);
             }
             if (is_dir($relativeInstallPath . '/Resources/Private/Installer/Distribution/Defaults')) {
                 Files::copyDirectoryRecursively($relativeInstallPath . '/Resources/Private/Installer/Distribution/Defaults', './', TRUE, TRUE);
             }
         }
     }
 }
 /**
  * Calls actions and install scripts provided by installed packages.
  *
  * @param \Composer\Script\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/');
     }
 }
Exemplo n.º 4
0
 /**
  * Hook up this function to package install to move files defined in composer.json -> extra -> dropin-paths
  * Run this command as post-install-package
  * @param Composer\Script\PackageEvent $event - Composer automatically tells information about itself for custom scripts
  */
 public function onPackageUpdate(PackageEvent $event)
 {
     //TODO: Keep record of moved files and delete them on updates and in package deletion
     //$package = $event->getOperation()->getInitialPackage(); //Do something for these.
     //Maybe symlinking/copying files would be better than moving.
     $package = $event->getOperation()->getTargetPackage();
     //For now just Ignore what happend earlier and assume that new files will replace earlier
     $this->dropNewFiles($package);
 }
Exemplo n.º 5
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();
 }
Exemplo n.º 6
0
 public function onPackageUnistall(\Composer\Script\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);
 }
 public static function post_install(PackageEvent $event)
 {
     $operation = $event->getOperation();
     $reason = $operation->getReason();
     if ($reason instanceof Rule) {
         switch ($reason->getReason()) {
             case Rule::RULE_PACKAGE_CONFLICT:
             case Rule::RULE_PACKAGE_SAME_NAME:
             case Rule::RULE_PACKAGE_REQUIRES:
                 $composer_error = $reason->getPrettyString($event->getPool());
                 break;
         }
         if (!empty($composer_error)) {
             WP_CLI::log(sprintf(" - Warning: %s", $composer_error));
         }
     }
 }
Exemplo n.º 8
0
 /**
  * Called from composer after update/install/uninstall of a package.
  *
  * @param \Composer\Script\PackageEvent $event The event themself
  *
  * @return void
  */
 public static function postPackageUpdateAndInstall(PackageEvent $event)
 {
     if (static::$statesManager === null) {
         static::$statesManager = new \Xinc\Packager\StatesManager();
     }
     $needStoppingStatesManager = false;
     if (!static::$statesManager->isInstallMode()) {
         static::$statesManager->startInstallMode();
         $needStoppingStatesManager = true;
     }
     $operation = $event->getOperation();
     if (!$operation instanceof \Composer\DependencyResolver\Operation\InstallOperation && !$operation instanceof \Composer\DependencyResolver\Operation\UninstallOperation && !$operation instanceof \Composer\DependencyResolver\Operation\UpdateOperation) {
         throw new \Exception('JobType "' . $operation->getJobType() . '" is not supported.');
     }
     switch ($operation->getJobType()) {
         case 'install':
             $composerPackage = $operation->getPackage();
             if ($composerPackage->getType() === 'xinc-application-package') {
                 $packege = static::composerPackage2PackagerPackage($composerPackage);
                 $packege->setState('active');
                 try {
                     static::$statesManager->addPackage($packege);
                 } catch (\Exception $e) {
                     // @TODO: Catch exception as we may called twice
                 }
             }
             break;
         case 'update':
             $composerPackage = $operation->getTargetPackage();
             if ($composerPackage->getType() === 'xinc-application-package') {
                 static::$statesManager->updatePackage(static::composerPackage2PackagerPackage($composerPackage));
             }
             break;
         case 'uninstall':
             $composerPackage = $operation->getPackage();
             if ($composerPackage->getType() === 'xinc-application-package') {
                 static::$statesManager->removePackage(static::composerPackage2PackagerPackageName($composerPackage));
             }
             break;
     }
     if ($needStoppingStatesManager) {
         static::$statesManager->stopInstallMode();
     }
 }
 /**
  * Remove the installed library from the lib Magento folder
  *
  * @param PackageEvent $event
  */
 public static function cleanPackageAction(PackageEvent $event)
 {
     $extras = $event->getComposer()->getPackage()->getExtra();
     if (isset($extras['magento-root-dir'])) {
         $magentoPath = $extras['magento-root-dir'];
         if (is_dir($magentoPath . 'lib/YellowCube')) {
             self::_recursiveRmDir($magentoPath . 'lib/YellowCube');
         }
         if (is_dir($magentoPath . 'lib/Assert')) {
             self::_recursiveRmDir($magentoPath . 'lib/Assert');
         }
         if (is_dir($magentoPath . 'lib/Wse')) {
             self::_recursiveRmDir($magentoPath . 'lib/Wse');
         }
         if (is_dir($magentoPath . 'lib/Psr')) {
             self::_recursiveRmDir($magentoPath . 'lib/Psr');
         }
     }
 }
 public function applyOverlay(PackageEvent $packageEvent)
 {
     switch ($packageEvent->getOperation()->getJobType()) {
         case 'install':
             $package = $packageEvent->getOperation()->getPackage();
             break;
         case 'update':
             $package = $packageEvent->getOperation() - getTargetPackage();
             break;
         default:
             return;
     }
     if (Installer\CoreInstaller::INSTALLER_TYPE === $package->getType()) {
         $extra = $packageEvent->getComposer()->getPackage()->getExtra();
         if (empty($extra['wordpress'])) {
             return;
         }
         $config = $extra['wordpress'];
         if (!empty($config['core-path']) && !empty($config['overlay-path'])) {
             $filesystem = new Filesystem();
             $corePath = $packageEvent->getComposer()->getInstallationManager()->getInstaller($package->getType())->getInstallPath($package);
             $overlayPath = $config['overlay-path'];
             $filesystem->mirror($overlayPath, $corePath, null, array('override' => true));
         }
     }
 }
Exemplo n.º 11
0
 /**
  * @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);
 }
 /**
  * post-package-uninstall event hook
  *
  * This routine exits early if any of the following conditions apply:
  *
  * - Executed in non-development mode
  * - No config/application.config.php is available
  * - The composer.json does not define one of either extra.zf.component
  *   or extra.zf.module
  * - The value used for either extra.zf.component or extra.zf.module are
  *   empty or not strings.
  *
  * Otherwise, it will attempt to update the application configuration
  * using the value(s) discovered in extra.zf.component and/or extra.zf.module,
  * removing their values from the `modules` list.
  *
  * @param PackageEvent $event
  * @return void
  */
 public function onPostPackageUninstall(PackageEvent $event)
 {
     if (!$event->isDevMode()) {
         // Do nothing in production mode.
         return;
     }
     $options = (new ConfigDiscovery())->getAvailableConfigOptions(array_keys($this->packageTypes), $this->projectRoot);
     if (empty($options)) {
         // No configuration options found; do nothing.
         return;
     }
     $package = $event->getOperation()->getPackage();
     $name = $package->getName();
     $extra = $this->getExtraMetadata($package->getExtra());
     $this->removePackageFromConfig($name, $extra, $options);
 }
Exemplo n.º 13
0
 /**
  * Function to run after a package has been updated
  */
 public function onPostPackageUpdate(PackageEvent $event)
 {
     /** @var \Composer\Package\CompletePackage $package */
     $package = $event->getOperation()->getTargetPackage();
     //$this->io->write('Called: ' . __METHOD__);
     $this->cleanPackage($package);
 }
Exemplo n.º 14
0
 /**
  * Event handler to the postUpdate/postInstall events: Collect the packages
  * as potential canditates for patching
  *
  * @param \Composer\Script\PackageEvent $event
  * @throws Exception
  */
 public function collect(PackageEvent $event)
 {
     $operation = $event->getOperation();
     if ($operation instanceof InstallOperation) {
         $package = $operation->getPackage();
     } elseif ($operation instanceof UpdateOperation) {
         $package = $operation->getTargetPackage();
     } else {
         throw new Exception('Unknown operation ' . get_class($operation));
     }
     $this->packagesToPatch[$package->getName()] = $package;
 }
 /**
  * Retrieves relevant package from the event.
  *
  * In the case of update, the target package is retrieved, as that will
  * provide the path the package will be installed to.
  *
  * @param \Composer\Script\PackageEvent $event
  * @return \Composer\Package\PackageInterface[]
  * @throws \Exception
  */
 protected function getPackagesFromEvent(PackageEvent $event)
 {
     $operation = $event->getOperation();
     if ($operation instanceof InstallOperation) {
         $packages = array($operation->getPackage());
     } elseif ($operation instanceof UpdateOperation) {
         $packages = array($operation->getInitialPackage(), $operation->getTargetPackage());
     } elseif ($operation instanceof UninstallOperation) {
         $packages = array($operation->getPackage());
     }
     return $packages;
 }
Exemplo n.º 16
0
 /**
  * Detects changes to config fixtures in the newly updated version of a
  * given package. Also installs any new configs fixtures not in this
  * installations config directory.
  *
  * The user is warned if a difference is detected, as they should manually
  * check to see what has changed.
  *
  * @param  PackageEvent $event The post-update package event
  *
  * @return void|false          Returns false if the method needn't run
  */
 public static function postUpdate(PackageEvent $event)
 {
     if (!static::isPackageCompatible($event->getOperation()->getInitialPackage())) {
         return false;
     }
     $package = $event->getOperation()->getInitialPackage();
     $fixtureDir = static::getConfigFixtureDir($event->getComposer(), $package);
     $workingDir = static::getWorkingDir();
     try {
         $fixtures = static::getFixtures($fixtureDir);
         if (!$fixtures) {
             return false;
         }
         foreach ($fixtures as $fixture) {
             $file = $workingDir . 'config/' . $fixture;
             $packageName = $event->getOperation()->getInitialPackage()->getPrettyName();
             // If config file for this fixture exists, detect + report any change in the fixture
             if (file_exists($file)) {
                 $checksum = md5_file($fixtureDir . $fixture);
                 if (isset(static::$_updatedFixtures[$package->getPrettyName()][$fixture]) && $checksum !== static::$_updatedFixtures[$package->getPrettyName()][$fixture]) {
                     $event->getIO()->write(sprintf('<warning>Package `%s` config fixture `%s` has changed: please review manually.</warning>', $package->getPrettyName(), $fixture));
                 }
             } else {
                 copy($fixtureDir . $fixture, $file);
                 $event->getIO()->write(sprintf('<info>Moved package `%s` config fixture `%s` to application config directory.</info>', $packageName, $fixture));
             }
         }
     } catch (Exception $e) {
         $event->getIO()->write('<error>' . $e->getMessage() . '</error>');
     }
 }
 public function onPostPackageUninstall(PackageEvent $packageEvent)
 {
     $package = $packageEvent->getOperation()->getPackage();
     $this->removeThemeFiles($package);
 }
 /**
  * Listener to the PRE_PACKAGE_UNINSTALL events
  * It contains the code that launch the execution of the update precedures
  *
  * @param  \Composer\Script\PackageEvent $event Event to handle
  *
  */
 public function onPrePackageUninstall(PackageEvent $event)
 {
     $package = $event->getOperation()->getPackage();
     $this->onEventHandler($package, "uninstall");
 }
Exemplo n.º 19
0
 /**
  * @param PackageEvent $packageEvent
  */
 public function onPostPackageUninstall(PackageEvent $packageEvent)
 {
     $package = $packageEvent->getOperation()->getPackage();
     $this->removeBlockFromLoader($package);
 }
 /**
  * post-package-uninstall event hook
  *
  * This routine exits early if any of the following conditions apply:
  *
  * - Executed in non-development mode
  * - No config/application.config.php is available
  * - The composer.json does not define one of either extra.zf.component
  *   or extra.zf.module
  * - The value used for either extra.zf.component or extra.zf.module are
  *   empty or not strings.
  *
  * Otherwise, it will attempt to update the application configuration
  * using the value(s) discovered in extra.zf.component and/or extra.zf.module,
  * removing their values from the `modules` list.
  *
  * @param PackageEvent $event
  * @return void
  */
 public static function postPackageUninstall(PackageEvent $event)
 {
     if (!$event->isDevMode()) {
         // Do nothing in production mode.
         return;
     }
     if (!is_file('config/application.config.php')) {
         // Do nothing if config/application.config.php does not exist
         return;
     }
     $package = $event->getOperation()->getPackage();
     $name = $package->getName();
     $extra = self::getExtraMetadata($package->getExtra());
     $io = $event->getIO();
     if (isset($extra['module']) && is_string($extra['module']) && !empty($extra['module'])) {
         $io->write(sprintf('<info>Uninstalling module %s (from package %s)</info>', $extra['module'], $name));
         self::removeModuleFromApplicationConfig($extra['module'], $io);
     }
     if (isset($extra['component']) && is_string($extra['component']) && !empty($extra['component'])) {
         $io->write(sprintf('<info>Uninstalling component module %s (from package %s)</info>', $extra['component'], $name));
         self::removeModuleFromApplicationConfig($extra['component'], $io);
     }
 }
 /**
  * @param PackageEvent $event
  */
 public function uninstallCore(PackageEvent $event)
 {
     switch ($event->getOperation()->getJobType()) {
         case "update":
             $package = $event->getOperation()->getInitialPackage();
             break;
         case "uninstall":
             $package = $event->getOperation()->getPackage();
             break;
     }
     if ($package->getType() === $this->type) {
         $options = new Options($this->composer->getPackage()->getExtra());
         $this->io->write(sprintf('%s<info>Removing: "%s" version: "%s" from: "%s"</info>', $this->ioPrefix, $package->getPrettyName(), $package->getVersion(), $options->getMagentoRootDir()));
         $this->getInstaller($options)->unInstall($this->getInstallPath($package), $options->getMagentoRootDir());
     }
 }
 protected function getPackage(PackageEvent $event, IOInterface $io)
 {
     $operation = $event->getOperation();
     foreach (array('getPackage', 'getTargetPackage') as $method) {
         if (method_exists($operation, $method)) {
             return $operation->{$method}();
         }
     }
     return NULL;
 }
 /**
  * Function to run after a package has been updated
  */
 public function onPostPackageUpdate(PackageEvent $event)
 {
     /** @var \Composer\Package\CompletePackage $package */
     $package = $event->getOperation()->getTargetPackage();
     $this->cleanPackage($package);
 }