mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 15:03:25 +00:00
Merge with master
This commit is contained in:
@@ -315,7 +315,7 @@ class 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);
|
||||||
}
|
}
|
||||||
|
@@ -56,7 +56,7 @@ class Edit extends RecordHelper
|
|||||||
*
|
*
|
||||||
* @var Array
|
* @var Array
|
||||||
*/
|
*/
|
||||||
protected $javascript_elements;
|
protected $javascript_elements = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@@ -545,7 +545,7 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper
|
|||||||
|
|
||||||
$user = \User_adapter::getInstance(array_pop($users), \appbox::get_instance());
|
$user = \User_adapter::getInstance(array_pop($users), \appbox::get_instance());
|
||||||
|
|
||||||
if ($user->is_template())
|
if ($user->is_template() || $user->is_special())
|
||||||
{
|
{
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@@ -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());
|
||||||
|
@@ -1280,6 +1280,9 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
|
|||||||
if ($this->_prefs)
|
if ($this->_prefs)
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
||||||
|
$registry = \registry::get_instance();
|
||||||
|
|
||||||
$sql = 'SELECT prop, value FROM usr_settings WHERE usr_id= :id';
|
$sql = 'SELECT prop, value FROM usr_settings WHERE usr_id= :id';
|
||||||
$stmt = $this->appbox->get_connection()->prepare($sql);
|
$stmt = $this->appbox->get_connection()->prepare($sql);
|
||||||
$stmt->execute(array(':id' => $this->id));
|
$stmt->execute(array(':id' => $this->id));
|
||||||
@@ -1295,6 +1298,11 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
|
|||||||
{
|
{
|
||||||
if (!isset($this->_prefs[$k]))
|
if (!isset($this->_prefs[$k]))
|
||||||
{
|
{
|
||||||
|
if($k == 'start_page_query' && $registry->get('GV_defaultQuery'))
|
||||||
|
{
|
||||||
|
$v = $registry->get('GV_defaultQuery');
|
||||||
|
}
|
||||||
|
|
||||||
$this->_prefs[$k] = $v;
|
$this->_prefs[$k] = $v;
|
||||||
$this->update_pref($k, $v);
|
$this->update_pref($k, $v);
|
||||||
}
|
}
|
||||||
|
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;
|
||||||
|
@@ -188,8 +188,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -159,9 +159,21 @@ class databox_status
|
|||||||
$statuses = array();
|
$statuses = array();
|
||||||
|
|
||||||
$sbas_ids = $user->ACL()->get_granted_sbas();
|
$sbas_ids = $user->ACL()->get_granted_sbas();
|
||||||
|
|
||||||
|
$see_all = array();
|
||||||
|
|
||||||
foreach ($sbas_ids as $databox)
|
foreach ($sbas_ids as $databox)
|
||||||
{
|
{
|
||||||
|
$see_all[$databox->get_sbas_id()] = false;
|
||||||
|
|
||||||
|
foreach($databox->get_collections() as $collection)
|
||||||
|
{
|
||||||
|
if($user->ACL()->has_right_on_base($collection->get_base_id(), 'chgstatus'))
|
||||||
|
{
|
||||||
|
$see_all[$databox->get_sbas_id()] = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$statuses[$databox->get_sbas_id()] = $databox->get_statusbits();
|
$statuses[$databox->get_sbas_id()] = $databox->get_statusbits();
|
||||||
@@ -177,15 +189,15 @@ class databox_status
|
|||||||
foreach ($statuses as $sbas_id => $status)
|
foreach ($statuses as $sbas_id => $status)
|
||||||
{
|
{
|
||||||
|
|
||||||
$see_all = false;
|
$see_this = isset($see_all[$sbas_id]) ? $see_all[$sbas_id] : false;
|
||||||
|
|
||||||
if ($user->ACL()->has_right_on_sbas($sbas_id, 'bas_modify_struct'))
|
if ($user->ACL()->has_right_on_sbas($sbas_id, 'bas_modify_struct'))
|
||||||
$see_all = true;
|
$see_this = true;
|
||||||
|
|
||||||
foreach ($status as $bit => $props)
|
foreach ($status as $bit => $props)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($props['searchable'] == 0 && !$see_all)
|
if ($props['searchable'] == 0 && !$see_this)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
$set = false;
|
$set = false;
|
||||||
|
@@ -1361,7 +1361,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;
|
||||||
}
|
}
|
||||||
@@ -1934,15 +1934,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1960,6 +1962,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));
|
||||||
}
|
}
|
||||||
|
@@ -353,7 +353,7 @@ class searchEngine_options implements Serializable
|
|||||||
{
|
{
|
||||||
if (!is_null($min_date) && trim($min_date) !== '')
|
if (!is_null($min_date) && trim($min_date) !== '')
|
||||||
{
|
{
|
||||||
$this->date_min = DateTime::createFromFormat('d/m/Y h:i:s', $min_date.' 00:00:00');
|
$this->date_min = DateTime::createFromFormat('d/m/Y H:i:s', $min_date.' 00:00:00');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@@ -377,7 +377,7 @@ class searchEngine_options implements Serializable
|
|||||||
{
|
{
|
||||||
if (!is_null($max_date) && trim($max_date) !== '')
|
if (!is_null($max_date) && trim($max_date) !== '')
|
||||||
{
|
{
|
||||||
$this->date_max = DateTime::createFromFormat('d/m/Y h:i:s', $max_date.' 23:59:59');
|
$this->date_max = DateTime::createFromFormat('d/m/Y H:i:s', $max_date.' 23:59:59');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
@@ -1051,7 +1051,6 @@ class system_file extends SplFileObject
|
|||||||
$li = $xptrdf->query('rdf:li', $bag->item(0));
|
$li = $xptrdf->query('rdf:li', $bag->item(0));
|
||||||
if ($li->length > 0)
|
if ($li->length > 0)
|
||||||
{
|
{
|
||||||
// $tfields[$src] = array();
|
|
||||||
for ($ili = 0; $ili < $li->length; $ili++)
|
for ($ili = 0; $ili < $li->length; $ili++)
|
||||||
{
|
{
|
||||||
$value = $base64_encoded ? base64_decode($li->item($ili)->nodeValue) : $li->item($ili)->nodeValue;
|
$value = $base64_encoded ? base64_decode($li->item($ili)->nodeValue) : $li->item($ili)->nodeValue;
|
||||||
|
@@ -19,9 +19,11 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||||||
|
|
||||||
class task_Scheduler
|
class task_Scheduler
|
||||||
{
|
{
|
||||||
|
|
||||||
const TASKDELAYTOQUIT = 60;
|
const TASKDELAYTOQUIT = 60;
|
||||||
|
|
||||||
protected $output;
|
protected $output;
|
||||||
|
protected static $connection;
|
||||||
|
|
||||||
protected function log($message)
|
protected function log($message)
|
||||||
{
|
{
|
||||||
@@ -31,12 +33,12 @@ class task_Scheduler
|
|||||||
}
|
}
|
||||||
|
|
||||||
$registry = registry::get_instance();
|
$registry = registry::get_instance();
|
||||||
$logdir = $registry->get('GV_RootPath') . 'logs/';
|
$logdir = $registry->get('GV_RootPath') . 'logs/';
|
||||||
|
|
||||||
logs::rotate($logdir . "scheduler.log");
|
logs::rotate($logdir . "scheduler.log");
|
||||||
|
|
||||||
$date_obj = new DateTime();
|
$date_obj = new DateTime();
|
||||||
$message = sprintf("%s %s \n", $date_obj->format(DATE_ATOM), $message);
|
$message = sprintf("%s %s \n", $date_obj->format(DATE_ATOM), $message);
|
||||||
|
|
||||||
file_put_contents($logdir . "scheduler.log", $message, FILE_APPEND);
|
file_put_contents($logdir . "scheduler.log", $message, FILE_APPEND);
|
||||||
|
|
||||||
@@ -61,14 +63,19 @@ class task_Scheduler
|
|||||||
$password = $connexion->get('password');
|
$password = $connexion->get('password');
|
||||||
$dbname = $connexion->get('dbname');
|
$dbname = $connexion->get('dbname');
|
||||||
|
|
||||||
return new connection_pdo('appbox', $hostname, $port, $user, $password, $dbname);
|
if (!self::$connection)
|
||||||
|
{
|
||||||
|
self::$connection = new connection_pdo ('appbox', $hostname, $port, $user, $password, $dbname);
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::$connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function run(OutputInterface $output = null, $log_tasks = true)
|
public function run(OutputInterface $output = null, $log_tasks = true)
|
||||||
{
|
{
|
||||||
require_once __DIR__ . '/../../bootstrap.php';
|
require_once __DIR__ . '/../../bootstrap.php';
|
||||||
$this->output = $output;
|
$this->output = $output;
|
||||||
$appbox = appbox::get_instance();
|
$appbox = appbox::get_instance();
|
||||||
$registry = $appbox->get_registry();
|
$registry = $appbox->get_registry();
|
||||||
|
|
||||||
$system = system_server::get_platform();
|
$system = system_server::get_platform();
|
||||||
@@ -77,7 +84,7 @@ class task_Scheduler
|
|||||||
|
|
||||||
for ($try = 0; true; $try++)
|
for ($try = 0; true; $try++)
|
||||||
{
|
{
|
||||||
$schedlock = fopen(($lockfile = ($lockdir . 'scheduler.lock')), 'a+');
|
$schedlock = fopen(($lockfile = ($lockdir . 'scheduler.lock')), 'a+');
|
||||||
if (flock($schedlock, LOCK_EX | LOCK_NB) != true)
|
if (flock($schedlock, LOCK_EX | LOCK_NB) != true)
|
||||||
{
|
{
|
||||||
$this->log(sprintf("failed to lock '%s' (try=%s/4)", $lockfile, $try));
|
$this->log(sprintf("failed to lock '%s' (try=%s/4)", $lockfile, $try));
|
||||||
@@ -110,7 +117,7 @@ class task_Scheduler
|
|||||||
|
|
||||||
$sleeptime = 3;
|
$sleeptime = 3;
|
||||||
|
|
||||||
$sql = "UPDATE sitepreff SET schedstatus='started', schedpid = :pid";
|
$sql = "UPDATE sitepreff SET schedstatus='started', schedpid = :pid";
|
||||||
$stmt = $conn->prepare($sql);
|
$stmt = $conn->prepare($sql);
|
||||||
$stmt->execute(array(':pid' => getmypid()));
|
$stmt->execute(array(':pid' => getmypid()));
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
@@ -153,14 +160,14 @@ class task_Scheduler
|
|||||||
$this->log(sprintf("Warning : abox connection lost, restarting in 10 min."));
|
$this->log(sprintf("Warning : abox connection lost, restarting in 10 min."));
|
||||||
}
|
}
|
||||||
sleep(60 * 10);
|
sleep(60 * 10);
|
||||||
$conn = self::get_connection();
|
$conn = self::get_connection();
|
||||||
$connwaslost = true;
|
$connwaslost = true;
|
||||||
}
|
}
|
||||||
if ($connwaslost)
|
if ($connwaslost)
|
||||||
{
|
{
|
||||||
$this->log("abox connection restored");
|
$this->log("abox connection restored");
|
||||||
|
|
||||||
$sql = 'UPDATE task SET crashed=0';
|
$sql = 'UPDATE task SET crashed=0';
|
||||||
$stmt = $conn->prepare($sql);
|
$stmt = $conn->prepare($sql);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
@@ -169,10 +176,10 @@ class task_Scheduler
|
|||||||
}
|
}
|
||||||
|
|
||||||
$schedstatus = '';
|
$schedstatus = '';
|
||||||
$sql = "SELECT schedstatus FROM sitepreff";
|
$sql = "SELECT schedstatus FROM sitepreff";
|
||||||
$stmt = $conn->prepare($sql);
|
$stmt = $conn->prepare($sql);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
|
|
||||||
if ($row)
|
if ($row)
|
||||||
@@ -182,13 +189,13 @@ class task_Scheduler
|
|||||||
|
|
||||||
if ($schedstatus == 'tostop')
|
if ($schedstatus == 'tostop')
|
||||||
{
|
{
|
||||||
$sql = 'UPDATE sitepreff SET schedstatus = "stopping"';
|
$sql = 'UPDATE sitepreff SET schedstatus = "stopping"';
|
||||||
$stmt = $conn->prepare($sql);
|
$stmt = $conn->prepare($sql);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
|
|
||||||
// if scheduler is stopped, stop the tasks
|
// if scheduler is stopped, stop the tasks
|
||||||
$sql = 'UPDATE task2 SET status="tostop" WHERE status != "stopped" and status != "manual"';
|
$sql = 'UPDATE task2 SET status="tostop" WHERE status != "stopped" and status != "manual"';
|
||||||
$stmt = $conn->prepare($sql);
|
$stmt = $conn->prepare($sql);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
@@ -208,10 +215,10 @@ class task_Scheduler
|
|||||||
$ttask[$tkey]["todel"] = true;
|
$ttask[$tkey]["todel"] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "SELECT * FROM task2";
|
$sql = "SELECT * FROM task2";
|
||||||
$stmt = $conn->prepare($sql);
|
$stmt = $conn->prepare($sql);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
|
|
||||||
foreach ($task_manager->get_tasks(true) as $task)
|
foreach ($task_manager->get_tasks(true) as $task)
|
||||||
@@ -232,27 +239,27 @@ class task_Scheduler
|
|||||||
case "WINDOWS":
|
case "WINDOWS":
|
||||||
case "LINUX":
|
case "LINUX":
|
||||||
$cmd = $phpcli . ' -f '
|
$cmd = $phpcli . ' -f '
|
||||||
. $registry->get('GV_RootPath')
|
. $registry->get('GV_RootPath')
|
||||||
. "bin/console task:run "
|
. "bin/console task:run "
|
||||||
. $task->get_task_id()
|
. $task->get_task_id()
|
||||||
. " --runner=scheduler ";
|
. " --runner=scheduler ";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$ttask[$tkey] = array(
|
$ttask[$tkey] = array(
|
||||||
"task" => $task,
|
"task" => $task,
|
||||||
"current_status" => $task->get_status(),
|
"current_status" => $task->get_status(),
|
||||||
"process" => null,
|
"process" => null,
|
||||||
"cmd" => $cmd,
|
"cmd" => $cmd,
|
||||||
"killat" => null,
|
"killat" => null,
|
||||||
"pipes" => null
|
"pipes" => null
|
||||||
);
|
);
|
||||||
$this->log(
|
$this->log(
|
||||||
sprintf(
|
sprintf(
|
||||||
"new Task %s, status=%s"
|
"new Task %s, status=%s"
|
||||||
, $ttask[$tkey]["task"]->get_task_id()
|
, $ttask[$tkey]["task"]->get_task_id()
|
||||||
, $task->get_status()
|
, $task->get_status()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -260,17 +267,17 @@ class task_Scheduler
|
|||||||
if ($ttask[$tkey]["current_status"] != $task->get_status())
|
if ($ttask[$tkey]["current_status"] != $task->get_status())
|
||||||
{
|
{
|
||||||
$this->log(
|
$this->log(
|
||||||
sprintf(
|
sprintf(
|
||||||
"Task %s, oldstatus=%s, newstatus=%s"
|
"Task %s, oldstatus=%s, newstatus=%s"
|
||||||
, $ttask[$tkey]["task"]->get_task_id()
|
, $ttask[$tkey]["task"]->get_task_id()
|
||||||
, $ttask[$tkey]["current_status"]
|
, $ttask[$tkey]["current_status"]
|
||||||
, $task->get_status()
|
, $task->get_status()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$ttask[$tkey]["current_status"] = $task->get_status();
|
$ttask[$tkey]["current_status"] = $task->get_status();
|
||||||
}
|
}
|
||||||
|
|
||||||
$ttask[$tkey]["task"] = $task;
|
$ttask[$tkey]["task"] = $task;
|
||||||
}
|
}
|
||||||
$ttask[$tkey]["todel"] = false;
|
$ttask[$tkey]["todel"] = false;
|
||||||
}
|
}
|
||||||
@@ -291,8 +298,8 @@ class task_Scheduler
|
|||||||
$runningtask = 0;
|
$runningtask = 0;
|
||||||
|
|
||||||
$common_status = array(
|
$common_status = array(
|
||||||
task_abstract::STATUS_STARTED
|
task_abstract::STATUS_STARTED
|
||||||
, task_abstract::RETURNSTATUS_STOPPED
|
, task_abstract::RETURNSTATUS_STOPPED
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($ttask as $tkey => $tv)
|
foreach ($ttask as $tkey => $tv)
|
||||||
@@ -300,21 +307,21 @@ class task_Scheduler
|
|||||||
if (!in_array($ttask[$tkey]["task"]->get_status(), $common_status))
|
if (!in_array($ttask[$tkey]["task"]->get_status(), $common_status))
|
||||||
{
|
{
|
||||||
$this->log(
|
$this->log(
|
||||||
sprintf(
|
sprintf(
|
||||||
'task %s has status %s'
|
'task %s has status %s'
|
||||||
, $ttask[$tkey]["task"]->get_task_id()
|
, $ttask[$tkey]["task"]->get_task_id()
|
||||||
, $ttask[$tkey]["task"]->get_status()
|
, $ttask[$tkey]["task"]->get_status()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
switch ($ttask[$tkey]["task"]->get_status())
|
switch ($ttask[$tkey]["task"]->get_status())
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
$this->log(
|
$this->log(
|
||||||
sprintf(
|
sprintf(
|
||||||
'Unknow status `%s`'
|
'Unknow status `%s`'
|
||||||
, $ttask[$tkey]["task"]->get_status()
|
, $ttask[$tkey]["task"]->get_status()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case task_abstract::RETURNSTATUS_TORESTART:
|
case task_abstract::RETURNSTATUS_TORESTART:
|
||||||
@@ -333,31 +340,31 @@ class task_Scheduler
|
|||||||
if ($schedstatus == 'started' && !$ttask[$tkey]["process"])
|
if ($schedstatus == 'started' && !$ttask[$tkey]["process"])
|
||||||
{
|
{
|
||||||
$descriptors = array(
|
$descriptors = array(
|
||||||
1 => array("pipe", "w")
|
1 => array("pipe", "w")
|
||||||
, 2 => array("pipe", "w")
|
, 2 => array("pipe", "w")
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($log_tasks === true)
|
if ($log_tasks === true)
|
||||||
{
|
{
|
||||||
$descriptors[1] = array(
|
$descriptors[1] = array(
|
||||||
"file"
|
"file"
|
||||||
, $logdir . "task_$tkey.log"
|
, $logdir . "task_$tkey.log"
|
||||||
, "a+"
|
, "a+"
|
||||||
);
|
);
|
||||||
$descriptors[2] = array(
|
$descriptors[2] = array(
|
||||||
"file"
|
"file"
|
||||||
, $logdir . "task_$tkey.error.log"
|
, $logdir . "task_$tkey.error.log"
|
||||||
, "a+"
|
, "a+"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$ttask[$tkey]["process"] = proc_open(
|
$ttask[$tkey]["process"] = proc_open(
|
||||||
$ttask[$tkey]["cmd"]
|
$ttask[$tkey]["cmd"]
|
||||||
, $descriptors
|
, $descriptors
|
||||||
, $ttask[$tkey]["pipes"]
|
, $ttask[$tkey]["pipes"]
|
||||||
, $registry->get('GV_RootPath') . "bin/"
|
, $registry->get('GV_RootPath') . "bin/"
|
||||||
, null
|
, null
|
||||||
, array('bypass_shell' => true)
|
, array('bypass_shell' => true)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (is_resource($ttask[$tkey]["process"]))
|
if (is_resource($ttask[$tkey]["process"]))
|
||||||
@@ -370,12 +377,12 @@ class task_Scheduler
|
|||||||
if ($ttask[$tkey]['task']->get_pid() !== null)
|
if ($ttask[$tkey]['task']->get_pid() !== null)
|
||||||
{
|
{
|
||||||
$this->log(
|
$this->log(
|
||||||
sprintf(
|
sprintf(
|
||||||
"Task %s '%s' started (pid=%s)"
|
"Task %s '%s' started (pid=%s)"
|
||||||
, $ttask[$tkey]['task']->get_task_id()
|
, $ttask[$tkey]['task']->get_task_id()
|
||||||
, $ttask[$tkey]["cmd"]
|
, $ttask[$tkey]["cmd"]
|
||||||
, $ttask[$tkey]['task']->get_pid()
|
, $ttask[$tkey]['task']->get_pid()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$runningtask++;
|
$runningtask++;
|
||||||
}
|
}
|
||||||
@@ -389,12 +396,12 @@ class task_Scheduler
|
|||||||
$ttask[$tkey]["process"] = null;
|
$ttask[$tkey]["process"] = null;
|
||||||
|
|
||||||
$this->log(
|
$this->log(
|
||||||
sprintf(
|
sprintf(
|
||||||
"Task %s '%s' failed to start %d times"
|
"Task %s '%s' failed to start %d times"
|
||||||
, $ttask[$tkey]["task"]->get_task_id()
|
, $ttask[$tkey]["task"]->get_task_id()
|
||||||
, $ttask[$tkey]["cmd"]
|
, $ttask[$tkey]["cmd"]
|
||||||
, $ttask[$tkey]["task"]->get_crash_counter()
|
, $ttask[$tkey]["task"]->get_crash_counter()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$ttask[$tkey]["task"]->increment_crash_counter();
|
$ttask[$tkey]["task"]->increment_crash_counter();
|
||||||
@@ -425,7 +432,7 @@ class task_Scheduler
|
|||||||
if ($proc_status['running'])
|
if ($proc_status['running'])
|
||||||
$runningtask++;
|
$runningtask++;
|
||||||
else
|
else
|
||||||
$crashed = true;
|
$crashed = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -447,11 +454,11 @@ class task_Scheduler
|
|||||||
$ttask[$tkey]["process"] = null;
|
$ttask[$tkey]["process"] = null;
|
||||||
|
|
||||||
$this->log(
|
$this->log(
|
||||||
sprintf(
|
sprintf(
|
||||||
"Task %s crashed %d times"
|
"Task %s crashed %d times"
|
||||||
, $ttask[$tkey]["task"]->get_task_id()
|
, $ttask[$tkey]["task"]->get_task_id()
|
||||||
, $ttask[$tkey]["task"]->get_crash_counter()
|
, $ttask[$tkey]["task"]->get_crash_counter()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
@@ -473,7 +480,7 @@ class task_Scheduler
|
|||||||
{
|
{
|
||||||
if ($ttask[$tkey]["killat"] === NULL)
|
if ($ttask[$tkey]["killat"] === NULL)
|
||||||
$ttask[$tkey]["killat"] = time() + self::TASKDELAYTOQUIT;
|
$ttask[$tkey]["killat"] = time() + self::TASKDELAYTOQUIT;
|
||||||
if (($dt = $ttask[$tkey]["killat"] - time()) < 0)
|
if (($dt = $ttask[$tkey]["killat"] - time()) < 0)
|
||||||
{
|
{
|
||||||
$ppid = $ttask[$tkey]['task']->get_pid();
|
$ppid = $ttask[$tkey]['task']->get_pid();
|
||||||
$pids = preg_split('/\s+/', `ps -o pid --no-heading --ppid $ppid`);
|
$pids = preg_split('/\s+/', `ps -o pid --no-heading --ppid $ppid`);
|
||||||
@@ -487,11 +494,11 @@ class task_Scheduler
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->log(
|
$this->log(
|
||||||
sprintf(
|
sprintf(
|
||||||
"SIGKILL sent to task %s (pid=%s)"
|
"SIGKILL sent to task %s (pid=%s)"
|
||||||
, $ttask[$tkey]["task"]->get_task_id()
|
, $ttask[$tkey]["task"]->get_task_id()
|
||||||
, $ttask[$tkey]["task"]->get_pid()
|
, $ttask[$tkey]["task"]->get_pid()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
proc_terminate($ttask[$tkey]["process"], 9);
|
proc_terminate($ttask[$tkey]["process"], 9);
|
||||||
@@ -507,11 +514,11 @@ class task_Scheduler
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->log(
|
$this->log(
|
||||||
sprintf(
|
sprintf(
|
||||||
"waiting task %s to quit (kill in %d seconds)"
|
"waiting task %s to quit (kill in %d seconds)"
|
||||||
, $ttask[$tkey]["task"]->get_task_id()
|
, $ttask[$tkey]["task"]->get_task_id()
|
||||||
, $dt
|
, $dt
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$runningtask++;
|
$runningtask++;
|
||||||
}
|
}
|
||||||
@@ -537,6 +544,7 @@ class task_Scheduler
|
|||||||
{
|
{
|
||||||
$conn->close();
|
$conn->close();
|
||||||
unset($conn);
|
unset($conn);
|
||||||
|
self::$connection = null;
|
||||||
$to_reopen = true;
|
$to_reopen = true;
|
||||||
}
|
}
|
||||||
sleep($sleeptime);
|
sleep($sleeptime);
|
||||||
@@ -546,7 +554,7 @@ class task_Scheduler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "UPDATE sitepreff SET schedstatus='stopped', schedpid='0'";
|
$sql = "UPDATE sitepreff SET schedstatus='stopped', schedpid='0'";
|
||||||
$stmt = $conn->prepare($sql);
|
$stmt = $conn->prepare($sql);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
|
@@ -102,7 +102,7 @@ $user = User_Adapter::getInstance($usr_id, $appbox);
|
|||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</head>
|
</head>
|
||||||
<body style="overflow:hidden;">
|
<body class="PNB" style="overflow:hidden;">
|
||||||
<div id="container" style="position:absolute;top:0;left:0;overflow:hidden;width:100%;height:100%;">
|
<div id="container" style="position:absolute;top:0;left:0;overflow:hidden;width:100%;height:100%;">
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
@@ -61,7 +61,7 @@ if ($parm["act"] == "START" || $parm["act"] == "WORK")
|
|||||||
foreach ($lst as $basrec)
|
foreach ($lst as $basrec)
|
||||||
{
|
{
|
||||||
$basrec = explode('_', $basrec);
|
$basrec = explode('_', $basrec);
|
||||||
$record = new record_adapter($barec[0], $basrec[1]);
|
$record = new record_adapter($basrec[0], $basrec[1]);
|
||||||
|
|
||||||
if ($record->is_grouping())
|
if ($record->is_grouping())
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user