1: | <?php |
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | namespace Aurora\Modules\MailSaveAttachmentsToFilesPlugin; |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | class Module extends \Aurora\System\Module\AbstractModule |
18: | { |
19: | |
20: | |
21: | |
22: | public $oApiFilecacheManager = null; |
23: | |
24: | public function getFilecacheManager() |
25: | { |
26: | if ($this->oApiFilecacheManager === null) { |
27: | $this->oApiFilecacheManager = new \Aurora\System\Managers\Filecache(); |
28: | } |
29: | |
30: | return $this->oApiFilecacheManager; |
31: | } |
32: | |
33: | public function init() |
34: | { |
35: | } |
36: | |
37: | |
38: | |
39: | |
40: | |
41: | public function Save($UserId, $AccountID, $Attachments = [], $Storage = 'personal', $Path = '') |
42: | { |
43: | $mResult = false; |
44: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
45: | |
46: | $oMailModuleDecorator = \Aurora\Modules\Mail\Module::Decorator(); |
47: | if ($oMailModuleDecorator) { |
48: | $aTempFiles = $oMailModuleDecorator->SaveAttachmentsAsTempFiles($AccountID, $Attachments); |
49: | if (\is_array($aTempFiles)) { |
50: | $sUUID = \Aurora\System\Api::getUserUUIDById($UserId); |
51: | foreach ($aTempFiles as $sTempName => $sData) { |
52: | $aData = \Aurora\System\Api::DecodeKeyValues($sData); |
53: | if (\is_array($aData) && isset($aData['FileName'])) { |
54: | $sFileName = (string) $aData['FileName']; |
55: | $rResource = $this->getFilecacheManager()->getFile($sUUID, $sTempName); |
56: | if ($rResource) { |
57: | $aArgs = array( |
58: | 'UserId' => $UserId, |
59: | 'Type' => $Storage, |
60: | 'Path' => $Path, |
61: | 'Name' => $sFileName, |
62: | 'Data' => $rResource, |
63: | 'Overwrite' => false, |
64: | 'RangeType' => 0, |
65: | 'Offset' => 0, |
66: | 'ExtendedProps' => array() |
67: | ); |
68: | \Aurora\System\Api::GetModuleManager()->broadcastEvent( |
69: | 'Files', |
70: | 'CreateFile', |
71: | $aArgs, |
72: | $mResult |
73: | ); |
74: | } |
75: | } |
76: | } |
77: | } |
78: | } |
79: | |
80: | return $mResult; |
81: | } |
82: | } |
83: | |