@@ -31,10 +31,10 @@ |
||
31 | 31 | |
32 | 32 | public function install() |
33 | 33 | { |
34 | - Models\File::migrate(); |
|
35 | - Models\FileAccessLog::migrate(); |
|
36 | - Models\FileContent::migrate(); |
|
37 | - Models\FileRemoteAccess::migrate(); |
|
34 | + Models\File::migrate(); |
|
35 | + Models\FileAccessLog::migrate(); |
|
36 | + Models\FileContent::migrate(); |
|
37 | + Models\FileRemoteAccess::migrate(); |
|
38 | 38 | |
39 | 39 | $downloadFiles = Permission::create(['name' => 'download files']); |
40 | 40 |
@@ -48,7 +48,7 @@ |
||
48 | 48 | |
49 | 49 | public static function boot() |
50 | 50 | { |
51 | - Route::group(['namespace' => 'Epesi\FileStorage'], function(){ |
|
51 | + Route::group(['namespace' => 'Epesi\FileStorage'], function() { |
|
52 | 52 | Route::get('file', 'FileStorageController@get')->middleware('web', FileStorageAccess::class); |
53 | 53 | }); |
54 | 54 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | |
35 | 35 | protected function setPeriodSelection() |
36 | 36 | { |
37 | - if (! $this->periodSelection) { |
|
37 | + if (!$this->periodSelection) { |
|
38 | 38 | $this->periodSelection = []; |
39 | 39 | foreach ([1, 2, 3, 4] as $count) { |
40 | 40 | $this->periodSelection[$count . ' weeks'] = trans_choice('{1} :count week |[2,*] :count weeks', $count); |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | } |
43 | 43 | |
44 | 44 | foreach ($this->periodSelection as $key => $period) { |
45 | - $default = $key == $this->defaultPeriod? ' (' . __('Default') . ')': ''; |
|
45 | + $default = $key == $this->defaultPeriod ? ' (' . __('Default') . ')' : ''; |
|
46 | 46 | |
47 | 47 | $this->periodSelection[$key] = $period . $default; |
48 | 48 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | |
51 | 51 | protected function addContents() |
52 | 52 | { |
53 | - if (! $this->file) { |
|
53 | + if (!$this->file) { |
|
54 | 54 | $this->set(__('Wrong parameters for file')); |
55 | 55 | return; |
56 | 56 | } |
@@ -70,13 +70,13 @@ discard block |
||
70 | 70 | |
71 | 71 | protected function addFileDetails($container = null) |
72 | 72 | { |
73 | - $container = $container?: $this; |
|
73 | + $container = $container ?: $this; |
|
74 | 74 | |
75 | 75 | $container->add(new FileDetailsLister($this->file)); |
76 | 76 | } |
77 | 77 | |
78 | 78 | protected function addFileRemoteLinks($container = null) { |
79 | - $container = $container?: $this; |
|
79 | + $container = $container ?: $this; |
|
80 | 80 | |
81 | 81 | foreach ($this->file->userActiveLinks() as $link) { |
82 | 82 | $container->add(['View', __('Remote access link expiring :expiry', ['expiry' => $link['expires_at']->format('Y-m-d H:i:s')])]); |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | $container->js(true, new jsExpression('new ClipboardJS(".copy-button")')); |
91 | 91 | |
92 | 92 | $container->on('click', '.delete-link', $this->add(['jsCallback', 'postTrigger' => 'link'])->set(function($j, $linkId) { |
93 | - if (! $link = FileRemoteAccess::create()->load($linkId)) return; |
|
93 | + if (!$link = FileRemoteAccess::create()->load($linkId)) return; |
|
94 | 94 | |
95 | 95 | $link->delete(); |
96 | 96 | |
@@ -101,19 +101,19 @@ discard block |
||
101 | 101 | protected function addFileControlButtons() { |
102 | 102 | $urls = FileStorageAccessJoint::getActionUrls($this->file); |
103 | 103 | |
104 | - if (! $this->actionDisabled('preview') && ($urls['preview']?? null)) { |
|
104 | + if (!$this->actionDisabled('preview') && ($urls['preview']?? null)) { |
|
105 | 105 | $this->add(['Button', 'class' => ['basic'], 'icon' => 'file alternate outline'])->set(__('View'))->link($urls['preview'])->setAttr(['target' => '_blank']); |
106 | 106 | } |
107 | 107 | |
108 | - if (! $this->actionDisabled('download') && ($urls['download']?? null)) { |
|
108 | + if (!$this->actionDisabled('download') && ($urls['download']?? null)) { |
|
109 | 109 | $this->add(['Button', 'class' => ['basic'], 'icon' => 'file download'])->set(__('Download'))->link($urls['download']); |
110 | 110 | } |
111 | 111 | |
112 | - if (! $this->actionDisabled('history')) { |
|
112 | + if (!$this->actionDisabled('history')) { |
|
113 | 113 | $this->add(['Button', 'class' => ['basic'], 'icon' => 'history'])->set(__('Access History'))->link(url('view/filestorage:file-access-history/body') . '?' . http_build_query(['id' => $this->file->id])); |
114 | 114 | } |
115 | 115 | |
116 | - if (! $this->actionDisabled('remote')) { |
|
116 | + if (!$this->actionDisabled('remote')) { |
|
117 | 117 | $linkControl = $this->add(['View', 'ui' => 'basic buttons']); |
118 | 118 | |
119 | 119 | $linkButton = $linkControl->add(['Button', 'class' => ['basic'], 'icon' => 'linkify'])->set(__('Get Remote Link')); |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | $dropdown->setSource($this->periodSelection); |
124 | 124 | |
125 | 125 | $dropdown->onChange(function($value) { |
126 | - $period = array_search($value, $this->periodSelection)?: $this->defaultPeriod; |
|
126 | + $period = array_search($value, $this->periodSelection) ?: $this->defaultPeriod; |
|
127 | 127 | |
128 | 128 | FileRemoteAccess::grant($this->file, $period); |
129 | 129 |
@@ -90,7 +90,9 @@ |
||
90 | 90 | $container->js(true, new jsExpression('new ClipboardJS(".copy-button")')); |
91 | 91 | |
92 | 92 | $container->on('click', '.delete-link', $this->add(['jsCallback', 'postTrigger' => 'link'])->set(function($j, $linkId) { |
93 | - if (! $link = FileRemoteAccess::create()->load($linkId)) return; |
|
93 | + if (! $link = FileRemoteAccess::create()->load($linkId)) { |
|
94 | + return; |
|
95 | + } |
|
94 | 96 | |
95 | 97 | $link->delete(); |
96 | 98 |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | |
34 | 34 | public function getDefaultSource() |
35 | 35 | { |
36 | - return $this->file? [ |
|
36 | + return $this->file ? [ |
|
37 | 37 | 'name' => [ |
38 | 38 | 'title'=> __('Name'), |
39 | 39 | 'descr'=> $this->file['name'] |
@@ -50,6 +50,6 @@ discard block |
||
50 | 50 | 'title'=> __('Stored At'), |
51 | 51 | 'descr'=> $this->file['created_at'] |
52 | 52 | ] |
53 | - ]: []; |
|
53 | + ] : []; |
|
54 | 54 | } |
55 | 55 | } |
56 | 56 | \ No newline at end of file |
@@ -13,228 +13,228 @@ |
||
13 | 13 | |
14 | 14 | class File extends Model |
15 | 15 | { |
16 | - use HasEpesiConnection; |
|
16 | + use HasEpesiConnection; |
|
17 | 17 | |
18 | 18 | public $table = 'filestorage_files'; |
19 | 19 | |
20 | - function init() { |
|
21 | - parent::init(); |
|
22 | - |
|
23 | - $this->addFields([ |
|
24 | - 'created_at' => ['caption' => __('Stored At')], |
|
25 | - 'name' => ['caption' => __('File Name')], |
|
26 | - 'link' => ['caption' => __('Link')], |
|
27 | - 'backref' |
|
28 | - ]); |
|
20 | + function init() { |
|
21 | + parent::init(); |
|
22 | + |
|
23 | + $this->addFields([ |
|
24 | + 'created_at' => ['caption' => __('Stored At')], |
|
25 | + 'name' => ['caption' => __('File Name')], |
|
26 | + 'link' => ['caption' => __('Link')], |
|
27 | + 'backref' |
|
28 | + ]); |
|
29 | 29 | |
30 | - $this->hasOne('created_by', [User::class, 'our_field' => 'created_by'])->addTitle(['field' => 'created_by_user', 'caption' => __('Stored By')]); |
|
30 | + $this->hasOne('created_by', [User::class, 'our_field' => 'created_by'])->addTitle(['field' => 'created_by_user', 'caption' => __('Stored By')]); |
|
31 | 31 | |
32 | - $this->hasOne('content', [FileContent::class, 'our_field' => 'content_id']); |
|
32 | + $this->hasOne('content', [FileContent::class, 'our_field' => 'content_id']); |
|
33 | 33 | |
34 | - $this->hasMany('links', [FileRemoteAccess::class, 'their_field' => 'file_id']); |
|
34 | + $this->hasMany('links', [FileRemoteAccess::class, 'their_field' => 'file_id']); |
|
35 | 35 | |
36 | - $this->addCalculatedField('thumbnail', [[__CLASS__, 'getThumbnailField']]); |
|
37 | - } |
|
36 | + $this->addCalculatedField('thumbnail', [[__CLASS__, 'getThumbnailField']]); |
|
37 | + } |
|
38 | 38 | |
39 | - public function userActiveLinks() |
|
40 | - { |
|
41 | - return $this->ref('links')->addCrits([ |
|
42 | - ['created_by', Auth::id()], |
|
43 | - ['expires_at', '>', date('Y-m-d H:i:s')] |
|
44 | - ]); |
|
45 | - } |
|
39 | + public function userActiveLinks() |
|
40 | + { |
|
41 | + return $this->ref('links')->addCrits([ |
|
42 | + ['created_by', Auth::id()], |
|
43 | + ['expires_at', '>', date('Y-m-d H:i:s')] |
|
44 | + ]); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Retrieve the file |
|
49 | - * |
|
50 | - * @param int|string $idOrLink Filestorage ID or unique link string |
|
51 | - * @param bool $useCache Use cache or not |
|
52 | - * |
|
53 | - * @return static |
|
54 | - * |
|
55 | - * @throws FileNotFound |
|
56 | - */ |
|
57 | - public static function retrieve($idOrLink) |
|
58 | - { |
|
59 | - $id = self::getIdByLink($idOrLink, true, true); |
|
47 | + /** |
|
48 | + * Retrieve the file |
|
49 | + * |
|
50 | + * @param int|string $idOrLink Filestorage ID or unique link string |
|
51 | + * @param bool $useCache Use cache or not |
|
52 | + * |
|
53 | + * @return static |
|
54 | + * |
|
55 | + * @throws FileNotFound |
|
56 | + */ |
|
57 | + public static function retrieve($idOrLink) |
|
58 | + { |
|
59 | + $id = self::getIdByLink($idOrLink, true, true); |
|
60 | 60 | |
61 | - $file = self::create()->tryLoad($id); |
|
61 | + $file = self::create()->tryLoad($id); |
|
62 | 62 | |
63 | - if (! $file->ref('content')['hash']) { |
|
64 | - throw new FileNotFound('File object does not have corresponding content'); |
|
65 | - } |
|
63 | + if (! $file->ref('content')['hash']) { |
|
64 | + throw new FileNotFound('File object does not have corresponding content'); |
|
65 | + } |
|
66 | 66 | |
67 | - return $file; |
|
68 | - } |
|
67 | + return $file; |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Get Filestorage ID by link |
|
72 | - * |
|
73 | - * @param string $link Unique link |
|
74 | - * @param bool $useCache Use cache or not |
|
75 | - * @param bool $throwException Throw exception if link is not found |
|
76 | - * |
|
77 | - * @return int Filestorage ID |
|
78 | - * @throws LinkNotFound |
|
79 | - */ |
|
80 | - public static function getIdByLink($link, $useCache = true, $throwException = false) |
|
81 | - { |
|
82 | - static $cache = []; |
|
83 | - |
|
84 | - if (is_numeric($link) || is_null($link)) return $link; |
|
85 | - |
|
86 | - if (is_object($link)) return $link['id']; |
|
87 | - |
|
88 | - if (!$useCache || !isset($cache[$link])) { |
|
89 | - $file = self::create()->tryLoadBy('link', $link); |
|
70 | + /** |
|
71 | + * Get Filestorage ID by link |
|
72 | + * |
|
73 | + * @param string $link Unique link |
|
74 | + * @param bool $useCache Use cache or not |
|
75 | + * @param bool $throwException Throw exception if link is not found |
|
76 | + * |
|
77 | + * @return int Filestorage ID |
|
78 | + * @throws LinkNotFound |
|
79 | + */ |
|
80 | + public static function getIdByLink($link, $useCache = true, $throwException = false) |
|
81 | + { |
|
82 | + static $cache = []; |
|
83 | + |
|
84 | + if (is_numeric($link) || is_null($link)) return $link; |
|
85 | + |
|
86 | + if (is_object($link)) return $link['id']; |
|
87 | + |
|
88 | + if (!$useCache || !isset($cache[$link])) { |
|
89 | + $file = self::create()->tryLoadBy('link', $link); |
|
90 | 90 | |
91 | - $cache[$link] = $file? $file->get('id'): null; |
|
91 | + $cache[$link] = $file? $file->get('id'): null; |
|
92 | 92 | |
93 | - if (!$cache[$link] && $throwException) { |
|
94 | - throw new LinkNotFound($link); |
|
95 | - } |
|
96 | - } |
|
93 | + if (!$cache[$link] && $throwException) { |
|
94 | + throw new LinkNotFound($link); |
|
95 | + } |
|
96 | + } |
|
97 | 97 | |
98 | - return $cache[$link]; |
|
99 | - } |
|
98 | + return $cache[$link]; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Mark file as deleted. Does not remove any content! |
|
103 | - * |
|
104 | - * @param int|string $idOrLink Filestorage ID or unique link |
|
105 | - */ |
|
106 | - public static function unlink($idOrLink) |
|
107 | - { |
|
101 | + /** |
|
102 | + * Mark file as deleted. Does not remove any content! |
|
103 | + * |
|
104 | + * @param int|string $idOrLink Filestorage ID or unique link |
|
105 | + */ |
|
106 | + public static function unlink($idOrLink) |
|
107 | + { |
|
108 | 108 | if ($id = self::getIdByLink($idOrLink, false)) { |
109 | 109 | self::create()->delete($id); |
110 | - } |
|
111 | - } |
|
110 | + } |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * Check if file exists |
|
115 | - * |
|
116 | - * @param int|static $idOrMeta Filestorage ID or file object |
|
117 | - * @param bool $throwException Throw exception on missing file or return false |
|
118 | - * |
|
119 | - * @return bool True if file exists, false otherwise |
|
120 | - * @throws FileNotFound May be thrown if $throwException set to true |
|
121 | - */ |
|
122 | - public static function exists($idOrMeta, $throwException = false) |
|
123 | - { |
|
124 | - try { |
|
125 | - $file = is_numeric($idOrMeta) ? self::retrieve($idOrMeta) : $idOrMeta; |
|
113 | + /** |
|
114 | + * Check if file exists |
|
115 | + * |
|
116 | + * @param int|static $idOrMeta Filestorage ID or file object |
|
117 | + * @param bool $throwException Throw exception on missing file or return false |
|
118 | + * |
|
119 | + * @return bool True if file exists, false otherwise |
|
120 | + * @throws FileNotFound May be thrown if $throwException set to true |
|
121 | + */ |
|
122 | + public static function exists($idOrMeta, $throwException = false) |
|
123 | + { |
|
124 | + try { |
|
125 | + $file = is_numeric($idOrMeta) ? self::retrieve($idOrMeta) : $idOrMeta; |
|
126 | 126 | |
127 | - if (! file_exists($file->ref('content')['path'])) { |
|
128 | - throw new FileNotFound('Exception - file not found: ' . $file->ref('content')['path']); |
|
129 | - } |
|
130 | - } catch (\Exception $exception) { |
|
131 | - if ($throwException) |
|
132 | - throw $exception; |
|
133 | - else |
|
134 | - return false; |
|
135 | - } |
|
136 | - |
|
137 | - return true; |
|
138 | - } |
|
127 | + if (! file_exists($file->ref('content')['path'])) { |
|
128 | + throw new FileNotFound('Exception - file not found: ' . $file->ref('content')['path']); |
|
129 | + } |
|
130 | + } catch (\Exception $exception) { |
|
131 | + if ($throwException) |
|
132 | + throw $exception; |
|
133 | + else |
|
134 | + return false; |
|
135 | + } |
|
136 | + |
|
137 | + return true; |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * Add multiple files, clone file if file id is provided. |
|
142 | - * May be used to update backref for all files. |
|
143 | - * |
|
144 | - * @param array $files array of existing filestorage ids or array with values for the new file |
|
145 | - * @param string|null $backref Backref for all files |
|
146 | - * @return array Newly created Meta Ids sorted in ascending order |
|
147 | - */ |
|
148 | - public static function storeMany($files, $backref = null) |
|
149 | - { |
|
150 | - $ids = []; |
|
151 | - foreach ((array) $files as $filePath) { |
|
152 | - if (! is_numeric($filePath)) { |
|
153 | - $ids[] = self::store($filePath); |
|
140 | + /** |
|
141 | + * Add multiple files, clone file if file id is provided. |
|
142 | + * May be used to update backref for all files. |
|
143 | + * |
|
144 | + * @param array $files array of existing filestorage ids or array with values for the new file |
|
145 | + * @param string|null $backref Backref for all files |
|
146 | + * @return array Newly created Meta Ids sorted in ascending order |
|
147 | + */ |
|
148 | + public static function storeMany($files, $backref = null) |
|
149 | + { |
|
150 | + $ids = []; |
|
151 | + foreach ((array) $files as $filePath) { |
|
152 | + if (! is_numeric($filePath)) { |
|
153 | + $ids[] = self::store($filePath); |
|
154 | 154 | |
155 | - continue; |
|
156 | - } |
|
155 | + continue; |
|
156 | + } |
|
157 | 157 | |
158 | - $file = self::retrieve($filePath, false); |
|
158 | + $file = self::retrieve($filePath, false); |
|
159 | 159 | |
160 | - if ($backref && $file['backref'] != $backref) { |
|
161 | - $file->save(compact('backref')); |
|
162 | - } |
|
160 | + if ($backref && $file['backref'] != $backref) { |
|
161 | + $file->save(compact('backref')); |
|
162 | + } |
|
163 | 163 | |
164 | - $ids[] = $file['id']; |
|
165 | - } |
|
164 | + $ids[] = $file['id']; |
|
165 | + } |
|
166 | 166 | |
167 | - sort($ids); |
|
167 | + sort($ids); |
|
168 | 168 | |
169 | - return $ids; |
|
170 | - } |
|
169 | + return $ids; |
|
170 | + } |
|
171 | 171 | |
172 | - /** |
|
173 | - * @param string|array $fileOrPath |
|
174 | - * @param string $content Content of the file |
|
175 | - * |
|
176 | - * @return int Filestorage ID |
|
177 | - * @throws LinkDuplicate |
|
178 | - */ |
|
179 | - public static function store($fileOrPath, $content = null) |
|
180 | - { |
|
181 | - $file = $fileOrPath; |
|
182 | - |
|
183 | - if (is_object($file)) { |
|
184 | - $file->action('update', [ |
|
185 | - 'content_id' => FileContent::store($content) |
|
186 | - ]); |
|
172 | + /** |
|
173 | + * @param string|array $fileOrPath |
|
174 | + * @param string $content Content of the file |
|
175 | + * |
|
176 | + * @return int Filestorage ID |
|
177 | + * @throws LinkDuplicate |
|
178 | + */ |
|
179 | + public static function store($fileOrPath, $content = null) |
|
180 | + { |
|
181 | + $file = $fileOrPath; |
|
182 | + |
|
183 | + if (is_object($file)) { |
|
184 | + $file->action('update', [ |
|
185 | + 'content_id' => FileContent::store($content) |
|
186 | + ]); |
|
187 | 187 | |
188 | - return $file['id']; |
|
189 | - } |
|
188 | + return $file['id']; |
|
189 | + } |
|
190 | 190 | |
191 | - if (! $content && is_string($fileOrPath)) { |
|
192 | - $content = file_get_contents($fileOrPath); |
|
191 | + if (! $content && is_string($fileOrPath)) { |
|
192 | + $content = file_get_contents($fileOrPath); |
|
193 | 193 | |
194 | - $file = [ |
|
195 | - 'name' => basename($fileOrPath) |
|
196 | - ]; |
|
197 | - } |
|
194 | + $file = [ |
|
195 | + 'name' => basename($fileOrPath) |
|
196 | + ]; |
|
197 | + } |
|
198 | 198 | |
199 | - if (! empty($file['link']) && self::getIdByLink($file['link'], false)) { |
|
200 | - throw new LinkDuplicate($file['link']); |
|
201 | - } |
|
199 | + if (! empty($file['link']) && self::getIdByLink($file['link'], false)) { |
|
200 | + throw new LinkDuplicate($file['link']); |
|
201 | + } |
|
202 | 202 | |
203 | - $content = $file['content']?? $content; |
|
203 | + $content = $file['content']?? $content; |
|
204 | 204 | |
205 | - if (is_array($content)) { |
|
206 | - $path = $content['path']; |
|
205 | + if (is_array($content)) { |
|
206 | + $path = $content['path']; |
|
207 | 207 | |
208 | - $file['name'] = $file['name']?? basename($path); |
|
208 | + $file['name'] = $file['name']?? basename($path); |
|
209 | 209 | |
210 | - $content = file_get_contents($path); |
|
211 | - } |
|
210 | + $content = file_get_contents($path); |
|
211 | + } |
|
212 | 212 | |
213 | - unset($file['content']); |
|
213 | + unset($file['content']); |
|
214 | 214 | |
215 | 215 | return self::create()->insert(array_merge([ |
216 | 216 | 'created_at' => date('Y-m-d H:i:s'), |
217 | 217 | 'created_by' => Auth::id(), |
218 | 218 | 'content_id' => FileContent::store($content) |
219 | 219 | ], $file)); |
220 | - } |
|
220 | + } |
|
221 | 221 | |
222 | - public static function getThumbnailField($model) |
|
223 | - { |
|
224 | - if (! $model->thumbnailPossible()) return false; |
|
222 | + public static function getThumbnailField($model) |
|
223 | + { |
|
224 | + if (! $model->thumbnailPossible()) return false; |
|
225 | 225 | |
226 | - $image = new \Imagick($model->ref('content')['path'] . '[0]'); |
|
226 | + $image = new \Imagick($model->ref('content')['path'] . '[0]'); |
|
227 | 227 | |
228 | - $image->setImageFormat('jpg'); |
|
228 | + $image->setImageFormat('jpg'); |
|
229 | 229 | |
230 | - return collect([ |
|
231 | - 'mime' => 'image/jpeg', |
|
232 | - 'name' => 'preview.jpeg', |
|
233 | - 'contents' => $image . '' |
|
234 | - ]); |
|
235 | - } |
|
230 | + return collect([ |
|
231 | + 'mime' => 'image/jpeg', |
|
232 | + 'name' => 'preview.jpeg', |
|
233 | + 'contents' => $image . '' |
|
234 | + ]); |
|
235 | + } |
|
236 | 236 | |
237 | - public function thumbnailPossible() { |
|
238 | - return $this->ref('content')['type'] == 'application/pdf' && class_exists('Imagick'); |
|
239 | - } |
|
237 | + public function thumbnailPossible() { |
|
238 | + return $this->ref('content')['type'] == 'application/pdf' && class_exists('Imagick'); |
|
239 | + } |
|
240 | 240 | } |
241 | 241 | \ No newline at end of file |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | |
61 | 61 | $file = self::create()->tryLoad($id); |
62 | 62 | |
63 | - if (! $file->ref('content')['hash']) { |
|
63 | + if (!$file->ref('content')['hash']) { |
|
64 | 64 | throw new FileNotFound('File object does not have corresponding content'); |
65 | 65 | } |
66 | 66 | |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | if (!$useCache || !isset($cache[$link])) { |
89 | 89 | $file = self::create()->tryLoadBy('link', $link); |
90 | 90 | |
91 | - $cache[$link] = $file? $file->get('id'): null; |
|
91 | + $cache[$link] = $file ? $file->get('id') : null; |
|
92 | 92 | |
93 | 93 | if (!$cache[$link] && $throwException) { |
94 | 94 | throw new LinkNotFound($link); |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | try { |
125 | 125 | $file = is_numeric($idOrMeta) ? self::retrieve($idOrMeta) : $idOrMeta; |
126 | 126 | |
127 | - if (! file_exists($file->ref('content')['path'])) { |
|
127 | + if (!file_exists($file->ref('content')['path'])) { |
|
128 | 128 | throw new FileNotFound('Exception - file not found: ' . $file->ref('content')['path']); |
129 | 129 | } |
130 | 130 | } catch (\Exception $exception) { |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | { |
150 | 150 | $ids = []; |
151 | 151 | foreach ((array) $files as $filePath) { |
152 | - if (! is_numeric($filePath)) { |
|
152 | + if (!is_numeric($filePath)) { |
|
153 | 153 | $ids[] = self::store($filePath); |
154 | 154 | |
155 | 155 | continue; |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | return $file['id']; |
189 | 189 | } |
190 | 190 | |
191 | - if (! $content && is_string($fileOrPath)) { |
|
191 | + if (!$content && is_string($fileOrPath)) { |
|
192 | 192 | $content = file_get_contents($fileOrPath); |
193 | 193 | |
194 | 194 | $file = [ |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | ]; |
197 | 197 | } |
198 | 198 | |
199 | - if (! empty($file['link']) && self::getIdByLink($file['link'], false)) { |
|
199 | + if (!empty($file['link']) && self::getIdByLink($file['link'], false)) { |
|
200 | 200 | throw new LinkDuplicate($file['link']); |
201 | 201 | } |
202 | 202 | |
@@ -221,9 +221,9 @@ discard block |
||
221 | 221 | |
222 | 222 | public static function getThumbnailField($model) |
223 | 223 | { |
224 | - if (! $model->thumbnailPossible()) return false; |
|
224 | + if (!$model->thumbnailPossible()) return false; |
|
225 | 225 | |
226 | - $image = new \Imagick($model->ref('content')['path'] . '[0]'); |
|
226 | + $image = new \Imagick($model->ref('content')['path'] . '[0]'); |
|
227 | 227 | |
228 | 228 | $image->setImageFormat('jpg'); |
229 | 229 |
@@ -81,9 +81,13 @@ discard block |
||
81 | 81 | { |
82 | 82 | static $cache = []; |
83 | 83 | |
84 | - if (is_numeric($link) || is_null($link)) return $link; |
|
84 | + if (is_numeric($link) || is_null($link)) { |
|
85 | + return $link; |
|
86 | + } |
|
85 | 87 | |
86 | - if (is_object($link)) return $link['id']; |
|
88 | + if (is_object($link)) { |
|
89 | + return $link['id']; |
|
90 | + } |
|
87 | 91 | |
88 | 92 | if (!$useCache || !isset($cache[$link])) { |
89 | 93 | $file = self::create()->tryLoadBy('link', $link); |
@@ -128,10 +132,11 @@ discard block |
||
128 | 132 | throw new FileNotFound('Exception - file not found: ' . $file->ref('content')['path']); |
129 | 133 | } |
130 | 134 | } catch (\Exception $exception) { |
131 | - if ($throwException) |
|
132 | - throw $exception; |
|
133 | - else |
|
134 | - return false; |
|
135 | + if ($throwException) { |
|
136 | + throw $exception; |
|
137 | + } else { |
|
138 | + return false; |
|
139 | + } |
|
135 | 140 | } |
136 | 141 | |
137 | 142 | return true; |
@@ -221,7 +226,9 @@ discard block |
||
221 | 226 | |
222 | 227 | public static function getThumbnailField($model) |
223 | 228 | { |
224 | - if (! $model->thumbnailPossible()) return false; |
|
229 | + if (! $model->thumbnailPossible()) { |
|
230 | + return false; |
|
231 | + } |
|
225 | 232 | |
226 | 233 | $image = new \Imagick($model->ref('content')['path'] . '[0]'); |
227 | 234 |
@@ -8,21 +8,21 @@ |
||
8 | 8 | |
9 | 9 | class FileAccessLog extends Model |
10 | 10 | { |
11 | - use HasEpesiConnection; |
|
11 | + use HasEpesiConnection; |
|
12 | 12 | |
13 | - public $table = 'filestorage_access_log'; |
|
13 | + public $table = 'filestorage_access_log'; |
|
14 | 14 | |
15 | - function init() { |
|
16 | - parent::init(); |
|
15 | + function init() { |
|
16 | + parent::init(); |
|
17 | 17 | |
18 | - $this->addFields([ |
|
19 | - 'file_id', |
|
20 | - 'accessed_at' => ['caption' => __('Accessed At'), 'type' => 'datetime'], |
|
21 | - 'action' => ['caption' => __('Action'), 'type' => 'enum', 'values' => ['download' => __('Download'), 'preview' => __('Preview'), 'inline' => __('Inline')]], |
|
22 | - 'ip_address' => ['caption' => __('IP Address')], |
|
23 | - 'host_name' => ['caption' => __('Host Name')] |
|
24 | - ]); |
|
18 | + $this->addFields([ |
|
19 | + 'file_id', |
|
20 | + 'accessed_at' => ['caption' => __('Accessed At'), 'type' => 'datetime'], |
|
21 | + 'action' => ['caption' => __('Action'), 'type' => 'enum', 'values' => ['download' => __('Download'), 'preview' => __('Preview'), 'inline' => __('Inline')]], |
|
22 | + 'ip_address' => ['caption' => __('IP Address')], |
|
23 | + 'host_name' => ['caption' => __('Host Name')] |
|
24 | + ]); |
|
25 | 25 | |
26 | - $this->hasOne('accessed_by', [User::class, 'our_field' => 'accessed_by'])->addTitle(['field' => 'accessed_by_user', 'caption' => __('Accessed By')]); |
|
27 | - } |
|
26 | + $this->hasOne('accessed_by', [User::class, 'our_field' => 'accessed_by'])->addTitle(['field' => 'accessed_by_user', 'caption' => __('Accessed By')]); |
|
27 | + } |
|
28 | 28 | } |
29 | 29 | \ No newline at end of file |
@@ -9,50 +9,50 @@ |
||
9 | 9 | |
10 | 10 | class FileRemoteAccess extends Model |
11 | 11 | { |
12 | - use HasEpesiConnection; |
|
12 | + use HasEpesiConnection; |
|
13 | 13 | |
14 | - const DEFAULT_PERIOD = '1 week'; |
|
14 | + const DEFAULT_PERIOD = '1 week'; |
|
15 | 15 | |
16 | - public $table = 'filestorage_remote_access'; |
|
16 | + public $table = 'filestorage_remote_access'; |
|
17 | 17 | |
18 | - public function init() |
|
19 | - { |
|
20 | - parent::init(); |
|
18 | + public function init() |
|
19 | + { |
|
20 | + parent::init(); |
|
21 | 21 | |
22 | - $this->addFields([ |
|
23 | - 'token', |
|
24 | - 'expires_at' => ['type' => 'datetime'], |
|
25 | - ]); |
|
22 | + $this->addFields([ |
|
23 | + 'token', |
|
24 | + 'expires_at' => ['type' => 'datetime'], |
|
25 | + ]); |
|
26 | 26 | |
27 | - $this->hasOne('file_id', File::class)->addTitle(['field' => 'file', 'caption' => __('File Name')]); |
|
28 | - $this->hasOne('created_by', User::class)->addTitle(['field' => 'created_by_user', 'caption' => __('Created By')]); |
|
27 | + $this->hasOne('file_id', File::class)->addTitle(['field' => 'file', 'caption' => __('File Name')]); |
|
28 | + $this->hasOne('created_by', User::class)->addTitle(['field' => 'created_by_user', 'caption' => __('Created By')]); |
|
29 | 29 | |
30 | - $this->addCalculatedField('href', [[__CLASS__, 'getHrefField']]); |
|
31 | - } |
|
30 | + $this->addCalculatedField('href', [[__CLASS__, 'getHrefField']]); |
|
31 | + } |
|
32 | 32 | |
33 | - public static function check($fileId, $token) |
|
34 | - { |
|
35 | - return (bool) self::create() |
|
36 | - ->addCrits([ |
|
37 | - ['file_id', $fileId], |
|
38 | - ['token', $token], |
|
39 | - ['expires_at', '>', date('Y-m-d H:i:s')] |
|
40 | - ]) |
|
41 | - ->action('count')->getOne(); |
|
42 | - } |
|
33 | + public static function check($fileId, $token) |
|
34 | + { |
|
35 | + return (bool) self::create() |
|
36 | + ->addCrits([ |
|
37 | + ['file_id', $fileId], |
|
38 | + ['token', $token], |
|
39 | + ['expires_at', '>', date('Y-m-d H:i:s')] |
|
40 | + ]) |
|
41 | + ->action('count')->getOne(); |
|
42 | + } |
|
43 | 43 | |
44 | - public static function grant($file, $expires = self::DEFAULT_PERIOD) |
|
45 | - { |
|
44 | + public static function grant($file, $expires = self::DEFAULT_PERIOD) |
|
45 | + { |
|
46 | 46 | return self::create()->insert([ |
47 | 47 | 'file_id' => is_numeric($file)? $file: $file->id, |
48 | 48 | 'token' => md5(uniqid(rand(), true)), |
49 | 49 | 'created_by' => Auth::id()?: 0, |
50 | 50 | 'expires_at' => date('Y-m-d H:i:s', strtotime($expires)), |
51 | 51 | ]); |
52 | - } |
|
52 | + } |
|
53 | 53 | |
54 | - public static function getHrefField($model) |
|
55 | - { |
|
56 | - return url('file') . '?' . http_build_query(['id' => $model['file_id'], 'token' => $model['token']]); |
|
57 | - } |
|
54 | + public static function getHrefField($model) |
|
55 | + { |
|
56 | + return url('file') . '?' . http_build_query(['id' => $model['file_id'], 'token' => $model['token']]); |
|
57 | + } |
|
58 | 58 | } |
59 | 59 | \ No newline at end of file |
@@ -44,9 +44,9 @@ |
||
44 | 44 | public static function grant($file, $expires = self::DEFAULT_PERIOD) |
45 | 45 | { |
46 | 46 | return self::create()->insert([ |
47 | - 'file_id' => is_numeric($file)? $file: $file->id, |
|
47 | + 'file_id' => is_numeric($file) ? $file : $file->id, |
|
48 | 48 | 'token' => md5(uniqid(rand(), true)), |
49 | - 'created_by' => Auth::id()?: 0, |
|
49 | + 'created_by' => Auth::id() ?: 0, |
|
50 | 50 | 'expires_at' => date('Y-m-d H:i:s', strtotime($expires)), |
51 | 51 | ]); |
52 | 52 | } |
@@ -10,135 +10,135 @@ |
||
10 | 10 | |
11 | 11 | class FileContent extends Model |
12 | 12 | { |
13 | - use HasEpesiConnection; |
|
13 | + use HasEpesiConnection; |
|
14 | 14 | |
15 | 15 | const HASH_METHOD = 'sha512'; |
16 | 16 | |
17 | 17 | public $table = 'filestorage_contents'; |
18 | 18 | |
19 | - protected $appends = ['path']; |
|
19 | + protected $appends = ['path']; |
|
20 | 20 | |
21 | - function init(){ |
|
22 | - parent::init(); |
|
21 | + function init(){ |
|
22 | + parent::init(); |
|
23 | 23 | |
24 | - $this->addFields([ |
|
25 | - 'hash', |
|
26 | - 'size', |
|
27 | - 'type' |
|
28 | - ]); |
|
24 | + $this->addFields([ |
|
25 | + 'hash', |
|
26 | + 'size', |
|
27 | + 'type' |
|
28 | + ]); |
|
29 | 29 | |
30 | - $this->hasMany('files', [File::class, 'their_field' => 'content_id']); |
|
31 | - $this->addCalculatedField('storage_path', [[__CLASS__, 'getStoragePathField']]); |
|
32 | - $this->addCalculatedField('path', [[__CLASS__, 'getPathField']]); |
|
33 | - $this->addCalculatedField('data', [[__CLASS__, 'getDataField']]); |
|
34 | - } |
|
30 | + $this->hasMany('files', [File::class, 'their_field' => 'content_id']); |
|
31 | + $this->addCalculatedField('storage_path', [[__CLASS__, 'getStoragePathField']]); |
|
32 | + $this->addCalculatedField('path', [[__CLASS__, 'getPathField']]); |
|
33 | + $this->addCalculatedField('data', [[__CLASS__, 'getDataField']]); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * One content can have many files associated with |
|
38 | - * The actual content is stored only once based on the content hash |
|
39 | - * |
|
40 | - * @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
41 | - */ |
|
42 | - public function files() |
|
43 | - { |
|
44 | - return $this->ref('files'); |
|
45 | - } |
|
36 | + /** |
|
37 | + * One content can have many files associated with |
|
38 | + * The actual content is stored only once based on the content hash |
|
39 | + * |
|
40 | + * @return \Illuminate\Database\Eloquent\Relations\HasMany |
|
41 | + */ |
|
42 | + public function files() |
|
43 | + { |
|
44 | + return $this->ref('files'); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Accessor method for retrieving of file content path when using the model |
|
49 | - * Having the $appends property in the File model listing the 'path' makes sure the value is also exported to arrays |
|
50 | - * |
|
51 | - * @return string |
|
52 | - */ |
|
53 | - public static function getPathField($model) |
|
54 | - { |
|
55 | - return self::storage()->path($model->getStoragePath($model->get('hash'))); |
|
56 | - } |
|
47 | + /** |
|
48 | + * Accessor method for retrieving of file content path when using the model |
|
49 | + * Having the $appends property in the File model listing the 'path' makes sure the value is also exported to arrays |
|
50 | + * |
|
51 | + * @return string |
|
52 | + */ |
|
53 | + public static function getPathField($model) |
|
54 | + { |
|
55 | + return self::storage()->path($model->getStoragePath($model->get('hash'))); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Accessor method for retrieving of file contents |
|
60 | - * |
|
61 | - * @return string |
|
62 | - */ |
|
63 | - public static function getDataField($model) |
|
64 | - { |
|
65 | - return self::storage()->get($model->get('storage_path')); |
|
66 | - } |
|
58 | + /** |
|
59 | + * Accessor method for retrieving of file contents |
|
60 | + * |
|
61 | + * @return string |
|
62 | + */ |
|
63 | + public static function getDataField($model) |
|
64 | + { |
|
65 | + return self::storage()->get($model->get('storage_path')); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Accessor method for file relative storage path |
|
70 | - * |
|
71 | - * @return string |
|
72 | - */ |
|
73 | - public static function getStoragePathField($model) |
|
74 | - { |
|
75 | - return $model->getStoragePath($model->get('hash')); |
|
76 | - } |
|
68 | + /** |
|
69 | + * Accessor method for file relative storage path |
|
70 | + * |
|
71 | + * @return string |
|
72 | + */ |
|
73 | + public static function getStoragePathField($model) |
|
74 | + { |
|
75 | + return $model->getStoragePath($model->get('hash')); |
|
76 | + } |
|
77 | 77 | |
78 | - protected static function getStoragePath($hash) |
|
79 | - { |
|
80 | - return implode(DIRECTORY_SEPARATOR, array_merge(str_split(substr($hash, 0, 5)), [substr($hash, 5)])); |
|
81 | - } |
|
78 | + protected static function getStoragePath($hash) |
|
79 | + { |
|
80 | + return implode(DIRECTORY_SEPARATOR, array_merge(str_split(substr($hash, 0, 5)), [substr($hash, 5)])); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Returns the storage where file contents are saved based on config settings |
|
85 | - * |
|
86 | - * @return \Illuminate\Contracts\Filesystem\Filesystem |
|
87 | - */ |
|
88 | - public static function storage() |
|
89 | - { |
|
90 | - return Storage::disk(config('epesi.filestorage', 'local')); |
|
91 | - } |
|
83 | + /** |
|
84 | + * Returns the storage where file contents are saved based on config settings |
|
85 | + * |
|
86 | + * @return \Illuminate\Contracts\Filesystem\Filesystem |
|
87 | + */ |
|
88 | + public static function storage() |
|
89 | + { |
|
90 | + return Storage::disk(config('epesi.filestorage', 'local')); |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * Add file to the filestorage |
|
95 | - * |
|
96 | - * @param string $file File path to save |
|
97 | - * |
|
98 | - * @return int File id in the database |
|
99 | - */ |
|
100 | - public static function storeFromFile($file) |
|
101 | - { |
|
102 | - return self::store(file_get_contents($file)); |
|
103 | - } |
|
93 | + /** |
|
94 | + * Add file to the filestorage |
|
95 | + * |
|
96 | + * @param string $file File path to save |
|
97 | + * |
|
98 | + * @return int File id in the database |
|
99 | + */ |
|
100 | + public static function storeFromFile($file) |
|
101 | + { |
|
102 | + return self::store(file_get_contents($file)); |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * Add content to the filestorage |
|
107 | - * |
|
108 | - * @param string $content Content to save |
|
109 | - * |
|
110 | - * @return int File id in the database |
|
111 | - */ |
|
112 | - public static function store($content) |
|
113 | - { |
|
114 | - $hash = self::hash($content); |
|
105 | + /** |
|
106 | + * Add content to the filestorage |
|
107 | + * |
|
108 | + * @param string $content Content to save |
|
109 | + * |
|
110 | + * @return int File id in the database |
|
111 | + */ |
|
112 | + public static function store($content) |
|
113 | + { |
|
114 | + $hash = self::hash($content); |
|
115 | 115 | |
116 | - $path = self::getStoragePath($hash); |
|
116 | + $path = self::getStoragePath($hash); |
|
117 | 117 | |
118 | - if (! self::storage()->exists($path)) { |
|
119 | - self::storage()->put($path, $content); |
|
120 | - } |
|
118 | + if (! self::storage()->exists($path)) { |
|
119 | + self::storage()->put($path, $content); |
|
120 | + } |
|
121 | 121 | |
122 | - $content = self::create()->addCondition('hash', $hash); |
|
122 | + $content = self::create()->addCondition('hash', $hash); |
|
123 | 123 | |
124 | - if (! $content->action('count')->getOne()) { |
|
125 | - return $content->insert([ |
|
126 | - 'size' => self::storage()->size($path), |
|
127 | - 'type' => self::storage()->mimeType($path) |
|
128 | - ]); |
|
129 | - } |
|
124 | + if (! $content->action('count')->getOne()) { |
|
125 | + return $content->insert([ |
|
126 | + 'size' => self::storage()->size($path), |
|
127 | + 'type' => self::storage()->mimeType($path) |
|
128 | + ]); |
|
129 | + } |
|
130 | 130 | |
131 | - return $content->loadAny()->get('id'); |
|
132 | - } |
|
131 | + return $content->loadAny()->get('id'); |
|
132 | + } |
|
133 | 133 | |
134 | - /** |
|
135 | - * Get the hash of the content using hash method defined as constant to the class |
|
136 | - * |
|
137 | - * @param string $content |
|
138 | - * @return string |
|
139 | - */ |
|
140 | - public static function hash($content) |
|
141 | - { |
|
142 | - return hash(self::HASH_METHOD, $content); |
|
143 | - } |
|
134 | + /** |
|
135 | + * Get the hash of the content using hash method defined as constant to the class |
|
136 | + * |
|
137 | + * @param string $content |
|
138 | + * @return string |
|
139 | + */ |
|
140 | + public static function hash($content) |
|
141 | + { |
|
142 | + return hash(self::HASH_METHOD, $content); |
|
143 | + } |
|
144 | 144 | } |
145 | 145 | \ No newline at end of file |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | |
19 | 19 | protected $appends = ['path']; |
20 | 20 | |
21 | - function init(){ |
|
21 | + function init() { |
|
22 | 22 | parent::init(); |
23 | 23 | |
24 | 24 | $this->addFields([ |
@@ -115,13 +115,13 @@ discard block |
||
115 | 115 | |
116 | 116 | $path = self::getStoragePath($hash); |
117 | 117 | |
118 | - if (! self::storage()->exists($path)) { |
|
118 | + if (!self::storage()->exists($path)) { |
|
119 | 119 | self::storage()->put($path, $content); |
120 | 120 | } |
121 | 121 | |
122 | 122 | $content = self::create()->addCondition('hash', $hash); |
123 | 123 | |
124 | - if (! $content->action('count')->getOne()) { |
|
124 | + if (!$content->action('count')->getOne()) { |
|
125 | 125 | return $content->insert([ |
126 | 126 | 'size' => self::storage()->size($path), |
127 | 127 | 'type' => self::storage()->mimeType($path) |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | */ |
50 | 50 | final public static function getActionUrls($file, $accessParams = []) |
51 | 51 | { |
52 | - $id = is_numeric($file)? $file: $file['id']; |
|
52 | + $id = is_numeric($file) ? $file : $file['id']; |
|
53 | 53 | |
54 | 54 | $urls = []; |
55 | 55 | foreach (static::$allowedActions as $action) { |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | */ |
67 | 67 | final protected function hasUserAccess() |
68 | 68 | { |
69 | - return $this->forUsersOnly? (bool) Auth::id(): true; |
|
69 | + return $this->forUsersOnly ? (bool) Auth::id() : true; |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -6,30 +6,30 @@ |
||
6 | 6 | |
7 | 7 | class FileStorageAccess |
8 | 8 | { |
9 | - public function handle($request, \Closure $next) |
|
10 | - { |
|
11 | - foreach (Integration\Joints\FileStorageAccessJoint::collect() as $joint) { |
|
12 | - if ($joint->accessGranted($request)) { |
|
13 | - $this->logFileAccess($request->get('id'), $request->get('action', 'download')); |
|
9 | + public function handle($request, \Closure $next) |
|
10 | + { |
|
11 | + foreach (Integration\Joints\FileStorageAccessJoint::collect() as $joint) { |
|
12 | + if ($joint->accessGranted($request)) { |
|
13 | + $this->logFileAccess($request->get('id'), $request->get('action', 'download')); |
|
14 | 14 | |
15 | - return $next($request); |
|
16 | - } |
|
17 | - } |
|
15 | + return $next($request); |
|
16 | + } |
|
17 | + } |
|
18 | 18 | |
19 | - return response('No access to file', 401); |
|
20 | - } |
|
19 | + return response('No access to file', 401); |
|
20 | + } |
|
21 | 21 | |
22 | - protected function logFileAccess($fileId, $action, $time = null) |
|
23 | - { |
|
24 | - $ip_address = request()->ip(); |
|
22 | + protected function logFileAccess($fileId, $action, $time = null) |
|
23 | + { |
|
24 | + $ip_address = request()->ip(); |
|
25 | 25 | |
26 | - Models\FileAccessLog::create()->insert([ |
|
27 | - 'file_id' => $fileId, |
|
28 | - 'accessed_at' => date('Y-m-d H:i:s', $time ?: time()), |
|
29 | - 'accessed_by' => Auth::id() ?: 0, |
|
30 | - 'action' => $action, |
|
31 | - 'ip_address' => $ip_address, |
|
32 | - 'host_name' => gethostbyaddr($ip_address) |
|
33 | - ]); |
|
34 | - } |
|
26 | + Models\FileAccessLog::create()->insert([ |
|
27 | + 'file_id' => $fileId, |
|
28 | + 'accessed_at' => date('Y-m-d H:i:s', $time ?: time()), |
|
29 | + 'accessed_by' => Auth::id() ?: 0, |
|
30 | + 'action' => $action, |
|
31 | + 'ip_address' => $ip_address, |
|
32 | + 'host_name' => gethostbyaddr($ip_address) |
|
33 | + ]); |
|
34 | + } |
|
35 | 35 | } |