Implement loading existing migration classes from the filesystem
[MAILPOET-4466]
This commit is contained in:
@ -2,6 +2,10 @@
|
||||
|
||||
namespace MailPoet\Migrator;
|
||||
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
use SplFileInfo;
|
||||
|
||||
class Repository {
|
||||
/** @var string */
|
||||
private $migrationsDir;
|
||||
@ -29,6 +33,21 @@ class Repository {
|
||||
}
|
||||
}
|
||||
|
||||
public function loadAll(): array {
|
||||
$files = new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator($this->migrationsDir, RecursiveDirectoryIterator::SKIP_DOTS)
|
||||
);
|
||||
|
||||
$migrations = [];
|
||||
foreach ($files as $file) {
|
||||
if ($file instanceof SplFileInfo && $file->isFile() && strtolower($file->getExtension()) === 'php') {
|
||||
$migrations[] = $file->getBasename('.' . $file->getExtension());
|
||||
}
|
||||
}
|
||||
sort($migrations);
|
||||
return $migrations;
|
||||
}
|
||||
|
||||
private function generateName(): string {
|
||||
return 'Migration_' . gmdate('Ymd_his');
|
||||
}
|
||||
|
Reference in New Issue
Block a user