From 25f1d85d6b9004b50990af525a67bf9bf721df99 Mon Sep 17 00:00:00 2001 From: umpirsky Date: Wed, 30 Apr 2014 19:04:41 +0200 Subject: [PATCH] Fix issue 9172 --- .../Bundle/FrameworkBundle/CHANGELOG.md | 1 + .../Command/TranslationUpdateCommand.php | 8 +++++++ .../Component/Translation/CHANGELOG.md | 1 + .../Translation/Dumper/FileDumper.php | 21 ++++++++++++++++++- .../Translation/Writer/TranslationWriter.php | 10 +++++++++ 5 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index 9658d5729c..25247608e5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -5,6 +5,7 @@ CHANGELOG ----- * Added `translation:debug` command + * Added `--no-backup` option to `translation:update` command * Added `config:debug` command * Added `yaml:lint` command * Deprecated the `RouterApacheDumperCommand` which will be removed in Symfony 3.0. diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php index b4c1e3efd7..8457656f08 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php @@ -52,6 +52,10 @@ class TranslationUpdateCommand extends ContainerAwareCommand 'force', null, InputOption::VALUE_NONE, 'Should the update be done' ), + new InputOption( + 'no-backup', null, InputOption::VALUE_NONE, + 'Should backup be disabled' + ), new InputOption( 'clean', null, InputOption::VALUE_NONE, 'Should clean not found messages' @@ -139,6 +143,10 @@ EOF } } + if ($input->getOption('no-backup') === true) { + $writer->disableBackup(); + } + // save the files if ($input->getOption('force') === true) { $output->writeln('Writing files'); diff --git a/src/Symfony/Component/Translation/CHANGELOG.md b/src/Symfony/Component/Translation/CHANGELOG.md index 467feacd90..8aedc370d4 100644 --- a/src/Symfony/Component/Translation/CHANGELOG.md +++ b/src/Symfony/Component/Translation/CHANGELOG.md @@ -5,6 +5,7 @@ CHANGELOG ----- * added relative file path template to the file dumpers + * added optional backup to the file dumpers * changed IcuResFileDumper to extend FileDumper 2.3.0 diff --git a/src/Symfony/Component/Translation/Dumper/FileDumper.php b/src/Symfony/Component/Translation/Dumper/FileDumper.php index a70e995dda..7672400f02 100644 --- a/src/Symfony/Component/Translation/Dumper/FileDumper.php +++ b/src/Symfony/Component/Translation/Dumper/FileDumper.php @@ -31,6 +31,13 @@ abstract class FileDumper implements DumperInterface */ protected $relativePathTemplate = '%domain%.%locale%.%extension%'; + /** + * Make file backup before the dump. + * + * @var bool + */ + private $backup = true; + /** * Sets the template for the relative paths to files. * @@ -41,6 +48,16 @@ abstract class FileDumper implements DumperInterface $this->relativePathTemplate = $relativePathTemplate; } + /** + * Sets backup flag. + * + * @param bool + */ + public function setBackup($backup) + { + $this->backup = $backup; + } + /** * {@inheritdoc} */ @@ -55,7 +72,9 @@ abstract class FileDumper implements DumperInterface // backup $fullpath = $options['path'].'/'.$this->getRelativePath($domain, $messages->getLocale()); if (file_exists($fullpath)) { - copy($fullpath, $fullpath.'~'); + if ($this->backup) { + copy($fullpath, $fullpath.'~'); + } } else { $directory = dirname($fullpath); if (!file_exists($directory) && !@mkdir($directory, 0777, true)) { diff --git a/src/Symfony/Component/Translation/Writer/TranslationWriter.php b/src/Symfony/Component/Translation/Writer/TranslationWriter.php index 9d70c12f37..8d90797d11 100644 --- a/src/Symfony/Component/Translation/Writer/TranslationWriter.php +++ b/src/Symfony/Component/Translation/Writer/TranslationWriter.php @@ -39,6 +39,16 @@ class TranslationWriter $this->dumpers[$format] = $dumper; } + /** + * Disables dumper backup. + */ + public function disableBackup() + { + foreach ($this->dumpers as $dumper) { + $dumper->setBackup(false); + } + } + /** * Obtains the list of supported formats. *