diff --git a/lib/classes/Controller/Setup/Installer.class.php b/lib/classes/Controller/Setup/Installer.class.php index 908d20a0c0..ebdb313203 100644 --- a/lib/classes/Controller/Setup/Installer.class.php +++ b/lib/classes/Controller/Setup/Installer.class.php @@ -287,7 +287,7 @@ class Controller_Setup_Installer implements ControllerProviderInterface $appbox->get_session()->authenticate($auth); - $redirection = '/admin/?section=taskmanager¬ice=install_success'; + $redirection = '/admin/index.php?section=taskmanager¬ice=install_success'; return $app->redirect($redirection); } diff --git a/lib/classes/Session/Handler.class.php b/lib/classes/Session/Handler.class.php index 46dfd229be..662e0c6e93 100644 --- a/lib/classes/Session/Handler.class.php +++ b/lib/classes/Session/Handler.class.php @@ -395,6 +395,7 @@ class Session_Handler foreach ($user->ACL()->get_granted_sbas() as $databox) { Session_Logger::create($databox, $browser, $this, $user); + \cache_databox::insertClient($databox); } $this->set_usr_lastconn($conn, $user->get_id()); diff --git a/lib/classes/cache/databox.class.php b/lib/classes/cache/databox.class.php index c4f5279002..c219d071c1 100644 --- a/lib/classes/cache/databox.class.php +++ b/lib/classes/cache/databox.class.php @@ -18,142 +18,118 @@ class cache_databox { - /** - * - * @var cache_databox - */ - private static $_instance = false; - /** - * - * @var cache - */ - protected $_c_obj = false; - - /** - * - * @return cache_databox - */ - function __construct() - { - $this->_c_obj = cache_adapter::getInstance(registry::get_instance()); - - return $this; - } - - /** - * @return cache_databox - */ - public static function getInstance() - { - if (!(self::$_instance instanceof self)) - self::$_instance = new self(); - - return self::$_instance; - } - - /** - * - * @param string $type - * @param string $what - * @return boolean - */ - public function get($type, $what) - { - return $this->_c_obj->get('_databox_' . $type . '_' . $what); - } - - /** - * - * @param string $type - * @param string $what - * @param mixed content $bin - * @return boolean - */ - public function set($type, $what, $bin) - { - return $this->_c_obj->set('_databox_' . $type . '_' . $what, $bin); - } - - /** - * - * @param string $type - * @param string $what - * @return boolean - */ - public function delete($type, $what) - { - return $this->_c_obj->delete('_databox_' . $type . '_' . $what); - } - /** * * @param int $sbas_id * @return cache_databox */ - function refresh($sbas_id) + public static function refresh($sbas_id) { - $date = new DateTime('-30 seconds'); + $databox = \databox::get_instance((int) $sbas_id); - $registry = registry::get_instance(); + $date = new \DateTime('-30 seconds'); - $cache_appbox = cache_appbox::getInstance(); - $last_update = $cache_appbox->get('memcached_update'); - if ($last_update) - $last_update = new DateTime($last_update); - else - $last_update = new DateTime('-10 years'); + $appbox = \appbox::get_instance(); - if ($date <= $last_update || !$cache_appbox->is_ok()) + $registry = \registry::get_instance(); - return $this; + $cache_appbox = $appbox->get_cache(); - $connsbas = connection::getInstance($sbas_id); + $last_update = null; - if (!$connsbas) - - return $this; - - $sql = 'SELECT type, value FROM memcached - WHERE site_id="' . $connsbas->escape_string($registry->get('GV_ServerName')) . '"'; - - if ($rs = $connsbas->query($sql)) + try { - $cache_thumbnail = cache_thumbnail::getInstance(); - $cache_preview = cache_preview::getInstance(); - while ($row = $connsbas->fetch_assoc($rs)) - { - switch ($row['type']) - { - case 'record': - $cache_thumbnail->delete($sbas_id, $row['value'], false); - $cache_preview->delete($sbas_id, $row['value'], false); - $sql = 'DELETE FROM memcached - WHERE site_id="' . $connsbas->escape_string($registry->get('GV_ServerName')) . '" - AND type="record" AND value="' . $row['value'] . '"'; - $connsbas->query($sql); - break; - case 'structure': - $cache_appbox->delete('list_bases'); - $sql = 'DELETE FROM memcached - WHERE site_id="' . $connsbas->escape_string($registry->get('GV_ServerName')) . '" - AND type="structure" AND value="' . $row['value'] . '"'; - $connsbas->query($sql); - break; - } - } - $connsbas->free_result($rs); + $last_update = $cache_appbox->get('memcached_update'); + } + catch (\Exception $e) + { + } - $date = new DateTime(); - $now = phraseadate::format_mysql($date); + if ($last_update) + $last_update = new \DateTime($last_update); + else + $last_update = new \DateTime('-10 years'); + + if ($date <= $last_update || !$cache_appbox->ping()) + { + return; + } + + $connsbas = \connection::getPDOConnection($sbas_id); + + $sql = 'SELECT type, value FROM memcached WHERE site_id = :site_id'; + $stmt = $connsbas->prepare($sql); + $stmt->execute(array(':site_id' => $registry->get('GV_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 = array( + ':site_id' => $registry->get('GV_ServerName') + , ':value' => $row['value'] + ); + + $stmt = $connsbas->prepare($sql); + $stmt->execute($params); + $stmt->closeCursor(); + break; + case 'structure': + $cache_appbox->delete(\appbox::CACHE_LIST_BASES); + $cache_appbox->delete(\appbox::CACHE_SBAS_IDS); + + $sql = 'DELETE FROM memcached + WHERE site_id = :site_id AND type="structure" AND value = :value'; + + $params = array( + ':site_id' => $registry->get('GV_ServerName') + , ':value' => $row['value'] + ); + + $stmt = $connsbas->prepare($sql); + $stmt->execute($params); + $stmt->closeCursor(); + break; + } + } + + $date = new \DateTime(); + $now = $date->format(DATE_ISO8601); + $cache_appbox->set('memcached_update', $now); - $conn = connection::getInstance(); - $sql = 'UPDATE sitepreff - SET memcached_update="' . $conn->escape_string($now) . '"'; - $conn->query($sql); + $conn = \connection::getPDOConnection(); - return $this; + $sql = 'UPDATE sitepreff SET memcached_update = :date'; + $stmt = $conn->prepare($sql); + $stmt->execute(array(':date' => $now)); + $stmt->closeCursor(); + + return; } /** @@ -163,28 +139,57 @@ class cache_databox * @param mixed content $value * @return Void */ - function update($sbas_id, $type, $value='') + public static function update($sbas_id, $type, $value = '') { - $connbas = connection::getPDOConnection($sbas_id); + $connbas = \connection::getPDOConnection($sbas_id); - $registry = registry::get_instance(); + $registry = \registry::get_instance(); $sql = 'SELECT distinct site_id as site_id FROM clients WHERE site_id != :site_id'; + $stmt = $connbas->prepare($sql); $stmt->execute(array(':site_id' => $registry->get('GV_ServerName'))); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); + $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC); $stmt->closeCursor(); $sql = 'REPLACE INTO memcached (site_id, type, value) VALUES (:site_id, :type, :value)'; + $stmt = $connbas->prepare($sql); + foreach ($rs as $row) { - $stmt->execute(array(':site_id' => $row['site_id'], ':type' => $type, ':value' => $value)); + $stmt->execute(array(':site_id' => $row['site_id'], ':type' => $type, ':value' => $value)); } + + $stmt->closeCursor(); + + return; + } + + public static function insertClient(\databox $databox) + { + $connbas = $databox->get_connection(); + + $registry = \registry::get_instance(); + + $sql = 'SELECT site_id FROM clients WHERE site_id = :site_id'; + $stmt = $connbas->prepare($sql); + $stmt->execute(array(':site_id' => $registry->get('GV_ServerName'))); + $rowCount = $stmt->rowCount(); + $stmt->closeCursor(); + + if ($rowCount > 0) + { + return; + } + + $sql = 'INSERT INTO clients (site_id) VALUES (:site_id)'; + $stmt = $connbas->prepare($sql); + $stmt->execute(array(':site_id' => $registry->get('GV_ServerName'))); $stmt->closeCursor(); return; diff --git a/lib/classes/connection.class.php b/lib/classes/connection.class.php index 7bf6e7b28a..a57e1be46a 100755 --- a/lib/classes/connection.class.php +++ b/lib/classes/connection.class.php @@ -171,8 +171,10 @@ class connection public static function close_PDO_connection($name) { if (isset(self::$_PDO_instance[$name])) + { + self::$_PDO_instance[$name] = null; unset(self::$_PDO_instance[$name]); - + } return; } diff --git a/lib/classes/module/prod/route/records/edit.class.php b/lib/classes/module/prod/route/records/edit.class.php index 70d6e66104..372f2e943d 100644 --- a/lib/classes/module/prod/route/records/edit.class.php +++ b/lib/classes/module/prod/route/records/edit.class.php @@ -46,7 +46,7 @@ class module_prod_route_records_edit extends module_prod_route_records_abstract * * @var Array */ - protected $javascript_elements; + protected $javascript_elements = array(); /** * diff --git a/lib/classes/record/adapter.class.php b/lib/classes/record/adapter.class.php index 7c35f2d3a3..731dec4918 100644 --- a/lib/classes/record/adapter.class.php +++ b/lib/classes/record/adapter.class.php @@ -1227,7 +1227,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface $db_field = \databox_field::get_instance($this->get_databox(), $param['meta_struct_id']); - if ($db_field->is_readonly() === false && !$force_readonly) + if ($db_field->is_readonly() === true && !$force_readonly) { continue; } @@ -1802,15 +1802,17 @@ class record_adapter implements record_Interface, cache_cacheableInterface */ public function get_data_from_cache($option = null) { + \cache_databox::refresh($this->get_sbas_id()); + $databox = $this->get_databox(); - + return $databox->get_data_from_cache($this->get_cache_key($option)); } public function set_data_to_cache($value, $option = null, $duration = 0) { $databox = $this->get_databox(); - + return $databox->set_data_to_cache($value, $this->get_cache_key($option), $duration); } @@ -1828,6 +1830,8 @@ class record_adapter implements record_Interface, cache_cacheableInterface break; } $databox = $this->get_databox(); + + \cache_databox::update($this->get_sbas_id(), 'record', $this->get_record_id()); return $databox->delete_data_from_cache($this->get_cache_key($option)); }