예제 #1
0
 /**
  * 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');
             }
         }
     }
 }
예제 #2
0
파일: scan.php 프로젝트: javigomez/neno
 /**
  * Execute the task
  *
  * @param   array $taskData Task data
  *
  * @return bool True on success, false otherwise
  */
 public function run($taskData)
 {
     /* @var $group NenoContentElementGroup */
     $group = NenoContentElementGroup::load(array('_order' => array('id' => 'asc'), '_limit' => 1, '_offset' => $taskData['group'] - 1));
     $group->refresh();
     NenoTaskMonitor::addTask('scan', array('group' => $taskData['group'] + 1));
 }
예제 #3
0
파일: neno.php 프로젝트: javigomez/neno
 /**
  * Entry point for CLI script
  *
  * @return  void
  *
  * @since   3.0
  */
 public function doExecute()
 {
     $nenoLoader = JPATH_LIBRARIES . '/neno/loader.php';
     if (file_exists($nenoLoader)) {
         JLoader::register('NenoLoader', $nenoLoader);
         // Register the Class prefix in the autoloader
         NenoLoader::init(false);
         // Load custom driver.
         JFactory::$database = null;
         JFactory::$database = NenoFactory::getDbo();
     }
     NenoTaskMonitor::runTask();
 }
예제 #4
0
 /**
  * Install language
  *
  * @return void
  */
 public function installLanguage()
 {
     $input = $this->input;
     $updateId = $input->post->getInt('update');
     $language = $input->post->getString('language');
     $placement = $input->post->getCmd('placement');
     if (NenoHelper::installLanguage($updateId, $placement != 'dashboard')) {
         /* @var $db NenoDatabaseDriverMysqlx */
         $db = JFactory::getDbo();
         $query = $db->getQuery(true);
         $query->select(array('l.lang_code', 'l.published', 'l.title', 'l.image', 'tr.state', 'SUM(tr.word_counter) AS word_count'))->from('#__languages AS l')->leftJoin('#__neno_content_element_translations AS tr ON tr.language = l.lang_code')->where('l.lang_code = ' . $db->quote($language))->group(array('l.lang_code', 'tr.state'))->order('lang_code');
         $db->setQuery($query);
         $languages = $db->loadObjectListMultiIndex('lang_code');
         $item = new stdClass();
         foreach ($languages as $language) {
             $translated = 0;
             $queued = 0;
             $changed = 0;
             $untranslated = 0;
             $item->lang_code = $language[0]->lang_code;
             $item->published = $language[0]->published;
             $item->title = $language[0]->title;
             $item->image = $language[0]->image;
             $item->errors = NenoHelper::getLanguageErrors((array) $language[0]);
             $item->translationMethods = NenoHelper::getLanguageDefault($item->lang_code);
             // If the language was installed from the dashboard, let's add a task to set all the shadow tables structure
             if ($placement == 'dashboard') {
                 // Add task to
                 NenoTaskMonitor::addTask('language', array('language' => $item->lang_code));
                 // Create menu structure for this language
                 NenoHelper::createMenuStructureForLanguage($item->lang_code);
             }
             $item->isInstalled = NenoHelper::isCompletelyInstall($language[0]->lang_code);
             foreach ($language as $internalItem) {
                 switch ($internalItem->state) {
                     case NenoContentElementTranslation::TRANSLATED_STATE:
                         $untranslated = (int) $internalItem->word_count;
                         break;
                     case NenoContentElementTranslation::QUEUED_FOR_BEING_TRANSLATED_STATE:
                         $untranslated = (int) $internalItem->word_count;
                         break;
                     case NenoContentElementTranslation::SOURCE_CHANGED_STATE:
                         $untranslated = (int) $internalItem->word_count;
                         break;
                     case NenoContentElementTranslation::NOT_TRANSLATED_STATE:
                         $untranslated = (int) $internalItem->word_count;
                         break;
                 }
             }
             $item->wordCount = new stdClass();
             $item->wordCount->translated = $translated;
             $item->wordCount->queued = $queued;
             $item->wordCount->changed = $changed;
             $item->wordCount->untranslated = $untranslated;
             $item->wordCount->total = $translated + $queued + $changed + $untranslated;
             $item->placement = $placement;
         }
         echo JLayoutHelper::render('languageconfiguration', get_object_vars($item), JPATH_NENO_LAYOUTS);
     } else {
         echo 'err';
     }
     JFactory::getApplication()->close();
 }
예제 #5
0
 /**
  * Calculate maximum execution time
  *
  * @return void
  */
 protected static function calculateMaxExecutionTime()
 {
     if (self::$maxExecutionTime === null) {
         // Setting max_execution_time to 1 hour
         $result = set_time_limit(3600);
         $executionTime = 3600;
         // If no value could be set, let's get the default one.
         if ($result === false) {
             $executionTime = ini_get('max_execution_time');
         }
         self::$maxExecutionTime = $executionTime * 0.9;
     }
 }
예제 #6
0
 public function saveTableFilters()
 {
     $app = JFactory::getApplication();
     $input = $app->input;
     $filters = $input->post->get('filters', array(), 'ARRAY');
     $tableId = $input->post->getInt('tableId');
     if (!empty($filters) && !empty($tableId)) {
         $db = JFactory::getDbo();
         $query = $db->getQuery(true);
         $query->delete('#__neno_content_element_table_filters')->where('table_id = ' . (int) $tableId);
         $db->setQuery($query);
         $db->execute();
         $query->clear()->insert('#__neno_content_element_table_filters')->columns(array('table_id', 'field_id', 'comparaison_operator', 'filter_value'));
         foreach ($filters as $filter) {
             $query->values($db->quote($tableId) . ',' . $db->quote($filter['field']) . ',' . $db->quote($filter['operator']) . ',' . $db->quote($filter['value']));
         }
         $db->setQuery($query);
         $db->execute();
         // Adding task for table maintenance
         NenoTaskMonitor::addTask('maintenance', array('tableId' => $tableId));
         echo 'ok';
     }
     $app->close();
 }
예제 #7
0
파일: job.php 프로젝트: javigomez/neno
 /**
  * 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;
 }