|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Itstructure\MFU\Processors; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Storage; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class UpdateProcessor |
|
9
|
|
|
* @package Itstructure\MFU\Processors |
|
10
|
|
|
* @author Andrey Girnik <[email protected]> |
|
11
|
|
|
*/ |
|
12
|
|
|
class UpdateProcessor extends SaveProcessor |
|
13
|
|
|
{ |
|
14
|
|
|
/************************* PROCESS ATTRIBUTES *************************/ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var array |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $previousFiles; |
|
19
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
/********************** PROCESS INTERNAL METHODS *********************/ |
|
22
|
|
|
protected function isFileRequired(): bool |
|
23
|
|
|
{ |
|
24
|
|
|
return false; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @return void |
|
29
|
|
|
* @throws \Exception |
|
30
|
|
|
*/ |
|
31
|
|
|
protected function setProcessParams(): void |
|
32
|
|
|
{ |
|
33
|
|
|
if (is_null($this->file)) { |
|
34
|
|
|
return; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
$this->currentDisk = $this->mediafileModel->getDisk(); |
|
38
|
|
|
|
|
39
|
|
|
$this->processDirectory = $this->file->getMimeType() == $this->mediafileModel->getMimeType() |
|
40
|
|
|
? pathinfo($this->mediafileModel->getPath())['dirname'] |
|
41
|
|
|
: $this->getNewProcessDirectory(); |
|
42
|
|
|
|
|
43
|
|
|
$this->outFileName = $this->getNewOutFileName(); |
|
44
|
|
|
|
|
45
|
|
|
$this->path = $this->processDirectory . '/' . $this->outFileName; |
|
46
|
|
|
|
|
47
|
|
|
$this->previousFiles = array_merge( |
|
48
|
|
|
[$this->mediafileModel->getPath()], array_values($this->mediafileModel->getThumbs()) |
|
49
|
|
|
); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @return bool |
|
54
|
|
|
* @throws \Exception |
|
55
|
|
|
*/ |
|
56
|
|
|
protected function process(): bool |
|
57
|
|
|
{ |
|
58
|
|
|
if (!is_null($this->file)) { |
|
59
|
|
|
|
|
60
|
|
|
if (!$this->sendFile()) { |
|
61
|
|
|
throw new \Exception('Error upload file.'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
Storage::disk($this->currentDisk)->delete($this->previousFiles); |
|
65
|
|
|
|
|
66
|
|
|
$this->setMediafileBaseData(); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
$this->setMediafileMetaData(); |
|
70
|
|
|
|
|
71
|
|
|
if (!$this->mediafileModel->save()) { |
|
72
|
|
|
throw new \Exception('Error save file data in database.'); |
|
73
|
|
|
} |
|
74
|
|
|
$this->mediafileModel->refresh(); |
|
75
|
|
|
return true; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
protected function afterProcess(): void |
|
79
|
|
|
{ |
|
80
|
|
|
return; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|