/** * @param string $cms_id * @param bool|TranslationProxy_Service $translation_service * * @return int|null translation id for the given cms_id's target */ public function get_translation_id($cms_id, $translation_service = false) { list($post_type, $element_id, , $target_lang) = $this->parse_cms_id($cms_id); $translation = $this->wpdb->get_row($this->wpdb->prepare("\n\t\t\t\t\t\t\t\t\t\t\t\t\tSELECT t.translation_id, j.job_id, t.element_id\n\t\t\t\t\t\t\t\t\t\t\t\t\tFROM {$this->wpdb->prefix}icl_translations t\n\t\t\t\t\t\t\t\t\t\t\t\t\tJOIN {$this->wpdb->prefix}icl_translations o\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tON o.trid = t.trid\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND o.element_type = t.element_type\n\t\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN {$this->wpdb->prefix}icl_translation_status st\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tON st.translation_id = t.translation_id\n\t\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN {$this->wpdb->prefix}icl_translate_job j\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tON j.rid = st.rid\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE o.element_id=%d\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND t.language_code=%s\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND o.element_type LIKE %s\n\t\t\t\t\t\t\t\t\t\t\t\t\tLIMIT 1", $element_id, $target_lang, '%_' . $post_type)); $translation_id = $this->maybe_cleanup_broken_row($translation, $translation_service); if ($translation_service && !isset($translation_id) && $translation_service) { $job_id = $this->job_factory->create_local_post_job($element_id, $target_lang); $job = $this->job_factory->get_translation_job($job_id, false, false, true); $translation_id = $job ? $job->get_translation_id() : 0; if ($translation_id) { $this->tm_records->icl_translation_status_by_translation_id($translation_id)->update(array('status' => ICL_TM_IN_PROGRESS, 'translation_service' => $translation_service->id)); } } return $translation_id; }
/** * @param string $link * @param int $post_id * @param string $lang * @param int $trid * * @return string */ public function filter_status_link($link, $post_id, $lang, $trid) { $translated_element_id = $this->post_translations->get_element_id($lang, $trid); $source_lang = $this->post_translations->get_source_lang_code($translated_element_id); if ((bool) $translated_element_id && (bool) $source_lang === false) { return $link; } $this->maybe_load_stats($trid); $is_remote = $this->is_remote($trid, $lang); $is_in_progress = $this->is_in_progress($trid, $lang); $use_tm_editor = $this->sitepress->get_setting('doc_translation_method'); $use_tm_editor = apply_filters('wpml_use_tm_editor', $use_tm_editor); $source_lang_code = $this->post_translations->get_element_lang_code($post_id); if ($is_remote && $is_in_progress || $this->is_in_basket($trid, $lang) || !$this->is_lang_pair_allowed($lang, $source_lang)) { $link = '###'; } elseif ($source_lang_code !== $lang) { if ($is_in_progress && !$is_remote || $use_tm_editor && $translated_element_id) { $job_id = $this->job_factory->job_id_by_trid_and_lang($trid, $lang); if ($job_id) { $link = $this->get_link_for_existing_job($job_id); } else { $link = $this->get_link_for_new_job($trid, $lang, $source_lang_code); } } elseif ($use_tm_editor && !$translated_element_id) { $link = $this->get_link_for_new_job($trid, $lang, $source_lang_code); } } return $link; }
public function cancel_open_local_translators_jobs() { $translation_filter = array('service' => 'local', 'translator' => 0, 'status__not' => ICL_TM_COMPLETE); $translation_jobs = $this->job_factory->get_translation_jobs($translation_filter, true, true); $jobs_count = count($translation_jobs); $deleted = 0; if ($jobs_count) { foreach ($translation_jobs as $job) { /** @var WPML_Translation_Job $job */ if ($job && $job->cancel()) { $deleted += 1; } } } $this->set_ignore_local_jobs(false); return $this->wpml_wp_api->wp_send_json_success(array('opens' => $jobs_count - $deleted, 'cancelled' => $deleted)); }
/** * @param string $link * @param int $post_id * @param string $lang * @param int $trid * * @return string */ public function filter_status_link($link, $post_id, $lang, $trid) { $this->maybe_load_stats($trid); $is_remote = $this->is_remote($trid, $lang); $is_in_progress = $this->is_in_progress($trid, $lang); $tm_editor_link_base_url = 'admin.php?page=' . WPML_TM_FOLDER . '/menu/translations-queue.php'; $use_tm_editor = $this->sitepress->get_setting('doc_translation_method'); if ($is_remote && $is_in_progress || $this->is_in_basket($trid, $lang) || !$this->is_lang_pair_allowed($lang)) { $link = '###'; } elseif (($source_lang_code = $this->post_translations->get_element_lang_code($post_id)) && $source_lang_code !== $lang) { if ($is_in_progress && !$is_remote || $use_tm_editor && $this->post_translations->get_element_id($lang, $trid)) { $link = $tm_editor_link_base_url . '&job_id=' . $this->job_factory->job_id_by_trid_and_lang($trid, $lang); } elseif ($use_tm_editor && !$this->post_translations->get_element_id($lang, $trid)) { $link = $tm_editor_link_base_url . '&trid=' . $trid . '&language_code=' . $lang . '&source_language_code=' . $source_lang_code; } } return $link; }
/** * @param int|WPML_Translation_Job $job_id * * @return array */ private function get_mail_elements($job_id) { $job = is_object($job_id) ? $job_id : $this->job_factory->get_translation_job($job_id, false, 0, true); if (is_object($job)) { $data = $job->get_basic_data(); $manager_id = isset($data->manager_id) ? $data->manager_id : -1; } else { $job = false; $manager_id = false; } return array($manager_id, $job); }
protected function load_job_data($job_id) { return $this->job_factory->get_translation_job($job_id, false, 1); }
/** * @return WPML_Translation_Job_Factory */ function wpml_tm_load_job_factory() { global $wpml_translation_job_factory, $wpdb; if (!isset($wpml_translation_job_factory)) { $tm_records = new WPML_TM_Records($wpdb); $wpml_translation_job_factory = new WPML_Translation_Job_Factory($tm_records); $wpml_translation_job_factory->init_hooks(); } return $wpml_translation_job_factory; }