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.
This commit is contained in:
Franz Liedke 2020-05-08 12:00:31 +02:00
parent 9bcfc4fafd
commit 814013ba48
2 changed files with 13 additions and 17 deletions

View File

@ -9,7 +9,7 @@
namespace Flarum\Database; namespace Flarum\Database;
use Flarum\Extension\Extension; use Flarum\Foundation\Paths;
use Illuminate\Filesystem\Filesystem; use Illuminate\Filesystem\Filesystem;
class MigrationCreator class MigrationCreator
@ -22,27 +22,28 @@ class MigrationCreator
protected $files; protected $files;
/** /**
* @var string * @var Paths
*/ */
protected $publicPath; protected $paths;
/** /**
* Create a new migrator instance. * Create a new migrator instance.
* *
* @param Filesystem $files * @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->files = $files;
$this->publicPath = $publicPath; $this->paths = $paths;
#
} }
/** /**
* Create a new migration for the given extension. * Create a new migration for the given extension.
* *
* @param string $name * @param string $name
* @param Extension $extension * @param string $extension
* @param string $table * @param string $table
* @param bool $create * @param bool $create
* @return string * @return string
@ -105,9 +106,11 @@ class MigrationCreator
*/ */
protected function getMigrationPath($extension) protected function getMigrationPath($extension)
{ {
$parent = $extension ? public_path('extensions/'.$extension) : __DIR__.'/../..'; if ($extension) {
return $this->paths->vendor.'/'.$extension.'/migrations';
return $parent.'/migrations'; } else {
return __DIR__.'/../../migrations';
}
} }
/** /**

View File

@ -23,12 +23,5 @@ class MigrationServiceProvider extends AbstractServiceProvider
$this->app->singleton(MigrationRepositoryInterface::class, function ($app) { $this->app->singleton(MigrationRepositoryInterface::class, function ($app) {
return new DatabaseMigrationRepository($app['flarum.db'], 'migrations'); 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
);
});
} }
} }