Skip to content

Commit

Permalink
Fix generate:migration command for extensions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
franzliedke committed May 8, 2020
1 parent 4884aad commit 443949f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
23 changes: 13 additions & 10 deletions src/Database/MigrationCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Flarum\Database;

use Flarum\Extension\Extension;
use Flarum\Foundation\Paths;
use Illuminate\Filesystem\Filesystem;

class MigrationCreator
Expand All @@ -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
Expand Down Expand Up @@ -105,9 +106,11 @@ protected function populateStub($stub, $table)
*/
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';
}
}

/**
Expand Down
7 changes: 0 additions & 7 deletions src/Database/MigrationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,5 @@ public function register()
$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
);
});
}
}

0 comments on commit 443949f

Please sign in to comment.