diff --git a/lib/classes/appbox.class.php b/lib/classes/appbox.class.php index 70a164bd3a..711230fcce 100644 --- a/lib/classes/appbox.class.php +++ b/lib/classes/appbox.class.php @@ -45,6 +45,7 @@ class appbox extends base protected $cache; protected $connection; protected $registry; + protected $Core; const CACHE_LIST_BASES = 'list_bases'; const CACHE_SBAS_IDS = 'sbas_ids'; @@ -54,11 +55,11 @@ class appbox extends base * * @return appbox */ - public static function get_instance(registryInterface &$registry = null) + public static function get_instance(\Alchemy\Phrasea\Core $Core, registryInterface &$registry = null) { if (!self::$_instance instanceof self) { - self::$_instance = new self($registry); + self::$_instance = new self($Core, $registry); } return self::$_instance; @@ -69,11 +70,12 @@ class appbox extends base * * @return appbox */ - protected function __construct(registryInterface $registry = null) + protected function __construct(\Alchemy\Phrasea\Core $Core, registryInterface $registry = null) { - $this->connection = connection::getPDOConnection(); + $this->Core = $Core; if (!$registry) - $registry = registry::get_instance(); + $registry = registry::get_instance($Core); + $this->connection = connection::getPDOConnection(null, $registry); $this->registry = $registry; $this->session = Session_Handler::getInstance($this); @@ -283,7 +285,7 @@ class appbox extends base $stmt->execute(array(':viewname' => $viewname, ':sbas_id' => $databox->get_sbas_id())); $stmt->closeCursor(); - $appbox = appbox::get_instance(); + $appbox = appbox::get_instance(\bootstrap::getCore()); $appbox->delete_data_from_cache(appbox::CACHE_LIST_BASES); cache_databox::update($databox->get_sbas_id(), 'structure'); @@ -571,7 +573,7 @@ class appbox extends base } catch (Exception $e) { - + } try @@ -619,7 +621,7 @@ class appbox extends base } catch (Exception $e) { - + } } @@ -636,7 +638,7 @@ class appbox extends base } catch (Exception $e) { - + } $sql = 'SELECT sbas_id FROM sbas'; diff --git a/lib/classes/base.class.php b/lib/classes/base.class.php index f85bae8a07..d0055bc579 100644 --- a/lib/classes/base.class.php +++ b/lib/classes/base.class.php @@ -161,15 +161,12 @@ abstract class base implements cache_cacheableInterface return $this->connection; } - /** - * - * @return cache_adapter - */ public function get_cache() { if (!$this->cache) - $this->cache = cache_adapter::get_instance($this->get_registry()); - + { + $this->cache = $this->Core->getCache(); + } return $this->cache; } @@ -191,7 +188,7 @@ abstract class base implements cache_cacheableInterface public function set_data_to_cache($value, $option = null, $duration = 0) { - return $this->get_cache()->set($this->get_cache_key($option), $value, $duration); + return $this->get_cache()->save($this->get_cache_key($option), $value, $duration); } public function delete_data_from_cache($option = null) diff --git a/lib/classes/bootstrap.class.php b/lib/classes/bootstrap.class.php index 9946c83eab..be22868824 100644 --- a/lib/classes/bootstrap.class.php +++ b/lib/classes/bootstrap.class.php @@ -44,7 +44,7 @@ class bootstrap if (\setup::is_installed()) { - $gatekeeper = \gatekeeper::getInstance(); + $gatekeeper = \gatekeeper::getInstance(static::$core); $gatekeeper->check_directory(); } diff --git a/lib/classes/collection.class.php b/lib/classes/collection.class.php index dfdac9877d..e7bbf53c5b 100644 --- a/lib/classes/collection.class.php +++ b/lib/classes/collection.class.php @@ -126,7 +126,7 @@ class collection implements cache_cacheableInterface $this->is_active = true; $this->delete_data_from_cache(); - $appbox = appbox::get_instance(); + $appbox = appbox::get_instance(\bootstrap::getCore()); $appbox->delete_data_from_cache(appbox::CACHE_LIST_BASES); $this->databox->delete_data_from_cache(databox::CACHE_COLLECTIONS); cache_databox::update($this->databox->get_sbas_id(), 'structure'); @@ -142,7 +142,7 @@ class collection implements cache_cacheableInterface $stmt->closeCursor(); $this->is_active = false; $this->delete_data_from_cache(); - $appbox = appbox::get_instance(); + $appbox = appbox::get_instance(\bootstrap::getCore()); $appbox->delete_data_from_cache(appbox::CACHE_LIST_BASES); $this->databox->delete_data_from_cache(databox::CACHE_COLLECTIONS); cache_databox::update($this->databox->get_sbas_id(), 'structure'); @@ -314,7 +314,7 @@ class collection implements cache_cacheableInterface $stmt->execute(array(':coll_id' => $this->get_coll_id())); $stmt->closeCursor(); - $appbox = appbox::get_instance(); + $appbox = appbox::get_instance(\bootstrap::getCore()); $sql = "DELETE FROM bas WHERE base_id = :base_id"; $stmt = $appbox->get_connection()->prepare($sql); @@ -481,7 +481,7 @@ class collection implements cache_cacheableInterface $conn = $appbox->get_connection(); $new_bas = false; - $appbox = appbox::get_instance(); + $appbox = appbox::get_instance(\bootstrap::getCore()); $session = $appbox->get_session(); $prefs = ' @@ -555,7 +555,7 @@ class collection implements cache_cacheableInterface public static function mount_collection($sbas_id, $coll_id, User_Adapter $user) { - $appbox = appbox::get_instance(); + $appbox = appbox::get_instance(\bootstrap::getCore()); $session = $appbox->get_session(); $sql = "INSERT INTO bas (base_id, active, server_coll_id, sbas_id, aliases) diff --git a/lib/classes/connection.class.php b/lib/classes/connection.class.php index 13d7a12228..b4637b8131 100755 --- a/lib/classes/connection.class.php +++ b/lib/classes/connection.class.php @@ -109,7 +109,7 @@ class connection * @param string $name * @return connection_pdo */ - public static function getPDOConnection($name = null) + public static function getPDOConnection($name = null, registryInterface $registry = null) { self::instantiate(); if (trim($name) == '') @@ -166,7 +166,7 @@ class connection try { - self::$_PDO_instance[$name] = new connection_pdo($name, $hostname, $port, $user, $password, $dbname); + self::$_PDO_instance[$name] = new connection_pdo($name, $hostname, $port, $user, $password, $dbname, array(), $registry); self::$_PDO_instance[$name]->query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'"); } catch (Exception $e) diff --git a/lib/classes/databox.class.php b/lib/classes/databox.class.php index 282fd0e3ff..9f923c2e8b 100644 --- a/lib/classes/databox.class.php +++ b/lib/classes/databox.class.php @@ -113,7 +113,7 @@ class databox extends base { $this->registry = registry::get_instance(); $this->connection = connection::getPDOConnection($sbas_id); - $this->cache = cache_adapter::get_instance($this->registry); + $this->Core = \bootstrap::getCore(); $this->id = $sbas_id; $connection_params = phrasea::sbas_params(); @@ -518,7 +518,7 @@ class databox extends base public static function mount(appbox $appbox, $host, $port, $user, $password, $dbname, registry $registry) { $name = 'test'; - $connection = new connection_pdo($name, $host, $port, $user, $password, $dbname); + $connection = new connection_pdo($name, $host, $port, $user, $password, $dbname, array(), $registry); $conn = $appbox->get_connection(); $sql = 'SELECT MAX(ord) as ord FROM sbas'; @@ -668,7 +668,7 @@ class databox extends base public function delete() { - $appbox = appbox::get_instance(); + $appbox = appbox::get_instance(\bootstrap::getCore()); $sql = 'DROP DATABASE `' . $this->get_dbname() . '`'; $stmt = $this->get_connection()->prepare($sql); @@ -859,7 +859,7 @@ class databox extends base $this->meta_struct = null; - $appbox = appbox::get_instance(); + $appbox = appbox::get_instance(\bootstrap::getCore()); $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); diff --git a/lib/classes/gatekeeper.class.php b/lib/classes/gatekeeper.class.php index 552d649038..b829168ced 100644 --- a/lib/classes/gatekeeper.class.php +++ b/lib/classes/gatekeeper.class.php @@ -41,15 +41,16 @@ class gatekeeper * @var gatekeeper */ protected static $_instance; + protected $Core; /** * * @return gatekeeper */ - public static function getInstance() + public static function getInstance(\Alchemy\Phrasea\Core $Core) { if (!(self::$_instance instanceof self)) - self::$_instance = new self(); + self::$_instance = new self($Core); return self::$_instance; } @@ -58,8 +59,10 @@ class gatekeeper * * @return gatekeeper */ - function __construct() + function __construct(\Alchemy\Phrasea\Core $Core) { + $this->Core = $Core; + return $this; } @@ -72,11 +75,10 @@ class gatekeeper function check_directory() { $request = \Symfony\Component\HttpFoundation\Request::createFromGlobals(); - $appbox = appbox::get_instance(); + $appbox = appbox::get_instance($this->Core); $session = $appbox->get_session(); if (http_request::is_command_line()) - return; if (isset($_SERVER['PHP_SELF']) && trim($_SERVER['PHP_SELF'])) @@ -100,7 +102,7 @@ class gatekeeper try { $cookie = Session_Handler::get_cookie('persistent'); - $auth = new Session_Authentication_PersistentCookie($appbox, $cookie); + $auth = new Session_Authentication_PersistentCookie($appbox, $cookie); $session->restore($auth->get_user(), $auth->get_ses_id()); } catch (Exception $e) @@ -116,7 +118,7 @@ class gatekeeper case 'prod': case 'client': $this->give_guest_access(); - if($request->isXmlHttpRequest()) + if ($request->isXmlHttpRequest()) { phrasea::headers(404); } @@ -127,9 +129,8 @@ class gatekeeper break; case 'thesaurus2': if ($this->_PHP_SELF == '/thesaurus2/xmlhttp/getterm.x.php' - || $this->_PHP_SELF == '/thesaurus2/xmlhttp/searchcandidate.x.php' - || $this->_PHP_SELF == '/thesaurus2/xmlhttp/getsy.x.php') - + || $this->_PHP_SELF == '/thesaurus2/xmlhttp/searchcandidate.x.php' + || $this->_PHP_SELF == '/thesaurus2/xmlhttp/getsy.x.php') return; phrasea::redirect('/login/?redirect=/thesaurus2'); break; @@ -138,7 +139,6 @@ class gatekeeper break; case 'admin': if ($this->_script_name === 'runscheduler.php') - return; phrasea::redirect('/login/?redirect=' . $_SERVER['REQUEST_URI']); break; @@ -158,7 +158,6 @@ class gatekeeper return; case 'setup': if ($appbox->upgradeavailable()) - return; else phrasea::redirect('/login/'); @@ -237,7 +236,7 @@ class gatekeeper */ protected function give_guest_access() { - $appbox = appbox::get_instance(); + $appbox = appbox::get_instance($this->Core); $request = http_request::getInstance(); $session = $appbox->get_session(); @@ -253,7 +252,7 @@ class gatekeeper catch (Exception $e) { $url = '/login/?redirect=' . $parm['redirect'] - . '&error=' . urlencode($e->getMessage()); + . '&error=' . urlencode($e->getMessage()); phrasea::redirect($url); } phrasea::redirect('/' . $this->_directory . '/'); @@ -269,13 +268,12 @@ class gatekeeper */ protected function token_access() { - $appbox = appbox::get_instance(); + $appbox = appbox::get_instance($this->Core); $request = new http_request(); $session = $appbox->get_session(); - $parm = $request->get_parms('LOG'); + $parm = $request->get_parms('LOG'); if (is_null($parm["LOG"])) - return $this; try @@ -312,7 +310,7 @@ class gatekeeper */ public function require_session() { - $appbox = appbox::get_instance(); + $appbox = appbox::get_instance($this->Core); $session = $appbox->get_session(); if ($session->is_authenticated()) { diff --git a/lib/classes/lazaret.class.php b/lib/classes/lazaret.class.php index ac278f38cf..c5b1accb97 100644 --- a/lib/classes/lazaret.class.php +++ b/lib/classes/lazaret.class.php @@ -25,7 +25,7 @@ class lazaret extends set_abstract */ function __construct() { - $appbox = appbox::get_instance(); + $appbox = appbox::get_instance(\bootstrap::getCore()); $session = $appbox->get_session(); $registry = $appbox->get_registry(); $conn = $appbox->get_connection(); diff --git a/lib/classes/lazaretFile.class.php b/lib/classes/lazaretFile.class.php index 6df683398c..f2b1f36cb4 100644 --- a/lib/classes/lazaretFile.class.php +++ b/lib/classes/lazaretFile.class.php @@ -147,7 +147,7 @@ class lazaretFile public static function move_uploaded_to_lazaret( system_file $system_file, $base_id, $filename, $errors='', $status=false) { - $appbox = appbox::get_instance(); + $appbox = appbox::get_instance(\bootstrap::getCore()); $session = $appbox->get_session(); $registry = $appbox->get_registry(); $conn = $appbox->get_connection(); diff --git a/lib/classes/liste.class.php b/lib/classes/liste.class.php index 284ba47d76..bdcc2459c9 100644 --- a/lib/classes/liste.class.php +++ b/lib/classes/liste.class.php @@ -5,7 +5,7 @@ class liste public static function filter($lst) { - $appbox = appbox::get_instance(); + $appbox = appbox::get_instance(\bootstrap::getCore()); $session = $appbox->get_session(); if (!is_array($lst)) diff --git a/lib/classes/p4file.class.php b/lib/classes/p4file.class.php index ec485570ed..0f6ba525b7 100644 --- a/lib/classes/p4file.class.php +++ b/lib/classes/p4file.class.php @@ -65,7 +65,7 @@ class p4file public static function archiveFile(system_file &$system_file, $base_id, $delete=true, $name=false) { - $appbox = appbox::get_instance(); + $appbox = appbox::get_instance(\bootstrap::getCore()); $session = $appbox->get_session(); $registry = $appbox->get_registry(); diff --git a/lib/classes/phrasea.class.php b/lib/classes/phrasea.class.php index 66723998b1..a5d6b65314 100644 --- a/lib/classes/phrasea.class.php +++ b/lib/classes/phrasea.class.php @@ -131,7 +131,7 @@ class phrasea function getHome($type='PUBLI', $context='prod') { - $appbox = appbox::get_instance(); + $appbox = appbox::get_instance(\bootstrap::getCore()); $session = $appbox->get_session(); $registry = $appbox->get_registry(); $user = User_Adapter::getInstance($session->get_usr_id(), $appbox); @@ -229,7 +229,7 @@ class phrasea public static function clear_sbas_params() { self::$_sbas_params = null; - $appbox = appbox::get_instance(); + $appbox = appbox::get_instance(\bootstrap::getCore()); $appbox->delete_data_from_cache(self::CACHE_SBAS_PARAMS); return true; @@ -241,7 +241,7 @@ class phrasea return self::$_sbas_params; - $appbox = appbox::get_instance(); + $appbox = appbox::get_instance(\bootstrap::getCore()); try { self::$_sbas_params = $appbox->get_data_from_cache(self::CACHE_SBAS_PARAMS); @@ -277,7 +277,7 @@ class phrasea if (!$usr_id) return false; - $appbox = appbox::get_instance(); + $appbox = appbox::get_instance(\bootstrap::getCore()); $user = User_Adapter::getInstance($usr_id, $appbox); return count($user->ACL()->get_granted_base()) > 0; @@ -329,7 +329,7 @@ class phrasea { if (!self::$_bas2sbas) { - $appbox = appbox::get_instance(); + $appbox = appbox::get_instance(\bootstrap::getCore()); try { self::$_bas2sbas = $appbox->get_data_from_cache(self::CACHE_SBAS_FROM_BAS); @@ -379,7 +379,7 @@ class phrasea public static function reset_baseDatas() { self::$_coll2bas = self::$_bas2coll = self::$_bas_names = self::$_bas2sbas = null; - $appbox = appbox::get_instance(); + $appbox = appbox::get_instance(\bootstrap::getCore()); $appbox->delete_data_from_cache( array( self::CACHE_BAS_2_COLL @@ -395,7 +395,7 @@ class phrasea public static function reset_sbasDatas() { self::$_sbas_names = self::$_sbas_params = self::$_bas2sbas = null; - $appbox = appbox::get_instance(); + $appbox = appbox::get_instance(\bootstrap::getCore()); $appbox->delete_data_from_cache( array( self::CACHE_SBAS_NAMES @@ -431,7 +431,7 @@ class phrasea { if (!self::$_sbas_names) { - $appbox = appbox::get_instance(); + $appbox = appbox::get_instance(\bootstrap::getCore()); try { self::$_sbas_names = $appbox->get_data_from_cache(self::CACHE_SBAS_NAMES); @@ -460,7 +460,7 @@ class phrasea { if (!self::$_bas_names) { - $appbox = appbox::get_instance(); + $appbox = appbox::get_instance(\bootstrap::getCore()); try { self::$_bas_names = $appbox->get_data_from_cache(self::CACHE_BAS_NAMES); diff --git a/lib/classes/queries.class.php b/lib/classes/queries.class.php index 0b63629061..9dd906eb5b 100644 --- a/lib/classes/queries.class.php +++ b/lib/classes/queries.class.php @@ -20,7 +20,7 @@ class queries public static function tree_topics() { - $appbox = appbox::get_instance(); + $appbox = appbox::get_instance(\bootstrap::getCore()); $session = $appbox->get_session(); $registry = $appbox->get_registry(); @@ -71,7 +71,7 @@ class queries public static function topics_exists() { - $appbox = appbox::get_instance(); + $appbox = appbox::get_instance(\bootstrap::getCore()); $session = $appbox->get_session(); $registry = $appbox->get_registry(); @@ -88,7 +88,7 @@ class queries public static function dropdown_topics() { - $appbox = appbox::get_instance(); + $appbox = appbox::get_instance(\bootstrap::getCore()); $session = $appbox->get_session(); $registry = $appbox->get_registry(); @@ -221,7 +221,7 @@ class queries public static function history() { - $appbox = appbox::get_instance(); + $appbox = appbox::get_instance(\bootstrap::getCore()); $session = $appbox->get_session(); $conn = $appbox->get_connection(); diff --git a/lib/classes/registry.class.php b/lib/classes/registry.class.php index ca98869192..556d779caa 100644 --- a/lib/classes/registry.class.php +++ b/lib/classes/registry.class.php @@ -20,7 +20,7 @@ class registry implements registryInterface /** * - * @var cache_opcode_adapter + * @var \Alchemy\Phrasea\Cache\Cache */ protected $cache; @@ -42,21 +42,22 @@ class registry implements registryInterface */ public static function get_instance() { - $prefix = crc32(__DIR__); if (!self::$_instance instanceof self) - self::$_instance = new self(new cache_opcode_adapter($prefix)); + { + self::$_instance = new self(); + } return self::$_instance; } /** * - * @param cache_opcode_interface $cache + * @param \Alchemy\Phrasea\Cache\Cache $cache * @return registry */ - protected function __construct(cache_opcode_interface $cache) + protected function __construct() { - $this->cache = $cache; + $this->cache = new Alchemy\Phrasea\Cache\ArrayCache(); $handler = new \Alchemy\Phrasea\Core\Configuration\Handler( new \Alchemy\Phrasea\Core\Configuration\Application(), @@ -64,12 +65,12 @@ class registry implements registryInterface ); $configuration = new \Alchemy\Phrasea\Core\Configuration($handler); - $this->cache->set('GV_RootPath', dirname(dirname(__DIR__)) . '/'); + $this->cache->save('GV_RootPath', dirname(dirname(__DIR__)) . '/'); if ($configuration->isInstalled()) { - $this->cache->set('GV_ServerName', $configuration->getPhraseanet()->get('servername')); - $this->cache->set('GV_debug', $configuration->isDebug()); - $this->cache->set('GV_maintenance', $configuration->isMaintained()); + $this->cache->save('GV_ServerName', $configuration->getPhraseanet()->get('servername')); + $this->cache->save('GV_debug', $configuration->isDebug()); + $this->cache->save('GV_maintenance', $configuration->isMaintained()); } return $this; @@ -81,7 +82,7 @@ class registry implements registryInterface */ protected function load() { - if ($this->cache->get('registry_loaded') !== true) + if ($this->cache->fetch('registry_loaded') !== true) { $rs = array(); $loaded = false; @@ -119,10 +120,10 @@ class registry implements registryInterface break; } - $this->cache->set($row['key'], $value); + $this->cache->save($row['key'], $value); } if ($loaded === true) - $this->cache->set('registry_loaded', true); + $this->cache->save('registry_loaded', true); } @@ -136,15 +137,15 @@ class registry implements registryInterface */ public function get($key, $defaultvalue = null) { - if (!$this->cache->is_set($key)) + if (!$this->cache->contains($key)) $this->load(); - if (!$this->cache->is_set($key) && !is_null($defaultvalue)) + if (!$this->cache->contains($key) && !is_null($defaultvalue)) return $defaultvalue; else - return $this->cache->get($key); + return $this->cache->fetch($key); } /** @@ -156,14 +157,6 @@ class registry implements registryInterface public function set($key, $value, $type) { $this->load(); - $delete_cache = false; - if ($key === 'GV_cache_server_type') - { - $current_cache = $this->get('GV_cache_server_type'); - if ($current_cache !== $value) - $delete_cache = true; - } - switch ($type) { @@ -195,13 +188,7 @@ class registry implements registryInterface $stmt->execute(array(':key' => $key, ':value' => $sql_value, ':type' => $type)); $stmt->closeCursor(); - $this->cache->set($key, $value); - - if ($delete_cache === true) - { - $cache = cache_adapter::get_instance($this); - $cache->flush(); - } + $this->cache->save($key, $value); return $this; } @@ -215,7 +202,7 @@ class registry implements registryInterface { $this->load(); - return $this->cache->is_set($key); + return $this->cache->contains($key); } /** @@ -233,7 +220,7 @@ class registry implements registryInterface $stmt->execute(array(':key' => $key)); $stmt->closeCursor(); - $this->cache->un_set($key); + $this->cache->delete($key); return $this; } diff --git a/lib/classes/setup.class.php b/lib/classes/setup.class.php index 780252d99d..3e560c0cf2 100644 --- a/lib/classes/setup.class.php +++ b/lib/classes/setup.class.php @@ -609,35 +609,27 @@ class setup function check_cache_memcache() { + $Core = \bootstrap::getCore(); echo '

' . _('setup:: Serveur Memcached') . '

'; echo '