Search all migration/ subdirectories for migration files. Now that's a piece of
authorJan Schneider <jan@horde.org>
Wed, 26 Jan 2011 16:40:27 +0000 (17:40 +0100)
committerJan Schneider <jan@horde.org>
Wed, 26 Jan 2011 16:40:27 +0000 (17:40 +0100)
PHP5 code!

framework/Db/lib/Horde/Db/Migration/Migrator.php

index ce25e99..fa918ce 100644 (file)
@@ -46,9 +46,13 @@ class Horde_Db_Migration_Migrator
     /**
      * Constructor.
      *
-     * @param   string  $direction
-     * @param   string  $migrationsPath
-     * @param   integer $targetVersion
+     * @param Horde_Db_Adapter $connection  A DB connection object.
+     * @param Horde_Log_Logger $logger      A logger object.
+     * @param array $options                Additional options for the migrator:
+     *                                      - migrationsPath: directory with the
+     *                                        migration files.
+     *                                      - schemaTableName: table for storing
+     *                                        the schema version.
      *
      * @throws Horde_Db_Migration_Exception
      */
@@ -200,8 +204,21 @@ class Horde_Db_Migration_Migrator
      */
     protected function _getMigrationFiles()
     {
-        $files = glob($this->_migrationsPath . '/[0-9]*_*.php');
-        return $this->_isDown() ? array_reverse($files) : $files;
+        return array_keys(
+            iterator_to_array(
+                new RegexIterator(
+                    new RecursiveIteratorIterator(
+                        new RecursiveDirectoryIterator(
+                            $this->_migrationsPath,
+                            FilesystemIterator::SKIP_DOTS
+                        )
+                    ),
+                    '/\/\d+_.*\.php$/',
+                    RecursiveRegexIterator::MATCH,
+                    RegexIterator::USE_KEY
+                )
+            )
+        );
     }
 
     /**