/** * @param array $configuration */ public function removeTemporaryConfigurationRootPath(array $configuration) { $configurationRootPath = $configuration['configurationRootPath']; $buildPath = $this->generateTemporaryConfigurationRootPath($configurationRootPath); if (@is_dir($buildPath)) { Files::removeDirectoryRecursively($buildPath); } }
/** * Removes a package from registry and deletes it from filesystem * * @param string $packageKey package to remove * @return void * @throws Exception\UnknownPackageException if the specified package is not known * @throws Exception\ProtectedPackageKeyException if a package is protected and cannot be deleted * @throws Exception * @api */ public function deletePackage($packageKey) { if (!$this->isPackageAvailable($packageKey)) { throw new Exception\UnknownPackageException('Package "' . $packageKey . '" is not available and cannot be removed.', 1166543253); } $package = $this->getPackage($packageKey); if ($package->isProtected()) { throw new Exception\ProtectedPackageKeyException('The package "' . $packageKey . '" is protected and cannot be removed.', 1220722120); } $packagePath = $package->getPackagePath(); if ($this->isPackageActive($packageKey)) { $this->deactivatePackage($packageKey); $packagePath = Files::concatenatePaths([$this->packagesBasePath, $this->buildInactivePackageRelativePath($packagePath)]); } $this->unregisterPackage($package); try { Files::removeDirectoryRecursively($packagePath); } catch (UtilityException $exception) { throw new Exception('Please check file permissions. The directory "' . $packagePath . '" for package "' . $packageKey . '" could not be removed.', 1301491089, $exception); } }
/** * @test */ public function unpublishPersistentResourceRemovesTheResourceMirrorAndNoOtherFiles() { $temporaryDirectory = Files::concatenatePaths(array(realpath(sys_get_temp_dir()), 'FlowFileSystemPublishingTargetTestTarget')) . '/'; Files::createDirectoryRecursively($temporaryDirectory); $mockResourcePointer = $this->getMock('TYPO3\\Flow\\Resource\\ResourcePointer', array(), array(), '', FALSE); $mockResourcePointer->expects($this->atLeastOnce())->method('getHash')->will($this->returnValue('ac9b6187f4c55b461d69e22a57925ff61ee89cb2')); $mockResource = $this->getMock('TYPO3\\Flow\\Resource\\Resource', array(), array(), '', FALSE); $mockResource->expects($this->atLeastOnce())->method('getResourcePointer')->will($this->returnValue($mockResourcePointer)); mkdir($temporaryDirectory . 'Persistent'); file_put_contents($temporaryDirectory . 'Persistent/ac9b6187f4c55b461d69e22a57925ff61ee89cb2.jpg', 'some data for deletion'); file_put_contents($temporaryDirectory . 'Persistent/92cfceb39d57d914ed8b14d0e37643de0797ae56.jpg', 'must not be deleted'); file_put_contents($temporaryDirectory . 'Persistent/186cd74009911bf433778c1fafff6ce90dd47b69.jpg', 'must not be deleted, too'); $publishingTarget = new \TYPO3\Flow\Resource\Publishing\FileSystemPublishingTarget(); $this->inject($publishingTarget, 'resourcesPublishingPath', $temporaryDirectory); $this->assertTrue(file_exists($temporaryDirectory . 'Persistent/ac9b6187f4c55b461d69e22a57925ff61ee89cb2.jpg')); $this->assertTrue(file_exists($temporaryDirectory . 'Persistent/92cfceb39d57d914ed8b14d0e37643de0797ae56.jpg')); $this->assertTrue(file_exists($temporaryDirectory . 'Persistent/186cd74009911bf433778c1fafff6ce90dd47b69.jpg')); $this->assertTrue($publishingTarget->unpublishPersistentResource($mockResource)); $this->assertFalse(file_exists($temporaryDirectory . 'Persistent/ac9b6187f4c55b461d69e22a57925ff61ee89cb2.jpg')); $this->assertTrue(file_exists($temporaryDirectory . 'Persistent/92cfceb39d57d914ed8b14d0e37643de0797ae56.jpg')); $this->assertTrue(file_exists($temporaryDirectory . 'Persistent/186cd74009911bf433778c1fafff6ce90dd47b69.jpg')); Files::removeDirectoryRecursively($temporaryDirectory); }
/** * @test */ public function unlinkProperlyRemovesSymlinksPointingToDirectories() { $targetPath = Files::concatenatePaths(array(dirname(tempnam($this->temporaryDirectory, '')), 'FlowFilesTestDirectory')); if (!is_dir($targetPath)) { Files::createDirectoryRecursively($targetPath); } $linkPath = Files::concatenatePaths(array(dirname(tempnam($this->temporaryDirectory, '')), 'FlowFilesTestDirectoryLink')); if (is_dir($linkPath)) { Files::removeDirectoryRecursively($linkPath); } symlink($targetPath, $linkPath); $this->assertTrue(Files::unlink($linkPath)); $this->assertTrue(file_exists($targetPath)); $this->assertFalse(file_exists($linkPath)); }
/** * @return void */ public function tearDown() { parent::tearDown(); Files::removeDirectoryRecursively($this->temporaryDirectory); }
/** * Recursively publishes static resources located in the specified directory. * These resources are typically public package resources provided by the active packages. * * @param string $sourcePath The full path to the source directory which should be published (includes sub directories) * @param string $relativeTargetPath Path relative to the target's root where resources should be published to. * @return boolean TRUE if publication succeeded or FALSE if the resources could not be published */ public function publishStaticResources($sourcePath, $relativeTargetPath) { if (!is_dir($sourcePath)) { return FALSE; } $sourcePath = rtrim(\TYPO3\Flow\Utility\Files::getUnixStylePath($this->realpath($sourcePath)), '/'); $targetPath = rtrim(\TYPO3\Flow\Utility\Files::concatenatePaths(array($this->resourcesPublishingPath, 'Static', $relativeTargetPath)), '/'); if ($this->settings['resource']['publishing']['fileSystem']['mirrorMode'] === 'link') { if (\TYPO3\Flow\Utility\Files::is_link($targetPath) && rtrim(\TYPO3\Flow\Utility\Files::getUnixStylePath($this->realpath($targetPath)), '/') === $sourcePath) { return TRUE; } elseif (is_dir($targetPath)) { \TYPO3\Flow\Utility\Files::removeDirectoryRecursively($targetPath); } elseif (is_link($targetPath)) { unlink($targetPath); } else { \TYPO3\Flow\Utility\Files::createDirectoryRecursively(dirname($targetPath)); } symlink($sourcePath, $targetPath); } else { foreach (\TYPO3\Flow\Utility\Files::readDirectoryRecursively($sourcePath) as $sourcePathAndFilename) { if (substr(strtolower($sourcePathAndFilename), -4, 4) === '.php') { continue; } $targetPathAndFilename = \TYPO3\Flow\Utility\Files::concatenatePaths(array($targetPath, str_replace($sourcePath, '', $sourcePathAndFilename))); if (!file_exists($targetPathAndFilename) || filemtime($sourcePathAndFilename) > filemtime($targetPathAndFilename)) { $this->mirrorFile($sourcePathAndFilename, $targetPathAndFilename, TRUE); } } } return TRUE; }
/** * @BeforeScenario @fixtures */ public function removeTestSitePackages() { $directories = glob(FLOW_PATH_PACKAGES . 'Sites/Test.*'); if (is_array($directories)) { foreach ($directories as $directory) { \TYPO3\Flow\Utility\Files::removeDirectoryRecursively($directory); } } }
protected function tearDown() { Files::removeDirectoryRecursively($this->testFilePath); unlink($this->logFilePath); }
/** * Cleans up the directory for storing persistent resources during testing * * @return void * @throws \Exception */ protected function cleanupPersistentResourcesDirectory() { $settings = self::$bootstrap->getObjectManager()->get(\TYPO3\Flow\Configuration\ConfigurationManager::class)->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS); $resourcesStoragePath = $settings['TYPO3']['Flow']['resource']['storages']['defaultPersistentResourcesStorage']['storageOptions']['path']; if (strpos($resourcesStoragePath, FLOW_PATH_DATA) === false) { throw new \Exception(sprintf('The storage path for persistent resources for the Testing context is "%s" but it must point to a directory below "%s". Please check the Flow settings for the Testing context.', $resourcesStoragePath, FLOW_PATH_DATA), 1382018388); } if (file_exists($resourcesStoragePath)) { Files::removeDirectoryRecursively($resourcesStoragePath); } }
/** * @return void */ public function tearDown() { parent::tearDown(); \TYPO3\Flow\Utility\Files::removeDirectoryRecursively($this->temporaryDirectory); }
/** * Renders reST files to fjson files which can be processed by the import command. * * @param string $bundle Bundle to render. If not specified all configured bundles will be rendered * @param string $format optional output format to be used * @return void */ public function renderCommand($bundle = NULL, $format = NULL) { $bundles = $bundle !== NULL ? array($bundle) : array_keys($this->settings['bundles']); $defaultConfiguration = isset($this->settings['defaultConfiguration']) ? $this->settings['defaultConfiguration'] : array(); if ($bundles === array()) { $this->outputLine('No bundles configured.'); $this->quit(1); } foreach ($bundles as $bundle) { if (!isset($this->settings['bundles'][$bundle])) { $this->outputLine('Bundle "%s" is not configured.', array($bundle)); $this->quit(1); } $configuration = Arrays::arrayMergeRecursiveOverrule($defaultConfiguration, $this->settings['bundles'][$bundle]); if ($this->arguments->getArgument('bundle')->getValue() === NULL && $configuration['renderByDefault'] !== TRUE) { $this->outputLine('Skipping bundle "%s".', array($bundle)); continue; } $outputFormat = $format; if ($outputFormat === NULL && isset($configuration['renderingOutputFormat'])) { $outputFormat = $configuration['renderingOutputFormat']; } elseif ($outputFormat === NULL) { $outputFormat = 'json'; } if ($outputFormat === NULL || !in_array($outputFormat, $this->supportedOutputFormats)) { $this->outputLine('ERROR: Output format "' . $outputFormat . '" is not supported. Choose one of the following: ' . implode(', ', $this->supportedOutputFormats)); continue; } $this->outputLine('Rendering bundle <b>%s</b> with format %s into directory %s.', array($bundle, $outputFormat, $configuration['renderedDocumentationRootPath'])); if (is_dir($configuration['renderedDocumentationRootPath']) && $outputFormat !== 'html') { Files::removeDirectoryRecursively($configuration['renderedDocumentationRootPath']); } $renderCommand = $this->sphinxConfiguration->buildRenderCommand($configuration, $outputFormat); exec($renderCommand, $output, $result); $this->sphinxConfiguration->removeTemporaryConfigurationRootPath($configuration); $this->outputLine(str_replace($configuration['documentationRootPath'], '', implode("\n", $output)), array(), 3); if ($result !== 0) { $this->outputLine('Could not execute sphinx-build command for Bundle %s. Tried to execute: "%s"', array($bundle, $renderCommand)); continue; } } }
public function tearDown() { \TYPO3\Flow\Utility\Files::removeDirectoryRecursively($this->temporaryDirectoryPath); \TYPO3\Flow\Utility\Files::removeDirectoryRecursively($this->publishPath); }