Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions core/ajax/cmd.ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
}
$info_cmd = array();
$info_cmd['id'] = $cmd->getId();
$info_cmd['html'] = $cmd->toHtml(init('version'), init('option'), init('cmdColor', null));
$info_cmd['html'] = $cmd->toHtml(init('version'), init('option'));
ajax::success($info_cmd);
}
}
Expand Down Expand Up @@ -385,8 +385,8 @@
}

if ($dateStart == '' && init('dateRange') != 'all') {
$now = date('Y-m-d');
$dateStart = $now->modify('- ' . init('dateRange'));
$now = new \DateTimeImmutable();
$dateStart = $now->modify('- ' . init('dateRange'))->format('Y-m-d H:i:s');
}

$return['maxValue'] = '';
Expand Down
2 changes: 1 addition & 1 deletion core/ajax/eqLogic.ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@
unset($used['cmd' . $cmd->getId()]);
}
$cmdData = array('node' => array(), 'link' => array());
$cmdData = $cmd->getLinkData($cmdData, 0, 2, null, false);
$cmdData = $cmd->getLinkData($cmdData, 0, 2, false);
if (isset($cmdData['node']['eqLogic' . $eqLogic->getId()])) {
unset($cmdData['node']['eqLogic' . $eqLogic->getId()]);
}
Expand Down
108 changes: 54 additions & 54 deletions core/class/DB.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ private static function initConnection() {
PDO::ATTR_ERRMODE => (DEBUG ? PDO::ERRMODE_EXCEPTION : PDO::ERRMODE_SILENT),
];
if (isset($CONFIG['db']['unix_socket'])) {
static::$connection = new PDO('mysql:unix_socket=' . $CONFIG['db']['unix_socket'] . ';dbname=' . $CONFIG['db']['dbname'],
self::$connection = new PDO('mysql:unix_socket=' . $CONFIG['db']['unix_socket'] . ';dbname=' . $CONFIG['db']['dbname'],
$CONFIG['db']['username'], $CONFIG['db']['password'], $_options);
} else {
static::$connection = new PDO('mysql:host=' . $CONFIG['db']['host'] . ';port=' . $CONFIG['db']['port'] . ';dbname=' . $CONFIG['db']['dbname'],
self::$connection = new PDO('mysql:host=' . $CONFIG['db']['host'] . ';port=' . $CONFIG['db']['port'] . ';dbname=' . $CONFIG['db']['dbname'],
$CONFIG['db']['username'], $CONFIG['db']['password'], $_options);
}
}
Expand All @@ -55,21 +55,21 @@ public static function getLastInsertId() {
}

public static function getConnection() {
if (static::$connection == null) {
static::initConnection();
static::$lastConnection = strtotime('now');
} elseif (static::$lastConnection + 120 < strtotime('now')) {
if (self::$connection == null) {
self::initConnection();
self::$lastConnection = strtotime('now');
} elseif (self::$lastConnection + 120 < strtotime('now')) {
try {
$result = @static::$connection->query('select 1;');
$result = @self::$connection->query('select 1;');
if (!$result) {
static::initConnection();
self::initConnection();
}
} catch (Exception $e) {
static::initConnection();
self::initConnection();
}
static::$lastConnection = strtotime('now');
self::$lastConnection = strtotime('now');
}
return static::$connection;
return self::$connection;
}

public static function &CallStoredProc($_procName, $_params, $_fetch_type, $_className = NULL, $_fetch_opt = NULL) {
Expand All @@ -94,10 +94,10 @@ public static function &Prepare($_query, $_params, $_fetchType = self::FETCH_TYP
if(preg_match('/^update|^replace|^delete|^create|^drop|^alter|^truncate/i', $_query)){
$errorInfo = $stmt->errorInfo();
if ($errorInfo[0] != 0000) {
static::$lastConnection = 0;
self::$lastConnection = 0;
throw new Exception('[MySQL] Error code : ' . $errorInfo[0] . ' (' . $errorInfo[1] . '). ' . $errorInfo[2] . ' : ' . $_query);
}
static::$lastConnection = strtotime('now');
self::$lastConnection = strtotime('now');
return $res;
}
if ($_fetchType == static::FETCH_TYPE_ROW) {
Expand All @@ -116,10 +116,10 @@ public static function &Prepare($_query, $_params, $_fetchType = self::FETCH_TYP
}
$errorInfo = $stmt->errorInfo();
if ($errorInfo[0] != 0000) {
static::$lastConnection = 0;
self::$lastConnection = 0;
throw new Exception('[MySQL] Error code : ' . $errorInfo[0] . ' (' . $errorInfo[1] . '). ' . $errorInfo[2] . ' : ' . $_query);
}
static::$lastConnection = strtotime('now');
self::$lastConnection = strtotime('now');
if ($_fetch_param == PDO::FETCH_CLASS) {
if (is_array($res) && count($res) > 0) {
foreach ($res as &$obj) {
Expand Down Expand Up @@ -186,29 +186,29 @@ public static function save($object, $_direct = false, $_replace = false) {
if (!$_direct && method_exists($object, 'preSave')) {
$object->preSave();
}
if (!static::getField($object, 'id')) {
if (!self::getField($object, 'id')) {
//New object to save.
$fields = static::getFields($object);
$fields = self::getFields($object);
if (in_array('id', $fields)) {
static::setField($object, 'id', null);
self::setField($object, 'id', null);
}
if (!$_direct && method_exists($object, 'preInsert')) {
$object->preInsert();
}
if (method_exists($object, 'encrypt')) {
$object->encrypt();
}
list($sql, $parameters) = static::buildQuery($object);
list($sql, $parameters) = self::buildQuery($object);
if ($_replace) {
$sql = 'REPLACE INTO `' . static::getTableName($object) . '` SET ' . implode(', ', $sql);
$sql = 'REPLACE INTO `' . self::getTableName($object) . '` SET ' . implode(', ', $sql);
} else {
$sql = 'INSERT INTO `' . static::getTableName($object) . '` SET ' . implode(', ', $sql);
$sql = 'INSERT INTO `' . self::getTableName($object) . '` SET ' . implode(', ', $sql);
}
$res = static::Prepare($sql, $parameters, DB::FETCH_TYPE_ROW);
$reflection = static::getReflectionClass($object);
$reflection = self::getReflectionClass($object);
if ($reflection->hasProperty('id')) {
try {
static::setField($object, 'id', static::getLastInsertId());
self::setField($object, 'id', static::getLastInsertId());
} catch (Exception $exc) {
trigger_error($exc->getMessage(), E_USER_NOTICE);
} catch (InvalidArgumentException $ex) {
Expand All @@ -234,14 +234,14 @@ public static function save($object, $_direct = false, $_replace = false) {
if (method_exists($object, 'encrypt')) {
$object->encrypt();
}
list($sql, $parameters) = static::buildQuery($object);
list($sql, $parameters) = self::buildQuery($object);
if (!$_direct && method_exists($object, 'getId')) {
$parameters['id'] = $object->getId(); //override if necessary
}
if ($_replace) {
$sql = 'REPLACE INTO `' . static::getTableName($object) . '` SET ' . implode(', ', $sql);
$sql = 'REPLACE INTO `' . self::getTableName($object) . '` SET ' . implode(', ', $sql);
} else {
$sql = 'UPDATE `' . static::getTableName($object) . '` SET ' . implode(', ', $sql) . ' WHERE id = :id';
$sql = 'UPDATE `' . self::getTableName($object) . '` SET ' . implode(', ', $sql) . ' WHERE id = :id';
}
$res = static::Prepare($sql, $parameters, DB::FETCH_TYPE_ROW);
} else {
Expand All @@ -264,12 +264,12 @@ public static function save($object, $_direct = false, $_replace = false) {
}

public static function refresh($object) {
if (!static::getField($object, 'id')) {
if (!self::getField($object, 'id')) {
throw new Exception('Can\'t refresh DB object without its ID');
}
$parameters = array('id' => static::getField($object, 'id'));
$parameters = array('id' => self::getField($object, 'id'));
$sql = 'SELECT ' . static::buildField(get_class($object)) .
' FROM `' . static::getTableName($object) . '` ' .
' FROM `' . self::getTableName($object) . '` ' .
' WHERE ';
foreach ($parameters as $field => $value) {
if ($value != '') {
Expand All @@ -283,14 +283,14 @@ public static function refresh($object) {
if (!is_object($newObject)) {
return false;
}
foreach (static::getFields($object) as $field) {
$reflection = static::getReflectionClass($object);
foreach (self::getFields($object) as $field) {
$reflection = self::getReflectionClass($object);
$property = $reflection->getProperty($field);
if (!$reflection->hasProperty($field)) {
throw new InvalidArgumentException('Unknown field ' . get_class($object) . '::' . $field);
}
$property->setAccessible(true);
$property->setValue($object, static::getField($newObject, $field));
$property->setValue($object, self::getField($newObject, $field));
$property->setAccessible(false);
}
return true;
Expand All @@ -300,13 +300,13 @@ public static function refresh($object) {
* Retourne une liste d'objets ou un objet en fonction de filtres
* @param $_filters Filtres à appliquer
* @param $_object Objet sur lequel appliquer les filtres
* @return Objet ou liste d'objets correspondant à la requête
* @return array<mixed>|null Objet ou liste d'objets correspondant à la requête
*/
public static function getWithFilter(array $_filters, $_object) {
// operators have to remain in this order. If you put '<' before '<=', algorithm won't make the difference & will think a '<=' is a '<'
$operators = array('!=', '<=', '>=', '<', '>', 'NOT LIKE', 'LIKE', '=');
$fields = static::getFields($_object);
$class = static::getReflectionClass($_object)->getName();
$fields = self::getFields($_object);
$class = self::getReflectionClass($_object)->getName();
// create query
$query = 'SELECT ' . static::buildField($class) . ' FROM ' . $class . '';
$values = array();
Expand Down Expand Up @@ -365,8 +365,8 @@ public static function remove($object) {
return false;
}
}
list($sql, $parameters) = static::buildQuery($object);
$sql = 'DELETE FROM `' . static::getTableName($object) . '` WHERE ';
list($sql, $parameters) = self::buildQuery($object);
$sql = 'DELETE FROM `' . self::getTableName($object) . '` WHERE ';
if (isset($parameters['id'])) {
$sql .= '`id`=:id AND ';
$parameters = array('id' => $parameters['id']);
Expand All @@ -381,9 +381,9 @@ public static function remove($object) {
}
$sql .= '1';
$res = static::Prepare($sql, $parameters, DB::FETCH_TYPE_ROW);
$reflection = static::getReflectionClass($object);
$reflection = self::getReflectionClass($object);
if ($reflection->hasProperty('id')) {
static::setField($object, 'id', null);
self::setField($object, 'id', null);
}
if (method_exists($object, 'postRemove')) {
$object->postRemove();
Expand All @@ -409,8 +409,8 @@ public static function lock($object) {
return false;
}
}
list($sql, $parameters) = static::buildQuery($object);
$sql = 'SELECT * FROM ' . static::getTableName($object) . ' WHERE ';
list($sql, $parameters) = self::buildQuery($object);
$sql = 'SELECT * FROM ' . self::getTableName($object) . ' WHERE ';
foreach ($parameters as $field => $value) {
if ($value != '') {
$sql .= '`' . $field . '`=:' . $field . ' AND ';
Expand Down Expand Up @@ -445,23 +445,23 @@ private static function getTableName($object) {
* @throws RuntimeException
*/
private static function getFields($object) {
$table = is_string($object) ? $object : static::getTableName($object);
if (isset(static::$fields[$table])) {
return static::$fields[$table];
$table = is_string($object) ? $object : self::getTableName($object);
if (isset(self::$fields[$table])) {
return self::$fields[$table];
}
$reflection = is_object($object) ? static::getReflectionClass($object) : new ReflectionClass($object);
$reflection = is_object($object) ? self::getReflectionClass($object) : new ReflectionClass($object);
$properties = $reflection->getProperties();
static::$fields[$table] = array();
self::$fields[$table] = array();
foreach ($properties as $property) {
$name = $property->getName();
if ('_' !== $name[0]) {
static::$fields[$table][] = $name;
self::$fields[$table][] = $name;
}
}
if (empty(static::$fields[$table])) {
if (empty(self::$fields[$table])) {
throw new RuntimeException('No fields found for class ' . get_class($object));
}
return static::$fields[$table];
return self::$fields[$table];
}

/**
Expand All @@ -477,7 +477,7 @@ private static function setField($object, $field, $value) {
if (method_exists($object, $method)) {
$object->$method($value);
} else {
$reflection = static::getReflectionClass($object);
$reflection = self::getReflectionClass($object);
if (!$reflection->hasProperty($field)) {
throw new InvalidArgumentException('Unknown field ' . get_class($object) . '::' . $field);
}
Expand All @@ -499,9 +499,9 @@ private static function setField($object, $field, $value) {
private static function buildQuery($object) {
$parameters = array();
$sql = array();
foreach (static::getFields($object) as $field) {
foreach (self::getFields($object) as $field) {
$sql[] = '`' . $field . '` = :' . $field;
$parameters[$field] = static::getField($object, $field);
$parameters[$field] = self::getField($object, $field);
}
return array($sql, $parameters);
}
Expand All @@ -521,7 +521,7 @@ private static function getField($object, $field) {
if (method_exists($object, $method)) {
$retval = $object->$method();
} else {
$reflection = static::getReflectionClass($object);
$reflection = self::getReflectionClass($object);
if ($reflection->hasProperty($field)) {
$property = $reflection->getProperty($field);
$property->setAccessible(true);
Expand Down Expand Up @@ -552,7 +552,7 @@ private static function getReflectionClass($object) {

public static function buildField($_class, $_prefix = '') {
$fields = array();
foreach (static::getFields($_class) as $field) {
foreach (self::getFields($_class) as $field) {
if ('_' !== $field[0]) {
if ($_prefix != '') {
$fields[] = '`' . $_prefix . '`.' . '`' . $field . '`';
Expand Down
8 changes: 4 additions & 4 deletions core/class/cache.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,13 @@ public static function isOk(){
}

public static function getConnection(){
if(static::$connection !== null){
return static::$connection;
if(self::$connection !== null){
return self::$connection;
}
$redis = new Redis();
$redis->connect(config::byKey('cache::redisaddr'), config::byKey('cache::redisport'));
static::$connection = $redis;
return static::$connection;
self::$connection = $redis;
return self::$connection;
}

public static function all(){
Expand Down
2 changes: 1 addition & 1 deletion core/class/config.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public static function remove(string $_key, string $_plugin = 'core') {
/**
* Get config by key
* @param string $_key nom de la clef dont on veut la valeur
* @return string valeur de la clef
* @return mixed valeur de la clef
*/
public static function byKey($_key, $_plugin = 'core', $_default = '', $_forceFresh = false) {
if (!$_forceFresh && isset(self::$cache[$_plugin . '::' . $_key]) && !in_array($_key, self::$nocache)) {
Expand Down
2 changes: 1 addition & 1 deletion core/class/event.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static function changes($_datetime, $_longPolling = null, $_filter = null
$max_cycle = $_longPolling / $waitTime;
while (count($return) == 0 && $i < $max_cycle) {
if ($waitTime < 1) {
usleep(1000000 * $waitTime);
usleep(1000000 * ((float) $waitTime));
} else {
sleep(round($waitTime));
}
Expand Down
8 changes: 4 additions & 4 deletions core/class/history.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,14 @@ public static function archive() {
config::save('historyArchiveTime', 2);
}
if (config::byKey('historyArchivePackage') >= config::byKey('historyArchiveTime')) {
config::save('historyArchivePackage', config::byKey('historyArchiveTime') - 1);
config::save('historyArchivePackage', (int) config::byKey('historyArchiveTime') - 1);
}
if (config::byKey('historyArchivePackage') >= config::byKey('historyArchiveTime')) {
config::save('historyArchivePackage', config::byKey('historyArchiveTime') - 1);
config::save('historyArchivePackage', (int) config::byKey('historyArchiveTime') - 1);
}
$archiveDatetime = (config::byKey('historyArchiveTime') < 1) ? date('Y-m-d H:i:s', strtotime('- 1 hours')) : date('Y-m-d H:i:s', strtotime('- ' . config::byKey('historyArchiveTime', 'core', 1) . ' hours'));
if (config::byKey('historyArchivePackage') < 1) {
$archivePackage = '00:' . config::byKey('historyArchivePackage') * 60 . ':00';
$archivePackage = '00:' . (int) config::byKey('historyArchivePackage') * 60 . ':00';
} else {
$archivePackage = config::byKey('historyArchivePackage') . ':00:00';
if (strlen($archivePackage) < 8) {
Expand Down Expand Up @@ -328,7 +328,7 @@ public static function archive() {
$mode = $cmd->getConfiguration('historizeMode', 'avg');
$values = array(
'cmd_id' => $sensors['cmd_id'],
'archivePackage' => config::byKey('historyArchivePackage') * 3600,
'archivePackage' => (int) config::byKey('historyArchivePackage') * 3600,
'archiveTime' => $archiveDatetime
);
$round = (is_numeric($cmd->getConfiguration('historizeRound'))) ? $cmd->getConfiguration('historizeRound') : 2;
Expand Down
2 changes: 1 addition & 1 deletion core/class/jeedom.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ public static function isDateOk() {
self::forceSyncHour();
sleep(3);
if (strtotime('now') < $mindate || strtotime('now') > $maxdate) {
log::add('core', 'error', __('La date du système est incorrecte (avant ' . $minDateValue . ' ou après ' . $maxDateValue . ') :', __FILE__) . ' ' . (new \DateTime())->format('Y-m-d H:i:s'), 'dateCheckFailed');
log::add('core', 'error', __('La date du système est incorrecte (avant ' . $minDateValue->format('Y-m-d H:i:s') . ' ou après ' . $maxDateValue . ') :', __FILE__) . ' ' . (new \DateTime())->format('Y-m-d H:i:s'), 'dateCheckFailed');
return false;
}
}
Expand Down
Loading