/** * * @param DOMDocument $dom_struct * @return databox */ public function saveStructure(DOMDocument $dom_struct) { $dom_struct->documentElement->setAttribute("modification_date", $now = date("YmdHis")); $sql = "UPDATE pref SET value= :structure, updated_on= :now\n WHERE prop='structure'"; $this->structure = $dom_struct->saveXML(); $stmt = $this->get_connection()->prepare($sql); $stmt->execute([':structure' => $this->structure, ':now' => $now]); $stmt->closeCursor(); $this->_sxml_structure = $this->_dom_structure = $this->_xpath_structure = null; $this->meta_struct = null; $this->app['phraseanet.appbox']->delete_data_from_cache(appbox::CACHE_LIST_BASES); $this->delete_data_from_cache(self::CACHE_STRUCTURE); $this->delete_data_from_cache(self::CACHE_META_STRUCT); cache_databox::update($this->app, $this->id, 'structure'); return $this; }
/** * @param Application $app * @param int $sbas_id * * @return cache_databox */ public static function refresh(Application $app, $sbas_id) { if (self::$refreshing) { return; } self::$refreshing = true; $databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id); $date = new \DateTime('-3 seconds'); $last_update = null; try { $last_update = $app['phraseanet.appbox']->get_data_from_cache('memcached_update_' . $sbas_id); } catch (\Exception $e) { } if ($last_update) { $last_update = new \DateTime($last_update); } else { $last_update = new \DateTime('-10 years'); } if ($date <= $last_update) { self::$refreshing = false; return; } $connsbas = $databox->get_connection(); $sql = 'SELECT type, value FROM memcached WHERE site_id = :site_id'; $stmt = $connsbas->prepare($sql); $stmt->execute([':site_id' => $app['conf']->get('servername')]); $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC); $stmt->closeCursor(); foreach ($rs as $row) { switch ($row['type']) { case 'record': $key = 'record_' . $sbas_id . '_' . $row['value']; $databox->delete_data_from_cache($key); $key = 'record_' . $sbas_id . '_' . $row['value'] . '_' . \record_adapter::CACHE_SUBDEFS; $databox->delete_data_from_cache($key); $key = 'record_' . $sbas_id . '_' . $row['value'] . '_' . \record_adapter::CACHE_GROUPING; $databox->delete_data_from_cache($key); $key = 'record_' . $sbas_id . '_' . $row['value'] . '_' . \record_adapter::CACHE_MIME; $databox->delete_data_from_cache($key); $key = 'record_' . $sbas_id . '_' . $row['value'] . '_' . \record_adapter::CACHE_ORIGINAL_NAME; $databox->delete_data_from_cache($key); $key = 'record_' . $sbas_id . '_' . $row['value'] . '_' . \record_adapter::CACHE_SHA256; $databox->delete_data_from_cache($key); $key = 'record_' . $sbas_id . '_' . $row['value'] . '_' . \record_adapter::CACHE_STATUS; $databox->delete_data_from_cache($key); $key = 'record_' . $sbas_id . '_' . $row['value'] . '_' . \record_adapter::CACHE_TECHNICAL_DATAS; $databox->delete_data_from_cache($key); $sql = 'DELETE FROM memcached WHERE site_id = :site_id AND type="record" AND value = :value'; $params = [':site_id' => $app['conf']->get('servername'), ':value' => $row['value']]; $stmt = $connsbas->prepare($sql); $stmt->execute($params); $stmt->closeCursor(); $record = new \record_adapter($app, $sbas_id, $row['value']); $record->get_caption()->delete_data_from_cache(); foreach ($record->get_subdefs() as $subdef) { $subdef->delete_data_from_cache(); } break; case 'structure': $app['phraseanet.appbox']->delete_data_from_cache(\appbox::CACHE_LIST_BASES); $app['phraseanet.appbox']->delete_data_from_cache(\appbox::CACHE_SBAS_IDS); $sql = 'DELETE FROM memcached WHERE site_id = :site_id AND type="structure" AND value = :value'; $params = [':site_id' => $app['conf']->get('servername'), ':value' => $row['value']]; $stmt = $connsbas->prepare($sql); $stmt->execute($params); $stmt->closeCursor(); break; } } $date = new \DateTime(); $now = $date->format(DATE_ISO8601); $app['phraseanet.appbox']->set_data_to_cache($now, 'memcached_update_' . $sbas_id); $conn = $app['phraseanet.appbox']->get_connection(); $sql = 'UPDATE sitepreff SET memcached_update = :date'; $stmt = $conn->prepare($sql); $stmt->execute([':date' => $now]); $stmt->closeCursor(); self::$refreshing = false; return; }
/** * * @param <type> $option * @return <type> */ public function get_data_from_cache($option = null) { if ($this->get_base_type() == self::DATA_BOX) { \cache_databox::refresh($this->app, $this->id); } $data = $this->get_cache()->get($this->get_cache_key($option)); if (is_object($data) && method_exists($data, 'hydrate')) { $data->hydrate($this->app); } return $data; }
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; }
public function delete_data_from_cache($option = null) { switch ($option) { case self::CACHE_STATUS: $this->status = null; break; case self::CACHE_SUBDEFS: $this->subdefs = null; break; default: break; } $databox = $this->get_databox(); \cache_databox::update($this->app, $this->get_sbas_id(), 'record', $this->get_record_id()); return $databox->delete_data_from_cache($this->get_cache_key($option)); }
/** * * @param DOMDocument $dom_struct * @return databox */ public function saveStructure(DOMDocument $dom_struct) { $old_structure = $this->get_dom_structure(); $dom_struct->documentElement->setAttribute("modification_date", $now = date("YmdHis")); $sql = "UPDATE pref SET value= :structure, updated_on= :now WHERE prop='structure'"; $this->structure = $dom_struct->saveXML(); $stmt = $this->get_connection()->prepare($sql); $stmt->execute([':structure' => $this->structure, ':now' => $now]); $stmt->closeCursor(); $this->_sxml_structure = $this->_dom_structure = $this->_xpath_structure = null; $this->meta_struct = null; $this->get_appbox()->delete_data_from_cache(appbox::CACHE_LIST_BASES); $this->delete_data_from_cache(self::CACHE_STRUCTURE); $this->delete_data_from_cache(self::CACHE_META_STRUCT); cache_databox::update($this->app, $this->id, 'structure'); $this->app['dispatcher']->dispatch(DataboxEvents::STRUCTURE_CHANGED, new StructureChangedEvent($this, array('dom_before' => $old_structure))); return $this; }
public function refreshAccount(Session $session) { if (!$this->app['repo.sessions']->find($session->getId())) { throw new RuntimeException('Unable to refresh the session, it does not exist anymore'); } if (null === ($user = $session->getUser())) { throw new RuntimeException('Unable to refresh the session'); } $this->session->clear(); $this->populateSession($session); foreach ($this->app['acl']->get($user)->get_granted_sbas() as $databox) { \cache_databox::insertClient($this->app, $databox); } $this->reinitUser(); return $session; }