/** * 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); } } } }
/** * Copies any distribution files to their place if needed. * * @param string $installerResourcesDirectory Path to the installer directory that contains the Distribution/Essentials and/or Distribution/Defaults directories. * @return void */ protected static function copyDistributionFiles($installerResourcesDirectory) { $essentialsPath = $installerResourcesDirectory . 'Distribution/Essentials'; if (is_dir($essentialsPath)) { Files::copyDirectoryRecursively($essentialsPath, getcwd() . '/', false, true); } $defaultsPath = $installerResourcesDirectory . 'Distribution/Defaults'; if (is_dir($defaultsPath)) { Files::copyDirectoryRecursively($defaultsPath, getcwd() . '/', true, true); } }
/** * @param string $configurationRootPath * @param array $additionalConfiguration * @return string */ protected function createTemporaryConfigurationRootPath($configurationRootPath, array $additionalConfiguration) { if ($additionalConfiguration === array()) { return $configurationRootPath; } $buildPath = $this->generateTemporaryConfigurationRootPath($configurationRootPath); if (@is_dir($buildPath)) { Files::removeDirectoryRecursively($buildPath); } Files::copyDirectoryRecursively($configurationRootPath, $buildPath); $additionalConfigurationLines = implode(PHP_EOL, $additionalConfiguration); file_put_contents(rtrim($buildPath, '/') . '/conf.py', $additionalConfigurationLines, FILE_APPEND); return $buildPath; }
/** * Moves a package from one path to another. * * @param string $fromAbsolutePath * @param string $toAbsolutePath * @return void */ protected function movePackage($fromAbsolutePath, $toAbsolutePath) { Files::createDirectoryRecursively($toAbsolutePath); Files::copyDirectoryRecursively($fromAbsolutePath, $toAbsolutePath, false, true); Files::removeDirectoryRecursively($fromAbsolutePath); }
/** * @test */ public function copyDirectoryRecursivelyKeepsExistingTargetFilesIfRequested() { Files::createDirectoryRecursively('vfs://Foo/source/bar/baz'); file_put_contents('vfs://Foo/source/bar/baz/file.txt', 'source content'); Files::createDirectoryRecursively('vfs://Foo/target/bar/baz'); file_put_contents('vfs://Foo/target/bar/baz/file.txt', 'target content'); Files::copyDirectoryRecursively('vfs://Foo/source', 'vfs://Foo/target', true); $this->assertEquals('target content', file_get_contents('vfs://Foo/target/bar/baz/file.txt')); }
/** * Moves a package from the regular package path to the inactive packages directory. * * @param string $packagePath absolute path to the package * @return void */ protected function movePackageToDeactivatedPackages($packagePath) { Files::copyDirectoryRecursively($packagePath, $this->buildInactivePackagePath($packagePath), false, true); Files::removeDirectoryRecursively($packagePath); }