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

garbageCollection   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Test Coverage

Coverage 9.68%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 74
ccs 3
cts 31
cp 0.0968
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A retryQueue() 0 6 1
A handle() 0 9 1
A checkArchiveFolder() 0 9 2
A checkChunkFolder() 0 9 2
A __construct() 0 3 1
1
<?php
2
3
namespace App\Console\Commands;
4
5
use Illuminate\Console\Command;
6
7
use Illuminate\Support\Facades\Log;
8
use Illuminate\Support\Facades\File;
9
use Illuminate\Support\Facades\Storage;
10
use Illuminate\Support\Facades\Artisan;
11
use Illuminate\Support\Facades\Queue;
12
use Symfony\Component\Console\Output\BufferedOutput;
13
14
class garbageCollection extends Command
15
{
16
    /**
17
     * The name and signature of the console command.
18
     *
19
     * @var string
20
     */
21
    protected $signature = 'garbagecollection:run';
22
23
    /**
24
     * The console command description.
25
     *
26
     * @var string
27
     */
28
    protected $description = 'Nightly maintenance script to wipe temporary and deleted data';
29
30
    /**
31
     * Create a new command instance.
32
     *
33
     * @return void
34
     */
35 2
    public function __construct()
36
    {
37 2
        parent::__construct();
38 2
    }
39
40
    /**
41
     * Execute the console command.
42
     *
43
     * @return mixed
44
     */
45
    public function handle()
46
    {
47
        Log::notice('Running Garbage Collection Job');
48
        $this->call('down');
49
        $this->retryQueue();
50
        $this->checkChunkFolder();
51
        $this->checkArchiveFolder();
52
        $this->call('up');
53
        Log::notice('Garbage Collection Job completed');
54
    }
55
56
    //  Check for any failed jobs in the work queue
57
    protected function retryQueue()
58
    {
59
        Log::info('Restarting Worker Queues');
60
        $this->call('queue:restart');
61
        Log::info('Retrying failed jobs');
62
        $this->call('queue:retry', ['id' => 'all']);
63
    }
64
65
    //  Determine if there are any files held over in the file chunks folder
66
    protected function checkChunkFolder()
67
    {
68
        $files = Storage::files('chunks');
69
        Log::info('Found partial files in the "chunks" folder');
70
        Log::info('File List - ', array($files));
71
72
        if($files)
0 ignored issues
show
Bug Best Practice introduced by
The expression $files of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
73
        {
74
            Storage::deleteDirectory('chunks');
75
        }
76
    }
77
78
    //  Determine if there are any files held over in the archive_downlaods folder
79
    protected function checkArchiveFolder()
80
    {
81
        $files = Storage::files('archive_downloads');
82
        Log::info('Found files in the "archive_downloads" folder');
83
        Log::debug('File List - ', array($files));
84
85
        if($files)
0 ignored issues
show
Bug Best Practice introduced by
The expression $files of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
86
        {
87
            Storage::deleteDirectory('archive_downloads');
88
        }
89
    }
90
}
91