Passed
Pull Request — master (#47)
by Rafael
04:41
created

FileSystemTask::mainAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Gewaer\Cli\Tasks;
4
5
use Phalcon\Cli\Task as PhTask;
6
use Gewaer\Models\FileSystem;
7
8
/**
9
 * Class AclTask
10
 *
11
 * @package Gewaer\Cli\Tasks;
12
 *
13
 * @property \Gewaer\Acl\Manager $acl
14
 */
15
class FileSystemTask extends PhTask
16
{
17
    /**
18
     * Create the default roles of the system
19
     *
20
     * @return void
21
     */
22
    public function mainAction()
23
    {
24
        echo 'Main action for FileSystem Task';
25
    }
26
27
    /**
28
     * Default roles for the crm system
29
     *
30
     * @return void
31
     */
32
    public function purgeImagesAction(array $params):void
33
    {
34
        $fullDelete = $params[0];
35
        $detachedImages = FileSystem::find([
36
            'conditions' => 'users_id = 0 and is_deleted = 0'
37
        ]);
38
39
        if ($fullDelete == 0 && is_object($detachedImages)) {
40
            foreach ($detachedImages as $detachedImage) {
41
                $detachedImage->is_deleted = 1;
42
43
                if ($detachedImage->update()) {
44
                    $output = shell_exec(`rm $detachedImage->path`);
0 ignored issues
show
Unused Code introduced by
The assignment to $output is dead and can be removed.
Loading history...
45
                    echo 'Image with id ' . $detachedImage->id . " has been soft deleted \n";
46
                }
47
            }
48
        } else {
49
            foreach ($detachedImages as $detachedImage) {
50
                echo 'Image with id ' . $detachedImage->id . " has been fully deleted \n";
51
                $detachedImage->delete();
52
                shell_exec(`rm $detachedImage->path`);
53
            }
54
        }
55
    }
56
}
57