mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-10 19:43:16 +00:00
199 lines
5.4 KiB
PHP
199 lines
5.4 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Phraseanet
|
|
*
|
|
* (c) 2005-2010 Alchemy
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
/**
|
|
*
|
|
* @package cache
|
|
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
|
* @link www.phraseanet.com
|
|
*/
|
|
class cache_databox
|
|
{
|
|
|
|
/**
|
|
*
|
|
* @param int $sbas_id
|
|
* @return cache_databox
|
|
*/
|
|
public static function refresh($sbas_id)
|
|
{
|
|
$databox = \databox::get_instance((int) $sbas_id);
|
|
|
|
$date = new \DateTime('-30 seconds');
|
|
|
|
$appbox = \appbox::get_instance();
|
|
|
|
$registry = \registry::get_instance();
|
|
|
|
$cache_appbox = $appbox->get_cache();
|
|
|
|
$last_update = null;
|
|
|
|
try
|
|
{
|
|
$last_update = $cache_appbox->get('memcached_update');
|
|
}
|
|
catch (\Exception $e)
|
|
{
|
|
|
|
}
|
|
|
|
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::getPDOConnection();
|
|
|
|
$sql = 'UPDATE sitepreff SET memcached_update = :date';
|
|
$stmt = $conn->prepare($sql);
|
|
$stmt->execute(array(':date' => $now));
|
|
$stmt->closeCursor();
|
|
|
|
return;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param int $sbas_id
|
|
* @param string $type
|
|
* @param mixed content $value
|
|
* @return Void
|
|
*/
|
|
public static function update($sbas_id, $type, $value = '')
|
|
{
|
|
|
|
$connbas = \connection::getPDOConnection($sbas_id);
|
|
|
|
$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);
|
|
$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->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;
|
|
}
|
|
|
|
}
|