Move the MigrationService to the main package

This commit is contained in:
Nabeel Shahzad 2019-04-07 18:53:24 -05:00
parent 905be6ffc3
commit 29a578ea6a
4 changed files with 24 additions and 11 deletions

View File

@ -1,6 +1,7 @@
<?php <?php
use App\Interfaces\Migration; use App\Interfaces\Migration;
use App\Services\Installer\MigrationService;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
class CreateSettingsTable extends Migration class CreateSettingsTable extends Migration
@ -9,7 +10,7 @@ class CreateSettingsTable extends Migration
public function __construct() public function __construct()
{ {
$this->migrationSvc = new \Modules\Installer\Services\MigrationService(); $this->migrationSvc = new MigrationService();
} }
/** /**
@ -37,7 +38,7 @@ class CreateSettingsTable extends Migration
$table->timestamps(); $table->timestamps();
}); });
$this->migrationSvc->updateAllSettings(); $this->migrationSvc->syncAllSettings();
} }
/** /**

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Modules\Installer\Services; namespace App\Services\Installer;
use App\Interfaces\Service; use App\Interfaces\Service;
use App\Models\Setting; use App\Models\Setting;
@ -26,14 +26,18 @@ class MigrationService extends Service
} }
/** /**
* Update all of the settings and sync them with the settings.yml file * Syncronize all of the seed files, run this after the
*/ */
public function updateAllSettings(): void public function syncAllSeeds(): void
{ {
$this->syncAllSettings();
}
public function syncAllSettings(): void {
$data = file_get_contents(database_path('/seeds/settings.yml')); $data = file_get_contents(database_path('/seeds/settings.yml'));
$yml = Yaml::parse($data); $yml = Yaml::parse($data);
foreach ($yml as $setting) { foreach ($yml as $setting) {
if ($setting['key'] === '') { if (\trim($setting['key']) === '') {
continue; continue;
} }

View File

@ -7,6 +7,7 @@ use App\Interfaces\Controller;
use App\Models\User; use App\Models\User;
use App\Repositories\AirlineRepository; use App\Repositories\AirlineRepository;
use App\Services\AnalyticsService; use App\Services\AnalyticsService;
use App\Services\Installer\MigrationService;
use App\Services\UserService; use App\Services\UserService;
use App\Support\Countries; use App\Support\Countries;
use Illuminate\Database\QueryException; use Illuminate\Database\QueryException;
@ -16,7 +17,6 @@ use Illuminate\Support\Facades\Validator;
use Log; use Log;
use Modules\Installer\Services\ConfigService; use Modules\Installer\Services\ConfigService;
use Modules\Installer\Services\DatabaseService; use Modules\Installer\Services\DatabaseService;
use Modules\Installer\Services\MigrationService;
use Modules\Installer\Services\RequirementsService; use Modules\Installer\Services\RequirementsService;
use Symfony\Component\HttpFoundation\File\Exception\FileException; use Symfony\Component\HttpFoundation\File\Exception\FileException;

View File

@ -3,9 +3,10 @@
namespace Modules\Installer\Http\Controllers; namespace Modules\Installer\Http\Controllers;
use App\Interfaces\Controller; use App\Interfaces\Controller;
use App\Services\Installer\MigrationService;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Log; use Log;
use Modules\Installer\Services\MigrationService;
/** /**
* Class UpdaterController * Class UpdaterController
@ -36,6 +37,10 @@ class UpdaterController extends Controller
/** /**
* Step 1. Check if there's an update available. Check if there * Step 1. Check if there's an update available. Check if there
* are any unrun migrations * are any unrun migrations
*
* @param Request $request
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/ */
public function step1(Request $request) public function step1(Request $request)
{ {
@ -49,22 +54,23 @@ class UpdaterController extends Controller
/** /**
* Step 2 Run all of the migrations * Step 2 Run all of the migrations
*
* @param Request $request * @param Request $request
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/ */
public function run_migrations(Request $request) public function run_migrations(Request $request)
{ {
Log::info('Update: run_migrations', $request->post()); Log::info('Update: run_migrations', $request->post());
// Resync all of the settings
$this->migrationSvc->updateAllSettings();
$migrations = $this->migrationSvc->migrationsAvailable(); $migrations = $this->migrationSvc->migrationsAvailable();
if(\count($migrations) === 0) { if(\count($migrations) === 0) {
$this->migrationSvc->syncAllSeeds();
return view('installer::update/steps/step3-update-complete'); return view('installer::update/steps/step3-update-complete');
} }
$output = $this->migrationSvc->runAllMigrations(); $output = $this->migrationSvc->runAllMigrations();
$this->migrationSvc->syncAllSeeds();
return view('installer::update/steps/step2-migrations-done', [ return view('installer::update/steps/step2-migrations-done', [
'console_output' => $output, 'console_output' => $output,
@ -73,7 +79,9 @@ class UpdaterController extends Controller
/** /**
* Final step * Final step
*
* @param Request $request * @param Request $request
*
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/ */
public function complete(Request $request) public function complete(Request $request)