From 56564610256c92a865e0810913541f52864604be Mon Sep 17 00:00:00 2001 From: Jelle Henkens Date: Fri, 25 May 2012 17:01:56 +0100 Subject: [PATCH] Adding overwrite option to the i18n extract task --- lib/Cake/Console/Command/Task/ExtractTask.php | 9 ++++++++ .../Console/Command/Task/ExtractTaskTest.php | 22 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/lib/Cake/Console/Command/Task/ExtractTask.php b/lib/Cake/Console/Command/Task/ExtractTask.php index fb7102787..46ce5b18a 100644 --- a/lib/Cake/Console/Command/Task/ExtractTask.php +++ b/lib/Cake/Console/Command/Task/ExtractTask.php @@ -302,6 +302,11 @@ class ExtractTask extends AppShell { ->addOption('exclude', array( 'help' => __d('cake_console', 'Comma separated list of directories to exclude.' . ' Any path containing a path segment with the provided values will be skipped. E.g. test,vendors') + )) + ->addOption('overwrite', array( + 'boolean' => true, + 'default' => false, + 'help' => __d('cake_console', 'Always overwrite existing .pot files.') )); } @@ -537,6 +542,10 @@ class ExtractTask extends AppShell { */ protected function _writeFiles() { $overwriteAll = false; + if (!empty($this->params['overwrite'])) { + $overwriteAll = true; + } + foreach ($this->_storage as $domain => $sentences) { $output = $this->_writeHeader(); foreach ($sentences as $sentence => $header) { diff --git a/lib/Cake/Test/Case/Console/Command/Task/ExtractTaskTest.php b/lib/Cake/Test/Case/Console/Command/Task/ExtractTaskTest.php index b144e37b9..a7f893c25 100644 --- a/lib/Cake/Test/Case/Console/Command/Task/ExtractTaskTest.php +++ b/lib/Cake/Test/Case/Console/Command/Task/ExtractTaskTest.php @@ -399,4 +399,26 @@ class ExtractTaskTest extends CakeTestCase { $pattern = '#Plugin/TestPlugin/Model/TestPluginPost.php:validation for field title#'; $this->assertNotRegExp($pattern, $result); } + + +/** + * Test that the extract shell overwrites existing files with the overwrite parameter + * + * @return void + */ + public function testExtractOverwrite() { + $this->Task->interactive = false; + + $this->Task->params['paths'] = CAKE . 'Test' . DS . 'test_app' . DS; + $this->Task->params['output'] = $this->path . DS; + $this->Task->params['overwrite'] = true; + + file_put_contents($this->path . DS . 'default.pot', 'will be overwritten'); + $this->assertTrue(file_exists($this->path . DS . 'default.pot')); + $original = file_get_contents($this->path . DS . 'default.pot'); + + $this->Task->execute(); + $result = file_get_contents($this->path . DS . 'default.pot'); + $this->assertNotEquals($original, $result); + } }