mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-14 21:43:18 +00:00
Fix cached desynchro
This commit is contained in:
@@ -287,7 +287,7 @@ class Controller_Setup_Installer implements ControllerProviderInterface
|
|||||||
|
|
||||||
$appbox->get_session()->authenticate($auth);
|
$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);
|
return $app->redirect($redirection);
|
||||||
}
|
}
|
||||||
|
@@ -395,6 +395,7 @@ class Session_Handler
|
|||||||
foreach ($user->ACL()->get_granted_sbas() as $databox)
|
foreach ($user->ACL()->get_granted_sbas() as $databox)
|
||||||
{
|
{
|
||||||
Session_Logger::create($databox, $browser, $this, $user);
|
Session_Logger::create($databox, $browser, $this, $user);
|
||||||
|
\cache_databox::insertClient($databox);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->set_usr_lastconn($conn, $user->get_id());
|
$this->set_usr_lastconn($conn, $user->get_id());
|
||||||
|
251
lib/classes/cache/databox.class.php
vendored
251
lib/classes/cache/databox.class.php
vendored
@@ -18,142 +18,118 @@
|
|||||||
class cache_databox
|
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
|
* @param int $sbas_id
|
||||||
* @return cache_databox
|
* @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();
|
$appbox = \appbox::get_instance();
|
||||||
$last_update = $cache_appbox->get('memcached_update');
|
|
||||||
if ($last_update)
|
|
||||||
$last_update = new DateTime($last_update);
|
|
||||||
else
|
|
||||||
$last_update = new DateTime('-10 years');
|
|
||||||
|
|
||||||
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)
|
try
|
||||||
|
|
||||||
return $this;
|
|
||||||
|
|
||||||
$sql = 'SELECT type, value FROM memcached
|
|
||||||
WHERE site_id="' . $connsbas->escape_string($registry->get('GV_ServerName')) . '"';
|
|
||||||
|
|
||||||
if ($rs = $connsbas->query($sql))
|
|
||||||
{
|
{
|
||||||
$cache_thumbnail = cache_thumbnail::getInstance();
|
$last_update = $cache_appbox->get('memcached_update');
|
||||||
$cache_preview = cache_preview::getInstance();
|
}
|
||||||
while ($row = $connsbas->fetch_assoc($rs))
|
catch (\Exception $e)
|
||||||
{
|
{
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$date = new DateTime();
|
if ($last_update)
|
||||||
$now = phraseadate::format_mysql($date);
|
$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);
|
$cache_appbox->set('memcached_update', $now);
|
||||||
|
|
||||||
$conn = connection::getInstance();
|
$conn = \connection::getPDOConnection();
|
||||||
$sql = 'UPDATE sitepreff
|
|
||||||
SET memcached_update="' . $conn->escape_string($now) . '"';
|
|
||||||
$conn->query($sql);
|
|
||||||
|
|
||||||
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
|
* @param mixed content $value
|
||||||
* @return Void
|
* @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
|
$sql = 'SELECT distinct site_id as site_id
|
||||||
FROM clients
|
FROM clients
|
||||||
WHERE site_id != :site_id';
|
WHERE site_id != :site_id';
|
||||||
|
|
||||||
$stmt = $connbas->prepare($sql);
|
$stmt = $connbas->prepare($sql);
|
||||||
$stmt->execute(array(':site_id' => $registry->get('GV_ServerName')));
|
$stmt->execute(array(':site_id' => $registry->get('GV_ServerName')));
|
||||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
$rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
|
|
||||||
$sql = 'REPLACE INTO memcached (site_id, type, value)
|
$sql = 'REPLACE INTO memcached (site_id, type, value)
|
||||||
VALUES (:site_id, :type, :value)';
|
VALUES (:site_id, :type, :value)';
|
||||||
|
|
||||||
$stmt = $connbas->prepare($sql);
|
$stmt = $connbas->prepare($sql);
|
||||||
|
|
||||||
foreach ($rs as $row)
|
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();
|
$stmt->closeCursor();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@@ -171,8 +171,10 @@ class connection
|
|||||||
public static function close_PDO_connection($name)
|
public static function close_PDO_connection($name)
|
||||||
{
|
{
|
||||||
if (isset(self::$_PDO_instance[$name]))
|
if (isset(self::$_PDO_instance[$name]))
|
||||||
|
{
|
||||||
|
self::$_PDO_instance[$name] = null;
|
||||||
unset(self::$_PDO_instance[$name]);
|
unset(self::$_PDO_instance[$name]);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -46,7 +46,7 @@ class module_prod_route_records_edit extends module_prod_route_records_abstract
|
|||||||
*
|
*
|
||||||
* @var Array
|
* @var Array
|
||||||
*/
|
*/
|
||||||
protected $javascript_elements;
|
protected $javascript_elements = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@@ -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']);
|
$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;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -1802,15 +1802,17 @@ class record_adapter implements record_Interface, cache_cacheableInterface
|
|||||||
*/
|
*/
|
||||||
public function get_data_from_cache($option = null)
|
public function get_data_from_cache($option = null)
|
||||||
{
|
{
|
||||||
|
\cache_databox::refresh($this->get_sbas_id());
|
||||||
|
|
||||||
$databox = $this->get_databox();
|
$databox = $this->get_databox();
|
||||||
|
|
||||||
return $databox->get_data_from_cache($this->get_cache_key($option));
|
return $databox->get_data_from_cache($this->get_cache_key($option));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function set_data_to_cache($value, $option = null, $duration = 0)
|
public function set_data_to_cache($value, $option = null, $duration = 0)
|
||||||
{
|
{
|
||||||
$databox = $this->get_databox();
|
$databox = $this->get_databox();
|
||||||
|
|
||||||
return $databox->set_data_to_cache($value, $this->get_cache_key($option), $duration);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
$databox = $this->get_databox();
|
$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));
|
return $databox->delete_data_from_cache($this->get_cache_key($option));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user