2020-01-04 13:28:00 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Traits;
|
|
|
|
|
2020-01-06 09:01:04 +00:00
|
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
2020-01-04 13:28:00 +00:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
2024-10-01 01:54:34 +00:00
|
|
|
use App\Http\Controllers\{PhotoController,VideoController};
|
2024-09-30 14:01:33 +00:00
|
|
|
use App\Jobs\CatalogDelete;
|
2020-01-05 10:55:26 +00:00
|
|
|
|
2020-01-04 13:28:00 +00:00
|
|
|
/**
|
|
|
|
* Multimedia Controller Functions
|
|
|
|
*
|
|
|
|
* @package App\Traits
|
|
|
|
*/
|
|
|
|
trait Multimedia
|
|
|
|
{
|
|
|
|
use Type;
|
|
|
|
|
2024-09-30 12:56:08 +00:00
|
|
|
protected const list_duplicates = 20;
|
|
|
|
protected const list_deletes = 50;
|
|
|
|
|
2020-01-04 13:28:00 +00:00
|
|
|
private function controller(string $type): string
|
|
|
|
{
|
|
|
|
switch (strtolower($type)) {
|
2024-10-01 01:54:34 +00:00
|
|
|
case 'photo': return PhotoController::class;
|
|
|
|
case 'video': return VideoController::class;
|
2020-01-04 13:28:00 +00:00
|
|
|
default: abort(500,'Type not handled?');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function deletesUpdate(Request $request)
|
|
|
|
{
|
|
|
|
$class = $this->getModelType($request->input('type'));
|
|
|
|
$this->updatePostItems($request,$class,TRUE);
|
|
|
|
|
2024-09-30 12:56:08 +00:00
|
|
|
return redirect()
|
|
|
|
->action(
|
2024-10-01 01:54:34 +00:00
|
|
|
[$this->controller($request->input('type')),'deletes'],
|
|
|
|
['page' => $request->input('page')]
|
2024-09-30 12:56:08 +00:00
|
|
|
);
|
2020-01-04 13:28:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function duplicatesUpdate(Request $request)
|
|
|
|
{
|
|
|
|
$class = $this->getModelType($request->input('type'));
|
|
|
|
$this->updatePostItems($request,$class);
|
|
|
|
|
2024-09-30 12:56:08 +00:00
|
|
|
return redirect()
|
|
|
|
->action(
|
2024-10-01 01:54:34 +00:00
|
|
|
[$this->controller($request->input('type')),'duplicates'],
|
|
|
|
['page' => $request->input('page')]
|
2024-09-30 12:56:08 +00:00
|
|
|
);
|
2020-01-04 13:28:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private function updatePostItems(Request $request,string $class,bool $delete=FALSE)
|
|
|
|
{
|
|
|
|
foreach ($request->input('items') as $id) {
|
2020-01-06 09:01:04 +00:00
|
|
|
try {
|
|
|
|
$o = $class::findOrFail($id);
|
2024-09-30 12:56:08 +00:00
|
|
|
|
2020-01-06 09:01:04 +00:00
|
|
|
} catch (ModelNotFoundException $e) {
|
|
|
|
Log::alert('Object not found: '.$id);
|
|
|
|
continue;
|
2024-09-30 12:56:08 +00:00
|
|
|
|
2020-01-06 09:01:04 +00:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
dd($e);
|
|
|
|
}
|
2020-01-04 13:28:00 +00:00
|
|
|
|
|
|
|
// Set if duplicate
|
|
|
|
$o->duplicate = $request->input('duplicate.'.$id) ? 1 : NULL;
|
|
|
|
|
|
|
|
// Set if ignore duplicate
|
|
|
|
$o->ignore_duplicate = $request->input('ignore_duplicate.'.$id) ? 1 : NULL;
|
|
|
|
|
|
|
|
// Set if flag
|
|
|
|
$o->flag = $request->input('flag.'.$id) ? 1 : NULL;
|
|
|
|
|
|
|
|
// Set if delete
|
2024-09-30 12:56:08 +00:00
|
|
|
if ($delete && $o->remove && ($request->input('remove.'.$id) ? 1 : NULL)) {
|
2020-01-06 09:01:04 +00:00
|
|
|
switch (strtolower($request->input('type'))) {
|
2020-01-05 10:55:26 +00:00
|
|
|
case 'photo':
|
|
|
|
case 'video':
|
|
|
|
Log::info(sprintf('Dispatching delete for [%s]',$o->id));
|
2024-09-30 14:01:33 +00:00
|
|
|
|
|
|
|
CatalogDelete::dispatch($o)
|
|
|
|
->onQueue('delete');
|
|
|
|
|
2020-01-05 10:55:26 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2020-01-06 09:01:04 +00:00
|
|
|
Log::info(sprintf('Ignoring delete for [%s] - not configured (%s).',$o->id,$class));
|
2020-01-05 10:55:26 +00:00
|
|
|
}
|
|
|
|
|
2020-01-04 13:28:00 +00:00
|
|
|
} else {
|
|
|
|
$o->remove = $request->input('remove.'.$id) ? 1 : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
$o->save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|