mirror of
https://github.com/flarum/core.git
synced 2025-10-12 23:44:27 +02:00
Restructure Flarum\Database namespace
This commit is contained in:
88
src/Database/Console/MigrateCommand.php
Normal file
88
src/Database/Console/MigrateCommand.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Database\Console;
|
||||
|
||||
use Flarum\Console\AbstractCommand;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
|
||||
class MigrateCommand extends AbstractCommand
|
||||
{
|
||||
/**
|
||||
* @var Container
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* @param Container $container
|
||||
*/
|
||||
public function __construct(Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('migrate')
|
||||
->setDescription('Run outstanding migrations');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function fire()
|
||||
{
|
||||
$this->info('Migrating Flarum...');
|
||||
|
||||
$this->upgrade();
|
||||
|
||||
$this->info('DONE.');
|
||||
}
|
||||
|
||||
public function upgrade()
|
||||
{
|
||||
$this->container->bind('Illuminate\Database\Schema\Builder', function ($container) {
|
||||
return $container->make('Illuminate\Database\ConnectionInterface')->getSchemaBuilder();
|
||||
});
|
||||
|
||||
$migrator = $this->container->make('Flarum\Database\Migrator');
|
||||
|
||||
$migrator->run(__DIR__.'/../../../migrations');
|
||||
|
||||
foreach ($migrator->getNotes() as $note) {
|
||||
$this->info($note);
|
||||
}
|
||||
|
||||
$extensions = $this->container->make('Flarum\Extension\ExtensionManager');
|
||||
|
||||
foreach ($extensions->getExtensions() as $name => $extension) {
|
||||
if (! $extension->isEnabled()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->info('Migrating extension: '.$name);
|
||||
|
||||
$notes = $extensions->migrate($extension);
|
||||
|
||||
foreach ($notes as $note) {
|
||||
$this->info($note);
|
||||
}
|
||||
}
|
||||
|
||||
$this->container->make('Flarum\Settings\SettingsRepositoryInterface')->set('version', $this->container->version());
|
||||
}
|
||||
}
|
@@ -12,7 +12,6 @@
|
||||
namespace Flarum\Database;
|
||||
|
||||
use Flarum\Foundation\AbstractServiceProvider;
|
||||
use Flarum\Foundation\Application;
|
||||
use Illuminate\Database\ConnectionResolver;
|
||||
use Illuminate\Database\Connectors\ConnectionFactory;
|
||||
use PDO;
|
||||
@@ -46,14 +45,6 @@ class DatabaseServiceProvider extends AbstractServiceProvider
|
||||
});
|
||||
|
||||
$this->app->alias('Illuminate\Database\ConnectionResolverInterface', 'db');
|
||||
|
||||
$this->app->singleton('Flarum\Database\MigrationRepositoryInterface', function ($app) {
|
||||
return new DatabaseMigrationRepository($app['db'], 'migrations');
|
||||
});
|
||||
|
||||
$this->app->bind(MigrationCreator::class, function (Application $app) {
|
||||
return new MigrationCreator($app->make('Illuminate\Filesystem\Filesystem'), $app->basePath());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
32
src/Database/MigrationServiceProvider.php
Normal file
32
src/Database/MigrationServiceProvider.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Database;
|
||||
|
||||
use Flarum\Foundation\AbstractServiceProvider;
|
||||
use Flarum\Foundation\Application;
|
||||
|
||||
class MigrationServiceProvider extends AbstractServiceProvider
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->singleton('Flarum\Database\MigrationRepositoryInterface', function ($app) {
|
||||
return new DatabaseMigrationRepository($app['db'], 'migrations');
|
||||
});
|
||||
|
||||
$this->app->bind(MigrationCreator::class, function (Application $app) {
|
||||
return new MigrationCreator($app->make('Illuminate\Filesystem\Filesystem'), $app->basePath());
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user