/** * Execute the task * * @param array $taskData Task data * * @return bool True on success, false otherwise */ public function run($taskData) { $languages = NenoHelper::getLanguages(); $defaultLanguage = NenoSettings::get('source_language'); $profiler = new JProfiler(); foreach ($languages as $language) { if ($language->lang_code !== $defaultLanguage) { $profiler->mark('Before create job' . $language->lang_code . ' Method: Machine'); $machineJob = NenoJob::createJob($language->lang_code, NenoContentElementTranslation::MACHINE_TRANSLATION_METHOD); $profiler->mark('After create job' . $language->lang_code . ' Method: Machine'); // If there are translations for this language and for this translation method if ($machineJob !== null) { NenoLog::add(count($machineJob->getTranslations()) . ' translations have been found to translate through machine translation'); } $proJob = NenoJob::createJob($language->lang_code, NenoContentElementTranslation::PROFESSIONAL_TRANSLATION_METHOD); // If there are translations for this language and for this translation method if ($proJob !== null) { NenoLog::add(count($proJob->getTranslations()) . ' translations have been found to translate through professional translation'); } if ($machineJob !== null || $proJob !== null) { NenoTaskMonitor::addTask('job_sender'); } } } }
/** * Execute the task * * @param array $taskData Task data * * @return bool True on success, false otherwise * * @throws Exception */ public function run($taskData) { $jobs = NenoJob::load(array('_order' => array('created_time' => 'ASC'), '_limit' => 1)); // If it's not an array, let's convert to that if (!is_array($jobs)) { $jobs = array($jobs); } /* @var $job NenoJob */ foreach ($jobs as $job) { $job->sendJob(); } }
/** * This task will create a job * * @return void */ public function createJob() { $app = JFactory::getApplication(); $input = $app->input; $type = $input->post->getString('type'); $language = $input->post->getString('language'); if (!empty($type) && !empty($language)) { $job = NenoJob::createJob($language, $type); if ($job !== null) { echo 'ok'; } else { echo 'err'; } } else { echo 'err'; } $app->close(); }
/** * Fetch job file from server * * @return void */ public function fetch() { $app = JFactory::getApplication(); $input = $app->input; $jobId = $input->getInt('jobId'); /* @var $job NenoJob */ $job = NenoJob::load($jobId, false, true); if ($job->fetchJobFromServer() === true) { if ($job->processJobFinished() === true) { $job->setState(NenoJob::JOB_STATE_PROCESSED)->persist(); $app->enqueueMessage('Job #' . $job->getId() . ' has been successfully processed.'); } else { $app->enqueueMessage('There as an error reading the content of the file.', 'error'); } } else { $app->enqueueMessage('There was an error fetching the file from the API server', 'error'); } $app->redirect('index.php?option=com_neno&view=jobs'); }
/** * Execute the task * * @param array|null $taskData Task data * * @return bool True on success, false otherwise */ public function run($taskData) { $jobs = NenoJob::load(array('state' => NenoJob::JOB_STATE_COMPLETED)); // If there is only one job, let's transform it to an array if (!is_array($jobs)) { $jobs = array($jobs); } /* @var $job NenoJob */ foreach ($jobs as $job) { if ($job->fetchJobFromServer() === true) { if ($job->processJobFinished() === true) { $job->setState(NenoJob::JOB_STATE_PROCESSED)->persist(); NenoLog::add('Job #' . $job->getId() . ' has been successfully processed.'); } else { NenoLog::add('There as an error reading the content of the file.', NenoLog::PRIORITY_ERROR); } } else { NenoLog::add('There was an error fetching the file from the API server', NenoLog::PRIORITY_ERROR); } } }
/** * Set a translation as ready * * @return void */ public function translationReady() { $input = $this->input; $jobId = $input->get->getString('jobId'); /* @var $job NenoJob */ $job = NenoJob::load($jobId); if ($job === null) { NenoLog::add('Job not found. Job Id:' . $jobId, NenoLog::PRIORITY_ERROR); } else { // Set the job as completed by the server but the component hasn't processed it yet. $job->setState(NenoJob::JOB_STATE_COMPLETED)->persist(); // Create task into the queue NenoTaskMonitor::addTask('job_fetcher'); echo 'ok'; } JFactory::getApplication()->close(); }
/** * Get the total amount of record * * @return int */ public function getTotal() { $result = NenoJob::load(array('_select' => array('COUNT(*) AS counter'))); return (int) $result['counter']; }
/** * Find a job and creates it. * * @param string $toLanguage JISO Language format * @param string $translationMethod Translation Method chosen * * @return NenoJob|null It will return a NenoJob object if there are translations pending or null if there aren't any. */ public static function createJob($toLanguage, $translationMethod) { /* @var $db NenoDatabaseDriverMysqlx */ $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('id')->from('#__neno_content_element_translations AS tr')->where(array('language = ' . $db->quote($toLanguage), 'state = ' . NenoContentElementTranslation::NOT_TRANSLATED_STATE, 'EXISTS (SELECT 1 FROM #__neno_content_element_translation_x_translation_methods AS trtm WHERE tr.id = trtm.translation_id AND translation_method_id = ' . $translationMethod . ')', 'NOT EXISTS (SELECT 1 FROM #__neno_jobs_x_translations AS jt WHERE tr.id = jt.translation_id)')); $db->setQuery($query); $translationObjects = $db->loadArray(); $job = null; if (!empty($translationObjects)) { $jobData = array('fromLanguage' => NenoSettings::get('source_language'), 'toLanguage' => $toLanguage, 'state' => self::JOB_STATE_GENERATED, 'createdTime' => new DateTime(), 'translationMethod' => $translationMethod); $job = new NenoJob($jobData); $job->setTranslations($translationObjects)->persist(); NenoTaskMonitor::addTask('job_sender'); } return $job; }