Skip to content

Commit

Permalink
Fix issue 9172
Browse files Browse the repository at this point in the history
  • Loading branch information
umpirsky authored and fabpot committed May 4, 2014
1 parent 8f8b20c commit 25f1d85
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Expand Up @@ -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.
Expand Down
Expand Up @@ -52,6 +52,10 @@ protected function configure()
'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'
Expand Down Expand Up @@ -139,6 +143,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
}

if ($input->getOption('no-backup') === true) {
$writer->disableBackup();
}

// save the files
if ($input->getOption('force') === true) {
$output->writeln('Writing files');
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Translation/CHANGELOG.md
Expand Up @@ -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
Expand Down
21 changes: 20 additions & 1 deletion src/Symfony/Component/Translation/Dumper/FileDumper.php
Expand Up @@ -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.
*
Expand All @@ -41,6 +48,16 @@ public function setRelativePathTemplate($relativePathTemplate)
$this->relativePathTemplate = $relativePathTemplate;
}

/**
* Sets backup flag.
*
* @param bool
*/
public function setBackup($backup)
{
$this->backup = $backup;
}

/**
* {@inheritdoc}
*/
Expand All @@ -55,7 +72,9 @@ public function dump(MessageCatalogue $messages, $options = array())
// 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)) {
Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Component/Translation/Writer/TranslationWriter.php
Expand Up @@ -39,6 +39,16 @@ public function addDumper($format, DumperInterface $dumper)
$this->dumpers[$format] = $dumper;
}

/**
* Disables dumper backup.
*/
public function disableBackup()
{
foreach ($this->dumpers as $dumper) {
$dumper->setBackup(false);
}
}

/**
* Obtains the list of supported formats.
*
Expand Down

0 comments on commit 25f1d85

Please sign in to comment.