Add a helper artisan command to update place model structure

This commit is contained in:
Jonny Barnes 2017-06-30 13:39:14 +01:00
parent 4afb6a3ae9
commit e540eb767f
3 changed files with 60 additions and 0 deletions

View file

@ -0,0 +1,58 @@
<?php
namespace App\Console\Commands;
use App\Place;
use Illuminate\Console\Command;
class UpdatePlacesURLs extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'places:update-urls';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Copy any URLs in the place model to the new external URLs JSON column.';
/**
* The places collection.
*
* @var Illuminate\Database\Eloquent\Collection
*/
protected $places;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
$this->places = Place::all();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
foreach ($this->places as $place) {
if ($place->foursqaure !== null) {
$place->external_urls = $place->foursquare;
}
}
$this->info('All Places have had their external URLs values updated to the new structure.');
}
}

View file

@ -17,6 +17,7 @@ class Kernel extends ConsoleKernel
Commands\ParseCachedWebMentions::class,
Commands\ReDownloadWebMentions::class,
Commands\GenerateToken::class,
Commands\UpdatePlacesURLs::class,
];
/**

View file

@ -2,6 +2,7 @@
## Version {next}
- Transition to using a JSON column for external urls of places
- Add a command to update external url structure of places
## Version 0.5.19 (2017-06-27)
- Fix error in App\\WebMention.php