/** * Runs the authentication request against the Translation Proxy API */ public function run() { $service = $this->get_current_service(); if ((bool) $service === false) { throw new RuntimeException('Tried to authenticate a service, but no service is active!'); } $service->custom_fields_data = $this->custom_field_data; $this->set_current_service($service); $project = $this->create_project($service); $translation_projects = $this->sitepress->get_setting('icl_translation_projects'); $extra_fields = $this->tp_networking->get_extra_fields_remote($project); // Store project, to be used if service is restored $translation_projects[TranslationProxy_Project::generate_service_index($service)] = array('id' => $project->id, 'access_key' => $project->access_key, 'ts_id' => $project->ts_id, 'ts_access_key' => $project->ts_access_key, 'extra_fields' => $extra_fields); $this->sitepress->set_setting('icl_translation_projects', $translation_projects, true); }
/** * Creates a translation project in TP. * * @return object * * @throws RuntimeException in case the project could not be created */ public function run() { $service = $this->project->service(); $params = array('service' => array('id' => $service->id), 'project' => $this->params, "custom_fields" => $service->custom_fields_data); try { $response = $this->networking->send_request(OTG_TRANSLATION_PROXY_URL . '/projects.json', $params, 'POST'); if (empty($response->project->id)) { throw new RuntimeException('Response: `' . serialize($response) . '` did not contain a valid project!'); } } catch (Exception $e) { $invalidation = new WPML_TP_Service_Invalidation($this->sitepress); $invalidation->run(); throw new RuntimeException('Could not create project with params: `' . serialize($this->params) . '`', 0, $e); } return $response->project; }