public function testLoadContainers() { self::$account->get_settings()->set("auth_token", "somethingNotNull"); //connected $url = sprintf("/prod/bridge/adapter/%s/load-containers/%s/", self::$account->get_id(), self::$account->get_api()->get_connector()->get_default_container_type()); $crawler = self::$DI['client']->request('GET', $url, ["page" => 1]); $elements = \Bridge_Element::get_elements_by_account(self::$DI['app'], self::$account); $this->assertTrue(self::$DI['client']->getResponse()->isOk()); $this->assertNotContains(self::$account->get_api()->generate_login_url(self::$DI['app']['url_generator'], self::$account->get_api()->get_connector()->get_name()), self::$DI['client']->getResponse()->getContent()); }
/** * @param Bridge_Element $element * * @return BridgeJob */ protected function update_element(Application $app, \Bridge_Element $element) { $account = $element->get_account(); $connector_status = $account->get_api()->get_element_status($element); $status = $element->get_account()->get_api()->map_connector_to_element_status($connector_status); $error_message = $element->get_account()->get_api()->get_error_message_from_status($connector_status); $previous_status = $element->get_status(); if ($status) { $element->set_status($status); $this->log('debug', 'updating status for : ' . $element->get_id() . " to " . $status); } $element->set_connector_status($connector_status); if ($status === $previous_status) { return; } switch ($status) { case \Bridge_Element::STATUS_ERROR: $app['dispatcher']->dispatch(new BridgeUploadFailureEvent($element, $error_message)); break; default: case \Bridge_Element::STATUS_DONE: case \Bridge_Element::STATUS_PENDING: case \Bridge_Element::STATUS_PROCESSING_SERVER: case \Bridge_Element::STATUS_PROCESSING: break; } return $this; }
public function doPostUpload(Application $app, Request $request) { $errors = []; $account = \Bridge_Account::load_account($app, $request->request->get('account_id')); $this->requireConnection($app, $account); $route = new RecordHelper\Bridge($app, $request); $route->grep_records($account->get_api()->acceptable_records()); $connector = $account->get_api()->get_connector(); // check constraints foreach ($route->get_elements() as $record) { $datas = $connector->get_upload_datas($request, $record); $errors = array_merge($errors, $connector->check_upload_constraints($datas, $record)); } if (count($errors) > 0) { $params = ['route' => $route, 'account' => $account, 'error_message' => $app->trans('Request contains invalid datas'), 'constraint_errors' => $errors, 'notice_message' => $request->request->get('notice'), 'adapter_action' => 'upload']; return $app['twig']->render('prod/actions/Bridge/' . $account->get_api()->get_connector()->get_name() . '/upload.html.twig', $params); } foreach ($route->get_elements() as $record) { $datas = $connector->get_upload_datas($request, $record); $title = isset($datas["title"]) ? $datas["title"] : ''; $default_type = $connector->get_default_element_type(); \Bridge_Element::create($app, $account, $record, $title, \Bridge_Element::STATUS_PENDING, $default_type, $datas); } return $app->redirect('/prod/bridge/adapter/' . $account->get_id() . '/load-records/?notice=' . $app->trans('%quantity% elements en attente', ['%quantity%' => count($route->get_elements())])); }
/** * * @param Bridge_Element $element * * @return Array */ public function get_element_status(Bridge_Element $element) { $url = sprintf("/%s/%s", $element->get_type(), $element->get_dist_id()); $result = $this->_api->call($url, ['fields' => ['status']], $this->oauth_token); return $result["status"]; }
/** * * @param Bridge_Element $element * * @return string */ public function get_element_status(Bridge_Element $element) { $this->_api->setMajorProtocolVersion(1); $state = $this->_api->getFullVideoEntry($element->get_dist_id())->getVideoState(); if (is_null($state)) { $result = Bridge_Element::STATUS_DONE; } else { $result = $state->getName(); } $this->_api->setMajorProtocolVersion(2); return $result; }
public function testGet_elements_by_account() { $elements = Bridge_Element::get_elements_by_account(self::$DI['app'], $this->account); $this->assertTrue(is_array($elements)); $this->assertGreaterThan(0, count($elements)); foreach ($elements as $element) { $this->assertInstanceOf('Bridge_Element', $element); } }
/** * * @return Void */ public function delete() { do { $elements = Bridge_Element::get_elements_by_account($this->app, $this); foreach ($elements as $element) { $element->delete(); } } while (count($elements) > 0); $sql = 'DELETE FROM bridge_accounts WHERE id = :id'; $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute([':id' => $this->id]); $stmt->closeCursor(); return; }
public function get_element_status(Bridge_Element $element) { try { $ticket = $this->checkTicket($element->get_dist_id(), $element->get_type()); if ($ticket["status"] == self::UPLOAD_STATE_DONE) { $this->get_element_from_id($ticket["dist_id"], $element->get_type()); $element->set_dist_id($ticket["dist_id"]); } } catch (\Exception $e) { return self::UPLOAD_STATE_FAILED; } return $ticket["status"]; }
/** * @param Bridge_Element $element * * @return BridgeJob */ protected function update_element(Application $app, \Bridge_Element $element) { $account = $element->get_account(); $connector_status = $account->get_api()->get_element_status($element); $status = $element->get_account()->get_api()->map_connector_to_element_status($connector_status); $error_message = $element->get_account()->get_api()->get_error_message_from_status($connector_status); $previous_status = $element->get_status(); if ($status) { $element->set_status($status); $this->log('debug', 'updating status for : ' . $element->get_id() . " to " . $status); } $element->set_connector_status($connector_status); if ($status === $previous_status) { return; } switch ($status) { case \Bridge_Element::STATUS_ERROR: $params = ['usr_id' => $account->get_user()->getId(), 'reason' => $error_message, 'account_id' => $account->get_id(), 'sbas_id' => $element->get_record()->get_sbas_id(), 'record_id' => $element->get_record()->get_record_id()]; $app['events-manager']->trigger('__BRIDGE_UPLOAD_FAIL__', $params); break; default: case \Bridge_Element::STATUS_DONE: case \Bridge_Element::STATUS_PENDING: case \Bridge_Element::STATUS_PROCESSING_SERVER: case \Bridge_Element::STATUS_PROCESSING: break; } return $this; }