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"; }
public static function createRequiredFiles(Event $event) { $fs = new Filesystem(); $root = static::getDrupalRoot(getcwd()); $dirs = ['modules', 'profiles', 'themes']; // Required for unit testing foreach ($dirs as $dir) { if (!$fs->exists($root . '/' . $dir)) { $fs->mkdir($root . '/' . $dir); $fs->touch($root . '/' . $dir . '/.gitkeep'); } } // Prepare the settings file for installation if (!$fs->exists($root . '/sites/default/settings.php')) { $fs->copy($root . '/sites/default/default.settings.php', $root . '/sites/default/settings.php'); $fs->chmod($root . '/sites/default/settings.php', 0666); $event->getIO()->write("Create a sites/default/settings.php file with chmod 0666"); } // Prepare the services file for installation if (!$fs->exists($root . '/sites/default/services.yml')) { $fs->copy($root . '/sites/default/default.services.yml', $root . '/sites/default/services.yml'); $fs->chmod($root . '/sites/default/services.yml', 0666); $event->getIO()->write("Create a sites/default/services.yml file with chmod 0666"); } // Create the files directory with chmod 0777 if (!$fs->exists($root . '/sites/default/files')) { $oldmask = umask(0); $fs->mkdir($root . '/sites/default/files', 0777); umask($oldmask); $event->getIO()->write("Create a sites/default/files directory with chmod 0777"); } }
/** * Saves the handled page * * @param \RedKiteCms\Content\BlockManager\BlockManagerApprover $approver * @param array $options * @param bool $saveCommonSlots Saves the common slots when true */ public function save(BlockManagerApprover $approver, array $options, $saveCommonSlots = true) { $this->contributorDefined(); $filesystem = new Filesystem(); $pageDir = $this->pagesDir . '/' . $options["page"]; $filesystem->copy($pageDir . '/' . $this->pageFile, $pageDir . '/page.json', true); $pageDir .= '/' . $options["language"] . '_' . $options["country"]; if ($this->seoFile != "seo.json") { $sourceFile = $pageDir . '/' . $this->seoFile; $values = json_decode(file_get_contents($sourceFile), true); if (array_key_exists("current_permalink", $values)) { $values["changed_permalinks"][] = $values["current_permalink"]; unset($values["current_permalink"]); file_put_contents($sourceFile, json_encode($values)); } $filesystem->copy($sourceFile, $pageDir . '/seo.json', true); } $approvedBlocks = $this->saveBlocks($approver, $pageDir, $options); if ($saveCommonSlots) { $slotsDir = $this->baseDir . '/slots'; $approvedCommonBlocks = $this->saveBlocks($approver, $slotsDir, $options); $approvedBlocks = array_merge($approvedBlocks, $approvedCommonBlocks); } Dispatcher::dispatch(PageEvents::PAGE_SAVED, new PageSavedEvent($pageDir, null, $approvedBlocks)); DataLogger::log(sprintf('Page "%s" was successfully saved in production', $options["page"])); }
/** * {@inheritdoc} */ public function save($tempPath, $fileName, $version, $storageOption = null) { $this->storageOption = new stdClass(); if ($storageOption) { $oldStorageOption = json_decode($storageOption); $segment = $oldStorageOption->segment; } else { $segment = sprintf('%0' . strlen($this->segments) . 'd', rand(1, $this->segments)); } $segmentPath = $this->uploadPath . '/' . $segment; $fileName = $this->getUniqueFileName($segmentPath, $fileName); $filePath = $this->getPathByFolderAndFileName($segmentPath, $fileName); $this->logger->debug('Check FilePath: ' . $filePath); if (!$this->filesystem->exists($segmentPath)) { $this->logger->debug('Try Create Folder: ' . $segmentPath); $this->filesystem->mkdir($segmentPath, 0777); } $this->logger->debug('Try to copy File "' . $tempPath . '" to "' . $filePath . '"'); if ($this->filesystem->exists($filePath)) { throw new FilenameAlreadyExistsException($filePath); } $this->filesystem->copy($tempPath, $filePath); $this->addStorageOption('segment', $segment); $this->addStorageOption('fileName', $fileName); return json_encode($this->storageOption); }
public static function setUpBeforeClass() { $fs = new Filesystem(); $fs->copy(__DIR__ . '/fixtures/base.png', __DIR__ . '/fixtures/visuel.png'); $fs->copy(__DIR__ . '/fixtures/base.png', __DIR__ . '/fixtures/visuel2.png'); $fs->copy(__DIR__ . '/fixtures/base.png', __DIR__ . '/fixtures/visuel3.png'); }
public function copyConfigs() { // Copy configs foreach ($this->configsToCopy() as $fileName) { $this->fs->copy($this->resourcesDir . '/conf/' . $fileName, $this->projectPath . '/docker/conf/' . $fileName); } // Change the default xdebug remote host on Mac, which uses a VM if (!Docker::native()) { $phpConfFile = $this->projectPath . '/docker/conf/php.ini'; $phpConf = file_get_contents($phpConfFile); $phpConf = str_replace('172.17.42.1', '192.168.99.1', $phpConf); file_put_contents($phpConfFile, $phpConf); } // Quick fix to make nginx PHP_IDE_CONFIG dynamic for now. $nginxConfFile = $this->projectPath . '/docker/conf/nginx.conf'; $nginxConf = file_get_contents($nginxConfFile); $nginxConf = str_replace('{{ platform }}', Platform::projectName() . '.' . Platform::projectTld(), $nginxConf); file_put_contents($nginxConfFile, $nginxConf); // stub in for Solr configs $finder = new Finder(); $finder->in($this->resourcesDir . '/conf/solr')->files()->depth('< 1')->name('*'); /** @var \SplFileInfo $file */ foreach ($finder as $file) { $this->fs->copy($file->getPathname(), $this->projectPath . '/docker/conf/solr/' . $file->getFilename()); } // copy ssl $this->fs->copy($this->resourcesDir . '/ssl/nginx.crt', $this->projectPath . '/docker/ssl/nginx.crt'); $this->fs->copy($this->resourcesDir . '/ssl/nginx.key', $this->projectPath . '/docker/ssl/nginx.key'); }
/** * From the specified plugin name, create a directory * Create views/, cache/ and src/Namespace directories * Generate cli-config.php, doctrine-config.php and plugin-identifier.php * * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { $pluginIdentifier = $input->getArgument('pluginIdentifier'); $pluginNameParts = explode('-', $pluginIdentifier); array_walk($pluginNameParts, function (&$value, $key) { $value = ucfirst($value); }); $pluginNamespace = join('', $pluginNameParts); $pluginName = join(' ', $pluginNameParts); $fs = new Filesystem(); // create directories try { $fs->mkdir(array('../' . $pluginIdentifier, '../' . $pluginIdentifier . '/resources', '../' . $pluginIdentifier . '/resources/views', '../' . $pluginIdentifier . '/resources/public', '../' . $pluginIdentifier . '/data', '../' . $pluginIdentifier . '/data/cache', '../' . $pluginIdentifier . '/data/proxies', '../' . $pluginIdentifier . '/src', '../' . $pluginIdentifier . '/src/' . $pluginNamespace, '../' . $pluginIdentifier . '/src/' . $pluginNamespace . '/Controller', '../' . $pluginIdentifier . '/src/' . $pluginNamespace . '/Entity', '../' . $pluginIdentifier . '/src/' . $pluginNamespace . '/Form/Type')); } catch (IOException $e) { $output->writeln('An error occured while creating directories: ' . $e->getMessage()); } $templatesDirectory = __DIR__ . '/../../../templates'; // generate files $loader = new \Twig_Loader_Filesystem($templatesDirectory); $twig = new \Twig_Environment($loader); file_put_contents('../' . $pluginIdentifier . '/doctrine-config.php', $twig->render('doctrine-config.php.twig', array('pluginIdentifier' => $pluginIdentifier, 'pluginNamespace' => $pluginNamespace))); file_put_contents('../' . $pluginIdentifier . '/' . $pluginIdentifier . '.php', $twig->render('plugin.php.twig', array('pluginIdentifier' => $pluginIdentifier, 'pluginNamespace' => $pluginNamespace, 'pluginName' => $pluginName))); file_put_contents('../' . $pluginIdentifier . '/src/' . $pluginNamespace . '/Controller/DefaultController.php', $twig->render('src/DefaultController.php.twig', array('pluginNamespace' => $pluginNamespace))); file_put_contents('../' . $pluginIdentifier . '/src/' . $pluginNamespace . '/Entity/Person.php', $twig->render('src/Person.php.twig', array('pluginIdentifier' => $pluginIdentifier, 'pluginNamespace' => $pluginNamespace))); file_put_contents('../' . $pluginIdentifier . '/src/' . $pluginNamespace . '/Form/Type/PersonType.php', $twig->render('src/PersonType.php.twig', array('pluginNamespace' => $pluginNamespace))); // copy files $fs->copy($templatesDirectory . '/resources/views/index.html.twig', '../' . $pluginIdentifier . '/resources/views/Default/index.html.twig'); $fs->copy($templatesDirectory . '/resources/views/create.html.twig', '../' . $pluginIdentifier . '/resources/views/Default/create.html.twig'); $fs->copy($templatesDirectory . '/resources/views/edit.html.twig', '../' . $pluginIdentifier . '/resources/views/Default/edit.html.twig'); $output->writeln('Created "' . $pluginName . '" plugin in "' . $pluginIdentifier . '".'); $output->writeln('Please ensure both "' . $pluginIdentifier . '/data/cache" and "' . $pluginIdentifier . '/data/proxies" exist and are writable by Apache\'s user.'); $output->writeln('To finish, you need to activate your plugin in "Plugins".'); }
/** * Uploads a file and checks for the uniqueness of the name * * @param string $source * @param string $destination * * @throws IcrLogicException */ public function uploadFile($source, $destination) { $fileExists = $this->filesystem->exists($destination); if ($fileExists) { throw new IcrLogicException("File {$destination} exists!"); } $this->filesystem->copy($source, $destination); }
/** * @param Bundle $bundle The bundle * @param array $parameters The template parameters * @param string $rootDir The root directory * @param OutputInterface $output */ public function generateTemplates(Bundle $bundle, array $parameters, $rootDir, OutputInterface $output) { $dirPath = $bundle->getPath(); $fullSkeletonDir = $this->skeletonDir . '/Resources/views'; $this->filesystem->copy(__DIR__ . '/../Resources/SensioGeneratorBundle/skeleton' . $fullSkeletonDir . '/Pages/Search/SearchPage/view.html.twig', $dirPath . '/Resources/views/Pages/Search/SearchPage/view.html.twig', true); GeneratorUtils::prepend("{% extends '" . $bundle->getName() . ":Page:layout.html.twig' %}\n", $dirPath . '/Resources/views/Pages/Search/SearchPage/view.html.twig'); $output->writeln('Generating Twig Templates : <info>OK</info>'); }
/** * @return Image */ private function createImage() { $image = new Image(); $image->setFilename('silvestra.png'); $image->setOriginalPath($this->filesystem->getRelativeFilePath($image->getFilename())); $this->symfonyFilesystem->copy(dirname(__FILE__) . '/../../Fixtures/silvestra.png', $this->filesystem->getActualFileDir($image->getFilename()) . '/' . $image->getFilename()); return $image; }
protected function copyTemplates() { $from = $this->kernel->locateResource('@AnimeDbCatalogBundle/Resources/views/'); $to = $this->root_dir . '/Resources/'; // overwrite twig error templates $this->fs->copy($from . 'errors/error.html.twig', $to . 'TwigBundle/views/Exception/error.html.twig', true); $this->fs->copy($from . 'errors/error404.html.twig', $to . 'TwigBundle/views/Exception/error404.html.twig', true); }
protected function execute(InputInterface $input, OutputInterface $output) { // Get kernel $kernel = $this->getContainer()->get('kernel'); // Get rootDir $rootDir = $kernel->getRootDir(); // Get Vendor dir $vendor = $rootDir . '/../vendor'; // Set chosen folder name $chosen = 'drmonty/chosen'; // Does the dir exists ? if (!$this->fs->exists($vendor . DIRECTORY_SEPARATOR . $chosen)) { $output->writeln("An error occurred while checking directory : " . $vendor . DIRECTORY_SEPARATOR . $chosen); } // Ckeck folders existence inside bundle if (!$this->fs->exists(dirname(__FILE__) . DIRECTORY_SEPARATOR . '../Resources/public/css')) { $this->fs->mkdir(dirname(__FILE__) . DIRECTORY_SEPARATOR . '../Resources/public/css', 0777); } if (!$this->fs->exists(dirname(__FILE__) . DIRECTORY_SEPARATOR . '../Resources/public/js')) { $this->fs->mkdir(dirname(__FILE__) . DIRECTORY_SEPARATOR . '../Resources/public/js', 0777); } // Get environnement $env = $kernel->getEnvironment(); // Get files if ($env == "dev") { $files = ['css' => 'chosen.css', 'js' => 'chosen.jquery.js']; } else { $files = ['css' => 'chosen.min.css', 'js' => 'chosen.jquery.min.js']; } $files += ['img' => ['chosen-sprite.png', '*****@*****.**']]; // Copy files into Public bundle's folder try { $this->fs->copy($vendor . DIRECTORY_SEPARATOR . $chosen . DIRECTORY_SEPARATOR . 'css/' . $files['css'], dirname(__FILE__) . DIRECTORY_SEPARATOR . '../Resources/public/css' . DIRECTORY_SEPARATOR . $files['css'], true); } catch (IOExceptionInterface $e) { $output->writeln("An error occurred while copying file " . $e->getPath()); } try { $this->fs->copy($vendor . DIRECTORY_SEPARATOR . $chosen . DIRECTORY_SEPARATOR . 'js/' . $files['js'], dirname(__FILE__) . DIRECTORY_SEPARATOR . '../Resources/public/js' . DIRECTORY_SEPARATOR . $files['js'], true); } catch (IOExceptionInterface $e) { $output->writeln("An error occurred while copying file " . $e->getPath()); } foreach ($files['img'] as $img) { try { $this->fs->copy($vendor . DIRECTORY_SEPARATOR . $chosen . DIRECTORY_SEPARATOR . 'css/' . $img, dirname(__FILE__) . DIRECTORY_SEPARATOR . '../Resources/public/css' . DIRECTORY_SEPARATOR . $img, true); } catch (IOExceptionInterface $e) { $output->writeln("An error occurred while copying image " . $e->getPath()); } } if ($input->getOption('asset')) { $app = $this->getApplication(); // Install assets $output->writeln("<info>Force install<info>"); $in = new ArrayInput(['command' => 'asset:install', '--env' => $env, '--symlink' => !$input->getOption('asset-link')]); $app->doRun($in, $output); } else { $output->writeln("<info>Your files have been copied to Kl3skChosenBundle, dont forget to install assets<info> <comment>php app/console asset:install</comment>"); } }
/** * Rename file, if it in the temp folder. * * @param EntityInterface $entity * @param string $target */ protected function renameFile(EntityInterface $entity, $target) { if ($entity->getFilename() && strpos($entity->getFilename(), 'tmp') !== false) { $filename = $entity->getFilename(); $entity->setFilename($target . pathinfo($filename, PATHINFO_BASENAME)); $root = $this->root . $entity->getDownloadPath() . '/'; $this->fs->copy($root . $filename, $root . $entity->getFilename(), true); } }
/** * {@inheritdoc } */ public function convert($file, $newVersion) { $tmpFile = $this->generateAbsolutePathOfTmpFile(); $this->command->run($file, $tmpFile, $newVersion); if (!$this->fs->exists($tmpFile)) { throw new \RuntimeException("The generated file '{$tmpFile}' was not found."); } $this->fs->copy($tmpFile, $file, true); }
/** * @beforeScenario */ public function prepWorkingDirectory() { $this->workingDirectory = tempnam(sys_get_temp_dir(), 'phpspec-behat'); $this->filesystem->remove($this->workingDirectory); $this->filesystem->mkdir($this->workingDirectory); chdir($this->workingDirectory); $this->filesystem->mkdir($this->workingDirectory . '/vendor'); $this->filesystem->copy(__DIR__ . '/autoloader/autoload.php', $this->workingDirectory . '/vendor/autoload.php'); }
/** * Download file. * * @param string $originFile * @param string $downloadFolder * @param string|null $name * * @return File */ public function download($originFile, $downloadFolder, $name = null) { if (null === $name) { $name = pathinfo($originFile, PATHINFO_FILENAME); } $filename = $name . '.' . $this->getFileExtension($originFile); $targetFile = rtrim($downloadFolder, '/\\') . DIRECTORY_SEPARATOR . $filename; $this->fileSystem->copy($originFile, $targetFile); return new File($this->fileSystem, $targetFile); }
/** * {@inheritdoc} */ public function write(OutputInterface $output) { $outputPath = $this->outputDir . '/' . $output->permalink()->relativeFilePath(); if ($output->hasFileReference()) { $this->filesystem->copy($output->file(), $outputPath, true); } else { $this->filesystem->mkdir(dirname($outputPath)); file_put_contents($outputPath, $output->formattedContent()); } }
private function addLogosAndIcons() { $this->log('Dumping logos and icons...'); $filesystem = new Filesystem(); $imgDir = __DIR__ . '/../../../Resources/public/images'; $webDir = __DIR__ . '/../../../../../../web'; $filesystem->mirror("{$imgDir}/logos", "{$webDir}/uploads/logos"); $filesystem->copy("{$imgDir}/ico/favicon.ico", "{$webDir}/favicon.ico", true); $filesystem->copy("{$imgDir}/ico/apple-touch-icon.png", "{$webDir}/apple-touch-icon.png", true); }
/** * Flush content to file * * @param string $content */ public function flush($content) { try { $this->checkPermissions(); $backupFilename = $this->generateBackupFilename(); $this->filesystem->copy($this->filename, $backupFilename); $this->dumpFile($this->filename, $content); } catch (Exception $exception) { throw new RuntimeException(sprintf('Unable to persist the data to "%s"', $this->filename), null, $exception); } }
/** * @return $this */ private function copyFiles() { $filename = 'defaults.yml'; $path = sprintf('%s/.drupal-vm-generator/%s', $this->getUserHomeDirectory(), $filename); if ($this->filesystem->exists($path) && !$this->input->getOption('overwrite')) { return $this->io->error(sprintf('%s already exists', $filename)); } $this->filesystem->copy(__DIR__ . '/../../config/dist/defaults.yml', $path); $this->io->success(sprintf('%s copied.', $filename)); return $this; }
public function copyConfigs() { // Copy configs foreach ($this->configsToCopy() as $fileName) { $this->fs->copy($this->resourcesDir . '/conf/' . $fileName, $this->projectPath . '/docker/conf/' . $fileName); } // Quick fix to make nginx PHP_IDE_CONFIG dynamic for now. $nginxConfFile = $this->projectPath . '/docker/conf/nginx.conf'; $nginxConf = file_get_contents($nginxConfFile); $nginxConf = str_replace('{{ platform }}', Platform::projectName() . '.platform', $nginxConf); file_put_contents($nginxConfFile, $nginxConf); }
/** * @param string $source * @param string $destination * * @return bool */ protected function copyFile($source, $destination) { $destinationDir = dirname($destination); try { if (!is_dir($destinationDir)) { $this->localFs->mkdir($destinationDir); } $this->localFs->copy($source, $destination, true); } catch (IOException $e) { return false; } return true; }
/** * {@inheritdoc} */ public function resize(ImageInterface $image, ResizeConfigurationInterface $config, ResizeOptionsInterface $options) { if ($image->getDimensions()->isUndefined() || $config->isEmpty()) { $image = $this->createImage($image, $image->getPath()); } else { $image = $this->processResize($image, $config, $options); } if (null !== $options->getTargetPath()) { $this->filesystem->copy($image->getPath(), $options->getTargetPath(), true); $image = $this->createImage($image, $options->getTargetPath()); } return $image; }
/** * {@inheritdoc} */ public function save($tmpPath, $id, $fileName, $options, $format) { $savePath = $this->getPath($this->path, $id, $fileName, $format); if (!is_dir(dirname($savePath))) { $this->filesystem->mkdir(dirname($savePath), 0775); } try { $this->filesystem->copy($tmpPath, $savePath); } catch (IOException $ioException) { return false; } return true; }
/** * @covers Kunstmaan\MediaBundle\Helper\Transformer\PdfTransformer::apply */ public function testApplyDoesNotOverwriteExisting() { $pdfFilename = $this->tempDir . '/sample.pdf'; $jpgFilename = $pdfFilename . '.jpg'; $pdf = $this->filesDir . '/sample.pdf'; $this->filesystem->copy($pdf, $pdfFilename); $this->assertTrue(file_exists($pdfFilename)); $this->filesystem->touch($jpgFilename); $transformer = new PdfTransformer(new \Imagick()); $absolutePath = $transformer->apply($pdfFilename); $this->assertEquals($jpgFilename, $absolutePath); $this->assertEmpty(file_get_contents($jpgFilename)); }
/** * 复制项目 * @param $src * @param $dst */ protected function copy($src, $dst) { $dir = opendir($src); while (false !== ($file = readdir($dir))) { if ($file != '.' && $file != '..') { if (is_dir("{$src}/{$file}")) { $this->copy("{$src}/{$file}", "{$dst}/{$file}"); } else { $this->filesystem->copy("{$src}/{$file}", "{$dst}/{$file}"); } } } closedir($dir); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $fs = new Filesystem(); $version = $this->getVersionFromGit(); $output->writeln('Release Coupe ' . $version); $output->writeln('Compiling phar ...'); if (0 != $this->compile($output)) { return 255; } chdir('build'); $output->writeln('Cloning repository ...'); $process = new Process('git clone git@github.com:kzykhys/coupe.git'); $process->run(); if (!$process->isSuccessful()) { $output->writeln('<error>Failed to clone git repository</error>'); return 9; } chdir('coupe'); $process = new Process('git fetch'); $process->run(); $process = new Process('git checkout -b gh-pages origin/gh-pages'); $process->run(); if (!$process->isSuccessful()) { $output->writeln('<error>Failed to checkout branch "gh-pages"</error>'); return 5; } $fs->copy('../coupe.phar', 'coupe.phar', true); $fs->copy('../../bin/install', 'install', true); file_put_contents('version', $version); $output->writeln('Staging...'); $process = new Process('git add coupe.phar version install'); $process->run(); $process = new Process('git status'); $process->run(); $output->writeln($process->getOutput()); /* @var \Symfony\Component\Console\Helper\DialogHelper $dialog */ $dialog = $this->getHelper('dialog'); if ($dialog->askConfirmation($output, 'Do you release ' . $version . '? [yes/no]: ', false)) { $process = new Process('git commit -m "Releases coupe ' . $version . '"'); $process->run(); $output->writeln($process->getOutput()); $process = new Process('git push origin gh-pages'); $process->run(); $output->writeln($process->getOutput()); } chdir('../'); $fs->remove('coupe/'); return 0; }
/** * @param array $regexes * @param bool $backupBeforeOverride */ protected function doConvert(array $regexes, $backupBeforeOverride = true) { $data = "<?php\nreturn " . var_export($regexes, true) . ';'; $regexesFile = $this->destination . '/regexes.php'; if ($backupBeforeOverride && $this->fs->exists($regexesFile)) { $currentHash = hash('sha512', file_get_contents($regexesFile)); $futureHash = hash('sha512', $data); if ($futureHash === $currentHash) { return; } $backupFile = $this->destination . '/regexes-' . $currentHash . '.php'; $this->fs->copy($regexesFile, $backupFile); } $this->fs->dumpFile($regexesFile, $data); }
/** * Generate a copy of a theme package. * * @param Request $request * * @throws PackageManagerException * * @return Response */ public function generateTheme(Request $request) { $theme = $request->get('theme'); $newName = $request->get('name'); if (empty($theme)) { return new Response(Trans::__('No theme name found. Theme is not generated.')); } if (!$newName) { $newName = basename($theme); } $source = $this->resources()->getPath('extensions/vendor/' . $theme); $destination = $this->resources()->getPath('themebase/' . $newName); if (is_dir($source)) { try { $filesystem = new Filesystem(); $filesystem->mkdir($destination); $filesystem->mirror($source, $destination); if (file_exists($destination . "/config.yml.dist")) { $filesystem->copy($destination . "/config.yml.dist", $destination . "/config.yml"); } return new Response(Trans::__('Theme successfully generated. You can now edit it directly from your theme folder.')); } catch (\Exception $e) { return new Response(Trans::__('We were unable to generate the theme. It is likely that your theme directory is not writable by Bolt. Check the permissions and try reinstalling.')); } } throw new PackageManagerException("Invalid theme source directory: {$source}"); }
/** * Creates copy of image * @param $copyFile * @param $dir */ protected function triggerCopy($copyFile, $dir) { $this->lg->info(sprintf("Executing copy in '%s' destination.", $copyFile)); $filename = $this->filename(0, $copyFile, false); $this->fs->copy($copyFile, $dir . $filename); $this->setFilePath(0, $dir, $filename); }