Файл: app/Http/Controllers/UpdateController.php
Строк: 107
<?php
namespace AppHttpControllers;
use AppModelsMigration;
use IlluminateSupportFacadesArtisan;
class UpdateController extends Controller
{
/**
* Show the Welcome page.
*
* @return IlluminateContractsFoundationApplication|IlluminateContractsViewFactory|IlluminateViewView
*/
public function index()
{
return view('update.container', ['view' => 'update.welcome']);
}
/**
* Show the Overview page.
*
* @return IlluminateContractsFoundationApplication|IlluminateContractsViewFactory|IlluminateViewView
*/
public function overview()
{
$migrations = $this->getMigrations();
$executedMigrations = $this->getExecutedMigrations();
return view('update.container', ['view' => 'update.overview', 'updates' => count($migrations) - count($executedMigrations)]);
}
/**
* Show the Complete page.
*
* @return IlluminateContractsFoundationApplication|IlluminateContractsViewFactory|IlluminateViewView
*/
public function complete()
{
return view('update.container', ['view' => 'update.complete']);
}
/**
* Update the database with the new migrations.
*
* @return IlluminateHttpRedirectResponse
*/
public function updateDatabase()
{
$migrateDatabase = $this->migrateDatabase();
if ($migrateDatabase !== true) {
return back()->with('error', __('Failed to migrate the database. ' . $migrateDatabase));
}
return redirect()->route('update.complete');
}
/**
* Migrate the database.
*
* @return bool|string
*/
private function migrateDatabase()
{
try {
Artisan::call('migrate', ['--force' => true]);
Artisan::call('view:clear');
Artisan::call('cache:clear');
Artisan::call('config:clear');
return true;
} catch (Exception $e) {
return $e->getMessage();
}
}
/**
* Get the available migrations.
*
* @return array
*/
private function getMigrations()
{
$migrations = scandir(database_path().'/migrations');
$output = [];
foreach($migrations as $migration) {
// Select only the .php files
if($migration != '.' && $migration != '..' && substr($migration, -4, 4) == '.php') {
$output[] = str_replace('.php', '', $migration);
}
}
return $output;
}
/**
* Get the executed migrations.
*
* @return IlluminateSupportCollection
*/
private function getExecutedMigrations()
{
return Migration::all()->pluck('migration');
}
}