diff --git a/app/Console/Commands/DevInstall.php b/app/Console/Commands/DevInstall.php index 652aef19b..8129d1af6 100644 --- a/app/Console/Commands/DevInstall.php +++ b/app/Console/Commands/DevInstall.php @@ -21,6 +21,14 @@ class DevInstall extends Command 'acars.yml', ]; + private $databaseSeeder; + + public function __construct(\DatabaseSeeder $databaseSeeder) + { + parent::__construct(); + $this->databaseSeeder = $databaseSeeder; + } + /** * Run dev related commands * @@ -45,16 +53,6 @@ public function handle() '--seed' => true, ]); - // - // - - $this->info('Importing sample data'); - foreach ($this->yaml_imports as $yml) { - $this->call('phpvms:yaml-import', [ - 'files' => ['app/Database/seeds/'.$yml], - ]); - } - $this->info('Done!'); } diff --git a/app/Database/migrations/2017_06_07_014930_create_settings_table.php b/app/Database/migrations/2017_06_07_014930_create_settings_table.php index 19cc394da..fed81ffa9 100644 --- a/app/Database/migrations/2017_06_07_014930_create_settings_table.php +++ b/app/Database/migrations/2017_06_07_014930_create_settings_table.php @@ -1,16 +1,16 @@ migrationSvc = new MigrationService(); + $this->seederSvc = app(SeederService::class); } /** @@ -38,7 +38,7 @@ public function up() $table->timestamps(); }); - $this->migrationSvc->syncAllSettings(); + $this->seederSvc->syncAllSettings(); } /** diff --git a/app/Database/migrations/2017_06_21_165410_create_ranks_table.php b/app/Database/migrations/2017_06_21_165410_create_ranks_table.php index 390192f9c..ff668e9e1 100644 --- a/app/Database/migrations/2017_06_21_165410_create_ranks_table.php +++ b/app/Database/migrations/2017_06_21_165410_create_ranks_table.php @@ -28,21 +28,6 @@ public function up() $table->unique('name'); }); - - /** - * Initial required data... - */ - $ranks = [ - [ - 'id' => 1, - 'name' => 'New Pilot', - 'hours' => 0, - 'acars_base_pay_rate' => 50, - 'manual_base_pay_rate' => 25, - ], - ]; - - $this->addData('ranks', $ranks); } /** diff --git a/app/Database/seeds/DatabaseSeeder.php b/app/Database/seeds/DatabaseSeeder.php index 06c1f459a..1911b1acb 100755 --- a/app/Database/seeds/DatabaseSeeder.php +++ b/app/Database/seeds/DatabaseSeeder.php @@ -1,19 +1,16 @@ 'dev', - 'qa' => 'dev', - 'staging' => 'dev', - ]; + private $seederService; - private static $always_seed = [ - 'permissions', - ]; + public function __construct() + { + $this->seederService = app(SeederService::class); + } /** * Run the database seeds. @@ -22,28 +19,6 @@ class DatabaseSeeder extends Seeder */ public function run() { - $env = App::environment(); - if (array_key_exists($env, self::$seed_mapper)) { - $env = self::$seed_mapper[$env]; - } - - Log::info('Seeding from environment '.$env); - $path = database_path('seeds/'.$env.'.yml'); - - if (!file_exists($path)) { - $path = database_path('seeds/prod.yml'); - } - - $svc = app(DatabaseService::class); - $svc->seed_from_yaml_file($path); - - // Always seed/sync these - foreach (self::$always_seed as $file) { - Log::info('Importing '.$file); - $path = database_path('seeds/'.$file.'.yml'); - if (file_exists($path)) { - $svc->seed_from_yaml_file($path); - } - } + $this->seederService->syncAllSeeds(); } } diff --git a/app/Database/seeds/acars.yml b/app/Database/seeds/acars.yml deleted file mode 100644 index 16c0ce532..000000000 --- a/app/Database/seeds/acars.yml +++ /dev/null @@ -1,55 +0,0 @@ -acars: - - id: acars_1 - pirep_id: pirepid_1 - type: 1 - nav_type: 2 - name: TNV - lat: 30.28852 - lon: -96.058239 - created_at: now - updated_at: now - - id: acars_2 - pirep_id: pirepid_1 - type: 1 - nav_type: 2 - name: IAH - lat: 29.95691 - lon: -95.345719 - created_at: now - updated_at: now - - id: acars_3 - pirep_id: pirepid_1 - type: 1 - nav_type: 2 - name: LCH - lat: 30.14151 - lon: -93.105569 - created_at: now - updated_at: now - - id: acars_4 - pirep_id: pirepid_1 - type: 1 - nav_type: 2 - name: MEI - lat: 32.37843 - lon: -88.804267 - created_at: now - updated_at: now - - id: acars_5 - pirep_id: pirepid_1 - type: 1 - nav_type: 2 - name: ATL - lat: 33.62907 - lon: -84.435064 - created_at: now - updated_at: now - - id: acars_6 - pirep_id: pirepid_1 - type: 1 - nav_type: 2 - name: SIE - lat: 39.0955 - lon: -74.800344 - created_at: now - updated_at: now diff --git a/app/Database/seeds/dev/acars.yml b/app/Database/seeds/dev/acars.yml new file mode 100644 index 000000000..0a6dec506 --- /dev/null +++ b/app/Database/seeds/dev/acars.yml @@ -0,0 +1,57 @@ +acars: + id_column: id + data: + - id: acars_1 + pirep_id: pirepid_1 + type: 1 + nav_type: 2 + name: TNV + lat: 30.28852 + lon: -96.058239 + created_at: now + updated_at: now + - id: acars_2 + pirep_id: pirepid_1 + type: 1 + nav_type: 2 + name: IAH + lat: 29.95691 + lon: -95.345719 + created_at: now + updated_at: now + - id: acars_3 + pirep_id: pirepid_1 + type: 1 + nav_type: 2 + name: LCH + lat: 30.14151 + lon: -93.105569 + created_at: now + updated_at: now + - id: acars_4 + pirep_id: pirepid_1 + type: 1 + nav_type: 2 + name: MEI + lat: 32.37843 + lon: -88.804267 + created_at: now + updated_at: now + - id: acars_5 + pirep_id: pirepid_1 + type: 1 + nav_type: 2 + name: ATL + lat: 33.62907 + lon: -84.435064 + created_at: now + updated_at: now + - id: acars_6 + pirep_id: pirepid_1 + type: 1 + nav_type: 2 + name: SIE + lat: 39.0955 + lon: -74.800344 + created_at: now + updated_at: now diff --git a/app/Database/seeds/dev.yml b/app/Database/seeds/dev/dev.yml similarity index 100% rename from app/Database/seeds/dev.yml rename to app/Database/seeds/dev/dev.yml diff --git a/app/Database/seeds/in_progress.yml b/app/Database/seeds/dev/in_progress.yml similarity index 100% rename from app/Database/seeds/in_progress.yml rename to app/Database/seeds/dev/in_progress.yml diff --git a/app/Database/seeds/dev/ranks.yml b/app/Database/seeds/dev/ranks.yml new file mode 100644 index 000000000..f65b29958 --- /dev/null +++ b/app/Database/seeds/dev/ranks.yml @@ -0,0 +1,26 @@ +ranks: + - id: 1 + name: New Pilot + hours: 0 + acars_base_pay_rate: 50 + manual_base_pay_rate: 25 + - id: 2 + name: Junior First Officer + hours: 10 + acars_base_pay_rate: 100 + manual_base_pay_rate: 90 + - id: 3 + name: First Officer + hours: 15 + acars_base_pay_rate: 250 + manual_base_pay_rate: 200 + auto_approve_acars: 1 + auto_approve_manual: 1 + - id: 4 + name: Senior Captain + hours: 20 + acars_base_pay_rate: 500 + manual_base_pay_rate: 400 + auto_approve_acars: 1 + auto_approve_manual: 1 + auto_promote: 0 diff --git a/app/Database/seeds/sample.yml b/app/Database/seeds/dev/sample.yml similarity index 96% rename from app/Database/seeds/sample.yml rename to app/Database/seeds/dev/sample.yml index e3dfd4124..93aa06464 100644 --- a/app/Database/seeds/sample.yml +++ b/app/Database/seeds/dev/sample.yml @@ -1,17 +1,19 @@ -airlines: - - id: 1 - icao: VMS - iata: VM - name: phpvms airlines - country: us - active: 1 - created_at: now - updated_at: now +#airlines: +# - id: 1 +# icao: VMS +# iata: VM +# name: phpvms airlines +# country: us +# active: 1 +# created_at: now +# updated_at: now roles: - - name: fleet-only - display_name: Edit Fleet + id_column: name + data: + - name: fleet-only + display_name: Edit Fleet users: - id: 1 @@ -83,29 +85,6 @@ role_user: role_id: 2 user_type: App\Models\User -# ranks -ranks: - - id: 2 - name: Junior First Officer - hours: 10 - acars_base_pay_rate: 100 - manual_base_pay_rate: 90 - - id: 3 - name: First Officer - hours: 15 - acars_base_pay_rate: 250 - manual_base_pay_rate: 200 - auto_approve_acars: 1 - auto_approve_manual: 1 - - id: 4 - name: Senior Captain - hours: 20 - acars_base_pay_rate: 500 - manual_base_pay_rate: 400 - auto_approve_acars: 1 - auto_approve_manual: 1 - auto_promote: 0 - awards: - id: 1 name: Pilot 50 flights diff --git a/app/Database/seeds/permissions.yml b/app/Database/seeds/permissions.yml index 06f1f7249..f6304354e 100644 --- a/app/Database/seeds/permissions.yml +++ b/app/Database/seeds/permissions.yml @@ -1,42 +1,41 @@ # All of the different permissions that can be assigned to roles --- -permissions: - - name: admin-access - display_name: Admin Access - description: Access the admin panel - - name: airlines - display_name: Airlines - description: Create/edit airlines - - name: airports - display_name: Airports - description: Create/edit airports - - name: addons - display_name: Addons - description: Edit/view addons - - name: awards - display_name: Awards - description: Create/edit award classes - - name: flights - display_name: Flights - description: Create/edit flights - - name: fleet - display_name: Fleet - description: Create/edit subfleets and fleets - - name: fares - display_name: Fares - description: Create/edit fares - - name: finances - display_name: Finances - description: Create/view finance related items - - name: pireps - display_name: PIREPs - description: Accept/reject/edit PIREPs - - name: ranks - display_name: Ranks - description: Create/edit ranks - - name: users - display_name: Users - description: Create/edit users - - name: settings - display_name: Settings - description: Edit VA settings +- name: admin-access + display_name: Admin Access + description: Access the admin panel +- name: airlines + display_name: Airlines + description: Create/edit airlines +- name: airports + display_name: Airports + description: Create/edit airports +- name: addons + display_name: Addons + description: Edit/view addons +- name: awards + display_name: Awards + description: Create/edit award classes +- name: flights + display_name: Flights + description: Create/edit flights +- name: fleet + display_name: Fleet + description: Create/edit subfleets and fleets +- name: fares + display_name: Fares + description: Create/edit fares +- name: finances + display_name: Finances + description: Create/view finance related items +- name: pireps + display_name: PIREPs + description: Accept/reject/edit PIREPs +- name: ranks + display_name: Ranks + description: Create/edit ranks +- name: users + display_name: Users + description: Create/edit users +- name: settings + display_name: Settings + description: Edit VA settings diff --git a/app/Database/seeds/prod.yml b/app/Database/seeds/prod/prod.yml similarity index 100% rename from app/Database/seeds/prod.yml rename to app/Database/seeds/prod/prod.yml diff --git a/app/Database/seeds/prod/ranks.yml b/app/Database/seeds/prod/ranks.yml new file mode 100644 index 000000000..be3e9151c --- /dev/null +++ b/app/Database/seeds/prod/ranks.yml @@ -0,0 +1,6 @@ +ranks: + - id: 1 + name: New Pilot + hours: 0 + acars_base_pay_rate: 50 + manual_base_pay_rate: 25 diff --git a/app/Models/Airport.php b/app/Models/Airport.php index 000dc494b..f0c549c6c 100644 --- a/app/Models/Airport.php +++ b/app/Models/Airport.php @@ -13,6 +13,7 @@ * @property string iata * @property string icao * @property string name + * @property string full_name * @property string location * @property string country * @property string timezone diff --git a/app/Models/Flight.php b/app/Models/Flight.php index a67e251e0..7e5b92987 100644 --- a/app/Models/Flight.php +++ b/app/Models/Flight.php @@ -13,7 +13,7 @@ * @property string id * @property mixed ident * @property Airline airline - * @property int airline_id + * @property int airline_id * @property mixed flight_number * @property mixed route_code * @property int route_leg @@ -21,8 +21,9 @@ * @property Collection field_values * @property Collection fares * @property Collection subfleets - * @property int days - * @property Airport dep_airport + * @property int days + * @property string route + * @property Airport dpt_airport * @property Airport arr_airport * @property Airport alt_airport * @property string dpt_airport_id diff --git a/app/Services/GeoService.php b/app/Services/GeoService.php index 50ad1099d..ce555fbc8 100644 --- a/app/Services/GeoService.php +++ b/app/Services/GeoService.php @@ -12,9 +12,9 @@ use App\Repositories\NavdataRepository; use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Support\Collection; +use Illuminate\Support\Facades\Log; use League\Geotools\Coordinate\Coordinate; use League\Geotools\Geotools; -use Log; /** * Class GeoService @@ -109,6 +109,7 @@ public function getCoordsFromRoute($dep_icao, $arr_icao, $start_coords, $route): continue; } + $point = null; $size = \count($points); if ($size === 0) { @@ -150,6 +151,10 @@ public function getCoordsFromRoute($dep_icao, $arr_icao, $start_coords, $route): } } + if ($point === null) { + continue; + } + $coords[] = $point; } diff --git a/app/Services/Installer/MigrationService.php b/app/Services/Installer/MigrationService.php index d48adfe8c..76ab28596 100644 --- a/app/Services/Installer/MigrationService.php +++ b/app/Services/Installer/MigrationService.php @@ -3,17 +3,13 @@ namespace App\Services\Installer; use App\Contracts\Service; -use App\Models\Setting; -use DB; -use Log; +use Illuminate\Support\Facades\App; +use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Log; use Nwidart\Modules\Facades\Module; -use Symfony\Component\Yaml\Yaml; class MigrationService extends Service { - private $counters = []; - private $offsets = []; - protected function getMigrator() { $m = app('migrator'); @@ -21,144 +17,6 @@ protected function getMigrator() return $m; } - /** - * Syncronize all of the seed files, run this after the migrations - * and on first install. - */ - public function syncAllSeeds(): void - { - $this->syncAllSettings(); - $this->syncAllPermissions(); - } - - public function syncAllSettings(): void - { - $data = file_get_contents(database_path('/seeds/settings.yml')); - $yml = Yaml::parse($data); - foreach ($yml as $setting) { - if (\trim($setting['key']) === '') { - continue; - } - - $this->addSetting($setting['key'], $setting); - } - } - - public function syncAllPermissions(): void - { - $data = file_get_contents(database_path('/seeds/permissions.yml')); - $yml = Yaml::parse($data); - foreach ($yml as $perm) { - $count = DB::table('permissions')->where('name', $perm['name'])->count('name'); - if ($count === 0) { - DB::table('permissions')->insert($perm); - } else { - DB::table('settings') - ->where('name', $perm['name']) - ->update($perm); - } - } - } - - /** - * @param $key - * @param $attrs - */ - public function addSetting($key, $attrs): void - { - $id = Setting::formatKey($key); - $group = $attrs['group']; - $order = $this->getNextOrderNumber($group); - - $attrs = array_merge( - [ - 'id' => $id, - 'key' => $key, - 'offset' => $this->offsets[$group], - 'order' => $order, - 'name' => '', - 'group' => $group, - 'value' => '', - 'default' => $attrs['value'], - 'options' => '', - 'type' => 'hidden', - 'description' => '', - ], - $attrs - ); - - $count = DB::table('settings')->where('id', $id)->count('id'); - if ($count === 0) { - DB::table('settings')->insert($attrs); - } else { - unset($attrs['value']); // Don't overwrite this - DB::table('settings') - ->where('id', $id) - ->update($attrs); - } - } - - /** - * Dynamically figure out the offset and the start number for a group. - * This way we don't need to mess with how to order things - * When calling getNextOrderNumber(users) 31, will be returned, then 32, and so on - * - * @param $name - * @param null $offset - * @param int $start_offset - */ - private function addCounterGroup($name, $offset = null, $start_offset = 0): void - { - if ($offset === null) { - $group = DB::table('settings') - ->where('group', $name) - ->first(); - - if ($group === null) { - $offset = (int) DB::table('settings')->max('offset'); - if ($offset === null) { - $offset = 0; - $start_offset = 1; - } else { - $offset += 100; - $start_offset = $offset + 1; - } - } else { - // Now find the number to start from - $start_offset = (int) DB::table('settings')->where('group', $name)->max('order'); - if ($start_offset === null) { - $start_offset = $offset + 1; - } else { - $start_offset++; - } - - $offset = $group->offset; - } - } - - $this->counters[$name] = $start_offset; - $this->offsets[$name] = $offset; - } - - /** - * Get the next increment number from a group - * - * @param $group - * - * @return int - */ - private function getNextOrderNumber($group): int - { - if (!\in_array($group, $this->counters, true)) { - $this->addCounterGroup($group); - } - - $idx = $this->counters[$group]; - $this->counters[$group]++; - - return $idx; - } - /** * Find all of the possible paths that migrations exist. * Include looking in all of the modules Database/migrations directories @@ -168,7 +26,7 @@ private function getNextOrderNumber($group): int public function getMigrationPaths(): array { $paths = [ - 'core' => \App::databasePath().'/migrations', + 'core' => App::databasePath().'/migrations', ]; $modules = Module::allEnabled(); @@ -208,8 +66,8 @@ public function runAllMigrations() { $output = ''; - \Artisan::call('migrate'); - $output .= trim(\Artisan::output()); + Artisan::call('migrate'); + $output .= trim(Artisan::output()); return $output; } diff --git a/app/Services/Installer/SeederService.php b/app/Services/Installer/SeederService.php new file mode 100644 index 000000000..82d5ebb30 --- /dev/null +++ b/app/Services/Installer/SeederService.php @@ -0,0 +1,197 @@ + 'dev', + 'qa' => 'dev', + 'staging' => 'dev', + ]; + + public function __construct(DatabaseService $databaseSvc) + { + $this->databaseSvc = $databaseSvc; + } + + /** + * Syncronize all of the seed files, run this after the migrations + * and on first install. + */ + public function syncAllSeeds(): void + { + $this->syncAllYamlFileSeeds(); + $this->syncAllSettings(); + $this->syncAllPermissions(); + } + + /** + * Read all of the YAML files from disk and seed them + */ + public function syncAllYamlFileSeeds(): void + { + Log::info('Running seeder'); + $env = App::environment(); + if (array_key_exists($env, self::$seed_mapper)) { + $env = self::$seed_mapper[$env]; + } + + // Gather all of the files to seed + collect() + ->concat(Storage::disk('seeds')->files($env)) + ->map(function ($file) { + return database_path('seeds/'.$file); + }) + ->filter(function ($file) { + $info = pathinfo($file); + return $info['extension'] === 'yml'; + }) + ->each(function ($file) { + Log::info('Seeding .'.$file); + $this->databaseSvc->seed_from_yaml_file($file); + }); + } + + public function syncAllSettings(): void + { + $data = file_get_contents(database_path('/seeds/settings.yml')); + $yml = Yaml::parse($data); + foreach ($yml as $setting) { + if (\trim($setting['key']) === '') { + continue; + } + + $this->addSetting($setting['key'], $setting); + } + } + + public function syncAllPermissions(): void + { + $data = file_get_contents(database_path('/seeds/permissions.yml')); + $yml = Yaml::parse($data); + foreach ($yml as $perm) { + $count = DB::table('permissions')->where('name', $perm['name'])->count('name'); + if ($count === 0) { + DB::table('permissions')->insert($perm); + } else { + DB::table('permissions') + ->where('name', $perm['name']) + ->update($perm); + } + } + } + + /** + * @param $key + * @param $attrs + */ + public function addSetting($key, $attrs): void + { + $id = Setting::formatKey($key); + $group = $attrs['group']; + $order = $this->getNextOrderNumber($group); + + $attrs = array_merge( + [ + 'id' => $id, + 'key' => $key, + 'offset' => $this->offsets[$group], + 'order' => $order, + 'name' => '', + 'group' => $group, + 'value' => '', + 'default' => $attrs['value'], + 'options' => '', + 'type' => 'hidden', + 'description' => '', + ], + $attrs + ); + + $count = DB::table('settings')->where('id', $id)->count('id'); + if ($count === 0) { + DB::table('settings')->insert($attrs); + } else { + unset($attrs['value']); // Don't overwrite this + DB::table('settings') + ->where('id', $id) + ->update($attrs); + } + } + + /** + * Dynamically figure out the offset and the start number for a group. + * This way we don't need to mess with how to order things + * When calling getNextOrderNumber(users) 31, will be returned, then 32, and so on + * + * @param $name + * @param null $offset + * @param int $start_offset + */ + private function addCounterGroup($name, $offset = null, $start_offset = 0): void + { + if ($offset === null) { + $group = DB::table('settings') + ->where('group', $name) + ->first(); + + if ($group === null) { + $offset = (int) DB::table('settings')->max('offset'); + if ($offset === null) { + $offset = 0; + $start_offset = 1; + } else { + $offset += 100; + $start_offset = $offset + 1; + } + } else { + // Now find the number to start from + $start_offset = (int) DB::table('settings')->where('group', $name)->max('order'); + if ($start_offset === null) { + $start_offset = $offset + 1; + } else { + $start_offset++; + } + + $offset = $group->offset; + } + } + + $this->counters[$name] = $start_offset; + $this->offsets[$name] = $offset; + } + + /** + * Get the next increment number from a group + * + * @param $group + * + * @return int + */ + private function getNextOrderNumber($group): int + { + if (!\in_array($group, $this->counters, true)) { + $this->addCounterGroup($group); + } + + $idx = $this->counters[$group]; + $this->counters[$group]++; + + return $idx; + } +} diff --git a/app/Services/PirepService.php b/app/Services/PirepService.php index ce3c7937d..87b30ff39 100644 --- a/app/Services/PirepService.php +++ b/app/Services/PirepService.php @@ -9,6 +9,7 @@ use App\Events\UserStateChanged; use App\Events\UserStatsChanged; use App\Models\Acars; +use App\Models\Aircraft; use App\Models\Bid; use App\Models\Enums\AcarsType; use App\Models\Enums\PirepSource; @@ -338,7 +339,7 @@ public function accept(Pirep $pirep): Pirep Log::info('PIREP '.$pirep->id.' state change to ACCEPTED'); // Update the aircraft - $pirep->aircraft->flight_time += $pirep->flight_time; + $pirep->aircraft->flight_time = $pirep->aircraft->flight_time + $pirep->flight_time; $pirep->aircraft->airport_id = $pirep->arr_airport_id; $pirep->aircraft->landing_time = $pirep->updated_at; $pirep->aircraft->save(); diff --git a/app/Support/Database.php b/app/Support/Database.php index 61684d0e5..8cb6c920e 100644 --- a/app/Support/Database.php +++ b/app/Support/Database.php @@ -5,7 +5,7 @@ use Carbon\Carbon; use Illuminate\Database\QueryException; use Illuminate\Support\Facades\DB; -use Log; +use Illuminate\Support\Facades\Log; use Symfony\Component\Yaml\Yaml; class Database @@ -48,12 +48,28 @@ public static function seed_from_yaml($yml, $ignore_errors = false): array return $imported; } - foreach ($yml as $table => $rows) { + foreach ($yml as $table => $data) { $imported[$table] = 0; + $id_column = 'id'; + if (array_key_exists('id_column', $data)) { + $id_column = $data['id_column']; + } + + $ignore_on_update = []; + if (array_key_exists('ignore_on_update', $data)) { + $ignore_on_update = $data['ignore_on_update']; + } + + if (array_key_exists('data', $data)) { + $rows = $data['data']; + } else { + $rows = $data; + } + foreach ($rows as $row) { try { - static::insert_row($table, $row); + static::insert_row($table, $row, $id_column, $ignore_on_update); } catch (QueryException $e) { if ($ignore_errors) { continue; @@ -70,15 +86,21 @@ public static function seed_from_yaml($yml, $ignore_errors = false): array } /** - * @param $table - * @param $row - * - * @throws \Exception + * @param string $table + * @param array $row + * @param string $id_col The ID column to use for update/insert + * @param array $ignore_on_updates + * @param bool $ignore_errors * * @return mixed */ - public static function insert_row($table, $row) - { + public static function insert_row( + $table, + $row, + $id_col = 'id', + $ignore_on_updates = [], + $ignore_errors = true + ) { // encrypt any password fields if (array_key_exists('password', $row)) { $row['password'] = bcrypt($row['password']); @@ -95,12 +117,30 @@ public static function insert_row($table, $row) } } + $count = 0; + if (array_key_exists($id_col, $row)) { + $count = DB::table($table)->where($id_col, $row[$id_col])->count($id_col); + } + try { - DB::table($table)->insert($row); + if ($count > 0) { + foreach ($ignore_on_updates as $ignore_column) { + if (array_key_exists($ignore_column, $row)) { + unset($row[$ignore_column]); + } + } + + DB::table($table) + ->where($id_col, $row[$id_col]) + ->update($row); + } else { + DB::table($table)->insert($row); + } } catch (QueryException $e) { Log::error($e); - - throw $e; + if (!$ignore_errors) { + throw $e; + } } return $row; diff --git a/config/filesystems.php b/config/filesystems.php index 46917c53c..5620f1ffe 100755 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -13,6 +13,11 @@ 'root' => storage_path('app'), ], + 'seeds' => [ + 'driver' => 'local', + 'root' => database_path('seeds'), + ], + 'public' => [ 'driver' => 'local', 'root' => public_path('uploads'), diff --git a/modules/Installer/Http/Controllers/UpdaterController.php b/modules/Installer/Http/Controllers/UpdaterController.php index d0be68591..9085d484e 100644 --- a/modules/Installer/Http/Controllers/UpdaterController.php +++ b/modules/Installer/Http/Controllers/UpdaterController.php @@ -4,6 +4,7 @@ use App\Contracts\Controller; use App\Services\Installer\MigrationService; +use App\Services\Installer\SeederService; use function count; use Illuminate\Http\Request; use Log; @@ -16,15 +17,19 @@ class UpdaterController extends Controller { private $migrationSvc; + private $seederSvc; /** * UpdaterController constructor. * @param MigrationService $migrationSvc + * @param SeederService $seederSvc */ public function __construct( - MigrationService $migrationSvc + MigrationService $migrationSvc, + SeederService $seederSvc ) { $this->migrationSvc = $migrationSvc; + $this->seederSvc = $seederSvc; } /** @@ -66,12 +71,12 @@ public function run_migrations(Request $request) $migrations = $this->migrationSvc->migrationsAvailable(); if(count($migrations) === 0) { - $this->migrationSvc->syncAllSeeds(); + $this->seederSvc->syncAllSeeds(); return view('installer::update/steps/step3-update-complete'); } $output = $this->migrationSvc->runAllMigrations(); - $this->migrationSvc->syncAllSeeds(); + $this->seederSvc->syncAllSeeds(); return view('installer::update/steps/step2-migrations-done', [ 'console_output' => $output, diff --git a/modules/Installer/Resources/views/update/steps/step1-update-available.blade.php b/modules/Installer/Resources/views/update/steps/step1-update-available.blade.php index 0dc84d2f8..5503a60fa 100644 --- a/modules/Installer/Resources/views/update/steps/step1-update-available.blade.php +++ b/modules/Installer/Resources/views/update/steps/step1-update-available.blade.php @@ -3,7 +3,7 @@ @section('content')
Updates have been found, click run to complete the update!.
+Click run to complete the update!.
{{ Form::open(['route' => 'update.run_migrations', 'method' => 'post']) }}
{{ Form::submit('Run >>', ['class' => 'btn btn-success']) }}
diff --git a/phpunit.xml b/phpunit.xml
index 5ed2f7ef7..7e1c06c04 100755
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -23,7 +23,7 @@