This repository has been archived on 2024-06-26. You can view files and clone it, but cannot push or open issues or pull requests.
sakura/app/Console/Command/DatabaseResetCommand.php

50 lines
1.1 KiB
PHP
Raw Normal View History

2016-07-30 13:48:09 +00:00
<?php
/**
* Holds the migration reset command controller.
* @package Sakura
*/
namespace Sakura\Console\Command;
use CLIFramework\Command;
use Illuminate\Database\Migrations\Migrator;
use Illuminate\Filesystem\Filesystem;
use Sakura\DB;
2016-08-05 02:35:37 +00:00
/**
* Resets the entire database.
* @package Sakura
* @author Julian van de Groep <me@flash.moe>
*/
2016-07-30 13:48:09 +00:00
class DatabaseResetCommand extends Command
{
2016-08-05 02:35:37 +00:00
/**
* A quick description of this command.
* @return string.
*/
2016-07-30 13:48:09 +00:00
public function brief()
{
return 'Rollback all database migrations';
}
2016-08-05 02:35:37 +00:00
/**
* Does the resetting.
*/
2016-07-30 13:48:09 +00:00
public function execute()
{
$repository = DB::getMigrationRepository();
$migrator = new Migrator($repository, $repository->getConnectionResolver(), new Filesystem);
if (!$migrator->repositoryExists()) {
$this->getLogger()->writeln("The migration repository doesn't exist!");
return;
}
$migrator->reset();
foreach ($migrator->getNotes() as $note) {
$this->getLogger()->writeln(strip_tags($note));
}
}
}