Passed
Push — 1.6 ( c1892f...19716f )
by Robbie
02:51
created

CleanupGeneratedPdfDailyTask   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 5
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
c 0
b 0
f 0
dl 0
loc 5
rs 10
1
<?php
2
class CleanupGeneratedPdfBuildTask extends BuildTask {
3
4
	protected $title = 'Cleanup generated PDFs';
5
	
6
	protected $description = 'Removes generated PDFs on the site, forcing a regeneration of all exports to PDF when users
7
		go to download them. This is most useful when templates have been changed so users should receive a new copy';
8
9
	public function run($request) {
10
		$path = sprintf('%s/%s', BASE_PATH, BasePage::config()->generated_pdf_path);
11
		if(!file_exists($path)) return false;
12
13
		exec(sprintf('if [ "$(ls -A %s 2> /dev/null)" != "" ]; then rm %s/*; fi', $path, $path), $output, $return_val);
14
15
		// output any errors
16
		if($return_val != 0) {
17
			user_error(sprintf('%s failed: ', get_class($this)) . implode("\n", $output), E_USER_ERROR);
18
		}
19
	}
20
21
}
22
class CleanupGeneratedPdfDailyTask extends DailyTask {
23
24
	public function process() {
25
		$task = new CleanupGeneratedPdfBuildTask();
26
		$task->run(null);
27
	}
28
29
}
30