public static function update_translation_batch($batch_name = false, $tp_id = false)
 {
     global $wpdb;
     $batch_name = $batch_name ? $batch_name : ((bool) $tp_id === false || $tp_id === 'local' ? self::get_generic_batch_name() : TranslationProxy_Basket::get_basket_name());
     if (!$batch_name) {
         return null;
     }
     $cache_key = md5($batch_name);
     $cache_group = 'update_translation_batch';
     $cache_found = false;
     $batch_id = wp_cache_get($cache_key, $cache_group, false, $cache_found);
     if ($cache_found && $batch_id) {
         return $batch_id;
     }
     $batch_id_sql = "SELECT id FROM {$wpdb->prefix}icl_translation_batches WHERE batch_name=%s";
     $batch_id_prepared = $wpdb->prepare($batch_id_sql, array($batch_name));
     $batch_id = $wpdb->get_var($batch_id_prepared);
     if (!$batch_id) {
         $data = array('batch_name' => $batch_name, 'last_update' => date('Y-m-d H:i:s'));
         if ($tp_id) {
             if ($tp_id === 'local') {
                 $tp_id = 0;
             }
             $data['tp_id'] = $tp_id;
         }
         $wpdb->insert($wpdb->prefix . 'icl_translation_batches', $data);
         $batch_id = $wpdb->insert_id;
         wp_cache_set($cache_key, $batch_id, $cache_group);
     }
     return $batch_id;
 }
 /**
  * Returns the name of the current translation basket.
  *
  * @return bool|string
  */
 function get_name()
 {
     return TranslationProxy_Basket::get_basket_name();
 }
Ejemplo n.º 3
0
 public function rollback_basket_commit()
 {
     TranslationProxy_Basket::get_basket(true);
     $basket_name = TranslationProxy_Basket::get_basket_name();
     $basket_name = $basket_name ? $basket_name : filter_input(INPUT_POST, 'basket_name', FILTER_SANITIZE_STRING);
     $batch_id = TranslationProxy::get_batch_id_from_name($basket_name);
     if ($batch_id) {
         $batch = new WPML_Translation_Batch($batch_id);
         $batch->cancel_all_remote_jobs();
     }
 }
 /**
  * Sends all jobs from basket in batch mode to translation proxy
  *
  * @param array $data POST data
  *
  * @return bool    Returns false in case of errors (read from TranslationManagement::get_messages('error') to get errors details)
  */
 function send_all_jobs($data)
 {
     if (!isset($data) || !is_array($data)) {
         return false;
     }
     // 1. get wp_option with basket
     $basket_name = TranslationProxy_Basket::get_basket_name();
     if (!$basket_name) {
         $basket_name = isset($data['basket_name']) ? $data['basket_name'] : false;
         if ($basket_name) {
             TranslationProxy_Basket::set_basket_name($basket_name);
         }
     }
     $this->set_translation_jobs_basket($data);
     // check if we have local and remote translators
     $translators = isset($data['translators']) ? $data['translators'] : array();
     // find all target languages for remote service (it is required to create proper batch in translation proxy)
     $this->set_remote_target_languages($translators);
     // save information about target languages for remote service
     TranslationProxy_Basket::set_remote_target_languages($this->remote_target_languages);
     $basket_items_types = TranslationProxy_Basket::get_basket_items_types();
     foreach ($basket_items_types as $item_type_name => $item_type) {
         $type_basket_items = array();
         if (isset($this->translation_jobs_basket[$item_type_name])) {
             $type_basket_items = $this->translation_jobs_basket[$item_type_name];
         }
         do_action('wpml_tm_send_' . $item_type_name . '_jobs', $item_type_name, $item_type, $type_basket_items, $translators, $basket_name);
     }
     // check if there were no errors
     return !$this->messages_by_type('error');
 }
 /**
  * @param bool|int $tp_batch_id
  *
  * @link http://git.icanlocalize.com/onthego/translation_proxy/wikis/commit_batch_job
  *
  * @return array|bool|mixed|null|stdClass|string
  */
 function commit_batch_job($tp_batch_id = false)
 {
     $tp_batch_id = $tp_batch_id ? $tp_batch_id : $this->get_batch_job_id();
     if (!$tp_batch_id) {
         return true;
     }
     $params = array("api_version" => TranslationProxy_Api::API_VERSION, 'project_id' => $this->id, 'accesskey' => $this->access_key, 'batch_id' => $tp_batch_id);
     try {
         $response = TranslationProxy_Api::proxy_request('/batches/{batch_id}/commit.json', $params, 'PUT', false);
         $basket_name = TranslationProxy_Basket::get_basket_name();
         if ($basket_name) {
             global $wpdb;
             $batch_id_sql = "SELECT id FROM {$wpdb->prefix}icl_translation_batches WHERE batch_name=%s";
             $batch_id_prepared = $wpdb->prepare($batch_id_sql, array($basket_name));
             $batch_id = $wpdb->get_var($batch_id_prepared);
             $batch_data = array('batch_name' => $basket_name, 'tp_id' => $tp_batch_id, 'last_update' => date('Y-m-d H:i:s'));
             if (isset($response) && $response) {
                 $batch_data['ts_url'] = serialize($response);
             }
             if (!$batch_id) {
                 $wpdb->insert($wpdb->prefix . 'icl_translation_batches', $batch_data);
             } else {
                 $wpdb->update($wpdb->prefix . 'icl_translation_batches', $batch_data, array('id' => $batch_id));
             }
         }
         return isset($response) ? $response : false;
     } catch (Exception $ex) {
         $this->add_error($ex->getMessage());
         return false;
     }
 }
 private function commit_basket($translation_id)
 {
     $basket_networking = wpml_tm_load_basket_networking();
     $translator_array = $this->build_translator_array($translation_id);
     if ($translator_array) {
         $basket_networking->commit_basket_chunk(array(), TranslationProxy_Basket::get_basket_name(), $translator_array);
     }
     $project = TranslationProxy::get_current_project();
     $project->commit_batch_job();
     TranslationProxy_Basket::delete_all_items_from_basket();
 }