/** * * @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; }
/** * Updates the gems database with the latest information about the surveys in this source adapter * * @param \Gems_Task_TaskRunnerBatch $batch * @param int $userId Id of the user who takes the action (for logging) * @return array Returns an array of messages */ public function synchronizeSurveyBatch(\Gems_Task_TaskRunnerBatch $batch, $userId) { // Surveys in Gems $select = $this->_gemsDb->select(); $select->from('gems__surveys', array('gsu_id_survey', 'gsu_surveyor_id'))->where('gsu_id_source = ?', $this->getId())->order('gsu_surveyor_id'); $gemsSurveys = $this->_gemsDb->fetchPairs($select); if (!$gemsSurveys) { $gemsSurveys = array(); } // Surveys in Source $sourceSurveys = $this->_getSourceSurveysForSynchronisation(); if ($sourceSurveys) { $sourceSurveys = array_combine($sourceSurveys, $sourceSurveys); } else { $sourceSurveys = array(); } // Always those already in the database foreach ($gemsSurveys as $surveyId => $sourceSurveyId) { if (isset($sourceSurveys[$sourceSurveyId])) { $batch->addTask('Tracker_CheckSurvey', $this->getId(), $sourceSurveyId, $surveyId, $userId); $batch->addTask('Tracker_AddRefreshQuestions', $this->getId(), $sourceSurveyId, $surveyId); } else { // Do not pass the source id when it no longer exists $batch->addTask('Tracker_CheckSurvey', $this->getId(), null, $surveyId, $userId); } } // Now add the new ones foreach (array_diff($sourceSurveys, $gemsSurveys) as $sourceSurveyId) { $batch->addTask('Tracker_CheckSurvey', $this->getId(), $sourceSurveyId, null, $userId); $batch->addTask('Tracker_AddRefreshQuestions', $sourceSurveyId, null, $userId); } }