diff --git a/src/Shell/Task/ExtractTask.php b/src/Shell/Task/ExtractTask.php index a2dc168ad0a..39f6dbdf3b0 100644 --- a/src/Shell/Task/ExtractTask.php +++ b/src/Shell/Task/ExtractTask.php @@ -462,6 +462,11 @@ protected function _buildFiles() { $paths = $this->_paths; $paths[] = realpath(APP) . DS; + + usort($paths, function ($a, $b) { + return strlen($a) - strlen($b); + }); + foreach ($this->_translations as $domain => $translations) { foreach ($translations as $msgid => $contexts) { foreach ($contexts as $context => $details) { @@ -694,18 +699,16 @@ protected function _searchFiles() $pattern = '/' . implode('|', $exclude) . '/'; } foreach ($this->_paths as $path) { + $path = realpath($path) . DS; $Folder = new Folder($path); $files = $Folder->findRecursive('.*\.(php|ctp|thtml|inc|tpl)', true); if (!empty($pattern)) { - foreach ($files as $i => $file) { - if (preg_match($pattern, $file)) { - unset($files[$i]); - } - } + $files = preg_grep($pattern, $files, PREG_GREP_INVERT); $files = array_values($files); } $this->_files = array_merge($this->_files, $files); } + $this->_files = array_unique($this->_files); } /** diff --git a/tests/TestCase/Shell/Task/ExtractTaskTest.php b/tests/TestCase/Shell/Task/ExtractTaskTest.php index a7f78243a6b..c6ea865f89e 100644 --- a/tests/TestCase/Shell/Task/ExtractTaskTest.php +++ b/tests/TestCase/Shell/Task/ExtractTaskTest.php @@ -89,18 +89,18 @@ public function testExecute() $this->assertFalse(file_exists($this->path . DS . 'cake.pot')); // extract.ctp - $pattern = '/\#: (\\\\|\/)extract\.ctp:\d+;\d+\n'; + $pattern = '/\#: Template[\/\\\\]Pages[\/\\\\]extract\.ctp:\d+;\d+\n'; $pattern .= 'msgid "You have %d new message."\nmsgid_plural "You have %d new messages."/'; $this->assertRegExp($pattern, $result); $pattern = '/msgid "You have %d new message."\nmsgstr ""/'; $this->assertNotRegExp($pattern, $result, 'No duplicate msgid'); - $pattern = '/\#: (\\\\|\/)extract\.ctp:\d+\n'; + $pattern = '/\#: Template[\/\\\\]Pages[\/\\\\]extract\.ctp:\d+\n'; $pattern .= 'msgid "You deleted %d message."\nmsgid_plural "You deleted %d messages."/'; $this->assertRegExp($pattern, $result); - $pattern = '/\#: (\\\\|\/)extract\.ctp:\d+\nmsgid "'; + $pattern = '/\#: Template[\/\\\\]Pages[\/\\\\]extract\.ctp:\d+\nmsgid "'; $pattern .= 'Hot features!'; $pattern .= '\\\n - No Configuration: Set-up the database and let the magic begin'; $pattern .= '\\\n - Extremely Simple: Just look at the name...It\'s Cake'; @@ -111,12 +111,12 @@ public function testExecute() $this->assertContains('msgid "double \\"quoted\\""', $result, 'Strings with quotes not handled correctly'); $this->assertContains("msgid \"single 'quoted'\"", $result, 'Strings with quotes not handled correctly'); - $pattern = '/\#: (\\\\|\/)extract\.ctp:\d+\n'; + $pattern = '/\#: Template[\/\\\\]Pages[\/\\\\]extract\.ctp:\d+\n'; $pattern .= 'msgctxt "mail"\n'; $pattern .= 'msgid "letter"/'; $this->assertRegExp($pattern, $result); - $pattern = '/\#: (\\\\|\/)extract\.ctp:\d+\n'; + $pattern = '/\#: Template[\/\\\\]Pages[\/\\\\]extract\.ctp:\d+\n'; $pattern .= 'msgctxt "alphabet"\n'; $pattern .= 'msgid "letter"/'; $this->assertRegExp($pattern, $result);