public function testGetTimestampFromFilename() { $test_data = array('2009_01_01_09_31_23.php' => '2009-01-01T09:31:23', '2008_02_27_10_42_59.php' => '2008-02-27T10:42:59', '1973_12_31_16_01_00' => '1973-12-31T16:01:00', '2054_13_01_00_00_00.php' => null, '1922_06_31_10_23_19.php' => null, '2001_02_30_18_23_45.php' => null, '2323_23_23_23_23.php' => null, '3434_34_34_34_43.p' => null); foreach ($test_data as $in => $out) { $this->assertEqual($out, MpmStringHelper::getTimestampFromFilename($in)); } }
/** * Returns an array of objects which hold data about a migration file (timestamp, file, etc.). * * @uses MPM_DB_PATH * @uses MpmStringHelper::getTimestampFromFilename() * * @param string $sort should either be old or new; determines how the migrations are sorted in the array * * @return array */ public static function getListOfFiles($sort = 'old') { $list = array(); if ($sort == 'new') { $sort_order = 1; } else { $sort_order = 0; } $files = scandir(MPM_DB_PATH, $sort_order); foreach ($files as $file) { $full_file = MPM_DB_PATH . $file; if ($file != 'schema.php' && $file != '.' && $file != '..' && !is_dir($full_file) && stripos($full_file, '.php') !== false) { $timestamp = MpmStringHelper::getTimestampFromFilename($file); if ($timestamp !== null) { $obj = (object) array(); $obj->timestamp = $timestamp; $obj->filename = $file; $obj->full_file = $full_file; $list[] = $obj; } } } return $list; }
/** * Returns an array of objects which hold data about a migration file (timestamp, file, etc.). * * @uses MPM_DB_PATH * @uses MpmStringHelper::getTimestampFromFilename() * * @param string $sort should either be old or new; determines how the migrations are sorted in the array * * @return array */ public static function getListOfFiles($sort = 'old') { $list = array(); $exclude_list = array("templates\\/", "schema\\.php\$", "test_data\\.php\$"); $exclude_list_pattern = implode("|", $exclude_list); // SKIP_DOTS (. / ..) suppose to be included by default, but apparently not; $dir_iter = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(MPM_DB_PATH, FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::SKIP_DOTS)); foreach ($dir_iter as $file) { $file_name = $file->getFilename(); // abc.js $file_local_path = $file->getPathName(); // /home/www/dev/jscommon/test/abc.js if (preg_match('/\\.php$/i', $file_name) && !preg_match('/' . $exclude_list_pattern . '/i', $file_name)) { $timestamp = MpmStringHelper::getTimestampFromFilename($file_name); if ($timestamp !== null) { $obj = (object) array(); $obj->timestamp = $timestamp; $obj->filename = $file_name; $obj->full_file = $file_local_path; $list[strtotime($timestamp)] = $obj; } } } // foreach // sort by timestamp if ($sort == 'new') { krsort($list, SORT_NUMERIC); } else { // 'old' ksort($list, SORT_NUMERIC); } return $list; }