diff --git a/core/class/cmd.class.php b/core/class/cmd.class.php index 7c0ffb79b5..c667a6fc09 100644 --- a/core/class/cmd.class.php +++ b/core/class/cmd.class.php @@ -1042,10 +1042,10 @@ public function formatValue($_value, $_quote = false) { return intval($binary xor boolval($this->getConfiguration('invertBinary', false))); case 'numeric': if ($this->getConfiguration('historizeRound') !== '' && is_numeric($this->getConfiguration('historizeRound')) && $this->getConfiguration('historizeRound') >= 0) { - if (!is_numeric($_value)) { - log::add('cmd', 'error', __('La formule de calcul doit retourner une valeur numérique uniquement : ', __FILE__) . $this->getHumanName() . ' => ' . $_value); - $_value = (float) (str_replace(',', '.', $_value)); - } + if (!is_numeric($_value)) { + log::add('cmd', 'error', __('La formule de calcul doit retourner une valeur numérique uniquement : ', __FILE__) . $this->getHumanName() . ' => ' . $_value); + $_value = (float) (str_replace(',', '.', $_value)); + } $_value = round($_value, $this->getConfiguration('historizeRound')); } if ($_value > $this->getConfiguration('maxValue', $_value)) { @@ -3071,7 +3071,7 @@ public function getDisplay($_key = '', $_default = '') { } public function setDisplay($_key, $_value) { - if ($this->getDisplay($_key) !== $_value) { + if ($this->getDisplay($_key, null) !== $_value) { $this->_needRefreshWidget = true; $this->_changed = true; } diff --git a/core/class/scenarioExpression.class.php b/core/class/scenarioExpression.class.php index 952352df20..4208bbcd78 100644 --- a/core/class/scenarioExpression.class.php +++ b/core/class/scenarioExpression.class.php @@ -194,17 +194,17 @@ public static function getDatesFromPeriod($_period = '1 hour') { if ($_period == 'day') $_period = '1 day'; if (ctype_digit($_period[0]) && !stristr($_period, "ago")) { - $_startTime = date('Y-m-d H:i:s',(int) strtotime('-' . $_period)); + $_startTime = date('Y-m-d H:i:s', (int) strtotime('-' . $_period)); } else { - $_startTime = date('Y-m-d H:i:s',(int) strtotime($_period)); + $_startTime = date('Y-m-d H:i:s', (int) strtotime($_period)); } $_endTime = date('Y-m-d H:i:s'); if ($_period == 'today') { $_startTime = date('Y-m-d') . ' 00:00:00'; } elseif ($_period == 'yesterday') { - $_startTime = date('Y-m-d',(int) strtotime('-1 day')) . ' 00:00:00'; - $_endTime = date('Y-m-d',(int) strtotime('-1 day')) . ' 23:59:59'; + $_startTime = date('Y-m-d', (int) strtotime('-1 day')) . ' 00:00:00'; + $_endTime = date('Y-m-d', (int) strtotime('-1 day')) . ' 23:59:59'; } return array($_startTime, $_endTime); } @@ -303,8 +303,8 @@ public static function averageBetween($_cmd_id, $_startDate, $_endDate, $_round if (!is_object($cmd) || $cmd->getIsHistorized() == 0) { return ''; } - $_startTime = date('Y-m-d H:i:s',(int) strtotime(self::setTags($_startDate))); - $_endTime = date('Y-m-d H:i:s',(int) strtotime(self::setTags($_endDate))); + $_startTime = date('Y-m-d H:i:s', (int) strtotime(self::setTags($_startDate))); + $_endTime = date('Y-m-d H:i:s', (int) strtotime(self::setTags($_endDate))); $historyStatistique = $cmd->getStatistique($_startTime, $_endTime); if (!isset($historyStatistique['avg'])) { return ''; @@ -328,8 +328,8 @@ public static function averageTemporalBetween($_cmd_id, $_startDate, $_endDate, if (!is_object($cmd) || $cmd->getIsHistorized() == 0) { return ''; } - $_startTime = date('Y-m-d H:i:s',(int) strtotime(self::setTags($_startDate))); - $_endTime = date('Y-m-d H:i:s',(int) strtotime(self::setTags($_endDate))); + $_startTime = date('Y-m-d H:i:s', (int) strtotime(self::setTags($_startDate))); + $_endTime = date('Y-m-d H:i:s', (int) strtotime(self::setTags($_endDate))); return round($cmd->getTemporalAvg($_startTime, $_endTime), $_round); } @@ -458,8 +458,8 @@ public static function maxBetween($_cmd_id, $_startDate, $_endDate, $_round = 1) if (!is_object($cmd) || $cmd->getIsHistorized() == 0) { return ''; } - $_startTime = date('Y-m-d H:i:s',(int) strtotime(self::setTags($_startDate))); - $_endTime = date('Y-m-d H:i:s',(int) strtotime(self::setTags($_endDate))); + $_startTime = date('Y-m-d H:i:s', (int) strtotime(self::setTags($_startDate))); + $_endTime = date('Y-m-d H:i:s', (int) strtotime(self::setTags($_endDate))); $historyStatistique = $cmd->getStatistique($_startTime, $_endTime); if (!isset($historyStatistique['max'])) { return ''; @@ -489,8 +489,8 @@ public static function minBetween($_cmd_id, $_startDate, $_endDate, $_round = 1) if (!is_object($cmd) || $cmd->getIsHistorized() == 0) { return ''; } - $_startTime = date('Y-m-d H:i:s',(int) strtotime(self::setTags($_startDate))); - $_endTime = date('Y-m-d H:i:s',(int) strtotime(self::setTags($_endDate))); + $_startTime = date('Y-m-d H:i:s', (int) strtotime(self::setTags($_startDate))); + $_endTime = date('Y-m-d H:i:s', (int) strtotime(self::setTags($_endDate))); $historyStatistique = $cmd->getStatistique($_startTime, $_endTime); if (!isset($historyStatistique['min'])) { return ''; @@ -642,8 +642,8 @@ public static function stateChangesBetween($_cmd_id, $_value, $_startDate, $_end $_endDate = func_get_arg(2); $_value = null; } - $_startTime = date('Y-m-d H:i:s',(int) strtotime(self::setTags($_startDate))); - $_endTime = date('Y-m-d H:i:s',(int) strtotime(self::setTags($_endDate))); + $_startTime = date('Y-m-d H:i:s', (int) strtotime(self::setTags($_startDate))); + $_endTime = date('Y-m-d H:i:s', (int) strtotime(self::setTags($_endDate))); return history::stateChanges($cmd_id, $_value, $_startTime, $_endTime); } @@ -724,8 +724,8 @@ public static function durationBetween($_cmd_id, $_value, $_startDate, $_endDate $_endDate = date('Y-m-d H:i:s'); } - $_startTime = date('Y-m-d H:i:s',(int) strtotime(self::setTags($_startDate))); - $_endTime = date('Y-m-d H:i:s',(int) strtotime(self::setTags($_endDate))); + $_startTime = date('Y-m-d H:i:s', (int) strtotime(self::setTags($_startDate))); + $_endTime = date('Y-m-d H:i:s', (int) strtotime(self::setTags($_endDate))); $_value = str_replace(',', '.', $_value); $_decimal = strlen(substr(strrchr($_value, "."), 1)); @@ -769,8 +769,8 @@ public static function lastBetween($_cmd_id, $_startDate, $_endDate) { if (!is_object($cmd) || $cmd->getIsHistorized() == 0) { return ''; } - $_startTime = date('Y-m-d H:i:s',(int) strtotime(self::setTags($_startDate))); - $_endTime = date('Y-m-d H:i:s',(int) strtotime(self::setTags($_endDate))); + $_startTime = date('Y-m-d H:i:s', (int) strtotime(self::setTags($_startDate))); + $_endTime = date('Y-m-d H:i:s', (int) strtotime(self::setTags($_endDate))); $historyStatistique = $cmd->getStatistique($_startTime, $_endTime); if (!isset($historyStatistique['last']) || $historyStatistique['last'] === '') { return ''; @@ -802,8 +802,8 @@ public static function statisticsBetween($_cmd_id, $_calc, $_startDate, $_endDat return ''; } $_calc = str_replace(' ', '', $_calc); - $_startTime = date('Y-m-d H:i:s',(int) strtotime(self::setTags($_startDate))); - $_endTime = date('Y-m-d H:i:s',(int) strtotime(self::setTags($_endDate))); + $_startTime = date('Y-m-d H:i:s', (int) strtotime(self::setTags($_startDate))); + $_endTime = date('Y-m-d H:i:s', (int) strtotime(self::setTags($_endDate))); $historyStatistique = $cmd->getStatistique(self::setTags($_startTime), self::setTags($_endTime)); return $historyStatistique[$_calc]; } @@ -960,7 +960,7 @@ public static function trigger($_name = '', &$_scenario = null) { if (trim($_name) == '') { return $_scenario->getTag('trigger_name'); } - if (trim(jeedom::toHumanReadable($_name),'#') == $_scenario->getTag('trigger_name')) { + if (trim(jeedom::toHumanReadable($_name), '#') == $_scenario->getTag('trigger_name')) { return 1; } return 0; @@ -1038,8 +1038,8 @@ public static function time_diff($_date1, $_date2, $_format = 'd', $_rnd = 2) { if ($_date2 < 100) $_date2 = '00' . $_date2; if ($_date2 < 1000) $_date2 = '0' . $_date2; } - $d1 = str_replace(array('"','\'',"'"), '', self::setTags($_date1)); - $d2 = str_replace(array('"','\'',"'"), '', self::setTags($_date2)); + $d1 = str_replace(array('"', '\'', "'"), '', self::setTags($_date1)); + $d2 = str_replace(array('"', '\'', "'"), '', self::setTags($_date2)); $date1 = new DateTime($d1); $date2 = new DateTime($d2); $duree = $date2->getTimestamp() - $date1->getTimestamp(); @@ -1275,6 +1275,9 @@ public static function setTags(&$_expression, &$_scenario = null, $_quote = fals } if ($_quote) { foreach ($replace1 as &$value) { + if ($value === null) { + continue; + } if (strpos($value, ' ') !== false || preg_match("/[a-zA-Z]/", $value) || $value === '') { $value = '"' . trim($value, '"') . '"'; } @@ -1386,7 +1389,7 @@ public function execute(&$scenario = null) { } $this->checkBackground(); if ($this->getOptions('background', 0) == 1) { - $key = 'scenarioElement'.$this->getId().'::' . config::genKey(16).'::'.strtotime('now'); + $key = 'scenarioElement' . $this->getId() . '::' . config::genKey(16) . '::' . strtotime('now'); cache::set($key, array('scenarioExpression' => $this, 'scenario' => $scenario), 60); $cmd = __DIR__ . '/../php/jeeScenarioExpression.php'; $cmd .= ' key=' . $key; @@ -1571,14 +1574,14 @@ public function execute(&$scenario = null) { } $this->setLog($scenario, $GLOBALS['JEEDOM_SCLOG_TEXT']['launchScenario']['txt'] . $actionScenario->getName() . ' ' . __('options :', __FILE__) . ' ' . json_encode($actionScenario->getTags())); if ($scenario !== null) { - $actionScenario->addTag('trigger','scenario'); - $actionScenario->addTag('trigger_message',$GLOBALS['JEEDOM_SCLOG_TEXT']['startByScenario']['txt'] . $scenario->getHumanName()); - $actionScenario->addTag('trigger_name',trim($scenario->getHumanName(),'#')); - $actionScenario->addTag('trigger_id',$scenario->getId()); + $actionScenario->addTag('trigger', 'scenario'); + $actionScenario->addTag('trigger_message', $GLOBALS['JEEDOM_SCLOG_TEXT']['startByScenario']['txt'] . $scenario->getHumanName()); + $actionScenario->addTag('trigger_name', trim($scenario->getHumanName(), '#')); + $actionScenario->addTag('trigger_id', $scenario->getId()); return $actionScenario->launch(); } else { - $actionScenario->addTag('trigger','other'); - $actionScenario->addTag('trigger_message',$GLOBALS['JEEDOM_SCLOG_TEXT']['startCausedBy']['txt']); + $actionScenario->addTag('trigger', 'other'); + $actionScenario->addTag('trigger_message', $GLOBALS['JEEDOM_SCLOG_TEXT']['startCausedBy']['txt']); return $actionScenario->launch(); } break; @@ -1597,14 +1600,14 @@ public function execute(&$scenario = null) { } $this->setLog($scenario, $GLOBALS['JEEDOM_SCLOG_TEXT']['launchScenario']['txt'] . $actionScenario->getName() . ' ' . __('options :', __FILE__) . ' ' . json_encode($actionScenario->getTags())); if ($scenario !== null) { - $actionScenario->addTag('trigger','scenario'); - $actionScenario->addTag('trigger_message',$GLOBALS['JEEDOM_SCLOG_TEXT']['startByScenario']['txt'] . $scenario->getHumanName()); - $actionScenario->addTag('trigger_name',trim($scenario->getHumanName(),'#')); - $actionScenario->addTag('trigger_id',$scenario->getId()); + $actionScenario->addTag('trigger', 'scenario'); + $actionScenario->addTag('trigger_message', $GLOBALS['JEEDOM_SCLOG_TEXT']['startByScenario']['txt'] . $scenario->getHumanName()); + $actionScenario->addTag('trigger_name', trim($scenario->getHumanName(), '#')); + $actionScenario->addTag('trigger_id', $scenario->getId()); return $actionScenario->launch(true); } else { - $actionScenario->addTag('trigger','other'); - $actionScenario->addTag('trigger_message',$GLOBALS['JEEDOM_SCLOG_TEXT']['startCausedBy']['txt']); + $actionScenario->addTag('trigger', 'other'); + $actionScenario->addTag('trigger_message', $GLOBALS['JEEDOM_SCLOG_TEXT']['startCausedBy']['txt']); return $actionScenario->launch(true); } break; @@ -1791,8 +1794,8 @@ public function execute(&$scenario = null) { $tmp_file = jeedom::getTmpFolder('history_export') . '/' . $options['name'] . '.csv'; $cmd_parameters = array('files' => [$tmp_file], 'title' => $options['name'], 'message' => $options['name']); - $start = date('Y-m-d H:i:s',(int) strtotime($options['start'])); - $end = date('Y-m-d H:i:s',(int) strtotime($options['end'])); + $start = date('Y-m-d H:i:s', (int) strtotime($options['start'])); + $end = date('Y-m-d H:i:s', (int) strtotime($options['end'])); $this->setLog($scenario, __('Export de l\'historique du', __FILE__) . ' ' . $start . ' ' . __('au', __FILE__) . ' ' . $end); $histories = array(); diff --git a/core/class/user.class.php b/core/class/user.class.php index 8f834215c1..95567f5302 100644 --- a/core/class/user.class.php +++ b/core/class/user.class.php @@ -122,7 +122,7 @@ public static function connect(string $_login, string $_mdp) { ->setProfils($profile); $user->save(); log::add("connection", "info", __('User created from the LDAP :', __FILE__) . ' ' . $_login); - jeedom::event('user_connect'); + jeedom::event('user_connect', false, array('trigger_value' => $_login)); // TODO : if username == password => change ldap password log::add('event', 'info', __('User connection accepted', __FILE__) . ' ' . $_login); return $user; @@ -145,7 +145,7 @@ public static function connect(string $_login, string $_mdp) { if (is_object($user)) { $user->setOptions('lastConnection', date('Y-m-d H:i:s')); $user->save(); - jeedom::event('user_connect'); + jeedom::event('user_connect', false, array('trigger_value' => $_login)); log::add('event', 'info', __('Local account found for', __FILE__) . ' ' . $_login); log::add('event', 'info', __('User connection accepted', __FILE__) . ' ' . $_login); } diff --git a/core/config/version b/core/config/version index 958d30d86d..4404a17bae 100644 --- a/core/config/version +++ b/core/config/version @@ -1 +1 @@ -4.5 \ No newline at end of file +4.5.1 diff --git a/core/template/dashboard/cmd.action.color.picker.html b/core/template/dashboard/cmd.action.color.picker.html index 3c4bf73cca..62d1f17f5a 100644 --- a/core/template/dashboard/cmd.action.color.picker.html +++ b/core/template/dashboard/cmd.action.color.picker.html @@ -19,7 +19,13 @@ if ('#time#' == 'duration' || '#time#' == 'date') { jeedom.cmd.displayDuration(_options.valueDate, cmd.querySelector('.timeCmd'), '#time#') } - cmd.querySelector('.action_colorpicker_change').value = (_options.display_value != '') ? _options.display_value.substr(0, 7) : '#000000' + if (_options.display_value.length == 0) { + cmd.querySelector('.action_colorpicker_change').value = '#000000' + } else if (_options.display_value.startsWith('#')) { + cmd.querySelector('.action_colorpicker_change').value = _options.display_value.substr(0, 7) + } else { + cmd.querySelector('.action_colorpicker_change').value = '#' + _options.display_value.substr(0, 6) + } } }) diff --git a/docs/fr_FR/changelog.md b/docs/fr_FR/changelog.md index b627fe88e9..dd8fc45589 100644 --- a/docs/fr_FR/changelog.md +++ b/docs/fr_FR/changelog.md @@ -1,5 +1,12 @@ # Changelog Jeedom V4.5 +# 4.5.1 + +- Le déclencheur de scénarios `#user_connect#` inclut dorénavant le tag `#trigger_value#` qui renseigne le nom de l'utilisateur venant de se connecter ([Détails](https://github.com/jeedom/core/pull/3109)) +- Montée de version de nodejs 20 vers 22 ([Détails](https://github.com/jeedom/core/issues/3147)) +- La sauvegarde se fera maintenant a une heure aléatoire entre 00:10 et 9:59 +- Correction d'un warning sur les valeurs de tags null + # 4.5 - [Développeurs] Ajout de la fonction `$listener->removeEvent($_id)` @@ -10,7 +17,7 @@ - Les graphiques se mettent à jour automatiquement lors de l'arrivée de nouvelles valeurs [LIEN](https://github.com/jeedom/core/issues/2749) - Jeedom ajoute automatiquement la hauteur de l'image lors de la création des widgets pour éviter les soucis de chevauchement en mobile [LIEN](https://github.com/jeedom/core/issues/2539) - Refonte de la partie backup cloud [LIEN](https://github.com/jeedom/core/issues/2765) -- **DEV** Mise en place d'un système de queue pour l'exécution d'actions [LIEN](https://github.com/jeedom/core/issues/2489) +- [Développeurs] Mise en place d'un système de queue pour l'exécution d'actions [LIEN](https://github.com/jeedom/core/issues/2489) - Les tags des scénarios sont maintenant propres à l'instance du scénario (si vous avez deux lancements de scénarios très proches, les tags du dernier n'écrasent plus le premier) [LIEN](https://github.com/jeedom/core/issues/2763) - Changement sur la partie trigger des scénarios : [LIEN](https://github.com/jeedom/core/issues/2414) - ``triggerId()`` est maintenant deprecated et sera retiré dans les futures mises à jour du core. Si vous avez ``triggerId() == 587`` il faut le remplacer par ``#trigger_id# == 587`` @@ -95,4 +102,4 @@ >**IMPORTANT** > -> La restauration d'un backup 4.4 peut dans certains cas finir par des erreurs dans l'interface web. Rien de grave cela peut facilement se corriger il suffit de faire : `cd /tmp;wget https://github.com/jeedom/core/archive/refs/tags/4.4.20.zip;unzip 4.4.19.zip;cd core-4.4.20;cp -rf * /var/www/html/;rm -rf /tmp/master.zip;rm -rf /tmp/core-4.4.20;`. Vous pouvez lancer cette commande depuis l'interface rescue de jeedom (ajouter `&rescue=1` dans l'url), ou directement en ssh. +> La restauration d'un backup 4.4 peut dans certains cas finir par des erreurs dans l'interface web. Rien de grave cela peut facilement se corriger il suffit de faire : `cd /tmp;wget https://github.com/jeedom/core/archive/refs/tags/4.4.20.zip;unzip 4.4.20.zip;cd core-4.4.20;cp -rf * /var/www/html/;rm -rf /tmp/master.zip;rm -rf /tmp/core-4.4.20;`. Vous pouvez lancer cette commande depuis l'interface rescue de jeedom (ajouter `&rescue=1` dans l'url), ou directement en ssh. diff --git a/docs/fr_FR/scenario.md b/docs/fr_FR/scenario.md index e002eafb7c..779d802487 100644 --- a/docs/fr_FR/scenario.md +++ b/docs/fr_FR/scenario.md @@ -236,7 +236,7 @@ Il existe des déclencheurs spécifiques (autre que ceux fournis par les command - ``#end_update#`` : Événement envoyé à la fin d’une mise à jour. - ``#begin_restore#`` : Événement envoyé au début d’une restauration. - ``#end_restore#`` : Événement envoyé à la fin d’une restauration. -- ``#user_connect#`` : Connexion d'un utilisateur +- ``#user_connect#`` : Connexion d'un utilisateur, le tag `#trigger_value#` contient le nom de l'utilisateur. - ``#variable(nom_variable)#`` : Changement de valeur de la variable nom_variable. - ``#genericType(GENERIC, #[Object]#)#`` : Changement d'une commande info de Type Generic GENERIC, dans l'objet Object. - ``#new_eqLogic#`` : Événement envoyé lors de la création d'un nouvelle équipement, vous avez dans les tags id (id de l'équipement crée), name (nom de l'équipement crée) et eqType (type/plugin de l'équipement crée) @@ -439,7 +439,7 @@ Une boîte à outils de fonctions génériques peut également servir à effectu - ``randText(texte1;texte2;texte…​..)`` : Permet de retourner un des textes aléatoirement (séparer les texte par un ; ). Il n’y a pas de limite dans le nombre de texte. - ``randomColor(min,max)`` : Donne une couleur aléatoire comprise entre 2 bornes ( 0 => rouge, 50 => vert, 100 => bleu). - ``trigger(commande)`` : Permet de connaître le déclencheur du scénario ou de savoir si c’est bien la commande passée en paramètre qui a déclenché le scénario. **=> Deprecated il vaut mieux utiliser le tag #trigger#** -- ``triggerValue()`` : Permet de connaître la valeur du déclencheur du scénario. **=> Deprecated il vaut mieux utiliser le tag #triggerValue#** +- ``triggerValue()`` : Permet de connaître la valeur du déclencheur du scénario. **=> Deprecated il vaut mieux utiliser le tag #trigger_value#** - ``round(valeur,[decimal])`` : Donne un arrondi au-dessus, [decimal] nombre de décimales après la virgule. - ``odd(valeur)`` : Permet de savoir si un nombre est impair ou non. Renvoie 1 si impair 0 sinon. - ``median(commande1,commande2…​.commandeN)`` : Renvoie la médiane des valeurs. diff --git a/install/consistency.php b/install/consistency.php index 3d3907538a..f432e2964d 100644 --- a/install/consistency.php +++ b/install/consistency.php @@ -128,333 +128,332 @@ if (is_object($cron)) { $cron->remove(); } - if (method_exists('utils', 'attrChanged')) { - $cron = cron::byClassAndFunction('plugin', 'cronDaily'); - if (!is_object($cron)) { - echo "Create plugin::cronDaily\n"; - $cron = new cron(); - } - $cron->setClass('plugin'); - $cron->setFunction('cronDaily'); - $cron->setSchedule('00 00 * * *'); - $cron->setTimeout(240); - $cron->setEnable(1); - $cron->setDeamon(0); - $cron->save(); - - $cron = cron::byClassAndFunction('jeedom', 'backup'); - if (!is_object($cron)) { - echo "Create jeedom::backup\n"; - $cron = new cron(); - $cron->setClass('jeedom'); - $cron->setFunction('backup'); - $cron->setSchedule(rand(10, 59) . ' 0' . rand(0, 7) . ' * * *'); - $cron->setEnable(1); - $cron->setDeamon(0); - $cron->setTimeout(60); - $cron->save(); - } - - $cron = cron::byClassAndFunction('plugin', 'cronHourly'); - if (!is_object($cron)) { - echo "Create plugin::cronHourly\n"; - $cron = new cron(); - } - $cron->setClass('plugin'); - $cron->setFunction('cronHourly'); - $cron->setSchedule('00 * * * *'); - $cron->setEnable(1); - $cron->setDeamon(0); - $cron->setTimeout(60); - $cron->save(); - - $cron = cron::byClassAndFunction('scenario', 'check'); - if (!is_object($cron)) { - echo "Create scenario::check\n"; - $cron = new cron(); - } - $cron->setClass('scenario'); - $cron->setFunction('check'); - $cron->setSchedule('* * * * *'); - $cron->setEnable(1); - $cron->setDeamon(0); - $cron->setTimeout(30); - $cron->save(); - - $cron = cron::byClassAndFunction('scenario', 'control'); - if (!is_object($cron)) { - echo "Create scenario::control\n"; - $cron = new cron(); - } - $cron->setClass('scenario'); - $cron->setFunction('control'); - $cron->setSchedule('* * * * *'); - $cron->setEnable(1); - $cron->setDeamon(0); - $cron->setTimeout(30); - $cron->save(); - - $cron = cron::byClassAndFunction('jeedom', 'cronDaily'); - if (!is_object($cron)) { - echo "Create jeedom::cronDaily\n"; - $cron = new cron(); - } - $cron->setClass('jeedom'); - $cron->setFunction('cronDaily'); - $cron->setSchedule(rand(0, 59) . ' ' . rand(0, 3) . ' * * *'); - $cron->setEnable(1); - $cron->setDeamon(0); - $cron->setTimeout(240); - $cron->save(); - - $cron = cron::byClassAndFunction('jeedom', 'cronHourly'); - if (!is_object($cron)) { - echo "Create jeedom::cronHourly\n"; - $cron = new cron(); - } - $cron->setClass('jeedom'); - $cron->setFunction('cronHourly'); - $cron->setSchedule(rand(0, 59) . ' * * * *'); - $cron->setEnable(1); - $cron->setDeamon(0); - $cron->setTimeout(60); - $cron->save(); - - $cron = cron::byClassAndFunction('jeedom', 'cron5'); - if (!is_object($cron)) { - echo "Create jeedom::cron5\n"; - $cron = new cron(); - } - $cron->setClass('jeedom'); - $cron->setFunction('cron5'); - $cron->setSchedule('*/5 * * * *'); - $cron->setEnable(1); - $cron->setDeamon(0); - $cron->setTimeout(5); - $cron->save(); - - $cron = cron::byClassAndFunction('jeedom', 'cron10'); - if (!is_object($cron)) { - echo "Create jeedom::cron10\n"; - $cron = new cron(); - } - $cron->setClass('jeedom'); - $cron->setFunction('cron10'); - $cron->setSchedule('*/10 * * * *'); - $cron->setEnable(1); - $cron->setDeamon(0); - $cron->setTimeout(10); - $cron->save(); - - $cron = cron::byClassAndFunction('jeedom', 'cron'); - if (!is_object($cron)) { - echo "Create jeedom::cron\n"; - $cron = new cron(); - } - $cron->setClass('jeedom'); - $cron->setFunction('cron'); - $cron->setSchedule('* * * * *'); - $cron->setTimeout(2); - $cron->setDeamon(0); - $cron->save(); - - $cron = cron::byClassAndFunction('plugin', 'cron'); - if (!is_object($cron)) { - echo "Create plugin::cron\n"; - $cron = new cron(); - } - $cron->setClass('plugin'); - $cron->setFunction('cron'); - $cron->setSchedule('* * * * *'); - $cron->setTimeout(2); - $cron->setDeamon(0); - $cron->save(); - - $cron = cron::byClassAndFunction('queue', 'cron'); - if (!is_object($cron)) { - echo "Create queue::cron\n"; - $cron = new cron(); - } - $cron->setClass('queue'); - $cron->setFunction('cron'); - $cron->setSchedule('* * * * *'); - $cron->setTimeout(2); - $cron->setDeamon(0); - $cron->save(); - - $cron = cron::byClassAndFunction('plugin', 'cron5'); - if (!is_object($cron)) { - echo "Create plugin::cron5\n"; - $cron = new cron(); - } - $cron->setClass('plugin'); - $cron->setFunction('cron5'); - $cron->setSchedule('*/5 * * * *'); - $cron->setTimeout(5); - $cron->setDeamon(0); - $cron->save(); - - $cron = cron::byClassAndFunction('plugin', 'cron10'); - if (!is_object($cron)) { - echo "Create plugin::cron10\n"; - $cron = new cron(); - } - $cron->setClass('plugin'); + $cron = cron::byClassAndFunction('plugin', 'cronDaily'); + if (!is_object($cron)) { + echo "Create plugin::cronDaily\n"; + $cron = new cron(); + } + $cron->setClass('plugin'); + $cron->setFunction('cronDaily'); + $cron->setSchedule('00 00 * * *'); + $cron->setTimeout(240); + $cron->setEnable(1); + $cron->setDeamon(0); + $cron->save(); + + $cron = cron::byClassAndFunction('jeedom', 'backup'); + if (!is_object($cron)) { + echo "Create jeedom::backup\n"; + $cron = new cron(); + } + $cron->setClass('jeedom'); + $cron->setFunction('backup'); + $cron->setEnable(1); + $cron->setDeamon(0); + $cron->setTimeout(60); + $cron->setSchedule(rand(10, 59) . ' 0' . rand(0, 9) . ' * * *'); + $cron->save(); + + $cron = cron::byClassAndFunction('plugin', 'cronHourly'); + if (!is_object($cron)) { + echo "Create plugin::cronHourly\n"; + $cron = new cron(); + } + $cron->setClass('plugin'); + $cron->setFunction('cronHourly'); + $cron->setSchedule('00 * * * *'); + $cron->setEnable(1); + $cron->setDeamon(0); + $cron->setTimeout(60); + $cron->save(); + + $cron = cron::byClassAndFunction('scenario', 'check'); + if (!is_object($cron)) { + echo "Create scenario::check\n"; + $cron = new cron(); + } + $cron->setClass('scenario'); + $cron->setFunction('check'); + $cron->setSchedule('* * * * *'); + $cron->setEnable(1); + $cron->setDeamon(0); + $cron->setTimeout(30); + $cron->save(); + + $cron = cron::byClassAndFunction('scenario', 'control'); + if (!is_object($cron)) { + echo "Create scenario::control\n"; + $cron = new cron(); + } + $cron->setClass('scenario'); + $cron->setFunction('control'); + $cron->setSchedule('* * * * *'); + $cron->setEnable(1); + $cron->setDeamon(0); + $cron->setTimeout(30); + $cron->save(); + + $cron = cron::byClassAndFunction('jeedom', 'cronDaily'); + if (!is_object($cron)) { + echo "Create jeedom::cronDaily\n"; + $cron = new cron(); + } + $cron->setClass('jeedom'); + $cron->setFunction('cronDaily'); + $cron->setSchedule(rand(0, 59) . ' ' . rand(0, 3) . ' * * *'); + $cron->setEnable(1); + $cron->setDeamon(0); + $cron->setTimeout(240); + $cron->save(); + + $cron = cron::byClassAndFunction('jeedom', 'cronHourly'); + if (!is_object($cron)) { + echo "Create jeedom::cronHourly\n"; + $cron = new cron(); + } + $cron->setClass('jeedom'); + $cron->setFunction('cronHourly'); + $cron->setSchedule(rand(0, 59) . ' * * * *'); + $cron->setEnable(1); + $cron->setDeamon(0); + $cron->setTimeout(60); + $cron->save(); + + $cron = cron::byClassAndFunction('jeedom', 'cron5'); + if (!is_object($cron)) { + echo "Create jeedom::cron5\n"; + $cron = new cron(); + } + $cron->setClass('jeedom'); + $cron->setFunction('cron5'); + $cron->setSchedule('*/5 * * * *'); + $cron->setEnable(1); + $cron->setDeamon(0); + $cron->setTimeout(5); + $cron->save(); + + $cron = cron::byClassAndFunction('jeedom', 'cron10'); + if (!is_object($cron)) { + echo "Create jeedom::cron10\n"; + $cron = new cron(); + } + $cron->setClass('jeedom'); + $cron->setFunction('cron10'); + $cron->setSchedule('*/10 * * * *'); + $cron->setEnable(1); + $cron->setDeamon(0); + $cron->setTimeout(10); + $cron->save(); + + $cron = cron::byClassAndFunction('jeedom', 'cron'); + if (!is_object($cron)) { + echo "Create jeedom::cron\n"; + $cron = new cron(); + } + $cron->setClass('jeedom'); + $cron->setFunction('cron'); + $cron->setSchedule('* * * * *'); + $cron->setTimeout(2); + $cron->setDeamon(0); + $cron->save(); + + $cron = cron::byClassAndFunction('plugin', 'cron'); + if (!is_object($cron)) { + echo "Create plugin::cron\n"; + $cron = new cron(); + } + $cron->setClass('plugin'); + $cron->setFunction('cron'); + $cron->setSchedule('* * * * *'); + $cron->setTimeout(2); + $cron->setDeamon(0); + $cron->save(); + + $cron = cron::byClassAndFunction('queue', 'cron'); + if (!is_object($cron)) { + echo "Create queue::cron\n"; + $cron = new cron(); + } + $cron->setClass('queue'); + $cron->setFunction('cron'); + $cron->setSchedule('* * * * *'); + $cron->setTimeout(2); + $cron->setDeamon(0); + $cron->save(); + + $cron = cron::byClassAndFunction('plugin', 'cron5'); + if (!is_object($cron)) { + echo "Create plugin::cron5\n"; + $cron = new cron(); + } + $cron->setClass('plugin'); + $cron->setFunction('cron5'); + $cron->setSchedule('*/5 * * * *'); + $cron->setTimeout(5); + $cron->setDeamon(0); + $cron->save(); + + $cron = cron::byClassAndFunction('plugin', 'cron10'); + if (!is_object($cron)) { + echo "Create plugin::cron10\n"; + $cron = new cron(); + } + $cron->setClass('plugin'); + $cron->setFunction('cron10'); + $cron->setSchedule('*/10 * * * *'); + $cron->setTimeout(10); + $cron->setDeamon(0); + $cron->save(); + + $cron = cron::byClassAndFunction('plugin', 'cron15'); + if (!is_object($cron)) { + echo "Create plugin::cron15\n"; + $cron = new cron(); + } + $cron->setClass('plugin'); + $cron->setFunction('cron15'); + $cron->setSchedule('*/15 * * * *'); + $cron->setTimeout(15); + $cron->setDeamon(0); + $cron->save(); + + $cron = cron::byClassAndFunction('plugin', 'cron30'); + if (!is_object($cron)) { + echo "Create plugin::cron30\n"; + $cron = new cron(); + } + $cron->setClass('plugin'); + $cron->setFunction('cron30'); + $cron->setSchedule('*/30 * * * *'); + $cron->setTimeout(30); + $cron->setDeamon(0); + $cron->save(); + + $cron = cron::byClassAndFunction('plugin', 'checkDeamon'); + if (!is_object($cron)) { + echo "Create plugin::checkDeamon\n"; + $cron = new cron(); + } + $cron->setClass('plugin'); + $cron->setFunction('checkDeamon'); + $cron->setSchedule('*/5 * * * *'); + $cron->setTimeout(5); + $cron->setDeamon(0); + $cron->save(); + + $cron = cron::byClassAndFunction('cache', 'persist'); + if (!is_object($cron)) { + echo "Create cache::persist\n"; + $cron = new cron(); + } + $cron->setClass('cache'); + $cron->setFunction('persist'); + $cron->setSchedule('*/30 * * * *'); + $cron->setTimeout(30); + $cron->setDeamon(0); + $cron->save(); + + $cron = cron::byClassAndFunction('history', 'archive'); + if (!is_object($cron)) { + echo "Create history::archive\n"; + $cron = new cron(); + } + $cron->setClass('history'); + $cron->setFunction('archive'); + $cron->setSchedule('00 5 * * *'); + $cron->setTimeout(240); + $cron->setDeamon(0); + $cron->save(); + + $cron = cron::byClassAndFunction('plugin', 'heartbeat'); + if (!is_object($cron)) { + echo "Create plugin::heartbeat\n"; + $cron = new cron(); + } + $cron->setClass('plugin'); + $cron->setFunction('heartbeat'); + $cron->setSchedule('*/5 * * * *'); + $cron->setEnable(1); + $cron->setDeamon(0); + $cron->setTimeout(10); + $cron->save(); + + $cron = cron::byClassAndFunction('network', 'cron10'); + if (!is_object($cron)) { + echo "Create network::cron10\n"; + $cron = new cron(); + $cron->setClass('network'); $cron->setFunction('cron10'); - $cron->setSchedule('*/10 * * * *'); - $cron->setTimeout(10); - $cron->setDeamon(0); - $cron->save(); - - $cron = cron::byClassAndFunction('plugin', 'cron15'); - if (!is_object($cron)) { - echo "Create plugin::cron15\n"; - $cron = new cron(); - } - $cron->setClass('plugin'); - $cron->setFunction('cron15'); - $cron->setSchedule('*/15 * * * *'); - $cron->setTimeout(15); - $cron->setDeamon(0); - $cron->save(); - - $cron = cron::byClassAndFunction('plugin', 'cron30'); - if (!is_object($cron)) { - echo "Create plugin::cron30\n"; - $cron = new cron(); - } - $cron->setClass('plugin'); - $cron->setFunction('cron30'); - $cron->setSchedule('*/30 * * * *'); - $cron->setTimeout(30); - $cron->setDeamon(0); - $cron->save(); - - $cron = cron::byClassAndFunction('plugin', 'checkDeamon'); - if (!is_object($cron)) { - echo "Create plugin::checkDeamon\n"; - $cron = new cron(); - } - $cron->setClass('plugin'); - $cron->setFunction('checkDeamon'); - $cron->setSchedule('*/5 * * * *'); - $cron->setTimeout(5); - $cron->setDeamon(0); - $cron->save(); - - $cron = cron::byClassAndFunction('cache', 'persist'); - if (!is_object($cron)) { - echo "Create cache::persist\n"; - $cron = new cron(); - } - $cron->setClass('cache'); - $cron->setFunction('persist'); - $cron->setSchedule('*/30 * * * *'); - $cron->setTimeout(30); - $cron->setDeamon(0); - $cron->save(); - - $cron = cron::byClassAndFunction('history', 'archive'); - if (!is_object($cron)) { - echo "Create history::archive\n"; - $cron = new cron(); + $rand_min = rand(0,9); + $cronString = ''; + for($i=0;$i<6;$i++){ + $cronString .= ($rand_min+($i*10)).','; } - $cron->setClass('history'); - $cron->setFunction('archive'); - $cron->setSchedule('00 5 * * *'); - $cron->setTimeout(240); - $cron->setDeamon(0); - $cron->save(); - - $cron = cron::byClassAndFunction('plugin', 'heartbeat'); - if (!is_object($cron)) { - echo "Create plugin::heartbeat\n"; - $cron = new cron(); - } - $cron->setClass('plugin'); - $cron->setFunction('heartbeat'); - $cron->setSchedule('*/5 * * * *'); + $cronString = trim($cronString,',').' * * * *'; + $cron->setSchedule($cronString); $cron->setEnable(1); $cron->setDeamon(0); - $cron->setTimeout(10); + $cron->setTimeout(60); $cron->save(); + } - $cron = cron::byClassAndFunction('network', 'cron10'); - if (!is_object($cron)) { - echo "Create network::cron10\n"; - $cron = new cron(); - $cron->setClass('network'); - $cron->setFunction('cron10'); - $rand_min = rand(0,9); - $cronString = ''; - for($i=0;$i<6;$i++){ - $cronString .= ($rand_min+($i*10)).','; - } - $cronString = trim($cronString,',').' * * * *'; - $cron->setSchedule($cronString); - $cron->setEnable(1); - $cron->setDeamon(0); - $cron->setTimeout(60); - $cron->save(); - } + if (!file_exists(__DIR__ . '/../plugins')) { + mkdir(__DIR__ . '/../plugins'); + } + try { + echo "\nCheck filesystem right..."; + jeedom::cleanFileSystemRight(); + echo "OK\n"; + } catch (Exception $e) { + echo "NOK\n"; + } - if (!file_exists(__DIR__ . '/../plugins')) { - mkdir(__DIR__ . '/../plugins'); - } + config::save('hardware_name', ''); + if (config::byKey('api') == '') { + echo "Fix default apikey...\n"; + config::save('api', config::genKey()); + } + if (file_exists(__DIR__ . '/../core/nodeJS')) { + echo "Remove unused nodejs folder...\n"; + shell_exec(system::getCmdSudo() . 'rm -rf ' . __DIR__ . '/../core/nodeJS'); + } + if (file_exists(__DIR__ . '/../script/ngrok')) { + echo "Remove unused ngrok folder...\n"; + shell_exec(system::getCmdSudo() . 'rm -rf ' . __DIR__ . '/../script/ngrok'); + } + + echo "Check jeedom object..."; + foreach (jeeObject::all() as $object) { try { - echo "\nCheck filesystem right..."; - jeedom::cleanFileSystemRight(); - echo "OK\n"; - } catch (Exception $e) { - echo "NOK\n"; + $object->save(); + } catch (Exception $exc) { } + } + echo "OK\n"; - config::save('hardware_name', ''); - if (config::byKey('api') == '') { - echo "Fix default apikey...\n"; - config::save('api', config::genKey()); - } - if (file_exists(__DIR__ . '/../core/nodeJS')) { - echo "Remove unused nodejs folder...\n"; - shell_exec(system::getCmdSudo() . 'rm -rf ' . __DIR__ . '/../core/nodeJS'); - } - if (file_exists(__DIR__ . '/../script/ngrok')) { - echo "Remove unused ngrok folder...\n"; - shell_exec(system::getCmdSudo() . 'rm -rf ' . __DIR__ . '/../script/ngrok'); - } - - echo "Check jeedom object..."; - foreach (jeeObject::all() as $object) { - try { - $object->save(); - } catch (Exception $exc) { + echo "Check jeedom cmd..."; + foreach (cmd::all() as $cmd) { + try { + $changed = false; + if ($cmd->getConfiguration('jeedomCheckCmdCmdActionId') != '') { + $cmd->setConfiguration('jeedomCheckCmdCmdActionId', ''); + $changed = true; } - } - echo "OK\n"; - - echo "Check jeedom cmd..."; - foreach (cmd::all() as $cmd) { - try { - $changed = false; - if ($cmd->getConfiguration('jeedomCheckCmdCmdActionId') != '') { - $cmd->setConfiguration('jeedomCheckCmdCmdActionId', ''); - $changed = true; - } - if (trim($cmd->getTemplate('dashboard')) != '' && strpos($cmd->getTemplate('dashboard'), '::') === false) { - $cmd->setTemplate('dashboard', 'core::' . $cmd->getTemplate('dashboard')); - $changed = true; - } - if (trim($cmd->getTemplate('mobile')) != '' && strpos($cmd->getTemplate('mobile'), '::') === false) { - $cmd->setTemplate('mobile', 'core::' . $cmd->getTemplate('mobile')); - $changed = true; - } - if ($changed) { - $cmd->save(true); - } - } catch (Exception $exc) { + if (trim($cmd->getTemplate('dashboard')) != '' && strpos($cmd->getTemplate('dashboard'), '::') === false) { + $cmd->setTemplate('dashboard', 'core::' . $cmd->getTemplate('dashboard')); + $changed = true; + } + if (trim($cmd->getTemplate('mobile')) != '' && strpos($cmd->getTemplate('mobile'), '::') === false) { + $cmd->setTemplate('mobile', 'core::' . $cmd->getTemplate('mobile')); + $changed = true; + } + if ($changed) { + $cmd->save(true); } + } catch (Exception $exc) { } } + echo "OK\n"; if (!file_exists(__DIR__ . '/../data/php/user.function.class.php')) { diff --git a/resources/install_nodejs.sh b/resources/install_nodejs.sh index 695498469e..c83ccc1d9f 100644 --- a/resources/install_nodejs.sh +++ b/resources/install_nodejs.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash -installVer='20' #NodeJS major version to be installed -minVer='20' #min NodeJS major version to be accepted +installVer='22' #NodeJS major version to be installed +minVer='22' #min NodeJS major version to be accepted # vérifier si toujours nécessaire, cette source traine encore sur certaines smart et si une source est invalide -> nodejs ne s'installera pas if ls /etc/apt/sources.list.d/deb-multimedia.list* &>/dev/null; then @@ -53,8 +53,8 @@ lsb_release -c | grep jessie if [ $? -eq 0 ] then today=$(date +%Y%m%d) - if [[ "$today" > "20200630" ]]; - then + if [[ "$today" > "20200630" ]]; + then echo "== ATTENTION Debian 8 Jessie n'est officiellement plus supportée depuis le 30 juin 2020, merci de mettre à jour votre distribution !!!" exit 1 fi @@ -65,8 +65,8 @@ lsb_release -c | grep stretch if [ $? -eq 0 ] then today=$(date +%Y%m%d) - if [[ "$today" > "20220630" ]]; - then + if [[ "$today" > "20220630" ]]; + then echo "== ATTENTION Debian 9 Stretch n'est officiellement plus supportée depuis le 30 juin 2022, merci de mettre à jour votre distribution !!!" exit 1 fi @@ -77,8 +77,8 @@ lsb_release -c | grep buster if [ $? -eq 0 ] then today=$(date +%Y%m%d) - if [[ "$today" > "20220630" ]]; - then + if [[ "$today" > "20220630" ]]; + then echo "== ATTENTION Debian 10 Buster n'est officiellement plus supportée depuis le 30 juin 2024, merci de mettre à jour votre distribution !!!" exit 1 fi @@ -87,9 +87,9 @@ fi #x86 32 bits not supported by nodesource anymore bits=$(getconf LONG_BIT) if { [ "$arch" = "i386" ] || [ "$arch" = "i686" ]; } && [ "$bits" -eq "32" ] -then +then echo "== ATTENTION Votre système est x86 en 32bits et NodeJS 12 n'y est pas supporté, merci de passer en 64bits !!!" -exit 1 +exit 1 fi @@ -104,7 +104,7 @@ then else echo "[ KO ]"; echo "Installation de NodeJS $installVer" - + #if npm exists type npm &>/dev/null if [ $? -eq 0 ]; then @@ -112,10 +112,10 @@ else else npmPrefix="/usr" fi - + sudo DEBIAN_FRONTEND=noninteractive apt-get -y --purge autoremove npm &>/dev/null sudo DEBIAN_FRONTEND=noninteractive apt-get -y --purge autoremove nodejs &>/dev/null - + if [[ $arch == "armv6l" ]] then #version to install for armv6 (to check on https://unofficial-builds.nodejs.org) @@ -152,13 +152,13 @@ else sudo apt-get update sudo DEBIAN_FRONTEND=noninteractive apt-get install -y nodejs fi - + npm config set prefix ${npmPrefix} &>/dev/null - if [ $(which node | wc -l) -ne 0 ] && [ $(which nodejs | wc -l) -eq 0 ]; then + if [ $(which node | wc -l) -ne 0 ] && [ $(which nodejs | wc -l) -eq 0 ]; then ln -s $(which node) $(which node)js fi - + new=`nodejs -v`; echo -n "[Check Version NodeJS après install : ${new} : " testVerAfter=$(php -r "echo version_compare('${new}','v${minVer}','>=');") @@ -173,7 +173,7 @@ fi type npm &>/dev/null if [ $? -ne 0 ]; then # Installation de npm car non présent (par sécu) - sudo DEBIAN_FRONTEND=noninteractive apt-get install -y npm + sudo DEBIAN_FRONTEND=noninteractive apt-get install -y npm sudo npm install -g npm fi @@ -183,7 +183,7 @@ if [ $? -eq 0 ]; then npmPrefixSudo=`sudo npm prefix -g` npmPrefixwwwData=`sudo -u www-data npm prefix -g` echo -n "[Check Prefix : $npmPrefix and sudo prefix : $npmPrefixSudo and www-data prefix : $npmPrefixwwwData : " - if [[ "$npmPrefixSudo" != "/usr" ]] && [[ "$npmPrefixSudo" != "/usr/local" ]]; then + if [[ "$npmPrefixSudo" != "/usr" ]] && [[ "$npmPrefixSudo" != "/usr/local" ]]; then echo "[ KO ]" if [[ "$npmPrefixwwwData" == "/usr" ]] || [[ "$npmPrefixwwwData" == "/usr/local" ]]; then echo "Reset prefix ($npmPrefixwwwData) pour npm `sudo whoami`" @@ -202,7 +202,7 @@ if [ $? -eq 0 ]; then sudo npm config set prefix /usr/local fi fi - fi + fi else if [[ "$npmPrefixwwwData" == "/usr" ]] || [[ "$npmPrefixwwwData" == "/usr/local" ]]; then if [[ "$npmPrefixwwwData" == "$npmPrefixSudo" ]]; then