|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Thinktomorrow\Chief\Mediagallery\Http; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
|
6
|
|
|
use Illuminate\Http\Request; |
|
7
|
|
|
use Thinktomorrow\Chief\MediaGallery\Application\ZipAction; |
|
8
|
|
|
use Thinktomorrow\Chief\MediaGallery\Application\RemovalAction; |
|
9
|
|
|
use Thinktomorrow\Chief\App\Http\Controllers\Controller; |
|
10
|
|
|
|
|
11
|
|
|
class BulkActionsController extends Controller |
|
12
|
|
|
{ |
|
13
|
|
|
/** @var ZipAction */ |
|
14
|
|
|
private $zipAction; |
|
15
|
|
|
|
|
16
|
|
|
/** @var RemovalAction */ |
|
17
|
|
|
private $removalAction; |
|
18
|
|
|
|
|
19
|
|
|
public function __construct(ZipAction $zipAction, RemovalAction $removalAction) |
|
20
|
|
|
{ |
|
21
|
|
|
$this->zipAction = $zipAction; |
|
22
|
|
|
$this->removalAction = $removalAction; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function bulk(Request $request) |
|
26
|
|
|
{ |
|
27
|
|
|
if($request->input('type') == 'download') { |
|
28
|
|
|
return $this->download($request); |
|
|
|
|
|
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
if($request->input('type') == 'remove') { |
|
32
|
|
|
return $this->remove($request); |
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
private function download(Request $request) |
|
37
|
|
|
{ |
|
38
|
|
|
$filename = Str::slug(config('app.name')) . '_assets_' . date('YmdHis') . '.zip'; |
|
39
|
|
|
|
|
40
|
|
|
// TODO: do the response here instead of the zip action itself |
|
41
|
|
|
return $this->zipAction->handle($filename, $request); |
|
|
|
|
|
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
private function remove(Request $request) |
|
45
|
|
|
{ |
|
46
|
|
|
$result = $this->removalAction->handle($request); |
|
47
|
|
|
|
|
48
|
|
|
if($result) { |
|
49
|
|
|
return redirect()->back()->with('messages.success', 'De mediabestanden zijn verwijderd'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
return redirect()->back()->with('messages.error', 'Er ging iets mis, er zijn geen bestanden verwijderd. Mogelijks probeerde je een bestand te verwijderen dat nog gebruikt wordt.'); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.