mirror of
https://github.com/Einundzwanzig-Podcast/einundzwanzig-portal.git
synced 2025-12-11 06:46:47 +00:00
55 lines
1.4 KiB
PHP
55 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands\Database;
|
|
|
|
use App\Models\City;
|
|
use App\Models\Country;
|
|
use App\Models\Meetup;
|
|
use Illuminate\Console\Command;
|
|
|
|
class ImportGithubMeetups extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
* @var string
|
|
*/
|
|
protected $signature = 'import:meetups';
|
|
|
|
/**
|
|
* The console command description.
|
|
* @var string
|
|
*/
|
|
protected $description = 'Command description';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
* @return int
|
|
*/
|
|
public function handle()
|
|
{
|
|
$meetups = json_decode(file_get_contents(config_path('meetups/github.json')), true, 512, JSON_THROW_ON_ERROR);
|
|
|
|
foreach ($meetups as $meetup) {
|
|
$city = City::firstOrCreate([
|
|
'name' => $meetup['city'],
|
|
], [
|
|
'country_id' => Country::firstOrCreate([
|
|
'code' => str($meetup['country'])
|
|
->lower()
|
|
->toString()
|
|
], ['name' => $meetup['country']])->id,
|
|
'longitude' => $meetup['longitude'],
|
|
'latitude' => $meetup['latitude'],
|
|
]);
|
|
$meetup = Meetup::updateOrCreate(
|
|
['name' => $meetup['name']],
|
|
[
|
|
'city_id' => $city->id,
|
|
'link' => $meetup['url'],
|
|
]);
|
|
}
|
|
|
|
return Command::SUCCESS;
|
|
}
|
|
}
|