protected function actionGenerate($force)
 {
     /* Why not allow multiple reports to generate at once?
        if (count($this->request_remainder) > 1 ) {
            I2CE::raiseError("Requested generation of invalid report " . implode('/', $this->request_remainder));
            return false;
        }
        */
     if (count($this->request_remainder) == 0) {
         $config = I2CE::getConfig()->modules->CustomReports;
         $config->generate_all->volatile(true);
         $timeConfig = I2CE::getConfig()->traverse('/modules/CustomReports/times', true);
         $timeConfig->volatile(true);
         $fail_time = null;
         $timeConfig->setIfIsSet($fail_time, 'fail');
         if (!is_integer($fail_time)) {
             $fail_time = 600;
         }
         $fail_time = (int) ((int) $fail_time * 60);
         $generation = 0;
         $timeConfig->setIfIsSet($generation, "generate_all/time");
         if (!(is_integer($generation) || ctype_digit($generation)) || (int) $generation < 1) {
             $generation = 0;
         }
         $generation = (int) $generation;
         $config->setIfIsSet($status, 'generate_all/status');
         if ($status === 'in_progress' && (!$force || time() - $generation < $fail_time)) {
             I2CE::raiseError("In progress");
             return true;
         }
         $config->generate_all->status = 'in_progress';
         $config->generate_all->time = time();
         //update the time
         $reports = I2CE::getConfig()->modules->CustomReports->reports->getKeys();
         $all = true;
     } else {
         $reports = $this->request_remainder;
         $all = false;
     }
     //         //generate caches.
     //         $wrangler = new I2CE_Wrangler();
     //         $cachedFormPage = $wrangler->getPage('CachedForms','cacheAll');
     //         if ($cachedFormPage instanceof I2CE_Page) {
     //             $cachedFormPage->cacheAll();
     //         }
     $errors = array();
     foreach ($reports as $report) {
         if (!I2CE_CustomReport::reportExists($report)) {
             I2CE::raiseError("Requested generation of report {$report} which does not exist");
             $errors[] = "Requested generation of report {$report} which does not exist";
             continue;
         }
         try {
             $reportObj = new I2CE_CustomReport($report);
         } catch (Exception $e) {
             $errors[] = "Could not instantiate the report {$report}";
             continue;
         }
         if (!$reportObj->generateCache($force)) {
             $errors[] = "Could not generate report for {$report}";
         }
     }
     foreach ($errors as $error) {
         $this->userMessage($error, 'notice');
     }
     if ($all) {
         if (count($errors) > 0) {
             $config->generate_all->status = 'failed';
         } else {
             $config->generate_all->status = 'done';
         }
         $config->generate_all->time = time();
     }
     return count($errors) == 0;
 }