Skip to content

Commit

Permalink
Merge branch 'jeedom:beta' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
MrWaloo authored Oct 19, 2024
2 parents 2710cc6 + 3ba5cff commit 932bc0b
Show file tree
Hide file tree
Showing 71 changed files with 555 additions and 500 deletions.
9 changes: 9 additions & 0 deletions .env.default
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# environment variables for docker-compose.yml
MYSQL_DATABASE=jeedom
MYSQL_USER=jeedom
MYSQL_PASSWORD=jeedom
DB_PORT=3306
DB_HOST=localhost
DEBUG=1
# TZ is one of https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
TIME_ZONE=Europe/Paris
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ tmp/*
!tmp/.htaccess

!.htaccess

.env
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
"dragonmantank/cron-expression": "^3",
"symfony/expression-language": "5 - 7",
"pragmarx/google2fa-qrcode": "^3",
"bacon/bacon-qr-code": "2 - 3"
"bacon/bacon-qr-code": "2 - 3",
"psr/log": "^1.1"
},
"config": {
"allow-plugins": {
"php-http/discovery": true
}
"allow-plugins": {
"php-http/discovery": true
}
}
}
}
2 changes: 1 addition & 1 deletion core/class/DB.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ private static function setField($object, $field, $value) {
$object->$method($value);
} else {
$reflection = static::getReflectionClass($object);
if ($reflection->hasProperty($field)) {
if (!$reflection->hasProperty($field)) {
throw new InvalidArgumentException('Unknown field ' . get_class($object) . '::' . $field);
}
$property = $reflection->getProperty($field);
Expand Down
6 changes: 5 additions & 1 deletion core/class/cache.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public static function fetch($_key){
FROM cache
WHERE `key`=:key';
$cache = DB::Prepare($sql,array('key' => $_key), DB::FETCH_TYPE_ROW, PDO::FETCH_CLASS,'cache');
if($cache === false){
if($cache === false || !is_object($cache)){
return null;
}
if($cache->getLifetime() > 0 && ($cache->getTimestamp() + $cache->getLifetime()) < strtotime('now')){
Expand Down Expand Up @@ -332,6 +332,10 @@ public static function all(){
public static function clean(){
foreach (ls(jeedom::getTmpFolder('cache'), '*',false,array('files')) as $file) {
$cache = unserialize(file_get_contents(jeedom::getTmpFolder('cache').'/'.$file));
if(!is_object($cache)){
unlink(jeedom::getTmpFolder('cache').'/'.$file);
continue;
}
if($cache->getLifetime() > 0 && ($cache->getTimestamp() + $cache->getLifetime()) < strtotime('now')){
unlink(jeedom::getTmpFolder('cache').'/'.$file);
}
Expand Down
33 changes: 22 additions & 11 deletions core/class/cmd.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ public static function returnState($_options) {
public static function deadCmd() {
$return = array();
foreach ((cmd::all()) as $cmd) {
if($cmd->getConfiguration('core::cmd::noDeadAnalyze',0) == 1){
if ($cmd->getConfiguration('core::cmd::noDeadAnalyze', 0) == 1) {
continue;
}
if (is_array($cmd->getConfiguration('actionCheckCmd', ''))) {
Expand Down Expand Up @@ -992,6 +992,12 @@ public function formatValue($_value, $_quote = false) {
$_value = 0;
}
if (trim($_value) == '' && $_value !== false && $_value !== 0) {
if($this->getSubType() == 'numeric'){
return 0;
}
if($this->getSubType() == 'binary'){
return 0;
}
return '';
}
$_value = trim(trim($_value), '"');
Expand Down Expand Up @@ -1027,7 +1033,7 @@ public function formatValue($_value, $_quote = false) {
$binary = true;
} elseif ((is_numeric(intval($_value)) && intval($_value) >= 1)) { // Handle number and numeric string
$binary = true;
} elseif (in_array(strtolower($_value), array('on', 'true', 'high', 'enable', 'enabled','online'))) { // Handle common string boolean values
} elseif (in_array(strtolower($_value), array('on', 'true', 'high', 'enable', 'enabled', 'online'))) { // Handle common string boolean values
$binary = true;
} else { // Handle everything else as false
$binary = false;
Expand Down Expand Up @@ -1144,7 +1150,7 @@ public function execute($_options = array()) {
}

private function pre_postExecCmd($_values = array(), $_type = 'jeedomPreExecCmd') {

if (!is_array($this->getConfiguration($_type)) || count($this->getConfiguration($_type)) == 0) {
return;
}
Expand Down Expand Up @@ -1892,7 +1898,7 @@ public function event($_value, $_datetime = null, $_loop = 1) {
}
if ($repeat && $this->getConfiguration('repeatEventManagement', 'never') == 'never') {
$this->addHistoryValue($value, $this->getCollectDate());
event::adds('cmd::update', array(array('cmd_id' => $this->getId(), 'value' => (strlen($value) < 3096) ? $value : substr($value,0,3096), 'display_value' => (strlen($display_value) < 3096) ? $display_value : substr($display_value,0,3096), 'unit' => $unit, 'raw_unit' => $raw_unit, 'valueDate' => $this->getValueDate(), 'collectDate' => $this->getCollectDate())));
event::adds('cmd::update', array(array('cmd_id' => $this->getId(), 'value' => (strlen($value) < 3096) ? $value : substr($value, 0, 3096), 'display_value' => (strlen($display_value) < 3096) ? $display_value : substr($display_value, 0, 3096), 'unit' => $unit, 'raw_unit' => $raw_unit, 'valueDate' => $this->getValueDate(), 'collectDate' => $this->getCollectDate())));
return;
}
$_loop++;
Expand All @@ -1909,13 +1915,13 @@ public function event($_value, $_datetime = null, $_loop = 1) {
$this->setCache(array('value' => $value, 'valueDate' => $this->getValueDate()));
scenario::check($this, false, $this->getGeneric_type(), $object, $value);
$level = $this->checkAlertLevel($value);
$events[] = array('cmd_id' => $this->getId(), 'value' => (strlen($value) < 3096) ? $value : substr($value,0,3096), 'display_value' => (strlen($display_value) < 3096) ? $display_value : substr($display_value,0,3096), 'unit' => $unit, 'raw_unit' => $raw_unit, 'valueDate' => $this->getValueDate(), 'collectDate' => $this->getCollectDate(), 'alertLevel' => $level);
$events[] = array('cmd_id' => $this->getId(), 'value' => (strlen($value) < 3096) ? $value : substr($value, 0, 3096), 'display_value' => (strlen($display_value) < 3096) ? $display_value : substr($display_value, 0, 3096), 'unit' => $unit, 'raw_unit' => $raw_unit, 'valueDate' => $this->getValueDate(), 'collectDate' => $this->getCollectDate(), 'alertLevel' => $level);
$foundInfo = false;
$value_cmd = self::byValue($this->getId(), null, true);
if (is_array($value_cmd) && count($value_cmd) > 0) {
foreach ($value_cmd as $cmd) {
if ($cmd->getType() == 'action') {
$events[] = array('cmd_id' => $cmd->getId(), 'value' => (strlen($value) < 3096) ? $value : substr($value,0,3096), 'display_value' => (strlen($display_value) < 3096) ? $display_value : substr($display_value,0,3096), 'valueDate' => $this->getValueDate(), 'collectDate' => $this->getCollectDate(), 'unit' => $unit);
$events[] = array('cmd_id' => $cmd->getId(), 'value' => (strlen($value) < 3096) ? $value : substr($value, 0, 3096), 'display_value' => (strlen($display_value) < 3096) ? $display_value : substr($display_value, 0, 3096), 'valueDate' => $this->getValueDate(), 'collectDate' => $this->getCollectDate(), 'unit' => $unit);
} else {
if ($_loop > 1) {
$cmd->event($cmd->execute(), null, $_loop);
Expand All @@ -1929,13 +1935,13 @@ public function event($_value, $_datetime = null, $_loop = 1) {
listener::backgroundCalculDependencyCmd($this->getId());
}
} else {
$events[] = array('cmd_id' => $this->getId(), 'value' => (strlen($value) < 3096) ? $value : substr($value,0,3096), 'display_value' => (strlen($display_value) < 3096) ? $display_value : substr($display_value,0,3096), 'unit' => $unit, 'raw_unit' => $raw_unit, 'valueDate' => $this->getValueDate(), 'collectDate' => $this->getCollectDate());
$events[] = array('cmd_id' => $this->getId(), 'value' => (strlen($value) < 3096) ? $value : substr($value, 0, 3096), 'display_value' => (strlen($display_value) < 3096) ? $display_value : substr($display_value, 0, 3096), 'unit' => $unit, 'raw_unit' => $raw_unit, 'valueDate' => $this->getValueDate(), 'collectDate' => $this->getCollectDate());
}
if (count($events) > 0) {
event::adds('cmd::update', $events);
}
if (!$repeat) {
listener::check($this->getId(), $value, $this->getCollectDate(),$this);
listener::check($this->getId(), $value, $this->getCollectDate(), $this);
jeeObject::checkSummaryUpdate($this->getId());
}
$this->addHistoryValue($value, $this->getCollectDate());
Expand All @@ -1958,8 +1964,8 @@ public function event($_value, $_datetime = null, $_loop = 1) {
}
$this->pushUrl($value);
$this->pushInflux($value);
if($this->getGeneric_type() == 'BATTERY' && $this->getUnite() == '%'){
$this->batteryStatus($value);
if ($this->getGeneric_type() == 'BATTERY' && $this->getUnite() == '%') {
$this->getEqLogic()->batteryStatus($value);
}
}
}
Expand Down Expand Up @@ -2851,7 +2857,12 @@ public function getLinkData(&$_data = array('node' => array(), 'link' => array()

public function getUsedBy($_array = false) {
$return = array('cmd' => array(), 'eqLogic' => array(), 'scenario' => array(), 'plan' => array(), 'view' => array());
$return['cmd'] = array_merge(self::searchConfiguration('#' . $this->getId() . '#'), cmd::byValue($this->getId()));
$cmds = array_merge(self::searchConfiguration('#' . $this->getId() . '#'), cmd::byValue($this->getId()));
if(is_array($cmds) && count($cmds) > 0){
foreach ($cmds as $cmd) {
$return['cmd'][$cmd->getId()] = $cmd;
}
}
$return['eqLogic'] = eqLogic::searchConfiguration('#' . $this->getId() . '#');
$return['object'] = jeeObject::searchConfiguration('#' . $this->getId() . '#');
$return['scenario'] = scenario::searchByUse(array(array('action' => '#' . $this->getId() . '#')));
Expand Down
9 changes: 4 additions & 5 deletions core/class/eqLogic.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1140,11 +1140,11 @@ public function batteryStatus($_pourcent = '', $_datetime = '') {
return;
}
$currentpourcent = null;
if ($_pourcent === '') {
$_pourcent = $this->getStatus('battery');
$_datetime = $this->getStatus('batteryDatetime');
if ($_pourcent === '' || !is_numeric($_pourcent)) {
$_pourcent = $this->getStatus('battery',100);
$_datetime = $this->getStatus('batteryDatetime',date('Y-m-d H:i:s'));
} else {
$currentpourcent = $this->getStatus('battery');
$currentpourcent = $this->getStatus('battery',100);
}
if ($_pourcent > 100) {
$_pourcent = 100;
Expand Down Expand Up @@ -1269,7 +1269,6 @@ public static function migrateEqlogic($_sourceId, $_targetId, $_mode = 'replace'
'parameters' => array(),
'height' => '',
'width' => '',
'height' => '',
'backGraph::format' => '',
'backGraph::type' => '',
'backGraph::color' => '',
Expand Down
17 changes: 13 additions & 4 deletions core/class/jeedom.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public static function health() {

$return[] = array(
'name' => __('Version OS', __FILE__),
'state' => (system::getDistrib() != 'debian' || version_compare(system::getOsVersion(), '10', '>=')),
'state' => (system::getDistrib() == 'debian' && version_compare(system::getOsVersion(), config::byKey('os::min'), '>=')),
'result' => system::getDistrib() . ' ' . system::getOsVersion(),
'comment' => '',
'key' => 'os::version'
Expand Down Expand Up @@ -1556,7 +1556,7 @@ public static function massReplace($_options = array(), $_eqlogics = array(), $_
if (count($_eqlogics) == 0 && count($_cmds) == 0) {
throw new Exception('{{Aucun équipement ou commande à remplacer ou copier}}');
}
foreach (['copyEqProperties', 'hideEqs', 'copyCmdProperties', 'removeCmdHistory', 'copyCmdHistory'] as $key) {
foreach (['copyEqProperties', 'hideEqs', 'copyCmdProperties', 'removeCmdHistory', 'copyCmdHistory','disableEqs'] as $key) {
if (!isset($_options[$key])) {
$_options[$key] = false;
}
Expand Down Expand Up @@ -1643,14 +1643,23 @@ public static function massReplace($_options = array(), $_eqlogics = array(), $_
$targetEq->save();
$return['eqlogics'] += 1;
}
} elseif ($_options['hideEqs'] == "true") {
}
if ($_options['hideEqs'] == "true") {
foreach ($_eqlogics as $_sourceId => $_targetId) {
$sourceEq = eqLogic::byId($_sourceId);
if (!is_object($sourceEq)) continue;
$sourceEq->setIsVisible(0);
$sourceEq->save();
}
}
if ($_options['disableEqs'] == "true") {
foreach ($_eqlogics as $_sourceId => $_targetId) {
$sourceEq = eqLogic::byId($_sourceId);
if (!is_object($sourceEq)) continue;
$sourceEq->setIsEnable(0);
$sourceEq->save();
}
}

//for each source cmd:
foreach ($_cmds as $_sourceId => $_targetId) {
Expand Down Expand Up @@ -1802,7 +1811,7 @@ public static function getHardwareName() {
$result = 'Atlas';
} else if (strpos($hostname, 'Luna') !== false) {
$result = 'Luna';
} else if (strpos(shell_exec('cat /proc/1/sched | head -n 1'),'systemd') === false){
} else if (file_exists('/proc/1/sched') && strpos(shell_exec('cat /proc/1/sched | head -n 1'),'systemd') === false){
$result = 'docker';
}
config::save('hardware_name', $result);
Expand Down
6 changes: 2 additions & 4 deletions core/class/listener.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,12 @@ public function emptyEvent() {
$this->event = array();
}

public function addEvent($_id, $_type = 'cmd') {
public function addEvent($_id) {
$event = $this->getEvent();
if (!is_array($event)) {
$event = array();
}
if ($_type == 'cmd') {
$id = str_replace('#', '', $_id);
}
$id = trim($_id, '#');
if (!in_array('#' . $id . '#', $event)) {
$event[] = '#' . $id . '#';
}
Expand Down
34 changes: 27 additions & 7 deletions core/class/log.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,42 @@
/* * ***************************Includes********************************* */
require_once __DIR__ . '/../../core/php/core.inc.php';

class log {
use Psr\Log\AbstractLogger;

class log extends AbstractLogger {
/* * *************************Constantes****************************** */

const DEFAULT_MAX_LINE = 200;

/* * *************************Attributs****************************** */


private $_log_name;

private static $config = null;
private static $level = array(
private static $level = array(
'debug' => 100,
'info' => 200,
'notice' => 250,
'warning' => 300,
'error' => 400,
'critical' => 500,
'alert' => 550,
'emergency' => 600
);

public function __construct($log_name) {
$this->_log_name = $log_name;
}

/* * ************Methods to suport Psr\Log\AbstractLogger & LoggerInterface ************ */
public static function getLogger($_logName) {
return new self($_logName);
}

public function log($level, $message, array $context = array()) {
log::add($this->_log_name, $level, $message);
}

/* * ***********************Methode static*************************** */

public static function getConfig($_key, $_default = '') {
Expand All @@ -51,10 +68,13 @@ public static function getConfig($_key, $_default = '') {
}

public static function getLogLevel($_log) {
if(strpos($_log,'_') !== false){
$_log = explode('_',$_log)[0];
}
$specific_level = self::getConfig('log::level::' . $_log);
if (!is_array($specific_level) && strpos($_log,'_') !== false) {
preg_match('/(.*?)\_[a-zA-Z]*?$/m', $_log, $matches);
if(isset($matches[1])){
$specific_level = self::getConfig('log::level::' . $matches[1]);
}
}
if (is_array($specific_level)) {
if (isset($specific_level['default']) && $specific_level['default'] == 1) {
return self::getConfig('log::level');
Expand Down Expand Up @@ -103,7 +123,7 @@ public static function add($_log, $_type, $_message, $_logicalId = '') {
$action = '<a href="/index.php?v=d&p=log&logfile=' . $_log . '">' . __('Log', __FILE__) . ' ' . $_log . '</a>';
if ($level == 400 && self::getConfig('addMessageForErrorLog') == 1) {
@message::add($_log, $_message, $action, $_logicalId);
} elseif ($level >= 500) {
} elseif ($level >= 500 && $_log != 'update') {
@message::add($_log, $_message, $action, $_logicalId);
}
} catch (Exception $e) {
Expand Down
9 changes: 9 additions & 0 deletions core/class/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,15 @@ public static function checkDeamon() {
}
}

public static function isInstalled($_pluginId): bool {
try {
plugin::byId($_pluginId);
return true;
} catch (Exception $e) {
return false;
}
}

/* * *********************Méthodes d'instance************************* */

public function report($_format = 'pdf', $_parameters = array()) {
Expand Down
15 changes: 9 additions & 6 deletions core/class/scenario.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class scenario {
private $_realTriggerValue = '';
/** @var bool */
private $_return = true;
private $_tags = array();
private $_tags = array('#trigger#' => '','#trigger_name#' => '','#trigger_id#' => '','#trigger_message#' => '','#trigger_value#' => '');
private $_do = true;
private $_changed = false;

Expand Down Expand Up @@ -1189,11 +1189,14 @@ public function calculateScheduleDate() {
$c = new Cron\CronExpression(checkAndFixCron($schedule), new Cron\FieldFactory);
$calculatedDate_tmp['prevDate'] = $c->getPreviousRunDate()->format('Y-m-d H:i:s');
$calculatedDate_tmp['nextDate'] = $c->getNextRunDate()->format('Y-m-d H:i:s');
if(count($schedule) == 6 && $schedule[5] != $c->getPreviousRunDate()->format('Y')){
$calculatedDate['prevDate'] = '';
}
if(count($schedule) == 6 && $schedule[5] != $c->getNextRunDate()->format('Y')){
$calculatedDate['nextDate'] = '';
$schedule_exp = explode(' ',trim($schedule));
if(is_array($schedule_exp) && count($schedule_exp) == 6 ){
if($schedule_exp[5] != $c->getPreviousRunDate()->format('Y')){
$calculatedDate['prevDate'] = '';
}
if($schedule_exp[5] != $c->getNextRunDate()->format('Y')){
$calculatedDate['nextDate'] = '';
}
}
} catch (Exception $exc) {
} catch (Error $exc) {
Expand Down
Loading

0 comments on commit 932bc0b

Please sign in to comment.