Esempio n. 1
0
 /**
  * Returns an associative array with the locale code as the key and the translated language name as the value.
  *
  * @return array
  */
 public function getLanguageList()
 {
     $languages = Language::getAll(true, true);
     return $languages;
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $kritikktyper = [];
     foreach (KritikkType::all() as $kilde) {
         $kritikktyper[mb_strtolower($kilde->navn)] = $kilde->id;
     }
     $this->info('');
     $this->warn(' This will re-populate the table from scratch. Any user contributed data will be lost!');
     if (!$this->confirm('Are you sure you want to continue? [y|N]')) {
         return;
     }
     $data = $this->getData('import/litteraturkritikk.json');
     $allespraak = array_flip(Language::getAll(true, true, 'nb'));
     $allespraak['finsk-svensk'] = 'sv';
     $allespraak['bokmål'] = 'nb';
     $allespraak['nynorsk'] = 'nn';
     $allespraak['bokmål (innslag av nynorsk)'] = 'nb';
     // Separate out 'person' columns
     $personColumns = ['forfatter_etternavn', 'forfatter_fornavn', 'forfatter_kjonn', 'kritiker_etternavn', 'kritiker_fornavn', 'kritiker_kjonn', 'kritiker_pseudonym'];
     $persons = array_map(function ($x) use($personColumns) {
         return array_only($x, array_merge(['id'], $personColumns));
     }, $data);
     $records = array_map(function ($x) use($personColumns) {
         return array_except($x, $personColumns);
     }, $data);
     foreach ($records as &$row) {
         $this->processRecordRow($row, $allespraak);
     }
     $this->comment('Clearing DB');
     \DB::delete('delete from litteraturkritikk_records');
     $this->comment('Inserting records');
     $chunks = array_chunk($records, 100);
     foreach ($chunks as $chunk) {
         \DB::table('litteraturkritikk_records')->insert($chunk);
     }
     $this->comment('Inserting persons');
     $this->stats = ['forfatter' => [], 'kritiker' => []];
     foreach ($persons as &$row) {
         $this->processCreators($row);
     }
     foreach ($this->stats['forfatter'] as $k => $v) {
         print "Forfatter: {$k} : {$v}\n";
     }
     foreach ($this->stats['kritiker'] as $k => $v) {
         print "Kritiker: {$k} : {$v}\n";
     }
     $this->info('Refreshing views');
     \DB::unprepared('REFRESH MATERIALIZED VIEW litteraturkritikk_records_search');
     $this->info('Updating sequences');
     \DB::unprepared('SELECT pg_catalog.setval(pg_get_serial_sequence(\'litteraturkritikk_records\', \'id\'), MAX(id)) FROM litteraturkritikk_records');
     \DB::unprepared('SELECT pg_catalog.setval(pg_get_serial_sequence(\'litteraturkritikk_personer\', \'id\'), MAX(id)) FROM litteraturkritikk_personer');
     $this->info('Done');
 }