Completed
Push — master ( 60e303...4c478a )
by
unknown
8s
created

src/Tasks/CleanupGeneratedPdfDailyTask.php (3 issues)

1
<?php
2
3
namespace CWP\PDFExport\Tasks;
4
5
use SilverStripe\Core\Config\Configurable;
6
use SilverStripe\Core\Injector\Injector;
7
use SilverStripe\CronTask\Interfaces\CronTask;
8
9
if (!interface_exists(CronTask::class)) {
10
    return;
11
}
12
13
/**
14
 * If the silverstripe/crontask module is installed, this will enable the PDF cleanup task to be run on a schedule
15
 */
16
class CleanupGeneratedPdfDailyTask implements CronTask
17
{
18
    use Configurable;
19
20
    /**
21
     * The cron schedule for this task (default: midnight every day)
22
     *
23
     * @config
24
     * @var string
25
     */
26
    private static $schedule = '0 0 * * *';
0 ignored issues
show
The private property $schedule is not used, and could be removed.
Loading history...
27
28
    /**
29
     * Whether this task is enabled (default false)
30
     *
31
     * @config
32
     * @return bool
33
     */
34
    private static $enabled = false;
0 ignored issues
show
The private property $enabled is not used, and could be removed.
Loading history...
35
36
    private static $segment = 'CleanupGeneratedPdfDailyTask';
0 ignored issues
show
The private property $segment is not used, and could be removed.
Loading history...
37
38
    public function getSchedule()
39
    {
40
        return $this->config()->get('schedule');
41
    }
42
43
    public function process()
44
    {
45
        if (!$this->config()->get('enabled')) {
46
            return;
47
        }
48
49
        $task = Injector::inst()->create(CleanupGeneratedPdfBuildTask::class);
50
        $task->run(null);
51
    }
52
}
53