Passed
Branch master (3256e3)
by Georgi
04:17
created
src/FileStorageCore.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@
 block discarded – undo
45 45
 	
46 46
 	public static function boot()
47 47
 	{
48
-		Route::group(['namespace' => 'Epesi\FileStorage'], function(){
48
+		Route::group(['namespace' => 'Epesi\FileStorage'], function() {
49 49
 			Route::get('file', 'FileStorageController@get')->middleware('web', FileStorageAccess::class);
50 50
 		});
51 51
 		
Please login to merge, or discard this patch.
src/FileStorageController.php 2 patches
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -7,49 +7,49 @@
 block discarded – undo
7 7
 
8 8
 class FileStorageController extends Controller
9 9
 {
10
-    public function get(Request $request)
11
-    {
12
-    	try {
13
-    		$meta = Database\Models\Meta::get($request->get('id'));
14
-    	} catch (\Exception $e) {
15
-    		abort(404);
16
-    	}
10
+	public function get(Request $request)
11
+	{
12
+		try {
13
+			$meta = Database\Models\Meta::get($request->get('id'));
14
+		} catch (\Exception $e) {
15
+			abort(404);
16
+		}
17 17
     	
18
-    	$useThumbnail = false;
19
-    	$disposition = 'attachment';
20
-    	switch ($request->get('action')) {	
21
-    		case 'preview':
22
-    			$useThumbnail = true;
23
-    		case 'inline':
24
-    			$disposition = 'inline';
25
-    			break;
18
+		$useThumbnail = false;
19
+		$disposition = 'attachment';
20
+		switch ($request->get('action')) {	
21
+			case 'preview':
22
+				$useThumbnail = true;
23
+			case 'inline':
24
+				$disposition = 'inline';
25
+				break;
26 26
     			
27
-    		default:
28
-    			break;
29
-    	}
27
+			default:
28
+				break;
29
+		}
30 30
 
31
-    	if ($useThumbnail && $request->get('thumbnail', 1) && ($thumbnail = $meta->thumbnail)) {
32
-    		$mime = $thumbnail['mime'];
33
-    		$filename = $thumbnail['name'];
34
-    		$contents = $thumbnail['contents'];
35
-    	}
36
-    	else {
37
-    		$mime = $meta->file->type;
38
-    		$filename = $meta->name;
39
-    		$contents = $meta->file->contents;
40
-    	}
31
+		if ($useThumbnail && $request->get('thumbnail', 1) && ($thumbnail = $meta->thumbnail)) {
32
+			$mime = $thumbnail['mime'];
33
+			$filename = $thumbnail['name'];
34
+			$contents = $thumbnail['contents'];
35
+		}
36
+		else {
37
+			$mime = $meta->file->type;
38
+			$filename = $meta->name;
39
+			$contents = $meta->file->contents;
40
+		}
41 41
 
42
-    	$headers = [
43
-    			'Content-Type' => $mime,
44
-    			'Content-Length' => strlen($contents),
45
-    			'Content-Disposition' => "$disposition; filename=\"$filename\"",
46
-    	];
42
+		$headers = [
43
+				'Content-Type' => $mime,
44
+				'Content-Length' => strlen($contents),
45
+				'Content-Disposition' => "$disposition; filename=\"$filename\"",
46
+		];
47 47
 
48
-    	if ($request->get('nocache')) {
49
-    		$headers['Pragma'] = 'no-cache';
50
-    		$headers['Expires'] = '0';
51
-    	}
48
+		if ($request->get('nocache')) {
49
+			$headers['Pragma'] = 'no-cache';
50
+			$headers['Expires'] = '0';
51
+		}
52 52
     	
53
-    	return response($contents, 200, $headers);
54
-    }
53
+		return response($contents, 200, $headers);
54
+	}
55 55
 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -32,8 +32,7 @@
 block discarded – undo
32 32
     		$mime = $thumbnail['mime'];
33 33
     		$filename = $thumbnail['name'];
34 34
     		$contents = $thumbnail['contents'];
35
-    	}
36
-    	else {
35
+    	} else {
37 36
     		$mime = $meta->file->type;
38 37
     		$filename = $meta->name;
39 38
     		$contents = $meta->file->contents;
Please login to merge, or discard this patch.
src/FileStorageAccess.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -6,30 +6,30 @@
 block discarded – undo
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($metaId, $action, $time = null)
23
-    {
24
-    	$ip_address = request()->ip();
22
+	protected function logFileAccess($metaId, $action, $time = null)
23
+	{
24
+		$ip_address = request()->ip();
25 25
 
26
-    	Database\Models\AccessLog::create([
27
-    			'meta_id' => $metaId,
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
+		Database\Models\AccessLog::create([
27
+				'meta_id' => $metaId,
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
 }
Please login to merge, or discard this patch.
src/Database/Models/File.php 2 patches
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -13,111 +13,111 @@
 block discarded – undo
13 13
 	
14 14
 	public $timestamps = false;
15 15
 	
16
-    protected $table = 'filestorage_files';
17
-    protected static $unguarded = true;    
16
+	protected $table = 'filestorage_files';
17
+	protected static $unguarded = true;    
18 18
     
19
-    protected $appends = ['path'];
19
+	protected $appends = ['path'];
20 20
     
21
-    /**
22
-     * One file can have many meta datas
23
-     * The actual content is stored only once based on the content hash
24
-     * 
25
-     * @return \Illuminate\Database\Eloquent\Relations\HasMany
26
-     */
27
-    public function meta()
28
-    {
29
-    	return $this->hasMany(Meta::class, 'file_id');
30
-    }
21
+	/**
22
+	 * One file can have many meta datas
23
+	 * The actual content is stored only once based on the content hash
24
+	 * 
25
+	 * @return \Illuminate\Database\Eloquent\Relations\HasMany
26
+	 */
27
+	public function meta()
28
+	{
29
+		return $this->hasMany(Meta::class, 'file_id');
30
+	}
31 31
     
32
-    /**
33
-     * Accessor method for retrieving of file content path when using the model
34
-     * Having the $appends property in the File model listing the 'path' makes sure the value is also exported to arrays
35
-     * 
36
-     * @return string
37
-     */
38
-    public function getPathAttribute()
39
-    {
40
-    	return self::storage()->path($this->getStoragePath($this->hash));
41
-    }
32
+	/**
33
+	 * Accessor method for retrieving of file content path when using the model
34
+	 * Having the $appends property in the File model listing the 'path' makes sure the value is also exported to arrays
35
+	 * 
36
+	 * @return string
37
+	 */
38
+	public function getPathAttribute()
39
+	{
40
+		return self::storage()->path($this->getStoragePath($this->hash));
41
+	}
42 42
     
43
-    /**
44
-     * Accessor method for retrieving of file contents
45
-     * 
46
-     * @return string
47
-     */
48
-    public function getContentsAttribute()
49
-    {
50
-    	return self::storage()->get($this->storage_path);
51
-    }
43
+	/**
44
+	 * Accessor method for retrieving of file contents
45
+	 * 
46
+	 * @return string
47
+	 */
48
+	public function getContentsAttribute()
49
+	{
50
+		return self::storage()->get($this->storage_path);
51
+	}
52 52
     
53
-    /**
54
-     * Accessor method for file relative storage path
55
-     * 
56
-     * @return string
57
-     */
58
-    public function getStoragePathAttribute()
59
-    {
60
-    	return $this->getStoragePath($this->hash);
61
-    }
53
+	/**
54
+	 * Accessor method for file relative storage path
55
+	 * 
56
+	 * @return string
57
+	 */
58
+	public function getStoragePathAttribute()
59
+	{
60
+		return $this->getStoragePath($this->hash);
61
+	}
62 62
     
63
-    protected static function getStoragePath($hash)
64
-    {
65
-    	return implode(DIRECTORY_SEPARATOR, array_merge(str_split(substr($hash, 0, 5)), [substr($hash, 5)]));
66
-    }
63
+	protected static function getStoragePath($hash)
64
+	{
65
+		return implode(DIRECTORY_SEPARATOR, array_merge(str_split(substr($hash, 0, 5)), [substr($hash, 5)]));
66
+	}
67 67
     
68
-    /**
69
-     * Returns the storage where file contents are saved based on config settings
70
-     * 
71
-     * @return \Illuminate\Contracts\Filesystem\Filesystem
72
-     */
73
-    public static function storage()
74
-    {
75
-    	return Storage::disk(config('epesi.filestorage', 'local'));
76
-    }
68
+	/**
69
+	 * Returns the storage where file contents are saved based on config settings
70
+	 * 
71
+	 * @return \Illuminate\Contracts\Filesystem\Filesystem
72
+	 */
73
+	public static function storage()
74
+	{
75
+		return Storage::disk(config('epesi.filestorage', 'local'));
76
+	}
77 77
         
78
-    /**
79
-     * Add file to the filestorage
80
-     *
81
-     * @param string $file File path to save
82
-     *
83
-     * @return int File id in the database
84
-     */
85
-    public static function putDataFromFile($file)
86
-    {
87
-    	return self::putData(file_get_contents($file));
88
-    }
78
+	/**
79
+	 * Add file to the filestorage
80
+	 *
81
+	 * @param string $file File path to save
82
+	 *
83
+	 * @return int File id in the database
84
+	 */
85
+	public static function putDataFromFile($file)
86
+	{
87
+		return self::putData(file_get_contents($file));
88
+	}
89 89
     
90
-    /**
91
-     * Add content to the filestorage
92
-     *
93
-     * @param string $content Content to save
94
-     *
95
-     * @return int File id in the database
96
-     */
97
-    public static function putData($content)
98
-    {
99
-    	$hash = self::hashContent($content);
90
+	/**
91
+	 * Add content to the filestorage
92
+	 *
93
+	 * @param string $content Content to save
94
+	 *
95
+	 * @return int File id in the database
96
+	 */
97
+	public static function putData($content)
98
+	{
99
+		$hash = self::hashContent($content);
100 100
     	
101
-    	$path = self::getStoragePath($hash);
101
+		$path = self::getStoragePath($hash);
102 102
     	
103
-    	if (! self::storage()->exists($path)) {
104
-    		self::storage()->put($path, $content);
105
-    	}
103
+		if (! self::storage()->exists($path)) {
104
+			self::storage()->put($path, $content);
105
+		}
106 106
     	
107
-    	return self::firstOrCreate(compact('hash'), [
108
-    			'size' => self::storage()->size($path),
109
-    			'type' => self::storage()->mimeType($path)
110
-    	])->id;
111
-    }
107
+		return self::firstOrCreate(compact('hash'), [
108
+				'size' => self::storage()->size($path),
109
+				'type' => self::storage()->mimeType($path)
110
+		])->id;
111
+	}
112 112
     
113
-    /**
114
-     * Get the hash of the content using hash method defined as constant to the class
115
-     * 
116
-     * @param string $content
117
-     * @return string
118
-     */
119
-    public static function hashContent($content)
120
-    {
121
-    	return hash(self::HASH_METHOD, $content);
122
-    }
113
+	/**
114
+	 * Get the hash of the content using hash method defined as constant to the class
115
+	 * 
116
+	 * @param string $content
117
+	 * @return string
118
+	 */
119
+	public static function hashContent($content)
120
+	{
121
+		return hash(self::HASH_METHOD, $content);
122
+	}
123 123
 }
124 124
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -100,7 +100,7 @@
 block discarded – undo
100 100
     	
101 101
     	$path = self::getStoragePath($hash);
102 102
     	
103
-    	if (! self::storage()->exists($path)) {
103
+    	if (!self::storage()->exists($path)) {
104 104
     		self::storage()->put($path, $content);
105 105
     	}
106 106
     	
Please login to merge, or discard this patch.
src/Database/Models/Meta.php 3 patches
Indentation   +159 added lines, -159 removed lines patch added patch discarded remove patch
@@ -15,205 +15,205 @@
 block discarded – undo
15 15
 {
16 16
 	use SoftDeletes;
17 17
 	
18
-    protected $table = 'filestorage_meta';
19
-    protected static $unguarded = true;
18
+	protected $table = 'filestorage_meta';
19
+	protected static $unguarded = true;
20 20
     
21
-    public function file()
22
-    {
23
-    	return $this->belongsTo(File::class, 'file_id');
24
-    }
21
+	public function file()
22
+	{
23
+		return $this->belongsTo(File::class, 'file_id');
24
+	}
25 25
     
26
-    /**
27
-     * Retrieve meta info about the file
28
-     *
29
-     * @param int|string $idOrLink Filestorage ID or unique link string
30
-     * @param bool $useCache Use cache or not
31
-     *
32
-     * @return array Metadata about the file.
33
-     *               Keys in array: hash, file, filename, link, backref,
34
-     *               created_at, created_by, deleted, file_id
35
-     * @throws FileNotFound
36
-     * @throws StorageNotFound
37
-     */
38
-    public static function get($idOrLink, $useCache = true)
39
-    {
40
-    	static $cache = [];
26
+	/**
27
+	 * Retrieve meta info about the file
28
+	 *
29
+	 * @param int|string $idOrLink Filestorage ID or unique link string
30
+	 * @param bool $useCache Use cache or not
31
+	 *
32
+	 * @return array Metadata about the file.
33
+	 *               Keys in array: hash, file, filename, link, backref,
34
+	 *               created_at, created_by, deleted, file_id
35
+	 * @throws FileNotFound
36
+	 * @throws StorageNotFound
37
+	 */
38
+	public static function get($idOrLink, $useCache = true)
39
+	{
40
+		static $cache = [];
41 41
 
42
-    	$id = self::getIdByLink($idOrLink, true, true);
42
+		$id = self::getIdByLink($idOrLink, true, true);
43 43
 
44
-    	if ($useCache && isset($cache[$id])) {
45
-    		return $cache[$id];
46
-    	}
44
+		if ($useCache && isset($cache[$id])) {
45
+			return $cache[$id];
46
+		}
47 47
 
48
-    	if (! $meta = self::with('file')->find($id)) {
49
-    		throw new StorageNotFound('Exception - DB storage object not found: ' . $id);
50
-    	}
48
+		if (! $meta = self::with('file')->find($id)) {
49
+			throw new StorageNotFound('Exception - DB storage object not found: ' . $id);
50
+		}
51 51
 
52
-    	if (empty($meta->file['hash'])) {
53
-    		throw new FileNotFound('File object does not have corresponding file hash');
54
-    	}
52
+		if (empty($meta->file['hash'])) {
53
+			throw new FileNotFound('File object does not have corresponding file hash');
54
+		}
55 55
 
56
-    	return $cache[$id] = $meta;
57
-    }
56
+		return $cache[$id] = $meta;
57
+	}
58 58
     
59
-    /**
60
-     * Get Filestorage ID by link
61
-     *
62
-     * @param string $link            Unique link
63
-     * @param bool   $useCache       Use cache or not
64
-     * @param bool   $throwException Throw exception if link is not found
65
-     *
66
-     * @return int Filestorage ID
67
-     * @throws LinkNotFound
68
-     */
69
-    public static function getIdByLink($link, $useCache = true, $throwException = false)
70
-    {
71
-    	static $cache = [];
59
+	/**
60
+	 * Get Filestorage ID by link
61
+	 *
62
+	 * @param string $link            Unique link
63
+	 * @param bool   $useCache       Use cache or not
64
+	 * @param bool   $throwException Throw exception if link is not found
65
+	 *
66
+	 * @return int Filestorage ID
67
+	 * @throws LinkNotFound
68
+	 */
69
+	public static function getIdByLink($link, $useCache = true, $throwException = false)
70
+	{
71
+		static $cache = [];
72 72
     	
73
-    	if (is_numeric($link)) return $link;
73
+		if (is_numeric($link)) return $link;
74 74
     	
75
-    	if (!$useCache || !isset($cache[$link])) {
76
-    		$cache[$link] = self::where('link', $link)->value('id');
75
+		if (!$useCache || !isset($cache[$link])) {
76
+			$cache[$link] = self::where('link', $link)->value('id');
77 77
     		
78
-    		if (!$cache[$link] && $throwException) {
79
-    			throw new LinkNotFound($link);
80
-    		}
81
-    	}
78
+			if (!$cache[$link] && $throwException) {
79
+				throw new LinkNotFound($link);
80
+			}
81
+		}
82 82
     	
83
-    	return $cache[$link];
84
-    }
83
+		return $cache[$link];
84
+	}
85 85
 
86
-    /**
87
-     * Mark file as deleted. Does not remove any content!
88
-     *
89
-     * @param int|string $idOrLink Filestorage ID or unique link
90
-     */
91
-    public static function deleteFile($idOrLink)
92
-    {
86
+	/**
87
+	 * Mark file as deleted. Does not remove any content!
88
+	 *
89
+	 * @param int|string $idOrLink Filestorage ID or unique link
90
+	 */
91
+	public static function deleteFile($idOrLink)
92
+	{
93 93
    		if ($id = self::getIdByLink($idOrLink, false)) {
94 94
    			self::find($id)->delete();
95
-    	}
96
-    }
95
+		}
96
+	}
97 97
     
98
-    /**
99
-     * Check if file exists
100
-     *
101
-     * @param int|static $idOrMeta              Filestorage ID or meta object
102
-     * @param bool      $throwException Throw exception on missing file or return false
103
-     *
104
-     * @return bool True if file exists, false otherwise
105
-     * @throws FileNotFound May be thrown if $throwException set to true
106
-     */
107
-    public static function fileExists($idOrMeta, $throwException = false)
108
-    {
109
-    	try {
110
-    		$meta = is_numeric($idOrMeta) ? self::get($idOrMeta) : $idOrMeta;
98
+	/**
99
+	 * Check if file exists
100
+	 *
101
+	 * @param int|static $idOrMeta              Filestorage ID or meta object
102
+	 * @param bool      $throwException Throw exception on missing file or return false
103
+	 *
104
+	 * @return bool True if file exists, false otherwise
105
+	 * @throws FileNotFound May be thrown if $throwException set to true
106
+	 */
107
+	public static function fileExists($idOrMeta, $throwException = false)
108
+	{
109
+		try {
110
+			$meta = is_numeric($idOrMeta) ? self::get($idOrMeta) : $idOrMeta;
111 111
     		
112
-    		if (! file_exists($meta->file->path)) {
113
-    			throw new FileNotFound('Exception - file not found: ' . $meta->file->path);
114
-    		}
115
-    	} catch (\Exception $exception) {
116
-    		if ($throwException)
117
-    			throw $exception;
118
-    		else
119
-    			return false;
120
-    	}
112
+			if (! file_exists($meta->file->path)) {
113
+				throw new FileNotFound('Exception - file not found: ' . $meta->file->path);
114
+			}
115
+		} catch (\Exception $exception) {
116
+			if ($throwException)
117
+				throw $exception;
118
+			else
119
+				return false;
120
+		}
121 121
     	
122
-    	return true;
123
-    }
122
+		return true;
123
+	}
124 124
     
125
-    /**
126
-     * Add multiple files, clone file if file id is provided.
127
-     * May be used to update backref for all files.
128
-     *
129
-     * @param array $files array of existing filestorage ids or array with values for the new file
130
-     * @param string|null $backref Backref for all files
131
-     * @return array Newly created Meta Ids sorted in ascending order
132
-     */
133
-    public static function putMany($files, $backref = null)
134
-    {
135
-    	$ids = [];
136
-    	foreach ((array) $files as $file) {
137
-    		if (! is_numeric($file)) {
138
-    			$ids[] = self::put($file);
125
+	/**
126
+	 * Add multiple files, clone file if file id is provided.
127
+	 * May be used to update backref for all files.
128
+	 *
129
+	 * @param array $files array of existing filestorage ids or array with values for the new file
130
+	 * @param string|null $backref Backref for all files
131
+	 * @return array Newly created Meta Ids sorted in ascending order
132
+	 */
133
+	public static function putMany($files, $backref = null)
134
+	{
135
+		$ids = [];
136
+		foreach ((array) $files as $file) {
137
+			if (! is_numeric($file)) {
138
+				$ids[] = self::put($file);
139 139
     			
140
-    			continue;
141
-    		}
140
+				continue;
141
+			}
142 142
     		
143
-    		$meta = self::get($file, false)->toArray();
143
+			$meta = self::get($file, false)->toArray();
144 144
     			
145
-    		if ($backref && $meta['backref'] != $backref) {
146
-    			$meta['backref'] = $backref;
147
-    			unset($meta['link']);
145
+			if ($backref && $meta['backref'] != $backref) {
146
+				$meta['backref'] = $backref;
147
+				unset($meta['link']);
148 148
     			
149
-    			self::put($meta);
150
-    		}
149
+				self::put($meta);
150
+			}
151 151
     			
152
-    		$ids[] = $file;
153
-    	}
152
+			$ids[] = $file;
153
+		}
154 154
     	
155
-    	sort($ids);
155
+		sort($ids);
156 156
     	
157
-    	return $ids;
158
-    }
157
+		return $ids;
158
+	}
159 159
         
160
-    /**
161
-     * @param string|array     $metaOrFile
162
-     * @param string     $content    Content of the file
163
-     * 
164
-     * @return int Filestorage ID
165
-     * @throws LinkDuplicate
166
-     */
167
-    public static function put($metaOrFile, $content = null) 
168
-    {
169
-    	$meta = $metaOrFile;
170
-    	if (! $content && is_string($metaOrFile)) {
171
-    		$content = file_get_contents($metaOrFile);
160
+	/**
161
+	 * @param string|array     $metaOrFile
162
+	 * @param string     $content    Content of the file
163
+	 * 
164
+	 * @return int Filestorage ID
165
+	 * @throws LinkDuplicate
166
+	 */
167
+	public static function put($metaOrFile, $content = null) 
168
+	{
169
+		$meta = $metaOrFile;
170
+		if (! $content && is_string($metaOrFile)) {
171
+			$content = file_get_contents($metaOrFile);
172 172
     		
173
-    		$meta = [
174
-    				'name' => basename($metaOrFile)
175
-    		];
176
-    	}
173
+			$meta = [
174
+					'name' => basename($metaOrFile)
175
+			];
176
+		}
177 177
     	
178
-    	if (!empty($meta['link']) && self::getIdByLink($meta['link'], false)) {
179
-    		throw new LinkDuplicate($meta['link']);
180
-    	}
178
+		if (!empty($meta['link']) && self::getIdByLink($meta['link'], false)) {
179
+			throw new LinkDuplicate($meta['link']);
180
+		}
181 181
     	
182
-    	if ($file = $meta['file']?? null) {
183
-    		$path = is_array($file)? $file['path']: $file;
182
+		if ($file = $meta['file']?? null) {
183
+			$path = is_array($file)? $file['path']: $file;
184 184
     		
185
-    		$meta['name'] = $meta['name']?? basename($path);
185
+			$meta['name'] = $meta['name']?? basename($path);
186 186
     		
187
-    		$content = $content?: file_get_contents($path);
187
+			$content = $content?: file_get_contents($path);
188 188
     		
189
-    		unset($meta['file']);
190
-    	}
189
+			unset($meta['file']);
190
+		}
191 191
 	
192
-    	return self::updateOrCreate(['id' => $meta['id']?? null], array_merge([
193
-    			'created_at' => time(),
194
-    			'created_by' => Auth::id(),
195
-    			'file_id' => File::putData($meta['content']?? $content)
196
-    	], $meta))->id;
197
-    }
192
+		return self::updateOrCreate(['id' => $meta['id']?? null], array_merge([
193
+				'created_at' => time(),
194
+				'created_by' => Auth::id(),
195
+				'file_id' => File::putData($meta['content']?? $content)
196
+		], $meta))->id;
197
+	}
198 198
     
199
-    public function getThumbnailAttribute()
200
-    {
201
-    	if (! $this->thumbnailPossible()) return false;
199
+	public function getThumbnailAttribute()
200
+	{
201
+		if (! $this->thumbnailPossible()) return false;
202 202
     	
203
-    	$image = new \Imagick($this->meta->file->path . '[0]');
203
+		$image = new \Imagick($this->meta->file->path . '[0]');
204 204
     	
205
-    	$image->setImageFormat('jpg');
205
+		$image->setImageFormat('jpg');
206 206
     	
207
-    	$mime = 'image/jpeg';
207
+		$mime = 'image/jpeg';
208 208
     	
209
-    	$name = 'preview.jpeg';
209
+		$name = 'preview.jpeg';
210 210
     	
211
-    	$contents = $image . '';
211
+		$contents = $image . '';
212 212
     	
213
-    	return collect(compact('mime', 'name', 'contents'));
214
-    }
213
+		return collect(compact('mime', 'name', 'contents'));
214
+	}
215 215
     
216
-    protected function thumbnailPossible() {
217
-    	return $this->file->type == 'application/pdf' && class_exists('Imagick');
218
-    }
216
+	protected function thumbnailPossible() {
217
+		return $this->file->type == 'application/pdf' && class_exists('Imagick');
218
+	}
219 219
 }
220 220
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
     		return $cache[$id];
46 46
     	}
47 47
 
48
-    	if (! $meta = self::with('file')->find($id)) {
48
+    	if (!$meta = self::with('file')->find($id)) {
49 49
     		throw new StorageNotFound('Exception - DB storage object not found: ' . $id);
50 50
     	}
51 51
 
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
     	try {
110 110
     		$meta = is_numeric($idOrMeta) ? self::get($idOrMeta) : $idOrMeta;
111 111
     		
112
-    		if (! file_exists($meta->file->path)) {
112
+    		if (!file_exists($meta->file->path)) {
113 113
     			throw new FileNotFound('Exception - file not found: ' . $meta->file->path);
114 114
     		}
115 115
     	} catch (\Exception $exception) {
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
     {
135 135
     	$ids = [];
136 136
     	foreach ((array) $files as $file) {
137
-    		if (! is_numeric($file)) {
137
+    		if (!is_numeric($file)) {
138 138
     			$ids[] = self::put($file);
139 139
     			
140 140
     			continue;
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
     public static function put($metaOrFile, $content = null) 
168 168
     {
169 169
     	$meta = $metaOrFile;
170
-    	if (! $content && is_string($metaOrFile)) {
170
+    	if (!$content && is_string($metaOrFile)) {
171 171
     		$content = file_get_contents($metaOrFile);
172 172
     		
173 173
     		$meta = [
@@ -180,11 +180,11 @@  discard block
 block discarded – undo
180 180
     	}
181 181
     	
182 182
     	if ($file = $meta['file']?? null) {
183
-    		$path = is_array($file)? $file['path']: $file;
183
+    		$path = is_array($file) ? $file['path'] : $file;
184 184
     		
185 185
     		$meta['name'] = $meta['name']?? basename($path);
186 186
     		
187
-    		$content = $content?: file_get_contents($path);
187
+    		$content = $content ?: file_get_contents($path);
188 188
     		
189 189
     		unset($meta['file']);
190 190
     	}
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
     
199 199
     public function getThumbnailAttribute()
200 200
     {
201
-    	if (! $this->thumbnailPossible()) return false;
201
+    	if (!$this->thumbnailPossible()) return false;
202 202
     	
203 203
     	$image = new \Imagick($this->meta->file->path . '[0]');
204 204
     	
Please login to merge, or discard this patch.
Braces   +11 added lines, -6 removed lines patch added patch discarded remove patch
@@ -70,7 +70,9 @@  discard block
 block discarded – undo
70 70
     {
71 71
     	static $cache = [];
72 72
     	
73
-    	if (is_numeric($link)) return $link;
73
+    	if (is_numeric($link)) {
74
+    		return $link;
75
+    	}
74 76
     	
75 77
     	if (!$useCache || !isset($cache[$link])) {
76 78
     		$cache[$link] = self::where('link', $link)->value('id');
@@ -113,10 +115,11 @@  discard block
 block discarded – undo
113 115
     			throw new FileNotFound('Exception - file not found: ' . $meta->file->path);
114 116
     		}
115 117
     	} catch (\Exception $exception) {
116
-    		if ($throwException)
117
-    			throw $exception;
118
-    		else
119
-    			return false;
118
+    		if ($throwException) {
119
+    		    			throw $exception;
120
+    		} else {
121
+    		    			return false;
122
+    		}
120 123
     	}
121 124
     	
122 125
     	return true;
@@ -198,7 +201,9 @@  discard block
 block discarded – undo
198 201
     
199 202
     public function getThumbnailAttribute()
200 203
     {
201
-    	if (! $this->thumbnailPossible()) return false;
204
+    	if (! $this->thumbnailPossible()) {
205
+    		return false;
206
+    	}
202 207
     	
203 208
     	$image = new \Imagick($this->meta->file->path . '[0]');
204 209
     	
Please login to merge, or discard this patch.
src/Database/Models/AccessLog.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@
 block discarded – undo
8 8
     
9 9
 	public $timestamps = false;
10 10
 	
11
-    protected $table = 'filestorage_access_log';
12
-    protected static $unguarded = true;    
11
+	protected $table = 'filestorage_access_log';
12
+	protected static $unguarded = true;    
13 13
 
14 14
 }
15 15
\ No newline at end of file
Please login to merge, or discard this patch.
src/Database/Models/Remote.php 2 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -6,23 +6,23 @@
 block discarded – undo
6 6
 use Illuminate\Support\Facades\Auth;
7 7
 
8 8
 class Remote extends Model {
9
-    const DEFAULT_PERIOD = '1 week';
9
+	const DEFAULT_PERIOD = '1 week';
10 10
     
11
-    protected $table = 'filestorage_remote';
12
-    protected static $unguarded = true;    
11
+	protected $table = 'filestorage_remote';
12
+	protected static $unguarded = true;    
13 13
 
14
-    public static function access($metaId, $token)
15
-    {
16
-    	return (bool) self::where('meta_id', $metaId)->where('token', $token)->where('expires_at', '>', date('Y-m-d H:i:s'))->count();
17
-    }
14
+	public static function access($metaId, $token)
15
+	{
16
+		return (bool) self::where('meta_id', $metaId)->where('token', $token)->where('expires_at', '>', date('Y-m-d H:i:s'))->count();
17
+	}
18 18
     
19
-    public static function grant($metaId, $expires = self::DEFAULT_PERIOD)
20
-    {
19
+	public static function grant($metaId, $expires = self::DEFAULT_PERIOD)
20
+	{
21 21
 		return self::create([
22 22
 				'meta_id' => $metaId,
23 23
 				'token' => md5(uniqid(rand(), true)),
24 24
 				'created_by' => Auth::id()?: 0,
25 25
 				'expires_at' => date('Y-m-d H:i:s', strtotime($expires)),
26 26
 		]);
27
-    }
27
+	}
28 28
 }
29 29
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@
 block discarded – undo
21 21
 		return self::create([
22 22
 				'meta_id' => $metaId,
23 23
 				'token' => md5(uniqid(rand(), true)),
24
-				'created_by' => Auth::id()?: 0,
24
+				'created_by' => Auth::id() ?: 0,
25 25
 				'expires_at' => date('Y-m-d H:i:s', strtotime($expires)),
26 26
 		]);
27 27
     }
Please login to merge, or discard this patch.
src/Database/Migrations/2019_11_16_091615_create_filestorage_tables.php 2 patches
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -6,74 +6,74 @@
 block discarded – undo
6 6
 
7 7
 class CreateFilestorageTables extends Migration
8 8
 {
9
-    /**
10
-     * Run the migrations.
11
-     *
12
-     * @return void
13
-     */
14
-    public function up()
15
-    {
16
-    	$this->down();
9
+	/**
10
+	 * Run the migrations.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function up()
15
+	{
16
+		$this->down();
17 17
     	
18
-        Schema::create('filestorage_files', function (Blueprint $table) {
19
-            $table->bigIncrements('id');
20
-            $table->string('hash', 128);
21
-            $table->integer('size');
22
-            $table->string('type', 256);
18
+		Schema::create('filestorage_files', function (Blueprint $table) {
19
+			$table->bigIncrements('id');
20
+			$table->string('hash', 128);
21
+			$table->integer('size');
22
+			$table->string('type', 256);
23 23
             
24
-            $table->softDeletes();
25
-        });
24
+			$table->softDeletes();
25
+		});
26 26
         
27
-        Schema::create('filestorage_meta', function (Blueprint $table) {
28
-            $table->bigIncrements('id');
29
-            $table->string('name', 256);
30
-            $table->string('link', 128)->nullable();
31
-            $table->string('backref', 128)->nullable();
32
-            $table->unsignedBigInteger('file_id');
33
-            $table->unsignedBigInteger('created_by')->nullable();
34
-            $table->timestamps();
27
+		Schema::create('filestorage_meta', function (Blueprint $table) {
28
+			$table->bigIncrements('id');
29
+			$table->string('name', 256);
30
+			$table->string('link', 128)->nullable();
31
+			$table->string('backref', 128)->nullable();
32
+			$table->unsignedBigInteger('file_id');
33
+			$table->unsignedBigInteger('created_by')->nullable();
34
+			$table->timestamps();
35 35
             
36
-            $table->softDeletes();
36
+			$table->softDeletes();
37 37
             
38
-            $table->foreign('file_id')->references('id')->on('filestorage_files');
39
-            $table->foreign('created_by')->references('id')->on('users');
40
-        });
38
+			$table->foreign('file_id')->references('id')->on('filestorage_files');
39
+			$table->foreign('created_by')->references('id')->on('users');
40
+		});
41 41
         
42
-        Schema::create('filestorage_remote', function (Blueprint $table) {
43
-            $table->bigIncrements('id');
44
-            $table->unsignedBigInteger('meta_id');            
45
-            $table->string('token', 128);
46
-            $table->unsignedBigInteger('created_by');
47
-            $table->timestamp('expires_at');
48
-            $table->timestamps();
42
+		Schema::create('filestorage_remote', function (Blueprint $table) {
43
+			$table->bigIncrements('id');
44
+			$table->unsignedBigInteger('meta_id');            
45
+			$table->string('token', 128);
46
+			$table->unsignedBigInteger('created_by');
47
+			$table->timestamp('expires_at');
48
+			$table->timestamps();
49 49
             
50
-            $table->foreign('meta_id')->references('id')->on('filestorage_meta');
51
-            $table->foreign('created_by')->references('id')->on('users');
52
-        });
50
+			$table->foreign('meta_id')->references('id')->on('filestorage_meta');
51
+			$table->foreign('created_by')->references('id')->on('users');
52
+		});
53 53
         
54
-        Schema::create('filestorage_access_log', function (Blueprint $table) {
55
-            $table->bigIncrements('id');
56
-            $table->unsignedBigInteger('meta_id');            
57
-            $table->timestamp('accessed_at');
58
-            $table->unsignedBigInteger('accessed_by');
59
-            $table->string('type', 32);
60
-            $table->string('ip_address', 32);
61
-            $table->string('host_name', 64);
54
+		Schema::create('filestorage_access_log', function (Blueprint $table) {
55
+			$table->bigIncrements('id');
56
+			$table->unsignedBigInteger('meta_id');            
57
+			$table->timestamp('accessed_at');
58
+			$table->unsignedBigInteger('accessed_by');
59
+			$table->string('type', 32);
60
+			$table->string('ip_address', 32);
61
+			$table->string('host_name', 64);
62 62
                         
63
-            $table->foreign('meta_id')->references('id')->on('filestorage_meta');
64
-        });
65
-    }
63
+			$table->foreign('meta_id')->references('id')->on('filestorage_meta');
64
+		});
65
+	}
66 66
 
67
-    /**
68
-     * Reverse the migrations.
69
-     *
70
-     * @return void
71
-     */
72
-    public function down()
73
-    {
74
-    	Schema::dropIfExists('filestorage_remote');
75
-    	Schema::dropIfExists('filestorage_access_log');
76
-    	Schema::dropIfExists('filestorage_meta');
77
-        Schema::dropIfExists('filestorage_files');
78
-    }
67
+	/**
68
+	 * Reverse the migrations.
69
+	 *
70
+	 * @return void
71
+	 */
72
+	public function down()
73
+	{
74
+		Schema::dropIfExists('filestorage_remote');
75
+		Schema::dropIfExists('filestorage_access_log');
76
+		Schema::dropIfExists('filestorage_meta');
77
+		Schema::dropIfExists('filestorage_files');
78
+	}
79 79
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
     {
16 16
     	$this->down();
17 17
     	
18
-        Schema::create('filestorage_files', function (Blueprint $table) {
18
+        Schema::create('filestorage_files', function(Blueprint $table) {
19 19
             $table->bigIncrements('id');
20 20
             $table->string('hash', 128);
21 21
             $table->integer('size');
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
             $table->softDeletes();
25 25
         });
26 26
         
27
-        Schema::create('filestorage_meta', function (Blueprint $table) {
27
+        Schema::create('filestorage_meta', function(Blueprint $table) {
28 28
             $table->bigIncrements('id');
29 29
             $table->string('name', 256);
30 30
             $table->string('link', 128)->nullable();
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
             $table->foreign('created_by')->references('id')->on('users');
40 40
         });
41 41
         
42
-        Schema::create('filestorage_remote', function (Blueprint $table) {
42
+        Schema::create('filestorage_remote', function(Blueprint $table) {
43 43
             $table->bigIncrements('id');
44 44
             $table->unsignedBigInteger('meta_id');            
45 45
             $table->string('token', 128);
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
             $table->foreign('created_by')->references('id')->on('users');
52 52
         });
53 53
         
54
-        Schema::create('filestorage_access_log', function (Blueprint $table) {
54
+        Schema::create('filestorage_access_log', function(Blueprint $table) {
55 55
             $table->bigIncrements('id');
56 56
             $table->unsignedBigInteger('meta_id');            
57 57
             $table->timestamp('accessed_at');
Please login to merge, or discard this patch.
src/FileStorageList.php 2 patches
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -47,14 +47,14 @@  discard block
 block discarded – undo
47 47
 
48 48
 		$this->grid->setModel($model = $this->getModel());
49 49
 		
50
-		if ($model->action('count')->getOne() ) {
50
+		if ($model->action('count')->getOne()) {
51 51
 			$this->grid->on('click', 'td', new jsExpression(
52 52
 					'document.location=\'?parentId=\'+[]',
53 53
 					[(new jQuery())->closest('tr')->data('id')]
54 54
 			));
55 55
 		}
56 56
 		
57
-		$this->grid->addDragHandler()->onReorder(function ($order) {
57
+		$this->grid->addDragHandler()->onReorder(function($order) {
58 58
 			$result = true;
59 59
 			foreach ($this->nodes()->get() as $node) {
60 60
 				$node->position = array_search($node->id, $order);
@@ -62,14 +62,14 @@  discard block
 block discarded – undo
62 62
 				$result &= $node->save();
63 63
 			}
64 64
 			
65
-			$notifier = $result? $this->notify(__('Items reordered!')): $this->notifyError(__('Error saving order!'));
65
+			$notifier = $result ? $this->notify(__('Items reordered!')) : $this->notifyError(__('Error saving order!'));
66 66
 			
67 67
 			return $this->grid->jsSave($notifier);
68 68
 		});
69 69
 		
70 70
 		$this->addContolButton('update', $this->getUpdateModal(), 'edit');
71 71
 			
72
-		$this->addContolButton('delete', function ($jschain, $id) {
72
+		$this->addContolButton('delete', function($jschain, $id) {
73 73
 			CommonData::find($id)->delete();
74 74
 				
75 75
 			return $jschain->closest('tr')->transition('fade left');
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 			$ret .= $button->getHtml();
92 92
 		}
93 93
 		
94
-		return $ret;;
94
+		return $ret; ;
95 95
 	}
96 96
 	
97 97
 	public function getUpdateModal()
@@ -100,9 +100,9 @@  discard block
 block discarded – undo
100 100
 		
101 101
 		$grid->pageUpdate = $grid->add($grid->pageUpdate ?: $grid->pageDefault, ['short_name'=>'edit']);
102 102
 		
103
-		$modal = new jsModal(__('Edit'), $grid->pageUpdate, [$grid->name => $grid->jsRow()->data('id'), $grid->name.'_sort' => $grid->getSortBy()]);
103
+		$modal = new jsModal(__('Edit'), $grid->pageUpdate, [$grid->name => $grid->jsRow()->data('id'), $grid->name . '_sort' => $grid->getSortBy()]);
104 104
 		
105
-		$grid->pageUpdate->set(function () {
105
+		$grid->pageUpdate->set(function() {
106 106
 			$grid = $this->grid;
107 107
 			
108 108
 			$grid->model->load($grid->app->stickyGet($grid->name));
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 			// set save handler with reload trigger
122 122
 			// adds default submit hook if it is not already set for this form
123 123
 			if (!$grid->formUpdate->hookHasCallbacks('submit')) {
124
-				$grid->formUpdate->onSubmit(function ($form) {
124
+				$grid->formUpdate->onSubmit(function($form) {
125 125
 					$form->model->save();
126 126
 					
127 127
 					return $this->grid->jsSaveUpdate();
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
 		
139 139
 		$this->grid->on('click', ".$class", $callback, [$this->grid->table->jsRow()->data('id')]);
140 140
 		
141
-		$this->buttons[$name] = new \atk4\ui\Button($icon? compact('icon'): $name);
141
+		$this->buttons[$name] = new \atk4\ui\Button($icon ? compact('icon') : $name);
142 142
 		
143 143
 		$this->buttons[$name]->app = $this->app;
144 144
 		
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 		
166 166
 		$rowsEmpty = [];
167 167
 		
168
-		$model = new \atk4\data\Model($rows? new \atk4\data\Persistence_Static($rows): new \atk4\data\Persistence_Array($rowsEmpty));
168
+		$model = new \atk4\data\Model($rows ? new \atk4\data\Persistence_Static($rows) : new \atk4\data\Persistence_Array($rowsEmpty));
169 169
 		
170 170
 		$captions = [
171 171
 				'position' => __('Position'),
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 		];
176 176
 		
177 177
 		foreach ($captions as $key => $caption) {
178
-			$field = $rows? $model->hasField($key): $model->addField($key);
178
+			$field = $rows ? $model->hasField($key) : $model->addField($key);
179 179
 			
180 180
 			if ($key === 'readonly') {
181 181
 				$field->setDefaults(['ui' => ['visible' => false]]);
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 	
192 192
 	public function getNodeForm()
193 193
 	{
194
-		if (! $this->form) {
194
+		if (!$this->form) {
195 195
 			$this->form = new Form(['buttonSave' => ['Button', __('Save'), 'primary']]);
196 196
 			
197 197
 			$this->form->addHook('submit', function($form) {
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 				
206 206
 				CommonData::create(array_merge($values, [
207 207
 						'position' => $this->nodes()->max('position') + 1
208
-				]), $this->parentId? CommonData::find($this->parentId): null);
208
+				]), $this->parentId ? CommonData::find($this->parentId) : null);
209 209
 				
210 210
 				return $this->grid->jsSaveCreate();
211 211
 			});
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -84,7 +84,9 @@
 block discarded – undo
84 84
 	
85 85
 	public function getControlButtonsHtml($row)
86 86
 	{
87
-		if ($row['readonly']) return '';
87
+		if ($row['readonly']) {
88
+			return '';
89
+		}
88 90
 		
89 91
 		$ret = '';
90 92
 		foreach ($this->buttons as $button) {
Please login to merge, or discard this patch.