Refactor Appbox

This commit is contained in:
Romain Neutron
2012-02-21 16:06:01 +01:00
parent 375fd3d493
commit e576989c7f
15 changed files with 90 additions and 114 deletions

View File

@@ -45,6 +45,7 @@ class appbox extends base
protected $cache; protected $cache;
protected $connection; protected $connection;
protected $registry; protected $registry;
protected $Core;
const CACHE_LIST_BASES = 'list_bases'; const CACHE_LIST_BASES = 'list_bases';
const CACHE_SBAS_IDS = 'sbas_ids'; const CACHE_SBAS_IDS = 'sbas_ids';
@@ -54,11 +55,11 @@ class appbox extends base
* *
* @return appbox * @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) if (!self::$_instance instanceof self)
{ {
self::$_instance = new self($registry); self::$_instance = new self($Core, $registry);
} }
return self::$_instance; return self::$_instance;
@@ -69,11 +70,12 @@ class appbox extends base
* *
* @return appbox * @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) if (!$registry)
$registry = registry::get_instance(); $registry = registry::get_instance($Core);
$this->connection = connection::getPDOConnection(null, $registry);
$this->registry = $registry; $this->registry = $registry;
$this->session = Session_Handler::getInstance($this); $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->execute(array(':viewname' => $viewname, ':sbas_id' => $databox->get_sbas_id()));
$stmt->closeCursor(); $stmt->closeCursor();
$appbox = appbox::get_instance(); $appbox = appbox::get_instance(\bootstrap::getCore());
$appbox->delete_data_from_cache(appbox::CACHE_LIST_BASES); $appbox->delete_data_from_cache(appbox::CACHE_LIST_BASES);
cache_databox::update($databox->get_sbas_id(), 'structure'); cache_databox::update($databox->get_sbas_id(), 'structure');
@@ -571,7 +573,7 @@ class appbox extends base
} }
catch (Exception $e) catch (Exception $e)
{ {
} }
try try
@@ -619,7 +621,7 @@ class appbox extends base
} }
catch (Exception $e) catch (Exception $e)
{ {
} }
} }
@@ -636,7 +638,7 @@ class appbox extends base
} }
catch (Exception $e) catch (Exception $e)
{ {
} }
$sql = 'SELECT sbas_id FROM sbas'; $sql = 'SELECT sbas_id FROM sbas';

View File

@@ -161,15 +161,12 @@ abstract class base implements cache_cacheableInterface
return $this->connection; return $this->connection;
} }
/**
*
* @return cache_adapter
*/
public function get_cache() public function get_cache()
{ {
if (!$this->cache) if (!$this->cache)
$this->cache = cache_adapter::get_instance($this->get_registry()); {
$this->cache = $this->Core->getCache();
}
return $this->cache; return $this->cache;
} }
@@ -191,7 +188,7 @@ abstract class base implements cache_cacheableInterface
public function set_data_to_cache($value, $option = null, $duration = 0) 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) public function delete_data_from_cache($option = null)

View File

@@ -44,7 +44,7 @@ class bootstrap
if (\setup::is_installed()) if (\setup::is_installed())
{ {
$gatekeeper = \gatekeeper::getInstance(); $gatekeeper = \gatekeeper::getInstance(static::$core);
$gatekeeper->check_directory(); $gatekeeper->check_directory();
} }

View File

@@ -126,7 +126,7 @@ class collection implements cache_cacheableInterface
$this->is_active = true; $this->is_active = true;
$this->delete_data_from_cache(); $this->delete_data_from_cache();
$appbox = appbox::get_instance(); $appbox = appbox::get_instance(\bootstrap::getCore());
$appbox->delete_data_from_cache(appbox::CACHE_LIST_BASES); $appbox->delete_data_from_cache(appbox::CACHE_LIST_BASES);
$this->databox->delete_data_from_cache(databox::CACHE_COLLECTIONS); $this->databox->delete_data_from_cache(databox::CACHE_COLLECTIONS);
cache_databox::update($this->databox->get_sbas_id(), 'structure'); cache_databox::update($this->databox->get_sbas_id(), 'structure');
@@ -142,7 +142,7 @@ class collection implements cache_cacheableInterface
$stmt->closeCursor(); $stmt->closeCursor();
$this->is_active = false; $this->is_active = false;
$this->delete_data_from_cache(); $this->delete_data_from_cache();
$appbox = appbox::get_instance(); $appbox = appbox::get_instance(\bootstrap::getCore());
$appbox->delete_data_from_cache(appbox::CACHE_LIST_BASES); $appbox->delete_data_from_cache(appbox::CACHE_LIST_BASES);
$this->databox->delete_data_from_cache(databox::CACHE_COLLECTIONS); $this->databox->delete_data_from_cache(databox::CACHE_COLLECTIONS);
cache_databox::update($this->databox->get_sbas_id(), 'structure'); 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->execute(array(':coll_id' => $this->get_coll_id()));
$stmt->closeCursor(); $stmt->closeCursor();
$appbox = appbox::get_instance(); $appbox = appbox::get_instance(\bootstrap::getCore());
$sql = "DELETE FROM bas WHERE base_id = :base_id"; $sql = "DELETE FROM bas WHERE base_id = :base_id";
$stmt = $appbox->get_connection()->prepare($sql); $stmt = $appbox->get_connection()->prepare($sql);
@@ -481,7 +481,7 @@ class collection implements cache_cacheableInterface
$conn = $appbox->get_connection(); $conn = $appbox->get_connection();
$new_bas = false; $new_bas = false;
$appbox = appbox::get_instance(); $appbox = appbox::get_instance(\bootstrap::getCore());
$session = $appbox->get_session(); $session = $appbox->get_session();
$prefs = '<?xml version="1.0" encoding="UTF-8"?> $prefs = '<?xml version="1.0" encoding="UTF-8"?>
@@ -555,7 +555,7 @@ class collection implements cache_cacheableInterface
public static function mount_collection($sbas_id, $coll_id, User_Adapter $user) 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(); $session = $appbox->get_session();
$sql = "INSERT INTO bas (base_id, active, server_coll_id, sbas_id, aliases) $sql = "INSERT INTO bas (base_id, active, server_coll_id, sbas_id, aliases)

View File

@@ -109,7 +109,7 @@ class connection
* @param string $name * @param string $name
* @return connection_pdo * @return connection_pdo
*/ */
public static function getPDOConnection($name = null) public static function getPDOConnection($name = null, registryInterface $registry = null)
{ {
self::instantiate(); self::instantiate();
if (trim($name) == '') if (trim($name) == '')
@@ -166,7 +166,7 @@ class connection
try 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'"); 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) catch (Exception $e)

View File

@@ -113,7 +113,7 @@ class databox extends base
{ {
$this->registry = registry::get_instance(); $this->registry = registry::get_instance();
$this->connection = connection::getPDOConnection($sbas_id); $this->connection = connection::getPDOConnection($sbas_id);
$this->cache = cache_adapter::get_instance($this->registry); $this->Core = \bootstrap::getCore();
$this->id = $sbas_id; $this->id = $sbas_id;
$connection_params = phrasea::sbas_params(); $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) public static function mount(appbox $appbox, $host, $port, $user, $password, $dbname, registry $registry)
{ {
$name = 'test'; $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(); $conn = $appbox->get_connection();
$sql = 'SELECT MAX(ord) as ord FROM sbas'; $sql = 'SELECT MAX(ord) as ord FROM sbas';
@@ -668,7 +668,7 @@ class databox extends base
public function delete() public function delete()
{ {
$appbox = appbox::get_instance(); $appbox = appbox::get_instance(\bootstrap::getCore());
$sql = 'DROP DATABASE `' . $this->get_dbname() . '`'; $sql = 'DROP DATABASE `' . $this->get_dbname() . '`';
$stmt = $this->get_connection()->prepare($sql); $stmt = $this->get_connection()->prepare($sql);
@@ -859,7 +859,7 @@ class databox extends base
$this->meta_struct = null; $this->meta_struct = null;
$appbox = appbox::get_instance(); $appbox = appbox::get_instance(\bootstrap::getCore());
$appbox->delete_data_from_cache(appbox::CACHE_LIST_BASES); $appbox->delete_data_from_cache(appbox::CACHE_LIST_BASES);
$this->delete_data_from_cache(self::CACHE_STRUCTURE); $this->delete_data_from_cache(self::CACHE_STRUCTURE);
$this->delete_data_from_cache(self::CACHE_META_STRUCT); $this->delete_data_from_cache(self::CACHE_META_STRUCT);

View File

@@ -41,15 +41,16 @@ class gatekeeper
* @var gatekeeper * @var gatekeeper
*/ */
protected static $_instance; protected static $_instance;
protected $Core;
/** /**
* *
* @return gatekeeper * @return gatekeeper
*/ */
public static function getInstance() public static function getInstance(\Alchemy\Phrasea\Core $Core)
{ {
if (!(self::$_instance instanceof self)) if (!(self::$_instance instanceof self))
self::$_instance = new self(); self::$_instance = new self($Core);
return self::$_instance; return self::$_instance;
} }
@@ -58,8 +59,10 @@ class gatekeeper
* *
* @return gatekeeper * @return gatekeeper
*/ */
function __construct() function __construct(\Alchemy\Phrasea\Core $Core)
{ {
$this->Core = $Core;
return $this; return $this;
} }
@@ -72,11 +75,10 @@ class gatekeeper
function check_directory() function check_directory()
{ {
$request = \Symfony\Component\HttpFoundation\Request::createFromGlobals(); $request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
$appbox = appbox::get_instance(); $appbox = appbox::get_instance($this->Core);
$session = $appbox->get_session(); $session = $appbox->get_session();
if (http_request::is_command_line()) if (http_request::is_command_line())
return; return;
if (isset($_SERVER['PHP_SELF']) && trim($_SERVER['PHP_SELF'])) if (isset($_SERVER['PHP_SELF']) && trim($_SERVER['PHP_SELF']))
@@ -100,7 +102,7 @@ class gatekeeper
try try
{ {
$cookie = Session_Handler::get_cookie('persistent'); $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()); $session->restore($auth->get_user(), $auth->get_ses_id());
} }
catch (Exception $e) catch (Exception $e)
@@ -116,7 +118,7 @@ class gatekeeper
case 'prod': case 'prod':
case 'client': case 'client':
$this->give_guest_access(); $this->give_guest_access();
if($request->isXmlHttpRequest()) if ($request->isXmlHttpRequest())
{ {
phrasea::headers(404); phrasea::headers(404);
} }
@@ -127,9 +129,8 @@ class gatekeeper
break; break;
case 'thesaurus2': case 'thesaurus2':
if ($this->_PHP_SELF == '/thesaurus2/xmlhttp/getterm.x.php' if ($this->_PHP_SELF == '/thesaurus2/xmlhttp/getterm.x.php'
|| $this->_PHP_SELF == '/thesaurus2/xmlhttp/searchcandidate.x.php' || $this->_PHP_SELF == '/thesaurus2/xmlhttp/searchcandidate.x.php'
|| $this->_PHP_SELF == '/thesaurus2/xmlhttp/getsy.x.php') || $this->_PHP_SELF == '/thesaurus2/xmlhttp/getsy.x.php')
return; return;
phrasea::redirect('/login/?redirect=/thesaurus2'); phrasea::redirect('/login/?redirect=/thesaurus2');
break; break;
@@ -138,7 +139,6 @@ class gatekeeper
break; break;
case 'admin': case 'admin':
if ($this->_script_name === 'runscheduler.php') if ($this->_script_name === 'runscheduler.php')
return; return;
phrasea::redirect('/login/?redirect=' . $_SERVER['REQUEST_URI']); phrasea::redirect('/login/?redirect=' . $_SERVER['REQUEST_URI']);
break; break;
@@ -158,7 +158,6 @@ class gatekeeper
return; return;
case 'setup': case 'setup':
if ($appbox->upgradeavailable()) if ($appbox->upgradeavailable())
return; return;
else else
phrasea::redirect('/login/'); phrasea::redirect('/login/');
@@ -237,7 +236,7 @@ class gatekeeper
*/ */
protected function give_guest_access() protected function give_guest_access()
{ {
$appbox = appbox::get_instance(); $appbox = appbox::get_instance($this->Core);
$request = http_request::getInstance(); $request = http_request::getInstance();
$session = $appbox->get_session(); $session = $appbox->get_session();
@@ -253,7 +252,7 @@ class gatekeeper
catch (Exception $e) catch (Exception $e)
{ {
$url = '/login/?redirect=' . $parm['redirect'] $url = '/login/?redirect=' . $parm['redirect']
. '&error=' . urlencode($e->getMessage()); . '&error=' . urlencode($e->getMessage());
phrasea::redirect($url); phrasea::redirect($url);
} }
phrasea::redirect('/' . $this->_directory . '/'); phrasea::redirect('/' . $this->_directory . '/');
@@ -269,13 +268,12 @@ class gatekeeper
*/ */
protected function token_access() protected function token_access()
{ {
$appbox = appbox::get_instance(); $appbox = appbox::get_instance($this->Core);
$request = new http_request(); $request = new http_request();
$session = $appbox->get_session(); $session = $appbox->get_session();
$parm = $request->get_parms('LOG'); $parm = $request->get_parms('LOG');
if (is_null($parm["LOG"])) if (is_null($parm["LOG"]))
return $this; return $this;
try try
@@ -312,7 +310,7 @@ class gatekeeper
*/ */
public function require_session() public function require_session()
{ {
$appbox = appbox::get_instance(); $appbox = appbox::get_instance($this->Core);
$session = $appbox->get_session(); $session = $appbox->get_session();
if ($session->is_authenticated()) if ($session->is_authenticated())
{ {

View File

@@ -25,7 +25,7 @@ class lazaret extends set_abstract
*/ */
function __construct() function __construct()
{ {
$appbox = appbox::get_instance(); $appbox = appbox::get_instance(\bootstrap::getCore());
$session = $appbox->get_session(); $session = $appbox->get_session();
$registry = $appbox->get_registry(); $registry = $appbox->get_registry();
$conn = $appbox->get_connection(); $conn = $appbox->get_connection();

View File

@@ -147,7 +147,7 @@ class lazaretFile
public static function move_uploaded_to_lazaret( public static function move_uploaded_to_lazaret(
system_file $system_file, $base_id, $filename, $errors='', $status=false) system_file $system_file, $base_id, $filename, $errors='', $status=false)
{ {
$appbox = appbox::get_instance(); $appbox = appbox::get_instance(\bootstrap::getCore());
$session = $appbox->get_session(); $session = $appbox->get_session();
$registry = $appbox->get_registry(); $registry = $appbox->get_registry();
$conn = $appbox->get_connection(); $conn = $appbox->get_connection();

View File

@@ -5,7 +5,7 @@ class liste
public static function filter($lst) public static function filter($lst)
{ {
$appbox = appbox::get_instance(); $appbox = appbox::get_instance(\bootstrap::getCore());
$session = $appbox->get_session(); $session = $appbox->get_session();
if (!is_array($lst)) if (!is_array($lst))

View File

@@ -65,7 +65,7 @@ class p4file
public static function archiveFile(system_file &$system_file, $base_id, $delete=true, $name=false) 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(); $session = $appbox->get_session();
$registry = $appbox->get_registry(); $registry = $appbox->get_registry();

View File

@@ -131,7 +131,7 @@ class phrasea
function getHome($type='PUBLI', $context='prod') function getHome($type='PUBLI', $context='prod')
{ {
$appbox = appbox::get_instance(); $appbox = appbox::get_instance(\bootstrap::getCore());
$session = $appbox->get_session(); $session = $appbox->get_session();
$registry = $appbox->get_registry(); $registry = $appbox->get_registry();
$user = User_Adapter::getInstance($session->get_usr_id(), $appbox); $user = User_Adapter::getInstance($session->get_usr_id(), $appbox);
@@ -229,7 +229,7 @@ class phrasea
public static function clear_sbas_params() public static function clear_sbas_params()
{ {
self::$_sbas_params = null; self::$_sbas_params = null;
$appbox = appbox::get_instance(); $appbox = appbox::get_instance(\bootstrap::getCore());
$appbox->delete_data_from_cache(self::CACHE_SBAS_PARAMS); $appbox->delete_data_from_cache(self::CACHE_SBAS_PARAMS);
return true; return true;
@@ -241,7 +241,7 @@ class phrasea
return self::$_sbas_params; return self::$_sbas_params;
$appbox = appbox::get_instance(); $appbox = appbox::get_instance(\bootstrap::getCore());
try try
{ {
self::$_sbas_params = $appbox->get_data_from_cache(self::CACHE_SBAS_PARAMS); self::$_sbas_params = $appbox->get_data_from_cache(self::CACHE_SBAS_PARAMS);
@@ -277,7 +277,7 @@ class phrasea
if (!$usr_id) if (!$usr_id)
return false; return false;
$appbox = appbox::get_instance(); $appbox = appbox::get_instance(\bootstrap::getCore());
$user = User_Adapter::getInstance($usr_id, $appbox); $user = User_Adapter::getInstance($usr_id, $appbox);
return count($user->ACL()->get_granted_base()) > 0; return count($user->ACL()->get_granted_base()) > 0;
@@ -329,7 +329,7 @@ class phrasea
{ {
if (!self::$_bas2sbas) if (!self::$_bas2sbas)
{ {
$appbox = appbox::get_instance(); $appbox = appbox::get_instance(\bootstrap::getCore());
try try
{ {
self::$_bas2sbas = $appbox->get_data_from_cache(self::CACHE_SBAS_FROM_BAS); self::$_bas2sbas = $appbox->get_data_from_cache(self::CACHE_SBAS_FROM_BAS);
@@ -379,7 +379,7 @@ class phrasea
public static function reset_baseDatas() public static function reset_baseDatas()
{ {
self::$_coll2bas = self::$_bas2coll = self::$_bas_names = self::$_bas2sbas = null; 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( $appbox->delete_data_from_cache(
array( array(
self::CACHE_BAS_2_COLL self::CACHE_BAS_2_COLL
@@ -395,7 +395,7 @@ class phrasea
public static function reset_sbasDatas() public static function reset_sbasDatas()
{ {
self::$_sbas_names = self::$_sbas_params = self::$_bas2sbas = null; self::$_sbas_names = self::$_sbas_params = self::$_bas2sbas = null;
$appbox = appbox::get_instance(); $appbox = appbox::get_instance(\bootstrap::getCore());
$appbox->delete_data_from_cache( $appbox->delete_data_from_cache(
array( array(
self::CACHE_SBAS_NAMES self::CACHE_SBAS_NAMES
@@ -431,7 +431,7 @@ class phrasea
{ {
if (!self::$_sbas_names) if (!self::$_sbas_names)
{ {
$appbox = appbox::get_instance(); $appbox = appbox::get_instance(\bootstrap::getCore());
try try
{ {
self::$_sbas_names = $appbox->get_data_from_cache(self::CACHE_SBAS_NAMES); self::$_sbas_names = $appbox->get_data_from_cache(self::CACHE_SBAS_NAMES);
@@ -460,7 +460,7 @@ class phrasea
{ {
if (!self::$_bas_names) if (!self::$_bas_names)
{ {
$appbox = appbox::get_instance(); $appbox = appbox::get_instance(\bootstrap::getCore());
try try
{ {
self::$_bas_names = $appbox->get_data_from_cache(self::CACHE_BAS_NAMES); self::$_bas_names = $appbox->get_data_from_cache(self::CACHE_BAS_NAMES);

View File

@@ -20,7 +20,7 @@ class queries
public static function tree_topics() public static function tree_topics()
{ {
$appbox = appbox::get_instance(); $appbox = appbox::get_instance(\bootstrap::getCore());
$session = $appbox->get_session(); $session = $appbox->get_session();
$registry = $appbox->get_registry(); $registry = $appbox->get_registry();
@@ -71,7 +71,7 @@ class queries
public static function topics_exists() public static function topics_exists()
{ {
$appbox = appbox::get_instance(); $appbox = appbox::get_instance(\bootstrap::getCore());
$session = $appbox->get_session(); $session = $appbox->get_session();
$registry = $appbox->get_registry(); $registry = $appbox->get_registry();
@@ -88,7 +88,7 @@ class queries
public static function dropdown_topics() public static function dropdown_topics()
{ {
$appbox = appbox::get_instance(); $appbox = appbox::get_instance(\bootstrap::getCore());
$session = $appbox->get_session(); $session = $appbox->get_session();
$registry = $appbox->get_registry(); $registry = $appbox->get_registry();
@@ -221,7 +221,7 @@ class queries
public static function history() public static function history()
{ {
$appbox = appbox::get_instance(); $appbox = appbox::get_instance(\bootstrap::getCore());
$session = $appbox->get_session(); $session = $appbox->get_session();
$conn = $appbox->get_connection(); $conn = $appbox->get_connection();

View File

@@ -20,7 +20,7 @@ class registry implements registryInterface
/** /**
* *
* @var cache_opcode_adapter * @var \Alchemy\Phrasea\Cache\Cache
*/ */
protected $cache; protected $cache;
@@ -42,21 +42,22 @@ class registry implements registryInterface
*/ */
public static function get_instance() public static function get_instance()
{ {
$prefix = crc32(__DIR__);
if (!self::$_instance instanceof self) if (!self::$_instance instanceof self)
self::$_instance = new self(new cache_opcode_adapter($prefix)); {
self::$_instance = new self();
}
return self::$_instance; return self::$_instance;
} }
/** /**
* *
* @param cache_opcode_interface $cache * @param \Alchemy\Phrasea\Cache\Cache $cache
* @return registry * @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( $handler = new \Alchemy\Phrasea\Core\Configuration\Handler(
new \Alchemy\Phrasea\Core\Configuration\Application(), new \Alchemy\Phrasea\Core\Configuration\Application(),
@@ -64,12 +65,12 @@ class registry implements registryInterface
); );
$configuration = new \Alchemy\Phrasea\Core\Configuration($handler); $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()) if ($configuration->isInstalled())
{ {
$this->cache->set('GV_ServerName', $configuration->getPhraseanet()->get('servername')); $this->cache->save('GV_ServerName', $configuration->getPhraseanet()->get('servername'));
$this->cache->set('GV_debug', $configuration->isDebug()); $this->cache->save('GV_debug', $configuration->isDebug());
$this->cache->set('GV_maintenance', $configuration->isMaintained()); $this->cache->save('GV_maintenance', $configuration->isMaintained());
} }
return $this; return $this;
@@ -81,7 +82,7 @@ class registry implements registryInterface
*/ */
protected function load() protected function load()
{ {
if ($this->cache->get('registry_loaded') !== true) if ($this->cache->fetch('registry_loaded') !== true)
{ {
$rs = array(); $rs = array();
$loaded = false; $loaded = false;
@@ -119,10 +120,10 @@ class registry implements registryInterface
break; break;
} }
$this->cache->set($row['key'], $value); $this->cache->save($row['key'], $value);
} }
if ($loaded === true) 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) public function get($key, $defaultvalue = null)
{ {
if (!$this->cache->is_set($key)) if (!$this->cache->contains($key))
$this->load(); $this->load();
if (!$this->cache->is_set($key) && !is_null($defaultvalue)) if (!$this->cache->contains($key) && !is_null($defaultvalue))
return $defaultvalue; return $defaultvalue;
else 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) public function set($key, $value, $type)
{ {
$this->load(); $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) switch ($type)
{ {
@@ -195,13 +188,7 @@ class registry implements registryInterface
$stmt->execute(array(':key' => $key, ':value' => $sql_value, ':type' => $type)); $stmt->execute(array(':key' => $key, ':value' => $sql_value, ':type' => $type));
$stmt->closeCursor(); $stmt->closeCursor();
$this->cache->set($key, $value); $this->cache->save($key, $value);
if ($delete_cache === true)
{
$cache = cache_adapter::get_instance($this);
$cache->flush();
}
return $this; return $this;
} }
@@ -215,7 +202,7 @@ class registry implements registryInterface
{ {
$this->load(); $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->execute(array(':key' => $key));
$stmt->closeCursor(); $stmt->closeCursor();
$this->cache->un_set($key); $this->cache->delete($key);
return $this; return $this;
} }

View File

@@ -609,35 +609,27 @@ class setup
function check_cache_memcache() function check_cache_memcache()
{ {
$Core = \bootstrap::getCore();
echo '<h1>' . _('setup:: Serveur Memcached') . '</h1>'; echo '<h1>' . _('setup:: Serveur Memcached') . '</h1>';
echo '<ul class="setup">'; echo '<ul class="setup">';
$registry = registry::get_instance(); $registry = registry::get_instance();
if ($registry->get('GV_cache_server_type') !== 'nocache') if ($Core->getCache()->isServer())
{ {
$cache = cache_adapter::get_instance(registry::get_instance()); $stats = $Core->getCache()->getStats();
if ($cache->ping()) foreach ($stats as $name => $stat)
{ {
$stats = $cache->getStats(); echo '<li>Statistics given by `' . $name . '`</li>';
echo '<li>' . sprintf(_('setup::Serveur actif sur %s'), $registry->get('GV_cache_server_host') . ':' . $registry->get('GV_cache_server_port')) . '</li>';
foreach ($stats as $name => $stat) echo "<table>";
foreach ($stat as $key => $value)
{ {
echo '<li>Statistics given by `' . $name . '`</li>'; echo "<tr class='even'><td>" . $key . "</td><td> " . $value . "</td></tr>";
echo '<li>' . sprintf(_('setup::Serveur actif sur %s'), $registry->get('GV_cache_server_host') . ':' . $registry->get('GV_cache_server_port')) . '</li>';
echo "<table>";
foreach ($stat as $key => $value)
{
echo "<tr class='even'><td>" . $key . "</td><td> " . $value . "</td></tr>";
}
echo "</table>";
} }
} echo "</table>";
else
{
echo '<li class="non-blocker">' . sprintf(_('Le serveur memcached ne repond pas, vous devriez desactiver le cache')) . '</li>';
} }
} }
else else