Passed
Push — master ( 1d6d9a...2a90e7 )
by Ron
02:47 queued 12s
created

KillFileLink   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 78.95%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 41
ccs 15
cts 19
cp 0.7895
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A removeLinkFiles() 0 13 3
A deleteFileLink() 0 9 1
A disableLink() 0 8 1
1
<?php
2
3
namespace App\Domains\FileLinks;
4
5
use Illuminate\Support\Facades\Log;
6
use Illuminate\Support\Facades\Auth;
7
8
use Carbon\Carbon;
9
10
use App\FileLinks;
11
use App\FileLinkFiles;
12
13
use App\Domains\FilesDomain;
14
15
class KillFileLink extends FilesDomain
16
{
17
    protected $linkID;
18
19
    //  Only disable the link by adjusting the expire date
20 2
    public function disableLink($linkID)
21
    {
22 2
        $linkData = FileLinks::findOrFail($linkID)->update([
23 2
            'expire' => Carbon::yesterday()
24
        ]);
25
26 2
        Log::info('File Link has been disabled by '.Auth::user()->full_name.'.  Link Data - ', array($linkData));
27 2
        return true;
28
    }
29
30
    //  Delete the file link and all attached files
31 2
    public function deleteFileLink($linkID)
32
    {
33 2
        $linkData = FileLinks::findOrFail($linkID);
34
35 2
        $this->removeLinkFiles();
36 2
        Log::notice('File Link has been deleted by '.Auth::user()->full_name.'.  Link Data - ', array($linkData));
37 2
        $linkData->delete();
38
39 2
        return true;
40
    }
41
42
    //  Remove all of the files attached to the link
43 2
    protected function removeLinkFiles()
44
    {
45 2
        $fileList = FileLinkFiles::where('link_id', $this->linkID);
46
47 2
        if(!empty($fileList))
48
        {
49 2
            foreach($fileList as $file)
50
            {
51
                Log::debug('File from File Link being deleted.  File Data - ', array($file));
52
                $fileID = $file->file_id;
53
                $file->delete();
54
55
                $this->deleteFile($fileID);
56
            }
57
        }
58 2
    }
59
}
60