/** * @param TranslationProxy_Project $project * * @return array */ function poll_for_translations($project) { /** @var WPML_String_Translation $WPML_String_Translation */ global $sitepress, $WPML_String_Translation; $pending_jobs = $project->pending_jobs(); $cancelled_jobs = $project->cancelled_jobs(); $results = array_fill_keys(array('completed', 'cancelled', 'errors'), 0); $posts_need_sync = array(); if ($pending_jobs) { foreach ($pending_jobs as $job) { $ret = $this->pro_translation->download_and_process_translation($job->id, $job->cms_id); if ($ret) { $results['completed']++; if ($job->cms_id) { list(, $id_to_sync) = $this->cms_id_helper->parse_cms_id($job->cms_id); } else { $id_to_sync = $job->id; } $posts_need_sync[] = $id_to_sync; } } } if (!empty($cancelled_jobs)) { foreach ($cancelled_jobs as $job) { $ret = false; if ($job->cms_id != "") { //we have a cms id for post translations $ret = $this->pro_translation->cancel_translation($job->id, $job->cms_id); $ret = $ret ? 1 : 0; } else { //we only have an empty string here for string translations if (isset($WPML_String_Translation)) { $ret = isset($job->id) ? $WPML_String_Translation->cancel_remote_translation($job->id) : false; } } if ($ret) { $results['cancelled'] += $ret; } } } $sitepress->set_setting('last_picked_up', strtotime(current_time('mysql'))); $sitepress->save_settings(); $this->pro_translation->enqueue_project_errors($project); do_action('wpml_new_duplicated_terms', $posts_need_sync, false); return $results; }
/** * Last ajax call in the multiple ajax calls made during the commit of a batch. * Empties the basket in case the commit worked error free responds to the ajax call. * */ function send_basket_commit() { $errors = array(); try { $translators = isset($_POST['translators']) ? $_POST['translators'] : array(); $has_remote_translators = $this->networking->contains_remote_translators($translators); $response = $this->project && $has_remote_translators ? $this->project->commit_batch_job() : true; $response = !empty($this->project->errors) ? false : $response; if ($response !== false && is_object($response)) { $response->call_to_action = '<strong>' . sprintf(__('You have sent items to %s. Please check if additional steps are required on their end', 'wpml-translation-management'), $this->project->current_service_name()) . '</strong>'; } $errors = $response === false && $this->project ? $this->project->errors : $errors; } catch (Exception $e) { $response = false; $errors[] = $e->getMessage(); } $this->send_json_response($response, $errors); }
/** * @param object $service * * @throw TranslationProxy_Project * @return TranslationProxy_Project */ private function create_project($service) { $icl_translation_projects = $this->sitepress->get_setting('icl_translation_projects', array()); $delivery = (int) $this->sitepress->get_setting('translation_pickup_method') === ICL_PRO_TRANSLATION_PICKUP_XMLRPC ? "xmlrpc" : "polling"; if (isset($icl_translation_projects[TranslationProxy_Project::generate_service_index($service)])) { $project = $this->project_factory->project($service, $delivery); } else { $wp_api = $this->sitepress->get_wp_api(); $url = $wp_api->get_option('siteurl'); $name = $wp_api->get_option('blogname'); $description = $wp_api->get_option('blogdescription'); $project = $this->project_factory->project($service); $project->create($url, $name, $description, $delivery); } return $project; }
/** * @return bool|array */ public static function get_extra_fields_local() { global $sitepress; $service = TranslationProxy::get_current_service(); $icl_translation_projects = $sitepress->get_setting('icl_translation_projects'); if (isset($icl_translation_projects[TranslationProxy_Project::generate_service_index($service)]['extra_fields']) && !empty($icl_translation_projects[TranslationProxy_Project::generate_service_index($service)]['extra_fields'])) { return $icl_translation_projects[TranslationProxy_Project::generate_service_index($service)]['extra_fields']; } else { return false; } }
/** * @param TranslationProxy_Project $project * @param bool $batch_mode * @param int $translator_id * @param WPML_TM_CMS_ID $cms_id_helper * @param TranslationManagement $tm_instance * @param null|string $note * * @return array */ function send_to_tp($project, $batch_mode, $translator_id, &$cms_id_helper, &$tm_instance, $note = null) { global $wpdb; $this->maybe_load_basic_data(); $file = $this->to_xliff_file(); $title = $this->get_title(); $cms_id = $cms_id_helper->cms_id_from_job_id($this->get_id()); $url = $this->get_url(true); $word_count = $this->estimate_word_count(); $note = isset($note) ? $note : ''; $is_update = intval($this->get_resultant_element_id()); $source_language = $this->get_source_language_code(); $target_language = $this->get_language_code(); try { if ($batch_mode) { $res = $project->send_to_translation_batch_mode($file, $title, $cms_id, $url, $source_language, $target_language, $word_count, $translator_id, $note, $is_update); } else { $res = $project->send_to_translation($file, $title, $cms_id, $url, $source_language, $target_language, $word_count, $translator_id, $note, $is_update); } } catch (Exception $err) { // The translation entry will be removed $res = 0; } $translation_id = $this->get_translation_id(); if ($res) { $tm_instance->update_translation_status(array('translation_id' => $translation_id, 'translator_id' => $translator_id, 'status' => ICL_TM_IN_PROGRESS, 'needs_update' => 0)); } else { $previous_state = $wpdb->get_var($wpdb->prepare("\tSELECT _prevstate\n\t\t\t\t\t\t\t\t\tFROM {$wpdb->prefix}icl_translation_status\n\t\t\t\t\t\t\t\t\tWHERE translation_id=%d\n\t\t\t\t\t\t\t\t\tLIMIT 1", $translation_id)); if (!empty($previous_state)) { $previous_state = unserialize($previous_state); $data = array('status' => $previous_state['status'], 'translator_id' => $previous_state['translator_id'], 'needs_update' => $previous_state['needs_update'], 'md5' => $previous_state['md5'], 'translation_service' => $previous_state['translation_service'], 'translation_package' => $previous_state['translation_package'], 'timestamp' => $previous_state['timestamp'], 'links_fixed' => $previous_state['links_fixed']); $data_where = array('translation_id' => $translation_id); $wpdb->update($wpdb->prefix . 'icl_translation_status', $data, $data_where); } else { $data = array('status' => ICL_TM_NOT_TRANSLATED, 'needs_update' => 0); $data_where = array('translation_id' => $translation_id); $wpdb->update($wpdb->prefix . 'icl_translation_status', $data, $data_where); } $err = true; } return array(isset($err) ? $err : false, $project, $res); }
private function icl_project_hash_key() { $icl_service = TranslationProxy_Service::get_service($this->get_icl_service_id()); return TranslationProxy_Project::generate_service_index($icl_service); }