public function generate() { set_error_handler(array($this, 'errorHandler'), E_WARNING); try { $this->_reportFile->status = Reports_File::STATUS_IN_PROGRESS; $this->_reportFile->save(); $this->_report = $this->_reportFile->getReport(); $this->_params = reports_convert_search_filters(unserialize($this->_report->query)); // Creates a random filename based on the type of report. $filter = new Omeka_Filter_Filename(); $filename = $filter->renameFile('report.' . $this->getExtension()); // Generates the report (passes to subclass) $tempFilePath = tempnam($this->_storage->getTempDir(), 'reports'); $tempFilePath = $this->generateReport($tempFilePath); // Store the report $destPath = $this->_storagePrefixDir . '/' . $filename; $this->_storage->store($tempFilePath, $destPath); $this->_reportFile->status = Reports_File::STATUS_COMPLETED; $this->_reportFile->filename = $filename; } catch (Exception $e) { $this->_reportFile->status = Reports_File::STATUS_ERROR; $this->_addStatusMessage('storagePrefixDir: ' . $this->_storagePrefixDir . ' filename: ' . $filename . ' error:' . $e->getMessage(), 'Error'); _log($e, Zend_Log::ERR); } $this->_reportFile->save(); }
/** * Spawns a background process to generate a new report file. */ public function generateAction() { $report = $this->_helper->db->findById(); $reportFile = new Reports_File(); $reportFile->report_id = $report->id; $reportFile->type = $_GET['format']; $reportFile->status = Reports_File::STATUS_STARTING; // Send the base URL to the background process for QR Code // This should be abstracted out to work more generally for // all generators. if ($reportFile->type == 'PdfQrCode') { $reportFile->options = serialize(array('baseUrl' => WEB_ROOT)); } $errors = array(); if (!$reportFile->canStore($errors)) { $errorMessage = __('The report cannot be saved. Please check your report storage settings.'); foreach ($errors as $error) { $errorMessage .= ' ' . $error; } $this->_helper->flashMessenger($errorMessage, 'error'); } else { $reportFile->save(); $this->_jobDispatcher->setQueueName('reports'); $this->_jobDispatcher->sendLongRunning('Reports_GenerateJob', array('fileId' => $reportFile->id)); } $this->_helper->redirector->gotoRoute(array('module' => 'reports', 'id' => $report->id, 'action' => 'show'), 'default'); }