Compare commits
1 Commits
dev
...
BE.add-com
Author | SHA1 | Date |
---|---|---|
fateme | d0f19f66f2 | 4 years ago |
@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use WM\Common\Services\Media\Media;
|
||||||
|
|
||||||
|
class FillMediaBusinessId extends Command
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'media:fill';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Fill media business_id and user_id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
Media::chunk(500, function ($medias){
|
||||||
|
foreach($medias as $media){
|
||||||
|
|
||||||
|
$media['business_id'] = $media->model ? $media->model->business_id : null;
|
||||||
|
$media['user_id'] = $media->model ? $media->model->user_id : null;
|
||||||
|
$media->save();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue