From 814013ba48b3a35238e045f75792e1b9ce79d758 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Fri, 8 May 2020 12:00:31 +0200 Subject: [PATCH] Fix generate:migration command for extensions Apparently, this code was from back when we had a special "extensions" directory for Composer packages marked as Flarum extensions. While we're at it, we now inject the Paths instance instead of using one of the global helpers (which I am trying to get rid of). Refs #2055. --- .../core/src/Database/MigrationCreator.php | 23 +++++++++++-------- .../src/Database/MigrationServiceProvider.php | 7 ------ 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/framework/core/src/Database/MigrationCreator.php b/framework/core/src/Database/MigrationCreator.php index 7db2ce326..a7e140ac0 100644 --- a/framework/core/src/Database/MigrationCreator.php +++ b/framework/core/src/Database/MigrationCreator.php @@ -9,7 +9,7 @@ namespace Flarum\Database; -use Flarum\Extension\Extension; +use Flarum\Foundation\Paths; use Illuminate\Filesystem\Filesystem; class MigrationCreator @@ -22,27 +22,28 @@ class MigrationCreator protected $files; /** - * @var string + * @var Paths */ - protected $publicPath; + protected $paths; /** * Create a new migrator instance. * * @param Filesystem $files - * @param string $publicPath + * @param Paths $paths */ - public function __construct(Filesystem $files, $publicPath) + public function __construct(Filesystem $files, Paths $paths) { $this->files = $files; - $this->publicPath = $publicPath; + $this->paths = $paths; + # } /** * Create a new migration for the given extension. * * @param string $name - * @param Extension $extension + * @param string $extension * @param string $table * @param bool $create * @return string @@ -105,9 +106,11 @@ class MigrationCreator */ protected function getMigrationPath($extension) { - $parent = $extension ? public_path('extensions/'.$extension) : __DIR__.'/../..'; - - return $parent.'/migrations'; + if ($extension) { + return $this->paths->vendor.'/'.$extension.'/migrations'; + } else { + return __DIR__.'/../../migrations'; + } } /** diff --git a/framework/core/src/Database/MigrationServiceProvider.php b/framework/core/src/Database/MigrationServiceProvider.php index 131522975..135cf0c45 100644 --- a/framework/core/src/Database/MigrationServiceProvider.php +++ b/framework/core/src/Database/MigrationServiceProvider.php @@ -23,12 +23,5 @@ class MigrationServiceProvider extends AbstractServiceProvider $this->app->singleton(MigrationRepositoryInterface::class, function ($app) { return new DatabaseMigrationRepository($app['flarum.db'], 'migrations'); }); - - $this->app->bind(MigrationCreator::class, function () { - return new MigrationCreator( - $this->app->make(Filesystem::class), - $this->app->make(Paths::class)->base - ); - }); } }