Browse Source

Merge pull request #8176 from cakephp/issue-8172-3x

Port changes in #8172 to 3.x
Mark Story 10 years ago
parent
commit
9711ea62b8
2 changed files with 13 additions and 10 deletions
  1. 8 5
      src/Shell/Task/ExtractTask.php
  2. 5 5
      tests/TestCase/Shell/Task/ExtractTaskTest.php

+ 8 - 5
src/Shell/Task/ExtractTask.php

@@ -462,6 +462,11 @@ class ExtractTask extends Shell
     {
         $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 @@ class ExtractTask extends Shell
             $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);
     }
 
     /**

+ 5 - 5
tests/TestCase/Shell/Task/ExtractTaskTest.php

@@ -89,18 +89,18 @@ class ExtractTaskTest extends TestCase
         $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 @@ class ExtractTaskTest extends TestCase
         $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);