public function run($request)
 {
     $files = DownloadTempFile::get();
     $num = 0;
     foreach ($files as $file) {
         $file->delete();
         $num++;
     }
     echo "{$num} files were deleted.";
 }
 /**
  * @param SS_HTTPRequest $req
  * @return HTMLText
  */
 public function process(SS_HTTPRequest $req)
 {
     $id = (int) $req->param('ID');
     if (!$id) {
         $this->httpError(404);
     }
     /** @var DownloadTempFile $file */
     $file = DownloadTempFile::get()->byID($id);
     if (!$file || !$file->ID) {
         $this->httpError(404);
     }
     // if the processing was already complete, just send them the file
     // this probably means they got overzealous and refreshed the browser
     switch ($file->ProcessingState) {
         case DownloadTempFile::COMPLETE:
             // This means the file was being processed but has finished
             // in the background and in the meantime we refreshed or something
             // so just send them the file.
             $this->addToLog(Session::get('DownloadableProcessingOrderID'), $file->SourceFiles(), $file);
             if (class_exists('CloudFileExtension')) {
                 if ($file instanceof CloudDownloadTempFile && $file->CloudStatus !== 'Live') {
                     return $this->displayCrunchingPage($file);
                 }
             }
             return $this->displayDownloadPage($file);
             break;
         case DownloadTempFile::ACTIVE:
             // This means the processing was started and is hopefully happening in the
             // background. We display the "crunching" page so the user knows what's
             // happening, and it will refresh every second or so to check on the status.
             if (!$file->isZombie()) {
                 return $this->displayCrunchingPage($file);
             }
             // otherwise fall through and restart processing
         // otherwise fall through and restart processing
         case DownloadTempFile::PENDING:
             if (!interface_exists('QueuedJob')) {
                 ini_set('max_execution_time', 0);
                 $file->process();
                 $this->addToLog(Session::get('DownloadableProcessingOrderID'), $file->SourceFiles(), $file);
                 return $this->sendTempFile($file);
             } else {
                 return $this->displayCrunchingPage($file);
             }
     }
 }