Ejemplo n.º 1
0
 public function run()
 {
     $exportItems = ExportItem::getUncompletedItems();
     if (count($exportItems) > 0) {
         foreach ($exportItems as $exportItem) {
             if (isset($exportItem->exportFileModel)) {
                 //continue;
             }
             $unserializedData = unserialize($exportItem->serializedData);
             if ($unserializedData instanceof RedBeanModelDataProvider) {
                 $formattedData = $unserializedData->getData();
             } else {
                 $formattedData = array();
                 foreach ($unserializedData as $idToExport) {
                     $model = call_user_func(array($exportItem->modelClassName, 'getById'), intval($idToExport));
                     $formattedData[] = $model;
                 }
             }
             if ($exportItem->exportFileType == 'csv') {
                 $headerData = array();
                 foreach ($formattedData as $model) {
                     if (ControllerSecurityUtil::doesCurrentUserHavePermissionOnSecurableItem($model, Permission::READ)) {
                         $modelToExportAdapter = new ModelToExportAdapter($model);
                         if (count($headerData) == 0) {
                             $headerData = $modelToExportAdapter->getHeaderData();
                         }
                         $data[] = $modelToExportAdapter->getData();
                     }
                 }
                 $output = ExportItemToCsvFileUtil::export($data, $headerData);
                 $fileContent = new FileContent();
                 $fileContent->content = $output;
                 $exportFileModel = new ExportFileModel();
                 $exportFileModel->fileContent = $fileContent;
                 $exportFileModel->name = $exportItem->exportFileName . ".csv";
                 $exportFileModel->type = 'application/octet-stream';
                 $exportFileModel->size = strlen($output);
                 $saved = $exportFileModel->save();
                 if ($saved) {
                     $exportItem->isCompleted = 1;
                     $exportItem->exportFileModel = $exportFileModel;
                     $exportItem->save();
                     $message = new NotificationMessage();
                     $message->htmlContent = Zurmo::t('ExportModule', 'Export of {fileName} requested on {dateTime} is completed. <a href="{url}">Click here</a> to download file!', array('{fileName}' => $exportItem->exportFileName, '{url}' => Yii::app()->createUrl('export/default/download', array('id' => $exportItem->id)), '{dateTime}' => DateTimeUtil::convertDbFormattedDateTimeToLocaleFormattedDisplay($exportItem->createdDateTime, 'long')));
                     $rules = new ExportProcessCompletedNotificationRules();
                     NotificationsUtil::submit($message, $rules);
                 }
             }
         }
     } else {
         return true;
     }
     return true;
 }
Ejemplo n.º 2
0
 public function run()
 {
     $cancelledItems = ExportItem::getCancelledItems();
     foreach ($cancelledItems as $item) {
         $item->delete();
         $message = Zurmo::t('ExportModule', 'Deleted export item with ID: {id}', array('{id}' => $item->id));
         $this->getMessageLogger()->addInfoMessage($message);
     }
     $exportItems = ExportItem::getUncompletedItems();
     $startTime = Yii::app()->performance->startClock();
     Yii::app()->performance->startMemoryUsageMarker();
     if (count($exportItems) > 0) {
         foreach ($exportItems as $exportItem) {
             $originalUser = Yii::app()->user->userModel;
             Yii::app()->user->userModel = $exportItem->owner;
             $message = Zurmo::t('ExportModule', 'run: Beginning processing of export item with ID: {id} ', array('{id}' => $exportItem->id));
             $this->getMessageLogger()->addInfoMessage($message);
             try {
                 //Update the job run status for the export item.
                 $exportItem->isJobRunning = true;
                 $exportItem->save();
                 $message = Zurmo::t('ExportModule', 'Update the job running status for export item with ID: {id} to true', array('{id}' => $exportItem->id));
                 $this->getMessageLogger()->addInfoMessage($message);
                 $this->processExportItem($exportItem);
             } catch (SecurityException $e) {
                 $message = Zurmo::t('ExportModule', 'Export Item could not be processed due a SecurityException ' . $e->getMessage());
                 $this->getMessageLogger()->addInfoMessage($message);
                 $exportItem->isJobRunning = false;
                 $exportItem->save();
                 $this->processCompletedWithSecurityExceptionExportItem($exportItem);
             }
             $exportItem->isJobRunning = false;
             $exportItem->save();
             $message = Zurmo::t('ExportModule', 'Update the job running status for export item with ID: {id} to false', array('{id}' => $exportItem->id));
             $this->getMessageLogger()->addInfoMessage($message);
             if ($this->hasReachedMaximumProcessingCount()) {
                 $this->addMaximumProcessingCountMessageForAllExportItems();
                 break;
             }
             if (!Yii::app()->performance->isMemoryUsageSafe()) {
                 $this->addMaximumMemoryUsageReachedForAllExportItems();
                 break;
             }
         }
         Yii::app()->user->userModel = $originalUser;
         if ($this->hasReachedMaximumProcessingCount() || !Yii::app()->performance->isMemoryUsageSafe()) {
             Yii::app()->jobQueue->add('Export', 5);
         }
     }
     $this->processEndMemoryUsageMessage((int) $startTime);
     return true;
 }
Ejemplo n.º 3
0
 public function run()
 {
     $exportItems = ExportItem::getUncompletedItems();
     $startTime = Yii::app()->performance->startClock();
     Yii::app()->performance->startMemoryUsageMarker();
     if (count($exportItems) > 0) {
         foreach ($exportItems as $exportItem) {
             $originalUser = Yii::app()->user->userModel;
             Yii::app()->user->userModel = $exportItem->owner;
             $message = Zurmo::t('ExportModule', 'run: Beginning processing of export item with ID: {id} ', array('{id}' => $exportItem->id));
             $this->getMessageLogger()->addInfoMessage($message);
             try {
                 $this->processExportItem($exportItem);
             } catch (SecurityException $e) {
                 $message = Zurmo::t('ExportModule', 'Export Item could not be processed due a SecurityException ' . $e->getMessage());
                 $this->getMessageLogger()->addInfoMessage($message);
                 $this->processCompletedWithSecurityExceptionExportItem($exportItem);
             }
             if ($this->hasReachedMaximumProcessingCount()) {
                 $this->addMaxmimumProcessingCountMessageForAllExportItems();
                 break;
             }
         }
         Yii::app()->user->userModel = $originalUser;
     }
     $this->processEndMemoryUsageMessage((int) $startTime);
     return true;
 }