/** * * @param \MUtil_Task_TaskBatch $batch Optional batch with different source etc.. * @return \MUtil_Task_TaskBatch */ public function getImportOnlyBatch(\MUtil_Task_TaskBatch $batch = null) { if (!$this->_importBatch instanceof \MUtil_Task_TaskBatch) { $batch = $this->loader->getTaskRunnerBatch(__CLASS__ . '_import_' . basename($this->sourceModel->getName()) . '_' . __FUNCTION__); $batch->setVariable('targetModel', $this->getTargetModel()); $this->_importBatch = $batch; } else { $batch = $this->_importBatch; } return parent::getImportOnlyBatch($batch); }
/** * * @return \Gems_Task_TaskRunnerBatch */ protected function getImportMergeBatch() { $batch = $this->loader->getTaskRunnerBatch('track_import_create_' . $this->formData['importId']); $import = $this->loadImportData(); $batch->setVariable('import', $import); $batch->setVariable('trackEngine', $this->trackEngine); if ($batch->isFinished()) { return $batch; } if (!$batch->isLoaded()) { $batch->addTask('Tracker\\Merge\\MergeTrackImportTask', $this->formData); $fieldDef = $this->trackEngine->getFieldsDefinition(); foreach ($import['fields'] as $lineNr => &$fieldData) { $field = $fieldDef->getFieldByOrder($fieldData['gtf_id_order']); if ($field instanceof FieldInterface) { $fieldData['gtf_id_field'] = $field->getFieldId(); } $batch->addTask('Tracker\\Import\\CreateTrackFieldImportTask', $lineNr, $fieldData); } foreach ($import['rounds'] as $lineNr => $roundData) { $batch->addTask('Tracker\\Import\\CreateTrackRoundImportTask', $lineNr, $roundData); } if (isset($import['deactivateRounds'])) { foreach ($import['deactivateRounds'] as $roundId => $roundDescription) { $batch->addTask('Tracker\\Merge\\DeactivateTrackFieldTask', $roundId, $roundDescription); } } $batch->addTask('AddTask', 'Tracker\\Import\\FinishTrackImport'); } return $batch; }
/** * Perform automatic job mail */ public function commJob() { $batch = $this->loader->getTaskRunnerBatch('cron'); $batch->minimalStepDurationMs = 3000; // 3 seconds max before sending feedback $batch->autoStart = true; if (!$batch->isLoaded()) { // Check for unprocessed tokens $tracker = $this->loader->getTracker(); $tracker->processCompletedTokens(null, $this->currentUser->getUserId()); $batch->addTask('Mail\\AddAllMailJobsTask'); } $title = $this->_('Executing cron jobs'); $this->_helper->BatchRunner($batch, $title, $this->accesslog); $this->html->br(); }
/** * * @return \Gems_Task_TaskRunnerBatch */ protected function getExportBatch($load = true) { if ($this->_batch) { return $this->_batch; } $this->_batch = $this->loader->getTaskRunnerBatch('track_export_' . $this->trackEngine->getTrackId()); if (!$load || $this->_batch->isFinished()) { return $this->_batch; } if (!$this->_batch->isLoaded()) { $filename = \MUtil_File::createTemporaryIn(GEMS_ROOT_DIR . '/var/tmp/export/track'); $trackId = $this->trackEngine->getTrackId(); $this->_batch->setSessionVariable('filename', $filename); $this->_batch->addTask('Tracker\\Export\\MainTrackExportTask', $this->trackEngine->getTrackId(), $this->formData['orgs']); // \MUtil_Echo::track($this->formData['fields']); foreach ($this->formData['fields'] as $fieldId) { $this->_batch->addTask('Tracker\\Export\\TrackFieldExportTask', $trackId, $fieldId); } $model = $this->getModel(); foreach ($model->getCol('surveyId') as $surveyId) { $this->_batch->addTask('Tracker\\Export\\TrackSurveyExportTask', $trackId, $surveyId); } foreach ($this->formData['rounds'] as $roundId) { $this->_batch->addTask('Tracker\\Export\\TrackRoundExportTask', $trackId, $roundId); } } else { $filename = $this->_batch->getSessionVariable('filename'); } $this->_batch->setVariable('file', fopen($filename, 'a')); return $this->_batch; }
/** * Executes the upgrades for a certain context * * optional: give from and to levels * * usage: execute/context/<context>{/from/int/to/int} */ protected function executeAction($from = null, $to = null) { $context = $this->getRequest()->getParam('id', 'gems'); $from = $this->getRequest()->getParam('from', $from); $to = $this->getRequest()->getParam('to', $to); $batch = $this->loader->getTaskRunnerBatch('upgrade' . $context); $batch->minimalStepDurationMs = 3000; // 3 seconds max before sending feedback if (!$batch->isLoaded()) { $this->_upgrades->setBatch($batch); $this->_upgrades->execute($context, $to, $from); } $title = sprintf($this->_('Upgrading %s'), $context); $this->_helper->BatchRunner($batch, $title, $this->accesslog); $this->html->br(); $this->compatibilityReportAction(); }
/** * * @return \Gems_Task_TaskRunnerBatch */ protected function getImportCreateBatch() { $batch = $this->loader->getTaskRunnerBatch('track_import_create_' . $this->formData['import_id']); $import = $this->loadImportData(); $batch->setVariable('import', $import); if ($batch->isFinished()) { return $batch; } if (!$batch->isLoaded()) { $batch->addTask('Tracker\\Import\\CreateTrackImportTask', $this->formData); foreach ($import['fields'] as $lineNr => $fieldData) { $batch->addTask('Tracker\\Import\\CreateTrackFieldImportTask', $lineNr, $fieldData); } foreach ($import['rounds'] as $lineNr => $roundData) { $batch->addTask('Tracker\\Import\\CreateTrackRoundImportTask', $lineNr, $roundData); } $batch->addTask('AddTask', 'Tracker\\Import\\FinishTrackImport'); } return $batch; }
/** * Recalculates all token dates, timing and results * and outputs text messages. * * Does not reflect changes to tracks or rounds. * * @param int $sourceId A source identifier * @param int $userId Id of the user who takes the action (for logging) * @return \Gems_Task_TaskRunnerBatch A batch to process the synchronization */ public function synchronizeSources($sourceId = null, $userId = null) { $batch_id = 'source_synch' . ($sourceId ? '_' . $sourceId : ''); $batch = $this->loader->getTaskRunnerBatch($batch_id); if (!$batch->isLoaded()) { if ($sourceId) { $sources = array($sourceId); } else { $select = $this->db->select(); $select->from('gems__sources', array('gso_id_source'))->where('gso_active = 1'); $sources = $this->db->fetchCol($select); } foreach ($sources as $source) { $batch->addTask('Tracker_SourceSyncSurveys', $source, $userId); // Reset cache after basic synch $batch->addTask('CleanCache'); // Reset cache after field synch $batch->addTask('AddTask', 'CleanCache'); $batch->addTask('AddTask', 'Tracker\\UpdateSyncDate', $source, $userId); } } return $batch; }
/** * Export model data */ public function exportAction() { $step = $this->request->getParam('step'); $post = $this->request->getPost(); $this->autofilterParameters = $this->autofilterParameters + $this->_autofilterExtraParameters; $model = $this->getExportModel(); if (isset($this->autofilterParameters['sortParamAsc'])) { $model->setSortParamAsc($this->autofilterParameters['sortParamAsc']); } if (isset($this->autofilterParameters['sortParamDesc'])) { $model->setSortParamDesc($this->autofilterParameters['sortParamDesc']); } $model->applyParameters($this->getSearchFilter(false), true); // Add any defaults. if (isset($this->autofilterParameters['extraFilter'])) { $model->addFilter($this->autofilterParameters['extraFilter']); } if (isset($this->autofilterParameters['extraSort'])) { $model->addSort($this->autofilterParameters['extraSort']); } if (!$step || $post && $step == 'form') { $this->addSnippet($this->exportFormSnippets); $batch = $this->loader->getTaskRunnerBatch('export_data'); $batch->reset(); } elseif ($step == 'batch') { $batch = $this->loader->getTaskRunnerBatch('export_data'); $batch->setVariable('model', $model); if (!$batch->count()) { $batch->minimalStepDurationMs = 2000; $batch->finishUrl = $this->view->url(array('step' => 'download')); $batch->setSessionVariable('files', array()); $batch->addTask('Export_ExportCommand', $post['type'], 'addExport', $post); $batch->addTask('addTask', 'Export_ExportCommand', $post['type'], 'finalizeFiles'); $batch->autoStart = true; } if ($batch->run($this->request)) { exit; } else { $controller = $this; if ($batch->isFinished()) { /*\MUtil_Echo::track('finished'); $file = $batch->getSessionVariable('file'); if ((!empty($file)) && isset($file['file']) && file_exists($file['file'])) { // Forward to download action $this->_session->exportFile = $file; }*/ } else { if ($batch->count()) { $controller->html->append($batch->getPanel($controller->view, $batch->getProgressPercentage() . '%')); } else { $controller->html->pInfo($controller->_('Nothing to do.')); } $controller->html->pInfo()->a(\MUtil_Html_UrlArrayAttribute::rerouteUrl($this->getRequest(), array('action' => 'index', 'step' => false)), array('class' => 'actionlink'), $this->_('Back')); } } } elseif ($step == 'download') { $this->view->layout()->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); $batch = $this->loader->getTaskRunnerBatch('export_data'); $file = $batch->getSessionVariable('file'); print_r($file); foreach ($file['headers'] as $header) { header($header); } while (ob_get_level()) { ob_end_clean(); } readfile($file['file']); // Now clean up the file unlink($file['file']); exit; } }