Passed
Push — development ( c2eef4...cd567a )
by Thomas
06:26
created

OkapiCleanup::run()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 5
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 11
rs 9.2
1
<?php
2
3
namespace OcLegacy\Cronjobs;
4
5
class OkapiCleanup
6
{
7
    /**
8
     * @var string
9
     */
10
    public $name = 'okapi_cleanup';
11
12
    /**
13
     * @var int
14
     */
15
    public $interval = 3600;
16
17
    /**
18
     * @var string
19
     */
20
    public $okapiVarDir;
21
22
    /**
23
     * @param string $okapiVarDir
24
     */
25
    public function __construct($okapiVarDir = __DIR__.'/../../../var/okapi')
26
    {
27
        $this->okapiVarDir = $okapiVarDir;
28
    }
29
30
    public function run()
31
    {
32
        $files = glob($this->okapiVarDir . '/garmin*.zip');
33
        foreach ($files as $file) {
34
            // delete old download files after 24 hours; this large interval filters out any
35
            // timezone mismatches in file systems (e.g. on unconventional development environments)
36
            if (is_file($file) && (time() - filemtime($file)) > 24 * 3600) {
37
                unlink($file);
38
            }
39
        }
40
    }
41
}
42