|
...
|
...
|
@@ -4,6 +4,7 @@ namespace App\Listeners; |
|
|
|
|
|
|
|
use App\Events\CopyImageFile;
|
|
|
|
use App\Events\UpdateHtml;
|
|
|
|
use App\Jobs\CopyImageFileJob;
|
|
|
|
use App\Jobs\updateHtmlJob;
|
|
|
|
use App\Models\File\File as FileModel;
|
|
|
|
use App\Models\File\Image as ImageModel;
|
|
...
|
...
|
@@ -12,39 +13,16 @@ use Illuminate\Contracts\Queue\ShouldQueue; |
|
|
|
|
|
|
|
class CopyImageFileListener implements ShouldQueue
|
|
|
|
{
|
|
|
|
use InteractsWithQueue, SerializesModels;
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the event.
|
|
|
|
*
|
|
|
|
* @param UpdateHtml $event
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function handle(CopyImageFile $event)
|
|
|
|
{
|
|
|
|
$this->param = $event->data;
|
|
|
|
$imageModel = new ImageModel();
|
|
|
|
//获取当前项目的所有图片
|
|
|
|
$imageList = $imageModel->list(['project_id'=>$this->param['project_id'],'is_cos'=>1],'id',['id','path','is_cos','size']);
|
|
|
|
if(!empty($imageList)){
|
|
|
|
$amazonS3Service = new AmazonS3Service();
|
|
|
|
foreach ($imageList as $k => $v){
|
|
|
|
$amazonS3Service->syncImageFiles(getImageUrl($v['path']));
|
|
|
|
$imageModel->edit(['is_cos'=>0],['id'=>$v['id']]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$fileModel = new FileModel();
|
|
|
|
$fileList = $fileModel->list(['project_id'=>$this->param['project_id'],'is_cos'=>1],'id',['id','path','is_cos']);
|
|
|
|
if(!empty($fileList)){
|
|
|
|
$amazonS3Service = new AmazonS3Service();
|
|
|
|
foreach ($fileList as $k => $v){
|
|
|
|
$amazonS3Service->syncImageFiles(getImageUrl($v['path']));
|
|
|
|
$fileList->edit(['is_cos'=>0],['id'=>$v['id']]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
// 将任务推送到队列,异步执行
|
|
|
|
dispatch(new CopyImageFileJob($event));
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|