1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Domains\FileLinks; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
6
|
|
|
use Illuminate\Support\Facades\Log; |
7
|
|
|
use Illuminate\Support\Facades\Auth; |
8
|
|
|
|
9
|
|
|
use App\FileLinks; |
10
|
|
|
use App\FileLinkFiles; |
11
|
|
|
|
12
|
|
|
use App\Domains\FilesDomain; |
13
|
|
|
|
14
|
|
|
use App\Http\Requests\FileLinkCreateRequest; |
15
|
|
|
use App\Http\Requests\FileLinkInstructionsRequest; |
16
|
|
|
use App\Http\Requests\FileLinkUpdateRequest; |
17
|
|
|
use App\Http\Requests\UpdateFileLinkRequest; |
|
|
|
|
18
|
|
|
use App\Http\Requests\UpdateFileLinkInstructionsRequest; |
|
|
|
|
19
|
|
|
|
20
|
|
|
class SetFileLinkDetails extends FilesDomain |
21
|
|
|
{ |
22
|
|
|
// Create a new File Link |
23
|
8 |
|
public function processNewLink(FileLinkCreateRequest $request) |
24
|
|
|
{ |
25
|
8 |
|
if(isset($request->file)) |
26
|
|
|
{ |
27
|
2 |
|
$fileID = $this->processFileChunk($request); |
28
|
2 |
|
if($fileID) |
29
|
|
|
{ |
30
|
2 |
|
$fileArr = session('newLinkFile') != null ? session('newLinkFile') : []; |
31
|
2 |
|
$fileArr[] = $fileID; |
32
|
2 |
|
session(['newLinkFile' => $fileArr]); |
33
|
|
|
} |
34
|
|
|
|
35
|
2 |
|
return false; |
36
|
|
|
} |
37
|
|
|
|
38
|
8 |
|
return $this->createLink($request); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
|
43
|
|
|
// Update the file link |
44
|
2 |
|
public function updateLink(FileLinkUpdateRequest $request, $linkID) |
45
|
|
|
{ |
46
|
2 |
|
$linkData = FileLinks::find($linkID)->update([ |
47
|
2 |
|
'link_name' => $request->name, |
48
|
2 |
|
'expire' => $request->expire, |
49
|
2 |
|
'allow_upload' => $request->allow_upload, |
50
|
2 |
|
'cust_id' => $request->cust_id, |
51
|
|
|
]); |
52
|
|
|
|
53
|
2 |
|
Log::info('File Link ID '.$linkID.' has been updated by '.Auth::user()->full_name.'. Link Data - ', array($linkData)); |
54
|
2 |
|
return true; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
// Update only the instructions attached to the link |
58
|
2 |
|
public function setLinkInstructions(FileLinkInstructionsRequest $request, $linkID) |
59
|
|
|
{ |
60
|
2 |
|
FileLinks::find($linkID)->update([ |
61
|
2 |
|
'note' => $request->instructions, |
62
|
|
|
]); |
63
|
|
|
|
64
|
2 |
|
Log::info('Instructions for File Link ID '.$linkID.' have been updated by '.Auth::user()->full_name.'. Instruction Details - ', array($request)); |
65
|
2 |
|
return true; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
// Create the new File Link |
69
|
8 |
|
protected function createLink($linkData) |
70
|
|
|
{ |
71
|
8 |
|
$link = FileLinks::create([ |
72
|
8 |
|
'user_id' => Auth::user()->user_id, |
73
|
8 |
|
'cust_id' => $linkData->customerID, |
74
|
8 |
|
'link_hash' => $this->generateHash(), |
75
|
8 |
|
'link_name' => $linkData->name, |
76
|
8 |
|
'expire' => $linkData->expire, |
77
|
8 |
|
'allow_upload' => isset($linkData->allowUp) && $linkData->allowUp ? true : false, |
78
|
8 |
|
'note' => $linkData->instructions |
79
|
|
|
]); |
80
|
|
|
|
81
|
8 |
|
$this->processFiles($link->link_id); |
82
|
8 |
|
Log::info('User '.Auth::user()->full_name.' created new file link. Data - ', array($link)); |
83
|
8 |
|
return $link->link_id; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
// Generate a random hash to use as the link. Verify it is not already in use |
87
|
8 |
|
protected function generateHash() |
88
|
|
|
{ |
89
|
|
|
do |
90
|
|
|
{ |
91
|
8 |
|
$hash = strtolower(Str::random(15)); |
92
|
8 |
|
$dup = FileLinks::where('link_hash', $hash)->get()->count(); |
93
|
8 |
|
Log::debug('New hash created - '.$hash.'. Checking for duplicate. Result - '.$dup); |
94
|
8 |
|
} while($dup != 0); |
95
|
|
|
|
96
|
8 |
|
return $hash; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
// For all files that were uploaded, move to the proper folder and attach to the tip |
100
|
8 |
|
protected function processFiles($linkID) |
101
|
|
|
{ |
102
|
8 |
|
if(session('newLinkFile') != null) |
103
|
|
|
{ |
104
|
2 |
|
$files = session('newLinkFile'); |
105
|
|
|
// $this->path = config('filesystems.paths.tips').DIRECTORY_SEPARATOR.$tipID; |
106
|
2 |
|
$this->path = config('filesystems.paths.links').DIRECTORY_SEPARATOR.$linkID; |
107
|
2 |
|
foreach($files as $file) |
108
|
|
|
{ |
109
|
2 |
|
$this->moveFile($this->path, $file); |
110
|
|
|
|
111
|
|
|
// Attach file to Tech Tip |
112
|
2 |
|
FileLinkFiles::create([ |
113
|
2 |
|
'link_id' => $linkID, |
114
|
2 |
|
'file_id' => $file, |
115
|
|
|
]); |
116
|
|
|
} |
117
|
|
|
|
118
|
2 |
|
session()->forget('newLinkFile'); |
119
|
|
|
} |
120
|
|
|
|
121
|
8 |
|
return true; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths