コード例 #1
0
 /**
  *
  * @param  string $key
  * @return string
  */
 public function delete($key)
 {
     $return_value = $this->get($key);
     $sql = 'DELETE FROM bridge_account_settings
         WHERE account_id = :account_id AND `key` = :key';
     $params = [':account_id' => $this->account->get_id(), ':key' => $key];
     $stmt = $this->appbox->get_connection()->prepare($sql);
     $stmt->execute($params);
     $stmt->closeCursor();
     return $return_value;
 }
コード例 #2
0
ファイル: AbstractTest.php プロジェクト: nlegoff/Phraseanet
 public function bootTestCase()
 {
     $application = self::$DI['app'];
     try {
         self::$api = Bridge_Api::get_by_api_name($application, 'apitest');
     } catch (Bridge_Exception_ApiNotFound $e) {
         self::$api = Bridge_Api::create($application, 'apitest');
     }
     try {
         self::$account = Bridge_Account::load_account_from_distant_id($application, self::$api, self::$DI['user'], 'kirikoo');
     } catch (Bridge_Exception_AccountNotFound $e) {
         self::$account = Bridge_Account::create($application, self::$api, self::$DI['user'], 'kirikoo', 'coucou');
     }
 }
コード例 #3
0
 /**
  *
  * @param  Array   $datas
  * @param  boolean $unread
  * @return Array
  */
 public function datas(array $data, $unread)
 {
     $reason = $data['reason'];
     $account_id = $data['account_id'];
     $sbas_id = $data['sbas_id'];
     $rid = $data['record_id'];
     try {
         $account = Bridge_Account::load_account($this->app, $account_id);
         $record = new record_adapter($this->app, $sbas_id, $rid);
     } catch (\Exception $e) {
         return [];
     }
     $ret = ['text' => $this->app->trans("L'upload concernant le record %title% sur le compte %bridge_name% a echoue pour les raisons suivantes : %reason%", ['%title%' => $record->get_title(), '%bridge_name%' => $account->get_api()->get_connector()->get_name(), '%reason%' => $reason]), 'class' => ''];
     return $ret;
 }
コード例 #4
0
 public function setUp()
 {
     parent::setUp();
     try {
         $sql = 'DELETE FROM bridge_apis WHERE name = "Apitest"';
         $stmt = self::$DI['app']['phraseanet.appbox']->get_connection()->prepare($sql);
         $stmt->execute();
         $stmt->closeCursor();
         $this->api = Bridge_Api::create(self::$DI['app'], 'Apitest');
         $this->dist_id = 'EZ1565loPP';
         $this->named = 'Fête à pinpins';
         $this->account = Bridge_Account::create(self::$DI['app'], $this->api, self::$DI['user'], $this->dist_id, $this->named);
         $this->object = new Bridge_AccountSettings(self::$DI['app']['phraseanet.appbox'], $this->account);
     } catch (Exception $e) {
         $this->fail($e->getMessage());
     }
 }
コード例 #5
0
ファイル: ElementTest.php プロジェクト: luisbrito/Phraseanet
 public function setUp()
 {
     parent::setUp();
     $sql = 'DELETE FROM bridge_apis WHERE name = "Apitest"';
     $stmt = self::$DI['app']->getApplicationBox()->get_connection()->prepare($sql);
     $stmt->execute();
     $stmt->closeCursor();
     $this->api = Bridge_Api::create(self::$DI['app'], 'Apitest');
     $this->dist_id = 'EZ1565loPP';
     $this->named = 'Fête à pinpins';
     $this->account = Bridge_Account::create(self::$DI['app'], $this->api, self::$DI['user'], $this->dist_id, $this->named);
     $this->title = 'GOGACKO';
     $this->status = 'Processing';
     $element = Bridge_Element::create(self::$DI['app'], $this->account, self::$DI['record_1'], $this->title, $this->status, $this->account->get_api()->get_connector()->get_default_element_type());
     $this->id = $element->get_id();
     $this->object = new Bridge_Element(self::$DI['app'], $this->account, $this->id);
 }
コード例 #6
0
ファイル: AbstractTest.php プロジェクト: luisbrito/Phraseanet
 public function setUp()
 {
     parent::setUp();
     $this->auth = $this->getMock("Bridge_Api_Auth_Interface");
     $this->bridgeApi = $this->getMock('Bridge_Api_Abstract', ["is_configured", "initialize_transport", "set_auth_params", "set_transport_authentication_params"], [self::$DI['app']['url_generator'], self::$DI['app']['conf'], $this->auth, self::$DI['app']['translator']]);
     if (!self::$api) {
         $application = $this->getApplication();
         try {
             self::$api = Bridge_Api::get_by_api_name($application, 'apitest');
         } catch (Bridge_Exception_ApiNotFound $e) {
             self::$api = Bridge_Api::create($application, 'apitest');
         }
         try {
             self::$account = Bridge_Account::load_account_from_distant_id($application, self::$api, self::$DI['user'], 'kirikoo');
         } catch (Bridge_Exception_AccountNotFound $e) {
             self::$account = Bridge_Account::create($application, self::$api, self::$DI['user'], 'kirikoo', 'coucou');
         }
     }
 }
コード例 #7
0
ファイル: BridgeJob.php プロジェクト: nlegoff/Phraseanet
 /**
  * {@inheritdoc}
  */
 protected function doJob(JobData $data)
 {
     $app = $data->getApplication();
     $status = [\Bridge_Element::STATUS_PENDING, \Bridge_Element::STATUS_PROCESSING, \Bridge_Element::STATUS_PROCESSING_SERVER];
     $params = [];
     $n = 1;
     foreach ($status as $stat) {
         $params[':status' . $n] = $stat;
         $n++;
     }
     $sql = 'SELECT id, account_id FROM bridge_elements' . ' WHERE (status = ' . implode(' OR status = ', array_keys($params)) . ')';
     $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
     $stmt->execute($params);
     $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
     $stmt->closeCursor();
     foreach ($rs as $row) {
         if (!$this->isStarted()) {
             break;
         }
         try {
             $account = \Bridge_Account::load_account($app, $row['account_id']);
             $element = new \Bridge_Element($app, $account, $row['id']);
             $this->log('debug', "process " . $element->get_id() . " with status " . $element->get_status());
             if ($element->get_status() == \Bridge_Element::STATUS_PENDING) {
                 $this->upload_element($element);
             } else {
                 $this->update_element($app, $element);
             }
         } catch (\Exception $e) {
             $this->log('error', sprintf("An error occured : %s", $e->getMessage()));
             $sql = 'UPDATE bridge_elements SET status = :status WHERE id = :id';
             $params = [':status' => \Bridge_Element::STATUS_ERROR, ':id' => $row['id']];
             $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
             $stmt->execute($params);
             $stmt->closeCursor();
         }
     }
 }
コード例 #8
0
 public function testDeleteAccount()
 {
     $account = \Bridge_Account::create(self::$DI['app'], self::$api, self::$DI['app']['authentication']->getUser(), 'hello', 'you');
     $url = "/prod/bridge/adapter/" . $account->get_id() . "/delete/";
     self::$DI['client']->request('POST', $url);
     $response = self::$DI['client']->getResponse();
     $this->assertTrue($response->isOk());
     $datas = json_decode($response->getContent(), true);
     $this->assertArrayHasKey('success', $datas);
     $this->assertTrue($datas['success']);
     try {
         \Bridge_Account::load_account(self::$DI['app'], $account->get_id());
         $this->fail('Account is not deleted');
     } catch (\Bridge_Exception_AccountNotFound $e) {
     }
     unset($account, $response);
 }
コード例 #9
0
ファイル: AccountTest.php プロジェクト: nlegoff/Phraseanet
 public function testLoad_account()
 {
     $account = Bridge_Account::load_account(self::$DI['app'], self::$object->get_id());
     $this->assertEquals(self::$object->get_id(), $account->get_id());
 }
コード例 #10
0
ファイル: Bridge.php プロジェクト: nlegoff/Phraseanet
 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())]));
 }
コード例 #11
0
ファイル: Element.php プロジェクト: luisbrito/Phraseanet
 public static function create(Application $app, Bridge_Account $account, record_adapter $record, $title, $status, $type, array $datas = [])
 {
     $sql = 'INSERT INTO bridge_elements
         (id, account_id, sbas_id, record_id, dist_id, title, `type`
           , serialized_datas, status, created_on, updated_on)
         VALUES
         (null, :account_id, :sbas_id, :record_id, null, :title, :type
           ,:datas , :status, NOW(), NOW())';
     $params = [':account_id' => $account->get_id(), ':sbas_id' => $record->get_sbas_id(), ':record_id' => $record->get_record_id(), ':status' => $status, ':title' => $title, ':type' => $type, ':datas' => serialize($datas)];
     $stmt = $app->getApplicationBox()->get_connection()->prepare($sql);
     $stmt->execute($params);
     $stmt->closeCursor();
     $element_id = $app->getApplicationBox()->get_connection()->lastInsertId();
     return new self($app, $account, $element_id);
 }
コード例 #12
0
ファイル: Api.php プロジェクト: nlegoff/Phraseanet
 /**
  *
  * @return Void
  */
 public function delete()
 {
     do {
         $accounts = Bridge_Account::get_accounts_by_api($this->app, $this);
         foreach ($accounts as $account) {
             $account->delete();
         }
     } while (count($accounts) > 0);
     $sql = 'DELETE FROM bridge_apis WHERE id = :id';
     $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql);
     $stmt->execute([':id' => $this->id]);
     $stmt->closeCursor();
     return;
 }
コード例 #13
0
 /**
  *
  * @param  Array   $datas
  * @param  boolean $unread
  * @return Array
  */
 public function datas($datas, $unread)
 {
     $sx = simplexml_load_string($datas);
     $reason = (string) $sx->reason;
     $account_id = (int) $sx->account_id;
     $sbas_id = (int) $sx->sbas_id;
     $rid = (int) $sx->record_id;
     try {
         $account = Bridge_Account::load_account($this->app, $account_id);
         $record = new record_adapter($this->app, $sbas_id, $rid);
     } catch (\Exception $e) {
         return [];
     }
     $ret = ['text' => $this->app->trans("L'upload concernant le record %title% sur le compte %bridge_name% a echoue pour les raisons suivantes : %reason%", ['%title%' => $record->get_title(), '%bridge_name%' => $account->get_api()->get_connector()->get_name(), '%reason%' => $reason]), 'class' => ''];
     return $ret;
 }