1 | <?php |
||
2 | |||
3 | namespace CWP\PDFExport\Tasks; |
||
4 | |||
5 | use CWP\CWP\PageTypes\BasePage; |
||
6 | use SilverStripe\Dev\BuildTask; |
||
7 | |||
8 | class CleanupGeneratedPdfBuildTask extends BuildTask |
||
9 | { |
||
10 | private static $segment = 'CleanupGeneratedPdfBuildTask'; |
||
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
11 | |||
12 | protected $title = 'Cleanup generated PDFs'; |
||
13 | |||
14 | protected $description = 'Removes generated PDFs on the site, forcing a regeneration of all exports to PDF ' |
||
15 | . 'when users go to download them. This is most useful when templates have been changed so users should ' |
||
16 | . 'receive a new copy'; |
||
17 | |||
18 | public function run($request) |
||
19 | { |
||
20 | $path = sprintf('%s/%s', BASE_PATH, BasePage::config()->get('generated_pdf_path')); |
||
21 | if (!file_exists($path)) { |
||
22 | return false; |
||
23 | } |
||
24 | |||
25 | exec(sprintf('if [ "$(ls -A %s 2> /dev/null)" != "" ]; then rm %s/*; fi', $path, $path), $output, $return_val); |
||
26 | |||
27 | // output any errors |
||
28 | if ($return_val != 0) { |
||
29 | user_error(sprintf('%s failed: ', get_class($this)) . implode("\n", $output), E_USER_ERROR); |
||
30 | } |
||
31 | } |
||
32 | } |
||
33 |