Esempio n. 1
0
 /**
  *
  * @param Application $app
  * @param databox     $databox
  * @param Browser     $browser
  *
  * @return Session_Logger
  */
 public static function create(Application $app, databox $databox, Browser $browser)
 {
     $colls = [];
     if ($app['authentication']->getUser()) {
         $bases = $app['acl']->get($app['authentication']->getUser())->get_granted_base([], [$databox->get_sbas_id()]);
         foreach ($bases as $collection) {
             $colls[] = $collection->get_coll_id();
         }
     }
     $conn = $databox->get_connection();
     $sql = "INSERT INTO log\n              (id, date,sit_session, user, site, usrid, nav,\n                version, os, res, ip, user_agent,appli, fonction,\n                societe, activite, pays)\n            VALUES\n              (null,now() , :ses_id, :usr_login, :site_id, :usr_id\n              , :browser, :browser_version,  :platform, :screen, :ip\n              , :user_agent, :appli, :fonction, :company, :activity, :country)";
     $params = [':ses_id' => $app['session']->get('session_id'), ':usr_login' => $app['authentication']->getUser() ? $app['authentication']->getUser()->getLogin() : null, ':site_id' => $app['conf']->get(['main', 'key']), ':usr_id' => $app['authentication']->isAuthenticated() ? $app['authentication']->getUser()->getId() : null, ':browser' => $browser->getBrowser(), ':browser_version' => $browser->getExtendedVersion(), ':platform' => $browser->getPlatform(), ':screen' => $browser->getScreenSize(), ':ip' => $browser->getIP(), ':user_agent' => $browser->getUserAgent(), ':appli' => serialize([]), ':fonction' => $app['authentication']->getUser() ? $app['authentication']->getUser()->getJob() : null, ':company' => $app['authentication']->getUser() ? $app['authentication']->getUser()->getCompany() : null, ':activity' => $app['authentication']->getUser() ? $app['authentication']->getUser()->getActivity() : null, ':country' => $app['authentication']->getUser() ? $app['authentication']->getUser()->getCountry() : null];
     $stmt = $conn->prepare($sql);
     $stmt->execute($params);
     $log_id = $conn->lastInsertId();
     $stmt->closeCursor();
     $sql = "INSERT INTO log_colls (id, log_id, coll_id) VALUES (null, :log_id, :coll_id)";
     $stmt = $conn->prepare($sql);
     foreach ($colls as $collId) {
         $stmt->execute([':log_id' => $log_id, ':coll_id' => $collId]);
     }
     $stmt->closeCursor();
     unset($stmt, $conn);
     return new Session_Logger($databox, $log_id);
 }
Esempio n. 2
0
 /**
  * Returns true if a databox is available given a configuration.
  *
  * @param \databox $databox
  *
  * @return Boolean
  */
 public function isDataboxAvailable(\databox $databox)
 {
     if (!$this->isRestricted()) {
         return true;
     }
     return in_array($databox->get_sbas_id(), $this->cache->fetch('available_databoxes'), true);
 }
 /**
  * @param array                $row
  * @param \record_adapter|null $record
  * @return \record_adapter
  */
 private function mapRecordFromResultRow(array $row, \record_adapter $record = null)
 {
     if (null === $record) {
         $record = new \record_adapter($this->app, $this->databox->get_sbas_id(), $row['record_id'], null, false);
     }
     $record->mapFromData($row);
     $record->putInCache();
     return $record;
 }
 public function getStructure(\databox $databox)
 {
     if (false !== ($status = $this->cache->fetch($this->get_cache_key($databox->get_sbas_id())))) {
         return new StatusStructure($databox, new ArrayCollection(json_decode($status, true)));
     }
     $structure = $this->provider->getStructure($databox);
     $this->cache->save($this->get_cache_key($databox->get_sbas_id()), json_encode($structure->toArray()));
     return $structure;
 }
 /**
  * Get the status structure according to the given databox
  *
  * @param \databox $databox
  *
  * @return StatusStructure
  */
 public function getStructure(\databox $databox)
 {
     $databox_id = $databox->get_sbas_id();
     if (isset($this->statusStructure[$databox_id])) {
         return $this->statusStructure[$databox_id];
     }
     $this->statusStructure[$databox_id] = $this->provider->getStructure($databox);
     return $this->statusStructure[$databox_id];
 }
 /**
  * Resets admin rights on a databox.
  *
  * @param \ACL     $acl
  * @param \databox $databox
  */
 private function doResetAdminRightsOnDatabox(\ACL $acl, \databox $databox)
 {
     $collections = $databox->get_collections();
     $acl->update_rights_to_sbas($databox->get_sbas_id(), ['bas_manage' => '1', 'bas_modify_struct' => '1', 'bas_modif_th' => '1', 'bas_chupub' => '1']);
     $acl->give_access_to_base(array_map(function (\collection $collection) {
         return $collection->get_base_id();
     }, $collections));
     foreach ($collections as $collection) {
         $this->doResetRightsOnCollection($acl, $collection);
     }
 }
 public function findElementsByDatabox(\databox $databox)
 {
     $dql = 'SELECT e
         FROM Phraseanet:BasketElement e
         JOIN e.basket b
         LEFT JOIN b.validation s
         LEFT JOIN s.participants p
         WHERE e.sbas_id = :sbas_id';
     $params = ['sbas_id' => $databox->get_sbas_id()];
     $query = $this->_em->createQuery($dql);
     $query->setParameters($params);
     return $query->getResult();
 }
 /**
  * @param \databox $databox
  * @param string   $token
  * @param int      $record_id
  * @param string   $subdef
  * @return \record_adapter
  */
 private function retrieveRecord(\databox $databox, $token, $record_id, $subdef)
 {
     try {
         $record = new \record_adapter($this->app, $databox->get_sbas_id(), $record_id);
         $subDefinition = new \media_subdef($this->app, $record, $subdef);
         $permalink = new \media_Permalink_Adapter($this->app, $databox, $subDefinition);
     } catch (\Exception $exception) {
         throw new NotFoundHttpException('Wrong token.', $exception);
     }
     if (!$permalink->get_is_activated()) {
         throw new NotFoundHttpException('This token has been disabled.');
     }
     /** @var FeedItemRepository $feedItemsRepository */
     $feedItemsRepository = $this->app['repo.feed-items'];
     if (in_array($subdef, [\databox_subdef::CLASS_PREVIEW, \databox_subdef::CLASS_THUMBNAIL]) && $feedItemsRepository->isRecordInPublicFeed($databox->get_sbas_id(), $record_id)) {
         return $record;
     } elseif ($permalink->get_token() == (string) $token) {
         return $record;
     }
     throw new NotFoundHttpException('Wrong token.');
 }
Esempio n. 9
0
 /**
  * Retrieve detailled informations about one databox
  * @param  databox $databox
  * @return array
  */
 protected function list_databox(databox $databox)
 {
     $ret = [];
     $ret['databox_id'] = $databox->get_sbas_id();
     $ret['name'] = $databox->get_dbname();
     $ret['viewname'] = $databox->get_viewname();
     $ret['labels'] = ['en' => $databox->get_label('en'), 'de' => $databox->get_label('de'), 'fr' => $databox->get_label('fr'), 'nl' => $databox->get_label('nl')];
     $ret['version'] = $databox->get_version();
     return $ret;
 }
Esempio n. 10
0
 public static function deleteStatus(Application $app, \databox $databox, $bit)
 {
     $status = self::getStatus($app, $databox->get_sbas_id());
     if (isset($status[$bit])) {
         $doc = $databox->get_dom_structure();
         if ($doc) {
             $xpath = $databox->get_xpath_structure();
             $entries = $xpath->query("/record/statbits/bit[@n=" . $bit . "]");
             foreach ($entries as $sbit) {
                 if ($p = $sbit->previousSibling) {
                     if ($p->nodeType == XML_TEXT_NODE && $p->nodeValue == "\n\t\t") {
                         $p->parentNode->removeChild($p);
                     }
                 }
                 if ($sbit->parentNode->removeChild($sbit)) {
                     $sql = 'UPDATE record SET status = status&(~(1<<' . $bit . '))';
                     $stmt = $databox->get_connection()->prepare($sql);
                     $stmt->execute();
                     $stmt->closeCursor();
                 }
             }
             $databox->saveStructure($doc);
             if (null !== $status[$bit]['img_off']) {
                 $app['filesystem']->remove($status[$bit]['path_off']);
             }
             if (null !== $status[$bit]['img_on']) {
                 $app['filesystem']->remove($status[$bit]['path_on']);
             }
             unset(self::$_status[$databox->get_sbas_id()]->status[$bit]);
             return true;
         }
     }
     return false;
 }
Esempio n. 11
0
 /**
  *
  * @param  Application    $app
  * @param  databox        $databox
  * @param  string         $token
  * @param  int            $record_id
  * @param  string         $name
  * @return record_adapter
  */
 public static function challenge_token(Application $app, databox $databox, $token, $record_id, $name)
 {
     $sql = 'SELECT p.id
         FROM permalinks p, subdef s
         WHERE s.record_id = :record_id
           AND s.name = :name
           AND s.subdef_id = p.subdef_id
           AND activated = "1"
           AND token = :token';
     $params = [':record_id' => $record_id, ':token' => $token, ':name' => $name];
     $stmt = $databox->get_connection()->prepare($sql);
     $stmt->execute($params);
     $row = $stmt->fetch(PDO::FETCH_ASSOC);
     $stmt->closeCursor();
     unset($stmt);
     if ($row) {
         return new record_adapter($app, $databox->get_sbas_id(), $record_id);
     }
     return null;
 }
Esempio n. 12
0
 public function findByDatabox(Application $app, \databox $databox)
 {
     $dql = 'SELECT s FROM Phraseanet:StoryWZ s WHERE s.sbas_id = :sbas_id';
     $query = $this->_em->createQuery($dql);
     $query->setParameters(['sbas_id' => $databox->get_sbas_id()]);
     $stories = $query->getResult();
     foreach ($stories as $key => $story) {
         try {
             $story->getRecord($app);
         } catch (NotFoundHttpException $e) {
             $this->getEntityManager()->remove($story);
             $this->getEntityManager()->flush();
             unset($stories[$key]);
         }
     }
     return $stories;
 }
Esempio n. 13
0
 public static function mount_collection(Application $app, databox $databox, $coll_id, User $user)
 {
     $sql = "INSERT INTO bas (base_id, active, server_coll_id, sbas_id, aliases, ord)\n            VALUES\n            (null, 1, :server_coll_id, :sbas_id, '', :ord)";
     $stmt = $databox->get_appbox()->get_connection()->prepare($sql);
     $stmt->execute([':server_coll_id' => $coll_id, ':sbas_id' => $databox->get_sbas_id(), ':ord' => self::getNewOrder($databox->get_appbox()->get_connection(), $databox->get_sbas_id())]);
     $stmt->closeCursor();
     $new_bas = $databox->get_appbox()->get_connection()->lastInsertId();
     $databox->get_appbox()->delete_data_from_cache(appbox::CACHE_LIST_BASES);
     $databox->delete_data_from_cache(databox::CACHE_COLLECTIONS);
     cache_databox::update($app, $databox->get_sbas_id(), 'structure');
     phrasea::reset_baseDatas($databox->get_appbox());
     $coll = self::get_from_base_id($app, $new_bas);
     $coll->set_admin($new_bas, $user);
     return $new_bas;
 }
Esempio n. 14
0
 /**
  * Search for a record on a databox by UUID
  *
  * @param Application $app
  * @param \databox    $databox
  * @param string      $uuid
  * @param int         $record_id Restrict check on a record_id
  *
  * @return \record_adapter
  */
 public static function get_record_by_uuid(Application $app, \databox $databox, $uuid, $record_id = null)
 {
     $sql = "SELECT record_id FROM record r\n                WHERE uuid IS NOT NULL AND uuid = :uuid";
     $params = [':uuid' => $uuid];
     if (!is_null($record_id)) {
         $sql .= ' AND record_id = :record_id';
         $params[':record_id'] = $record_id;
     }
     $stmt = $databox->get_connection()->prepare($sql);
     $stmt->execute($params);
     $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
     $stmt->closeCursor();
     $records = [];
     foreach ($rs as $row) {
         $records[] = new record_adapter($app, $databox->get_sbas_id(), $row['record_id']);
     }
     return $records;
 }
Esempio n. 15
0
 /**
  *
  * @param  databox $databox
  * @return <type>
  */
 public function is_databox_indexable(databox $databox)
 {
     $sql = 'SELECT indexable FROM sbas WHERE sbas_id = :sbas_id';
     $stmt = $this->get_connection()->prepare($sql);
     $stmt->execute([':sbas_id' => $databox->get_sbas_id()]);
     $row = $stmt->fetch(PDO::FETCH_ASSOC);
     $stmt->closeCursor();
     $indexable = $row ? $row['indexable'] : null;
     return (bool) $indexable;
 }
Esempio n. 16
0
 /**
  * Update the original name of a record
  *
  * @staticvar \PDO_statement $stmt
  * @param \databox $databox
  * @param array    $record
  */
 protected function setOriginalName(\databox $databox, array $record)
 {
     static $stmt;
     if (!isset($stmt[$databox->get_sbas_id()])) {
         $sql = 'UPDATE record SET originalname = :originalname WHERE record_id = :record_id';
         $stmt[$databox->get_sbas_id()] = $databox->get_connection()->prepare($sql);
     }
     $original = '';
     if (false !== ($sxe = simplexml_load_string($record['xml']))) {
         foreach ($sxe->doc->attributes() as $key => $value) {
             if (trim($key) != 'originalname') {
                 continue;
             }
             $original = basename(trim($value));
             break;
         }
     }
     $stmt[$databox->get_sbas_id()]->execute([':originalname' => $original, ':record_id' => $record['record_id']]);
 }
Esempio n. 17
0
 /**
  *
  * @param Application $app
  * @param \databox    $databox
  * @param int         $id
  *
  * @return \databox_field
  */
 public static function get_instance(Application $app, databox $databox, $id)
 {
     $cache_key = 'field_' . $id;
     $instance_id = $databox->get_sbas_id() . '_' . $id;
     if (!isset(self::$_instance[$instance_id]) || self::$_instance[$instance_id] instanceof self === false) {
         try {
             self::$_instance[$instance_id] = $databox->get_data_from_cache($cache_key);
         } catch (\Exception $e) {
             self::$_instance[$instance_id] = new self($app, $databox, $id);
             $databox->set_data_to_cache(self::$_instance[$instance_id], $cache_key);
         }
     }
     self::$_instance[$instance_id]->app = $app;
     return self::$_instance[$instance_id];
 }
Esempio n. 18
0
 /**
  * Retrieve detailled informations about one \databox
  *
  * @param  \databox $databox
  *
  * @return array
  */
 private function list_databox(\databox $databox)
 {
     return ['databox_id' => $databox->get_sbas_id(), 'name' => $databox->get_dbname(), 'viewname' => $databox->get_viewname(), 'labels' => ['en' => $databox->get_label('en'), 'de' => $databox->get_label('de'), 'fr' => $databox->get_label('fr'), 'nl' => $databox->get_label('nl')], 'version' => $databox->get_version()];
 }