0

I use spatie media library for one of my project. requirement is when uploaded image status is approved then generate conversions of that particular image. So, i write code for that in My Model is:

public function registerMediaConversions(Media $media = null)
{
    $listingStatus = ListingStatus::where('type', Listing::ITEM_TYPE_PHOTOS)->where('item_id', $media->id)->where('status', self::STATUS_APPROVED)->whereNotNull('review_by')->first();
    if ($listingStatus)
        $this->registerBaseConversions(true);
}

and when image getting approved then i dispatch job for run command.

$this->dispatch(new GenerateMediaCollection($mediaId));

Job:

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Log;

class GenerateMediaCollection implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

private $mediaId;
/**
 * Create a new job instance.
 *
 * @return void
 */
public function __construct($mediaId)
{
    $this->mediaId = $mediaId;
}

/**
 * Execute the job.
 *
 * @return void
 */
public function handle()
{
    Log::info('generate Media collection');
    exec('php artisan medialibrary:regenerate --ids='.$this->mediaId);
}
}

so, in Local all is working perfectly but in server, job is processed but conversions not added. if i run command in server from terminal then it is working. So, what i have to do for this issue? TIA.

apokryfos
  • 38,771
  • 9
  • 70
  • 114
Jinal Somaiya
  • 1,931
  • 15
  • 29

1 Answers1

0

Try adding --force to arguments. I.e. make it

exec('php artisan medialibrary:regenerate --ids='.$this->mediaId --force')