|
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
|
|
|
|
|
11
|
|
|
use App\Domains\FileLinks\SaveFileLinkFile; |
|
12
|
|
|
use App\Http\Requests\FileLinkCreateRequest; |
|
13
|
|
|
use App\Http\Requests\NewFileLinkRequest; |
|
14
|
|
|
|
|
15
|
|
|
class CreateFileLink extends SaveFileLinkFile |
|
16
|
|
|
{ |
|
17
|
|
|
// // Create a brand new file link and determine if any files should be linked to it |
|
18
|
|
|
// public function create(FileLinkCreateRequest $request) |
|
19
|
|
|
// { |
|
20
|
|
|
// $linkID = $this->createLink($request); |
|
21
|
|
|
|
|
22
|
|
|
// if($request->session()->has('newLinkFile')) |
|
23
|
|
|
// { |
|
24
|
|
|
// $this->relocateFiles($linkID); |
|
25
|
|
|
// } |
|
26
|
|
|
|
|
27
|
|
|
// return ['link' => $linkID, 'name' => Str::slug($request->name)]; |
|
28
|
|
|
// } |
|
29
|
|
|
|
|
30
|
|
|
// // Build a new link data in the database |
|
31
|
|
|
// protected function createLink($data) |
|
32
|
|
|
// { |
|
33
|
|
|
// $link = FileLinks::create([ |
|
34
|
|
|
// 'user_id' => Auth::user()->user_id, |
|
35
|
|
|
// 'cust_id' => $data->customerID, |
|
36
|
|
|
// 'link_hash' => $this->generateHash(), |
|
37
|
|
|
// 'link_name' => $data->name, |
|
38
|
|
|
// 'expire' => $data->expire, |
|
39
|
|
|
// 'allow_upload' => isset($data->allowUp) && $data->allowUp ? true : false, |
|
40
|
|
|
// 'note' => $data->instructions |
|
41
|
|
|
// ]); |
|
42
|
|
|
|
|
43
|
|
|
// Log::info('User '.Auth::user()->full_name.' created new file link. Data - ', array($link)); |
|
44
|
|
|
// return $link->link_id; |
|
45
|
|
|
// } |
|
46
|
|
|
|
|
47
|
|
|
// // Generate a random hash to use as the link. Verify it is not already in use |
|
48
|
|
|
// protected function generateHash() |
|
49
|
|
|
// { |
|
50
|
|
|
// do |
|
51
|
|
|
// { |
|
52
|
|
|
// $hash = strtolower(Str::random(15)); |
|
53
|
|
|
// $dup = FileLinks::where('link_hash', $hash)->get()->count(); |
|
54
|
|
|
// Log::debug('New hash created - '.$hash.'. Checking for duplicate. Result - '.$dup); |
|
55
|
|
|
// } while($dup != 0); |
|
56
|
|
|
|
|
57
|
|
|
// return $hash; |
|
58
|
|
|
// } |
|
59
|
|
|
} |
|
60
|
|
|
|