| Total Complexity | 3 |
| Total Lines | 16 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 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 | } |
||
| 30 |