/** * {@inheritDoc} */ public function cleanup() { if (!is_null($this->path) && $this->path !== '/') { $this->filesystem->remove($this->path); $this->path = null; } }
protected function tearDownTestProject() { $projectDir = self::ProjectDir(); if (self::$fs->exists($projectDir)) { self::$fs->remove($projectDir); } }
/** * {@inheritdoc} */ public function clear($cacheDir) { $this->filesystem->remove($cacheDir . '/contao/config'); $this->filesystem->remove($cacheDir . '/contao/dca'); $this->filesystem->remove($cacheDir . '/contao/languages'); $this->filesystem->remove($cacheDir . '/contao/sql'); }
protected function tearDown() { if (PHP_VERSION_ID < 50400) { return; } $this->filesystem->remove($this->directory); }
public function tearDown() { // Delete local files $finder = new Finder(); $fs = new Filesystem(); $fs->remove($finder->files()->in($this->tmpDir . "/download")); $fs->remove($finder->files()->in($this->tmpDir)); $fs->remove($this->tmpDir . "/download"); $fs->remove($this->tmpDir); // Delete file uploads $options = new ListFilesOptions(); $options->setTags(["docker-bundle-test"]); $files = $this->client->listFiles($options); foreach ($files as $file) { $this->client->deleteFile($file["id"]); } if ($this->client->bucketExists("in.c-docker-test")) { // Delete tables foreach ($this->client->listTables("in.c-docker-test") as $table) { $this->client->dropTable($table["id"]); } // Delete bucket $this->client->dropBucket("in.c-docker-test"); } if ($this->client->bucketExists("in.c-docker-test-redshift")) { // Delete tables foreach ($this->client->listTables("in.c-docker-test-redshift") as $table) { $this->client->dropTable($table["id"]); } // Delete bucket $this->client->dropBucket("in.c-docker-test-redshift"); } }
/** * @expectedException \Sonatra\Bundle\MailerBundle\Exception\RuntimeException * @expectedExceptionMessageRegExp /Impossible to read the private key of the DKIM swiftmailer signer "([\w.~:\\\/]+)\/private_key"/ */ public function testBeforeSendPerformedWithInvalidPrivateKey() { $path = $this->cache . '/private_key'; $this->fs->remove($path); $this->message->expects($this->never())->method('attachSigner'); $this->plugin->beforeSendPerformed($this->event); }
protected function tearDown() { parent::tearDown(); $filesystem = new Filesystem(); $filesystem->remove($this->getRootCacheDirectory()); $filesystem->remove($this->builder->buildPrefix()); }
protected function tearDown() { if (version_compare(PHP_VERSION, '5.4.0', '<')) { return; } $this->filesystem->remove($this->directory); }
/** * @param string $targetPath * @param string $installPath * @param array $map * @param bool $isSymlink * @param bool $isRelative * * @throws IOException * @throws \InvalidArgumentException * * @api * * @quality:method [B] */ public function publish($targetPath, $installPath, array $map, $isSymlink, $isRelative) { $targetPath = rtrim($targetPath, '/'); $installPath = rtrim($installPath, '/'); $this->filesystem->mkdir($targetPath, 0777); foreach ($map as $from => $to) { $targetDir = realpath($targetPath) . '/' . $to; $sourceDir = realpath($installPath) . '/' . $from; $this->filesystem->remove($targetDir); if ($isSymlink) { $this->io->write(sprintf('Trying to install AdminLTE %s assets as symbolic links.', $from)); $originDir = $sourceDir; if ($isRelative) { $originDir = $this->filesystem->makePathRelative($sourceDir, realpath($targetPath)); } try { $this->filesystem->symlink($originDir, $targetDir); $this->io->write(sprintf('The AdminLTE %s assets were installed using symbolic links.', $from)); } catch (IOException $e) { $this->hardCopy($sourceDir, $targetDir); $this->io->write(sprintf('It looks like your system doesn\'t support symbolic links, so the AdminLTE %s assets were installed by copying them.', $from)); } } else { $this->io->write(sprintf('Installing AdminLTE %s assets as <comment>hard copies</comment>.', $from)); $this->hardCopy($sourceDir, $targetDir); } } }
protected function execute(InputInterface $input, OutputInterface $output) { $fs = new Filesystem(); $fs->remove($this->cacheDirectory . '/app'); $fs->remove($this->cacheDirectory . '/github'); $output->writeln('Caches cleared'); }
/** * @param Attachment $attachment * @param array $dimensionIds * * @return ImageInstance */ public function create(Attachment $attachment, DimensionContainer $dimensionContainer) { $validate = $this->constraints->getConstraints($attachment, $dimensionContainer); if ($validate) { $fs = new Filesystem(); $fs->remove(sprintf('%s/%s', $this->tempPath, $attachment->getFile())); $fs->remove(sprintf('%s/%s', $this->uploadPath, $attachment->getFile())); $this->objectManager->remove($attachment); $this->objectManager->flush(); return $validate; } $instance = new ImageInstance(); $instance->setName($attachment->getName()); $this->objectManager->persist($instance); foreach ($dimensionContainer->getDimensions() as $dimension) { $cropping = new ImageCropping(); $cropping->setAttachment($attachment); $cropping->setInstance($instance); $cropping->setDimension($dimension); $cropping->setName($attachment->getName()); $this->objectManager->persist($cropping); } $this->objectManager->flush(); return $instance; }
/** * * @param Project $project * @return string * @throws DeployException */ public function deploy(Project $project) { $path = sys_get_temp_dir() . '/AwesomeDeployer'; $this->filesystem->mkdir($path); chdir($path); $process = new Process('git clone ' . $project->getRepo() . ' project'); $process->mustRun(); $out = $process->getOutput(); $pathProject = $path . '/project'; chdir($pathProject); $script = $project->getScript(); if ($script !== null) { $script = new Process($script); $script->mustRun(); $out .= $script->getOutput(); } switch ($project->getStrategy()) { case Project::STRATEGY_FABRIC: $command = $project->getCommand(); break; default: throw new DeployException('Strategy not supported'); } $deployment = new Process($command); $deployment->mustRun(); $this->filesystem->remove($path); $out .= $deployment->getOutput(); return $out; }
protected function setUp() { $this->previousCurrentDir = getcwd(); chdir(__DIR__); $fs = new Filesystem(); if ($fs->exists(static::$cacheDir)) { $fs->remove(static::$cacheDir); } if ($fs->exists(static::$dumpDir)) { $fs->remove(static::$dumpDir); } $app = new Application(); $app->register(new ValidatorServiceProvider()); $app['validator.mapping.class_metadata_factory'] = new ClassMetadataFactory(new YamlFilesLoader([static::$originalConfigDir . '/validation.yml'])); //custom providers and services $app['fakery.faker.config'] = $app->share(function ($app) { return new FakerConfig(static::$configDir, 'faker.yml', static::$cacheDir . '/cache/', true); }); $app['fakery.config_serializer'] = $app->share(function ($app) { return new ConfigSerializer(static::$cacheDir . '/cache/', static::$configDir, true); }); $app['fakery.dumper_manager'] = $app->share(function ($app) { return new DumpManager($app['fakery.config_serializer']); }); $app['fakery.console_dumper_manager'] = $app->share(function ($app) { return new ConsoleDumpManager($app['fakery.config_serializer']); }); $this->silex = $app; }
/** * {@inheritdoc} */ public function tearDown() { $fs = new Filesystem(); $fs->remove($this->getRootDir() . '/system/logs'); $fs->remove($this->getRootDir() . '/system/themes'); $fs->remove($this->getRootDir() . '/web'); }
/** * キャッシュを削除する. * * doctrine, profiler, twig によって生成されたキャッシュディレクトリを削除する. * キャッシュは $app['config']['root_dir'].'/app/cache' に生成されます. * * @param Application $app * @param boolean $isAll .gitkeep を残してすべてのファイル・ディレクトリを削除する場合 true, 各ディレクトリのみを削除する場合 false * @param boolean $isTwig Twigキャッシュファイルのみ削除する場合 true * @return boolean 削除に成功した場合 true */ public static function clear($app, $isAll, $isTwig = false) { $cacheDir = $app['config']['root_dir'] . '/app/cache'; $filesystem = new Filesystem(); if ($isAll) { $finder = Finder::create()->in($cacheDir)->notName('.gitkeep'); $filesystem->remove($finder); } elseif ($isTwig) { if (is_dir($cacheDir . '/twig')) { $finder = Finder::create()->in($cacheDir . '/twig'); $filesystem->remove($finder); } } else { if (is_dir($cacheDir . '/doctrine')) { $finder = Finder::create()->in($cacheDir . '/doctrine'); $filesystem->remove($finder); } if (is_dir($cacheDir . '/profiler')) { $finder = Finder::create()->in($cacheDir . '/profiler'); $filesystem->remove($finder); } if (is_dir($cacheDir . '/twig')) { $finder = Finder::create()->in($cacheDir . '/twig'); $filesystem->remove($finder); } } return true; }
private function symlinkPackageToVendor($packagePath, $vendorPath) { $relative = $this->fileSystem->makePathRelative(realpath($packagePath), realpath($vendorPath . '/../')); $this->fileSystem->rename($vendorPath, $vendorPath . '_linked', true); $this->fileSystem->symlink($relative, $vendorPath); $this->fileSystem->remove($vendorPath . '_linked'); }
/** * Dumps an array into the parameters.yml file. * * @param array $config */ public function dump(array $config, $mode = 0777) { $values = ['parameters' => array_merge($this->getConfigValues(), $config)]; $yaml = Yaml::dump($values); $this->fileSystem->dumpFile($this->configFile, $yaml, $mode); $this->fileSystem->remove(sprintf('%s/%s.php', $this->kernel->getCacheDir(), $this->kernel->getContainerCacheClass())); }
public function remove($filename) { if (empty($filename)) { throw new \LogicException('File name can not be empty string.'); } $this->fs->remove($this->uploadDir->getRealPath() . '/' . $filename); }
/** * {@inheritdoc} */ public function launch(Payload $payload, Iteration $iteration, Config $config) { $name = XDebugUtil::filenameFromIteration($iteration); $dir = $config['output_dir']; $phpConfig = ['xdebug.trace_output_name' => $name, 'xdebug.trace_output_dir' => $dir, 'xdebug.trace_format' => '1', 'xdebug.auto_trace' => '1', 'xdebug.coverage_enable' => '0', 'xdebug.collect_params' => '3']; $payload->setPhpConfig($phpConfig); $path = $dir . DIRECTORY_SEPARATOR . $name . '.xt'; // if the file exists, remove it. XDebug might not be installed // on the PHP binary and the file may not be generated. We should // fail in such a case and not use the file from a previous run. if ($this->filesystem->exists($path)) { $this->filesystem->remove($path); } $result = $payload->launch(); if (false === $this->filesystem->exists($path)) { throw new \RuntimeException(sprintf('Trace file at "%s" was not generated.', $path)); } $dom = $this->converter->convert($path); $subject = $iteration->getVariant()->getSubject(); $class = $subject->getBenchmark()->getClass(); // remove leading slash from class name for matching // the class in the trace. if (substr($class, 0, 1) == '\\') { $class = substr($class, 1); } // extract only the timings for the benchmark class, ignore the bootstrapping $selector = '//entry[@function="' . $class . '->' . $subject->getName() . '"]'; // calculate stats from the trace $time = (int) ($dom->evaluate(sprintf('number(%s/@end-time) - number(%s/@start-time)', $selector, $selector)) * 1000000.0); $memory = (int) $dom->evaluate(sprintf('number(%s/@end-memory) - number(%s/@start-memory)', $selector, $selector)); $funcCalls = (int) $dom->evaluate('count(' . $selector . '//*)'); $iteration->setResult(new TimeResult($result['time'])); $iteration->setResult(MemoryResult::fromArray($result['mem'])); $iteration->setResult(new XDebugTraceResult($time, $memory, $funcCalls, $dom)); }
/** * Dumps all translation files. * * @param string $targetDir Target directory. * @param boolean $symlink True if generate symlink * * @return null */ public function dump($targetDir = 'web', $symlink = false, $directory = null) { $route = $this->router->getRouteCollection()->get('bazinga_exposetranslation_js'); $directory = null === $directory ? $this->kernel->getRootDir() . '/../' : $directory; $requirements = $route->getRequirements(); $formats = explode('|', $requirements['_format']); $routeDefaults = $route->getDefaults(); $defaultFormat = $routeDefaults['_format']; $parts = array_filter(explode('/', $route->getPattern())); $this->filesystem->remove($directory . $targetDir . "/" . current($parts)); foreach ($this->getTranslationMessages() as $locale => $domains) { foreach ($domains as $domain => $messageList) { foreach ($formats as $format) { $content = $this->engine->render('BazingaExposeTranslationBundle::exposeTranslation.' . $format . '.twig', array('messages' => array($domain => $messageList), 'locale' => $locale, 'defaultDomains' => $domain)); $path[$format] = $directory . $targetDir . strtr($route->getPattern(), array('{domain_name}' => $domain, '{_locale}' => $locale, '{_format}' => $format)); $this->filesystem->mkdir(dirname($path[$format]), 0777); if (file_exists($path[$format])) { $this->filesystem->remove($path[$format]); } file_put_contents($path[$format], $content); } $targetFile = $directory . $targetDir; $targetFile .= strtr($route->getPattern(), array('{domain_name}' => $domain, '{_locale}' => $locale, '.{_format}' => '')); if (true === $symlink) { $this->filesystem->symlink($path[$defaultFormat], $targetFile); } else { $this->filesystem->copy($path[$defaultFormat], $targetFile); } } } }
/** * Remove all temp files */ protected function cleanup() { foreach ($this->temp_files as $file) { $this->filesystem->remove($file); } $this->temp_files = []; }
/** * Deploy build. * * @throws runtime_exception If deployment failed * @return $this */ public function deploy_build() { if (!$this->fs->exists($this->build_dir)) { return $this; } $this->build_parents(); $current_build = false; if ($this->fs->exists($this->production_link)) { if (is_link($this->production_link)) { $current_build = readlink($this->production_link); } } try { $new_build = $this->repo_dir . 'prod_' . time(); $this->fs->rename($this->build_dir, $new_build); $this->fs->remove($this->production_link); $this->fs->symlink($new_build, $this->production_link); } catch (\Exception $e) { $this->fs->remove($this->production_link); if ($current_build) { $this->fs->symlink($current_build, $this->production_link); } throw new runtime_exception('PACKAGES_BUILD_DEPLOYMENT_FAILED'); } if ($current_build) { $this->fs->remove($current_build); } return $this; }
/** * Validate the form */ private function validateForm() { // Is the form submitted? if ($this->frm->isSubmitted()) { // Cleanup the submitted fields, ignore fields that were added by hackers $this->frm->cleanupFields(); // XML provided? if ($this->frm->getField('wordpress')->isFilled()) { $this->frm->getField('wordpress')->isAllowedExtension(array('xml'), BL::err('XMLFilesOnly')); } else { // No file $this->frm->getField('wordpress')->addError(BL::err('FieldIsRequired')); } // No errors? if ($this->frm->isCorrect()) { // Move the file $this->frm->getField('wordpress')->moveFile(FRONTEND_FILES_PATH . '/wordpress.xml'); // Process the XML $this->processXML(); // Remove the file $this->fs->remove(FRONTEND_FILES_PATH . '/wordpress.xml'); // Everything is saved, so redirect to the overview $this->redirect(BackendModel::createURLForAction('index') . '&report=imported'); } } }
/** * @override \ComponentManager\Step\Step * * @param \ComponentManager\Task\InstallTask $task */ public function execute($task, LoggerInterface $logger) { $resolvedComponentVersions = $task->getResolvedComponentVersions(); foreach ($resolvedComponentVersions as $resolvedComponentVersion) { $logger->info('Installing component', ['component' => $resolvedComponentVersion->getComponent()->getName(), 'packageRepository' => $resolvedComponentVersion->getPackageRepository()->getName(), 'version' => $resolvedComponentVersion->getVersion()->getVersion(), 'release' => $resolvedComponentVersion->getVersion()->getRelease()]); $projectLockFile = $this->project->getProjectLockFile(); $component = $resolvedComponentVersion->getComponent(); $packageSource = $this->project->getPackageSource($resolvedComponentVersion->getSpecification()->getPackageSource()); $typeDirectory = $this->moodle->getPluginTypeDirectory($component->getPluginType()); $targetDirectory = $this->platform->joinPaths([$typeDirectory, $component->getPluginName()]); $tempDirectory = $this->platform->createTempDirectory(); $sourceDirectory = $packageSource->obtainPackage($tempDirectory, $resolvedComponentVersion, $this->filesystem, $logger); if ($resolvedComponentVersion->getFinalVersion() === null) { $logger->warning('Package source did not indicate final version; defaulting to desired version', ['version' => $resolvedComponentVersion->getVersion()->getVersion()]); $resolvedComponentVersion->setFinalVersion($resolvedComponentVersion->getVersion()->getVersion()); } $logger->debug('Downloaded component source', ['packageSource' => $packageSource->getName(), 'sourceDirectory' => $sourceDirectory]); if ($this->filesystem->exists($targetDirectory)) { $logger->info('Component directory already exists; removing', ['targetDirectory' => $targetDirectory]); $this->filesystem->remove($targetDirectory); } $logger->info('Copying component source to Moodle directory', ['sourceDirectory' => $sourceDirectory, 'targetDirectory' => $targetDirectory]); $this->filesystem->mirror($sourceDirectory, $targetDirectory); $logger->info('Pinning component at installed final version', ['finalVersion' => $resolvedComponentVersion->getFinalVersion()]); $projectLockFile->addResolvedComponentVersion($resolvedComponentVersion); $logger->info('Cleaning up after component installation', ['tempDirectory' => $tempDirectory]); try { $this->filesystem->chmod([$tempDirectory], 0750, 00, true); $this->filesystem->remove([$tempDirectory]); } catch (IOException $e) { $logger->warning('Unable to clean up temporary directory', ['code' => $e->getCode(), 'message' => $e->getMessage(), 'tempDirectory' => $tempDirectory]); } } }
/** * Execute the console command. * * @return mixed */ public function fire() { $parentFolder = app_path('database/migrations'); $allFolder = scandir($parentFolder); $_fileService = new Filesystem(); $_tmpPath = app_path('storage') . DIRECTORY_SEPARATOR . 'migrations'; if (!is_dir($_tmpPath) && !$_fileService->exists($_tmpPath)) { $_fileService->mkdir($_tmpPath); } $this->info("Gathering migration files to {$_tmpPath}"); if (!empty($allFolder)) { $_fileService->remove($_tmpPath); foreach ($allFolder as $folder) { if (is_dir($parentFolder . '/' . $folder) && $folder != '.' && $folder != '..') { $_fileService->mirror($parentFolder . '/' . $folder, $_tmpPath); } } $this->info("Migrating..."); $this->call('migrate', array('--path' => ltrim(str_replace(base_path(), '', $_tmpPath), '/'))); // Delete all temp migration files $this->info("Cleaning temporary files"); $_fileService->remove($_tmpPath); // Done $this->info("DONE!"); } }
public static function postInstallUpdate() { $filesystem = new Filesystem(); $baseDir = realpath(__DIR__ . '/../../../../../../../'); $packageDir = realpath(__DIR__ . '/../../../../'); echo "...\n"; if (!$filesystem->exists($baseDir . '/web')) { echo "Creating web folder\n"; $filesystem->mkdir($baseDir . '/web'); $filesystem->mirror($packageDir . '/web', $baseDir . '/web'); } echo "Creating config folder with example config.\n"; $filesystem->mkdir($baseDir . '/config'); $filesystem->copy($packageDir . '/config/config.example.yml', $baseDir . '/config/config.example.yml'); $filesystem->copy($packageDir . '/config/modules.example.php', $baseDir . '/config/modules.example.php'); $filesystem->copy($packageDir . '/config/repositories.example.php', $baseDir . '/config/repositories.example.php'); echo "Creating cache folder, deleting eventually current cache files.\n"; $filesystem->remove($baseDir . '/twig-cache'); $filesystem->mkdir($baseDir . '/twig-cache'); $filesystem->remove($baseDir . '/doctrine-cache'); $filesystem->mkdir($baseDir . '/doctrine-cache'); echo "Installing console.\n"; $filesystem->mkdir($baseDir . '/console'); $filesystem->copy($packageDir . '/console/console', $baseDir . '/console/console'); echo "...\n"; echo "Done.\n"; }
/** * @param string $currentRevision * @param string $distantRevision */ protected function upgrade($currentRevision, $distantRevision) { $fs = new Filesystem(); $versionDir = sprintf('%s/versions', $this->config->get('twgit.protected.global.root_dir')); if (!is_dir($versionDir)) { mkdir($versionDir, 0755); } $newPharFile = sprintf('%s/twgit-%s.phar', $versionDir, $distantRevision); $oldPharFile = sprintf('%s/twgit-%s.phar-old', $versionDir, $currentRevision); $currentPharFile = realpath(str_replace(['phar://', '/src/NMR/Command'], ['', ''], __DIR__)); $this->getLogger()->info('Download new version...'); $this->getClient()->get(self::REMOTE_URL_PHAR, ['save_to' => $newPharFile]); if ($fs->exists($newPharFile)) { $this->getLogger()->info('Backup current version...'); if ($fs->exists($oldPharFile)) { $fs->remove($oldPharFile); } $fs->rename($currentPharFile, $oldPharFile); $this->getLogger()->info('Install new version...'); $fs->remove($currentPharFile); $fs->rename($newPharFile, $currentPharFile); $fs->chmod($currentPharFile, 0777); } else { $this->getLogger()->error('Failed to download new version.'); } }
/** * {@inheritdoc} */ public function execute(InputInterface $input, OutputInterface $output) { $ext = pathinfo($input->getArgument('destination'), PATHINFO_EXTENSION); if (!in_array($ext, array('zip', 'gz'))) { throw new \RuntimeException(sprintf('Invalid filename: %s', $input->getArgument('destination'))); } $fs = new Filesystem(); if ($fs->exists($input->getArgument('destination'))) { $fs->remove($input->getArgument('destination')); } $tmpFile = sprintf("%s/composer_archive_%s.%s", sys_get_temp_dir(), sha1($input->getArgument('destination')), $ext); if ($fs->exists($tmpFile)) { $fs->remove($tmpFile); } if ($ext == 'gz') { $cmd = sprintf("cd %s && tar czf %s . %s", $input->getArgument('folder'), $tmpFile, $input->getOption('vcs') ? '' : '--exclude-vcs'); } elseif ($ext == 'zip') { $cmd = sprintf("cd %s && zip -r -q %s . %s", $input->getArgument('folder'), $tmpFile, $input->getOption('vcs') ? '' : '-x *.git* *.svn*'); } $output->writeln(sprintf("Creating temporary file: <info>%s</info>", $tmpFile)); $output->writeln(sprintf("Starting command %s", $cmd)); $process = new Process($cmd); $process->setTimeout(null); $process->run(function ($type, $data) use($output) { $output->write($data, false, OutputInterface::OUTPUT_PLAIN); }); $fs->rename($tmpFile, $input->getArgument('destination')); }
protected function execute(InputInterface $input, OutputInterface $output) { $identifier = $input->getArgument('identifier'); if (!$identifier) { $identifier = '1799-Auobj'; } $path = utils::normalize(__DIR__ . "/../data/{$identifier}.json"); $content = file_get_contents($path); $data = json_decode($content); $localFile = utils::normalize(__DIR__ . "/../tmp/{$data->name}"); $file = fopen($localFile, 'wb'); $http = new \ADN\Extract\HttpRequest($data->uri, [], null, null); $response = $http->get(function ($code, $chunk) use($file, $data, $path) { if ($code != 'data') { return false; } fwrite($file, $chunk); $data->bytesRead += strlen($chunk); file_put_contents($path, json_encode($data)); return true; }); fclose($file); if (!$response || $response->code != Response::HTTP_OK) { $output->writeln('oops'); $fs = new Filesystem(); $fs->remove($path); $fs->remove($localFile); return; } $data->size = utils::findKey($response->headers, 'Content-Length'); $data->bytesRead = $data->size; file_put_contents($path, json_encode($data)); utils::log('ok'); }
/** * @param EntityInterface $entity */ protected function removeOldFiles(EntityInterface $entity) { $root = $this->root . $entity->getDownloadPath() . '/'; foreach ($entity->getOldFilenames() as $filename) { $this->fs->remove($root . $filename); } }