From ddc28e8a9a8d1c162416e61f1dfa25301d6dfd9e Mon Sep 17 00:00:00 2001 From: Luc SANCHEZ <4697568+ColonelMoutarde@users.noreply.github.com> Date: Thu, 3 Jul 2025 08:45:34 +0200 Subject: [PATCH 1/7] Update jeedom.class.php --- core/class/jeedom.class.php | 314 ++++++++++++++++-------------------- 1 file changed, 138 insertions(+), 176 deletions(-) diff --git a/core/class/jeedom.class.php b/core/class/jeedom.class.php index d090860d81..a567246a39 100644 --- a/core/class/jeedom.class.php +++ b/core/class/jeedom.class.php @@ -23,7 +23,6 @@ class jeedom { /* * *************************Attributs****************************** */ private static $jeedomConfiguration; - private static $jeedom_encryption = null; private static $cache = array(); /* * ***********************Methode static*************************** */ @@ -93,7 +92,7 @@ public static function getThemeConfig() { $return = config::byKeys($key); $return['current_desktop_theme'] = $return['jeedom_theme_main']; $return['current_mobile_theme'] = $return['mobile_theme_color']; - if ($return['theme_changeAccordingTime'] == 1 && (date('Gi') < intval(str_replace(':', '', $return['theme_start_day_hour'])) || date('Gi') > intval(str_replace(':', '', $return['theme_end_day_hour'])))) { + if ($return['theme_changeAccordingTime'] == 1 && (date('Gi') < (int)str_replace(':', '', $return['theme_start_day_hour']) || date('Gi') > intval(str_replace(':', '', $return['theme_end_day_hour'])))) { $return['current_desktop_theme'] = $return['jeedom_theme_alternate']; $return['current_mobile_theme'] = $return['mobile_theme_color_night']; } @@ -138,7 +137,7 @@ public static function getThemeConfig() { return $return; } - public static function addRemoveHistory($_data) { + public static function addRemoveHistory($_data): void { try { $remove_history = array(); if (file_exists(__DIR__ . '/../../data/remove_history.json')) { @@ -151,15 +150,13 @@ public static function addRemoveHistory($_data) { } } - public static function deadCmd() { + public static function deadCmd(): array { global $JEEDOM_INTERNAL_CONFIG; $return = array(); $cmd = config::byKey('interact::warnme::defaultreturncmd', 'core', ''); - if ($cmd != '') { - if (!cmd::byId(str_replace('#', '', $cmd))) { - $return[] = array('detail' => __('Administration', __FILE__), 'help' => __('Commande retour interactions', __FILE__), 'who' => $cmd); - } - } + if (($cmd != '') && !cmd::byId(str_replace('#', '', $cmd))) { + $return[] = array('detail' => __('Administration', __FILE__), 'help' => __('Commande retour interactions', __FILE__), 'who' => $cmd); + } foreach ($JEEDOM_INTERNAL_CONFIG['alerts'] as $level => $value) { $cmds = config::byKey('alert::' . $level . 'Cmd', 'core', ''); preg_match_all("/#([0-9]*)#/", $cmds, $matches); @@ -172,12 +169,12 @@ public static function deadCmd() { return $return; } - public static function health() { + public static function health(): array { $return = array(); $return[] = array( 'name' => __('Matériel', __FILE__), 'state' => true, - 'result' => jeedom::getHardwareName(), + 'result' => self::getHardwareName(), 'comment' => '', 'key' => 'hardware' ); @@ -499,7 +496,7 @@ public static function health() { } $return[] = $cache_health; - if (jeedom::getHardwareName() != 'docker') { + if (self::getHardwareName() != 'docker') { $state = shell_exec('systemctl show apache2 | grep PrivateTmp | grep yes | wc -l'); $return[] = array( 'name' => __('Apache private tmp', __FILE__), @@ -575,7 +572,7 @@ public static function getApiKey($_plugin = 'core', $_mode = 'enable') { } public static function apiModeResult($_mode = 'enable') { - if ($_mode == 'localhost' && jeedom::getHardwareName() == 'docker') { + if ($_mode == 'localhost' && self::getHardwareName() == 'docker') { $_mode = 'whiteip'; } switch ($_mode) { @@ -626,7 +623,7 @@ public static function apiAccess($_apikey = '', $_plugin = 'core') { return false; } $apikey = self::getApiKey($_plugin); - if (trim($apikey) != '' && $apikey === $_apikey) { + if (trim($apikey) !== '' && $apikey === $_apikey) { /** @var bool $_RESTRICTED */ global $_RESTRICTED; $_RESTRICTED = config::byKey('api::' . $_plugin . '::restricted', 'core', false); @@ -822,7 +819,7 @@ public static function consistency() { /********************************************BACKUP*****************************************************************/ - public static function backup($_background = false) { + public static function backup($_background = false): void { if ($_background) { log::clear('backup'); $cmd = __DIR__ . '/../../install/backup.php'; @@ -833,7 +830,7 @@ public static function backup($_background = false) { } } - public static function listBackup() { + public static function listBackup(): array { if (substr(config::byKey('backup::path'), 0, 1) != '/') { $backup_dir = __DIR__ . '/../../' . config::byKey('backup::path'); } else { @@ -847,7 +844,7 @@ public static function listBackup() { return $return; } - public static function removeBackup($_backup) { + public static function removeBackup($_backup): void { if (file_exists($_backup)) { unlink($_backup); } else { @@ -855,7 +852,7 @@ public static function removeBackup($_backup) { } } - public static function restore($_backup = '', $_background = false) { + public static function restore($_backup = '', $_background = false): void { if ($_background) { log::clear('restore'); $cmd = __DIR__ . '/../../install/restore.php "backup=' . $_backup . '"'; @@ -870,7 +867,7 @@ public static function restore($_backup = '', $_background = false) { /****************************UPDATE*****************************************************************/ - public static function update($_options = array()) { + public static function update($_options = array()): void { log::clear('update'); $params = ''; if (is_array($_options) && count($_options) > 0) { @@ -924,13 +921,13 @@ private static function checkValueInconfiguration($_key, $_value) { } self::$jeedomConfiguration[$_key] = $_value; return $_value; - } else { - $config = config::byKey($_key); - return ($config == '') ? $_value : $config; } - } - public static function version() { + $config = config::byKey($_key); + return ($config == '') ? $_value : $config; + } + + public static function version(): string { if (file_exists(__DIR__ . '/../config/version')) { return trim(file_get_contents(__DIR__ . '/../config/version')); } @@ -939,7 +936,7 @@ public static function version() { /**********************START AND DATE MANAGEMENT*************************************************************/ - public static function stop() { + public static function stop(): void { echo "Disable all task"; config::save('enableCron', 0); foreach ((cron::all()) as $cron) { @@ -947,14 +944,11 @@ public static function stop() { try { $cron->halt(); echo '.'; - } catch (Exception $e) { - sleep(5); - $cron->halt(); - } catch (Error $e) { + } catch (Exception|Error $e) { sleep(5); $cron->halt(); } - } + } } echo " OK\n"; @@ -975,18 +969,15 @@ public static function stop() { try { $scenario->stop(); echo '.'; - } catch (Exception $e) { - sleep(5); - $scenario->stop(); - } catch (Error $e) { + } catch (Exception|Error $e) { sleep(5); $scenario->stop(); } - } + } echo " OK\n"; } - public static function start() { + public static function start(): void { try { /* * *********Réactivation des scénarios**************** */ echo "Enable scenario : "; @@ -1000,22 +991,16 @@ public static function start() { echo "Check Network Conf : "; network::checkConf('internal'); echo "OK\n"; - } catch (Exception $e) { + } catch (Exception|Error $e) { if (!isset($_GET['mode']) || $_GET['mode'] != 'force') { throw $e; - } else { - echo '***ERROR*** ' . log::exception($e); } - } catch (Error $e) { - if (!isset($_GET['mode']) || $_GET['mode'] != 'force') { - throw $e; - } else { - echo '***ERROR*** ' . log::exception($e); - } - } - } - public static function isStarted() { + echo '***ERROR*** ' . log::exception($e); + } + } + + public static function isStarted(): bool { return file_exists(self::getTmpFolder() . '/started'); } @@ -1023,7 +1008,7 @@ public static function isStarted() { * * @return boolean */ - public static function isDateOk() { + public static function isDateOk(): bool { if (config::byKey('ignoreHourCheck') == 1) { return true; } @@ -1040,10 +1025,10 @@ public static function isDateOk() { $mindate = strtotime($minDateValue->format('Y-m-d 00:00:00')); $maxDateValue = $minDateValue->modify('+6 year')->format('Y-m-d 00:00:00'); $maxdate = strtotime($maxDateValue); - if (strtotime('now') < $mindate || strtotime('now') > $maxdate) { + if (time() < $mindate || time() > $maxdate) { self::forceSyncHour(); sleep(3); - if (strtotime('now') < $mindate || strtotime('now') > $maxdate) { + if (time() < $mindate || time() > $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'); return false; } @@ -1051,7 +1036,7 @@ public static function isDateOk() { return true; } - public static function event($_event, $_forceSyncMode = false, $_options = null) { + public static function event($_event, $_forceSyncMode = false, $_options = null): void { scenario::check($_event, $_forceSyncMode, null, null, null, $_options); } @@ -1065,17 +1050,14 @@ public static function cron5() { $class::cron5(); } } - } catch (Exception $e) { - log::add('jeedom', 'error', log::exception($e)); - } catch (Error $e) { + } catch (Exception|Error $e) { log::add('jeedom', 'error', log::exception($e)); } - try { + try { eqLogic::checkAlive(); - } catch (Exception $e) { - } catch (Error $e) { + } catch (Exception|Error $e) { } - } + } public static function cron10() { try { @@ -1085,14 +1067,12 @@ public static function cron10() { $class::cron10(); } } - } catch (Exception $e) { - log::add('jeedom', 'error', log::exception($e)); - } catch (Error $e) { + } catch (Exception|Error $e) { log::add('jeedom', 'error', log::exception($e)); } - } + } - public static function cron() { + public static function cron(): void { if (!self::isStarted()) { echo date('Y-m-d H:i:s') . ' starting Jeedom'; log::add('starting', 'debug', __('Démarrage de jeedom', __FILE__)); @@ -1102,78 +1082,62 @@ public static function cron() { if ($cron->running() && $cron->getClass() != 'jeedom' && $cron->getFunction() != 'cron') { try { $cron->halt(); - } catch (Exception $e) { - log::add('starting', 'error', __('Erreur sur l\'arrêt d\'une tâche cron :', __FILE__) . ' ' . log::exception($e)); - } catch (Error $e) { + } catch (Exception|Error $e) { log::add('starting', 'error', __('Erreur sur l\'arrêt d\'une tâche cron :', __FILE__) . ' ' . log::exception($e)); } - } + } } - } catch (Exception $e) { - log::add('starting', 'error', __('Erreur sur l\'arrêt des tâches crons :', __FILE__) . ' ' . log::exception($e)); - } catch (Error $e) { + } catch (Exception|Error $e) { log::add('starting', 'error', __('Erreur sur l\'arrêt des tâches crons :', __FILE__) . ' ' . log::exception($e)); } - try { + try { log::add('starting', 'debug', __('Restauration du cache', __FILE__)); cache::restore(); - } catch (Exception $e) { - log::add('starting', 'error', __('Erreur sur la restauration du cache :', __FILE__) . ' ' . log::exception($e)); - } catch (Error $e) { + } catch (Exception|Error $e) { log::add('starting', 'error', __('Erreur sur la restauration du cache :', __FILE__) . ' ' . log::exception($e)); } - try { + try { log::add('starting', 'debug', __('Consolidation de l\'historique', __FILE__)); history::checkCurrentValueAndHistory(); - } catch (Exception $e) { - log::add('starting', 'error', __('Erreur sur la consolidation de l\'historique :', __FILE__) . ' ' . log::exception($e)); - } catch (Error $e) { + } catch (Exception|Error $e) { log::add('starting', 'error', __('Erreur sur la consolidation de l\'historique :', __FILE__) . ' ' . log::exception($e)); } - try { + try { log::add('starting', 'debug', __('Nettoyage du cache des péripheriques USB', __FILE__)); $cache = cache::byKey('jeedom::usbMapping'); $cache->remove(); - } catch (Exception $e) { - log::add('starting', 'error', __('Erreur sur le nettoyage du cache des péripheriques USB :', __FILE__) . ' ' . log::exception($e)); - } catch (Error $e) { + } catch (Exception|Error $e) { log::add('starting', 'error', __('Erreur sur le nettoyage du cache des péripheriques USB :', __FILE__) . ' ' . log::exception($e)); } - try { + try { log::add('starting', 'debug', __('Nettoyage du cache des péripheriques Bluetooth', __FILE__)); $cache = cache::byKey('jeedom::bluetoothMapping'); $cache->remove(); - } catch (Exception $e) { - log::add('starting', 'error', __('Erreur sur le nettoyage du cache des péripheriques Bluetooth :', __FILE__) . ' ' . log::exception($e)); - } catch (Error $e) { + } catch (Exception|Error $e) { log::add('starting', 'error', __('Erreur sur le nettoyage du cache des péripheriques Bluetooth :', __FILE__) . ' ' . log::exception($e)); } - try { + try { log::add('starting', 'debug', __('Démarrage des processus Internet de Jeedom', __FILE__)); self::start(); - } catch (Exception $e) { - log::add('starting', 'error', __('Erreur sur le démarrage interne de Jeedom :', __FILE__) . ' ' . log::exception($e)); - } catch (Error $e) { + } catch (Exception|Error $e) { log::add('starting', 'error', __('Erreur sur le démarrage interne de Jeedom :', __FILE__) . ' ' . log::exception($e)); } - try { + try { log::add('starting', 'debug', __('Ecriture du fichier', __FILE__) . ' ' . self::getTmpFolder() . '/started'); if (file_put_contents(self::getTmpFolder() . '/started', date('Y-m-d H:i:s')) === false) { log::add('starting', 'error', __('Impossible d\'écrire', __FILE__) . ' ' . self::getTmpFolder() . '/started'); } - } catch (Exception $e) { - log::add('starting', 'error', __('Impossible d\'écrire', __FILE__) . ' ' . self::getTmpFolder() . '/started : ' . log::exception($e)); - } catch (Error $e) { + } catch (Exception|Error $e) { log::add('starting', 'error', __('Impossible d\'écrire', __FILE__) . ' ' . self::getTmpFolder() . '/started : ' . log::exception($e)); } - if (!file_exists(self::getTmpFolder() . '/started')) { + if (!file_exists(self::getTmpFolder() . '/started')) { log::add('starting', 'critical', __('Impossible d\'écrire', __FILE__) . ' ' . self::getTmpFolder() . __('/started pour une raison inconnue. Jeedom ne peut démarrer', __FILE__)); return; } @@ -1183,22 +1147,18 @@ public static function cron() { if (!network::test('internal')) { network::checkConf('internal'); } - } catch (Exception $e) { - log::add('starting', 'error', __('Erreur sur la configuration réseau interne :', __FILE__) . ' ' . log::exception($e)); - } catch (Error $e) { + } catch (Exception|Error $e) { log::add('starting', 'error', __('Erreur sur la configuration réseau interne :', __FILE__) . ' ' . log::exception($e)); } - try { + try { log::add('starting', 'debug', __('Envoi de l\'événement de démarrage', __FILE__)); self::event('start'); - } catch (Exception $e) { - log::add('starting', 'error', __('Erreur sur l\'envoi de l\'événement de démarrage :', __FILE__) . ' ' . log::exception($e)); - } catch (Error $e) { + } catch (Exception|Error $e) { log::add('starting', 'error', __('Erreur sur l\'envoi de l\'événement de démarrage :', __FILE__) . ' ' . log::exception($e)); } - try { + try { log::add('starting', 'debug', __('Démarrage des plugins', __FILE__)); plugin::start(); } catch (Exception $e) { @@ -1212,12 +1172,10 @@ public static function cron() { log::add('starting', 'debug', __('Test de connexion au market', __FILE__)); repo_market::test(); } - } catch (Exception $e) { - log::add('starting', 'error', __('Erreur sur la connexion au market :', __FILE__) . ' ' . log::exception($e)); - } catch (Error $e) { + } catch (Exception|Error $e) { log::add('starting', 'error', __('Erreur sur la connexion au market :', __FILE__) . ' ' . log::exception($e)); } - log::add('starting', 'debug', __('Démarrage de jeedom fini avec succès', __FILE__)); + log::add('starting', 'debug', __('Démarrage de jeedom fini avec succès', __FILE__)); } self::isDateOk(); } @@ -1234,24 +1192,20 @@ public static function cronDaily() { user::regenerateHash(); jeeObject::cronDaily(); timeline::clean(false); - } catch (Exception $e) { - log::add('jeedom', 'error', log::exception($e)); - } catch (Error $e) { + } catch (Exception|Error $e) { log::add('jeedom', 'error', log::exception($e)); } - try { + try { foreach ((update::listRepo()) as $name => $repo) { $class = 'repo_' . $name; if (class_exists($class) && method_exists($class, 'cronDaily') && config::byKey($name . '::enable') == 1) { $class::cronDaily(); } } - } catch (Exception $e) { - log::add('jeedom', 'error', log::exception($e)); - } catch (Error $e) { + } catch (Exception|Error $e) { log::add('jeedom', 'error', log::exception($e)); } - $disk_space = self::checkSpaceLeft(); + $disk_space = self::checkSpaceLeft(); if($disk_space < 10){ log::add('jeedom', 'error',__('Espace disque disponible faible : ',__FILE__).$disk_space.'%.'.__('Veuillez faire de la place (suppression de backup, de video/capture du plugin camera, d\'historique...)',__FILE__)); } @@ -1260,19 +1214,15 @@ public static function cronDaily() { public static function cronHourly() { try { cache::set('hour', strtotime('UTC')); - } catch (Exception $e) { - log::add('jeedom', 'error', log::exception($e)); - } catch (Error $e) { + } catch (Exception|Error $e) { log::add('jeedom', 'error', log::exception($e)); } - try { + try { cache::clean(); - } catch (Exception $e) { - log::add('jeedom', 'error', log::exception($e)); - } catch (Error $e) { + } catch (Exception|Error $e) { log::add('jeedom', 'error', log::exception($e)); } - try { + try { //Check for updates every 24h according to config if (config::byKey('update::autocheck', 'core', 1) == 1 && (config::byKey('update::lastCheck') == '' || (strtotime('now') - strtotime(config::byKey('update::lastCheck'))) > (23 * 3600) || strtotime('now') < strtotime(config::byKey('update::lastCheck')))) { update::checkAllUpdate(); @@ -1292,46 +1242,48 @@ public static function cronHourly() { } } } - } catch (Exception $e) { - log::add('jeedom', 'error', log::exception($e)); - } catch (Error $e) { + } catch (Exception|Error $e) { log::add('jeedom', 'error', log::exception($e)); } - try { + try { foreach ((update::listRepo()) as $name => $repo) { $class = 'repo_' . $name; if (class_exists($class) && method_exists($class, 'cronHourly') && config::byKey($name . '::enable') == 1) { $class::cronHourly(); } } - } catch (Exception $e) { - log::add('jeedom', 'error', log::exception($e)); - } catch (Error $e) { + } catch (Exception|Error $e) { log::add('jeedom', 'error', log::exception($e)); } - } + } /*************************************************************************************/ - public static function replaceTag(array $_replaces) { + public static function replaceTag(array $_replaces): void { $datas = array(); - foreach ($_replaces as $key => $value) { - $datas = array_merge($datas, cmd::searchConfiguration($key)); - $datas = array_merge($datas, eqLogic::searchConfiguration($key)); - $datas = array_merge($datas, jeeObject::searchConfiguration($key)); - $datas = array_merge($datas, scenario::searchByUse(array(array('action' => $key)))); - $datas = array_merge($datas, scenarioExpression::searchExpression($key, $key, false)); - $datas = array_merge($datas, scenarioExpression::searchExpression('variable(' . str_replace('#', '', $key) . ')')); - $datas = array_merge($datas, scenarioExpression::searchExpression('variable', str_replace('#', '', $key), true)); - $datas = array_merge($datas, scenarioExpression::searchExpression('genericType(' . str_replace('#', '', $key) . ')')); - $datas = array_merge($datas, scenarioExpression::searchExpression('genericType', str_replace('#', '', $key), true)); - $datas = array_merge($datas, viewData::searchByConfiguration($key)); - $datas = array_merge($datas, plan::searchByConfiguration($key)); - $datas = array_merge($datas, plan3d::searchByConfiguration($key)); - $datas = array_merge($datas, listener::searchEvent($key)); - $datas = array_merge($datas, user::searchByOptions($key)); - $datas = array_merge($datas, user::searchByRight($key)); - } + foreach ($_replaces as $key => $value) { + $cleanKey = str_replace('#', '', $key); + $searchExpressions = [ + cmd::searchConfiguration($key), + eqLogic::searchConfiguration($key), + jeeObject::searchConfiguration($key), + scenario::searchByUse([['action' => $key]]), + scenarioExpression::searchExpression($key, $key, false), + scenarioExpression::searchExpression("variable($cleanKey)"), + scenarioExpression::searchExpression('variable', $cleanKey, true), + scenarioExpression::searchExpression("genericType($cleanKey)"), + scenarioExpression::searchExpression('genericType', $cleanKey, true), + viewData::searchByConfiguration($key), + plan::searchByConfiguration($key), + plan3d::searchByConfiguration($key), + listener::searchEvent($key), + user::searchByOptions($key), + user::searchByRight($key), + ]; + foreach ($searchExpressions as $result) { + $datas = array_merge($datas, $result); + } + } if (count($datas) > 0) { foreach ($datas as $data) { try { @@ -1567,8 +1519,10 @@ public static function massReplace($_options = array(), $_eqlogics = array(), $_ foreach ($_eqlogics as $_sourceId => $_targetId) { $sourceEq = eqLogic::byId($_sourceId); $targetEq = eqLogic::byId($_targetId); - if (!is_object($sourceEq) || !is_object($targetEq)) continue; - jeedom::replaceTag(array('eqLogic' . $_sourceId => 'eqLogic' . $_targetId)); + if (!is_object($sourceEq) || !is_object($targetEq)) { + continue; + } + self::replaceTag(array('eqLogic' . $_sourceId => 'eqLogic' . $_targetId)); $return['eqlogics'] += 1; } } @@ -1579,7 +1533,9 @@ public static function massReplace($_options = array(), $_eqlogics = array(), $_ foreach ($_eqlogics as $_sourceId => $_targetId) { $sourceEq = eqLogic::byId($_sourceId); $targetEq = eqLogic::byId($_targetId); - if (!is_object($sourceEq) || !is_object($targetEq)) continue; + if (!is_object($sourceEq) || !is_object($targetEq)) { + continue; + } //Migrate plan cmd config for eqLogic: $planEqlogics = plan::byLinkTypeLinkId('eqLogic', $sourceEq->getId()); @@ -1623,7 +1579,7 @@ public static function massReplace($_options = array(), $_eqlogics = array(), $_ $targetEq->setDisplay('layout::dashboard::table::parameters', $sourceEq->getDisplay('layout::dashboard::table::parameters', null)); foreach ($sourceDisplay as $key => $value) { $query = 'layout::dashboard::table::cmd::'; - if (substr($key, 0, strlen($query)) === $query) { + if (strpos($key, $query) === 0) { $targetEq->setDisplay($key, null); $sourceCmdId = explode('::', str_replace($query, '', $key))[0]; $end = explode('::', str_replace($query, '', $key))[1]; @@ -1640,7 +1596,9 @@ public static function massReplace($_options = array(), $_eqlogics = array(), $_ if ($_options['hideEqs'] == "true") { foreach ($_eqlogics as $_sourceId => $_targetId) { $sourceEq = eqLogic::byId($_sourceId); - if (!is_object($sourceEq)) continue; + if (!is_object($sourceEq)) { + continue; + } $sourceEq->setIsVisible(0); $sourceEq->save(); } @@ -1648,7 +1606,9 @@ public static function massReplace($_options = array(), $_eqlogics = array(), $_ if ($_options['disableEqs'] == "true") { foreach ($_eqlogics as $_sourceId => $_targetId) { $sourceEq = eqLogic::byId($_sourceId); - if (!is_object($sourceEq)) continue; + if (!is_object($sourceEq)) { + continue; + } $sourceEq->setIsEnable(0); $sourceEq->save(); } @@ -1658,8 +1618,12 @@ public static function massReplace($_options = array(), $_eqlogics = array(), $_ foreach ($_cmds as $_sourceId => $_targetId) { $sourceCmd = cmd::byId($_sourceId); $targetCmd = cmd::byId($_targetId); - if (!is_object($sourceCmd) || !is_object($targetCmd)) continue; - if ($sourceCmd->getLogicalId() == 'refresh') continue; + if (!is_object($sourceCmd) || !is_object($targetCmd)) { + continue; + } + if ($sourceCmd->getLogicalId() == 'refresh') { + continue; + } //copy properties: if ($_options['copyCmdProperties'] == "true") { @@ -1668,7 +1632,7 @@ public static function massReplace($_options = array(), $_eqlogics = array(), $_ if ($_mode == 'replace') { //replace command where used: - jeedom::replaceTag(array('#' . str_replace('#', '', $sourceCmd->getId()) . '#' => '#' . str_replace('#', '', $targetCmd->getId()) . '#')); + self::replaceTag(array('#' . str_replace('#', '', $sourceCmd->getId()) . '#' => '#' . str_replace('#', '', $targetCmd->getId()) . '#')); } //remove history: @@ -1677,11 +1641,9 @@ public static function massReplace($_options = array(), $_eqlogics = array(), $_ } //copy history: - if ($_options['copyCmdHistory'] == "true" && $sourceCmd->getIsHistorized() == 1) { - if ($sourceCmd->getSubType() == $targetCmd->getSubType()) { - history::copyHistoryToCmd($sourceCmd->getId(), $targetCmd->getId()); - } - } + if ($_options['copyCmdHistory'] == "true" && $sourceCmd->getIsHistorized() == 1 && $sourceCmd->getSubType() == $targetCmd->getSubType()) { + history::copyHistoryToCmd($sourceCmd->getId(), $targetCmd->getId()); + } $return['cmds'] += 1; } @@ -1691,7 +1653,7 @@ public static function massReplace($_options = array(), $_eqlogics = array(), $_ /******************************SYSTEM MANAGEMENT**********************************************************/ - public static function haltSystem() { + public static function haltSystem(): void { plugin::stop(); cache::persist(); if (self::isCapable('sudo')) { @@ -1701,7 +1663,7 @@ public static function haltSystem() { } } - public static function rebootSystem() { + public static function rebootSystem(): void { plugin::stop(); cache::persist(); if (self::isCapable('sudo')) { @@ -1711,14 +1673,14 @@ public static function rebootSystem() { } } - public static function forceSyncHour() { + public static function forceSyncHour(): void { if (config::byKey('disable_ntp', 'core', 0) == 1) { return; } shell_exec(system::getCmdSudo() . 'service ntp stop;' . system::getCmdSudo() . 'ntpdate -s ' . config::byKey('ntp::optionalServer', 'core', '0.debian.pool.ntp.org') . ';' . system::getCmdSudo() . 'service ntp start'); } - public static function cleanDatabase() { + public static function cleanDatabase(): void { log::clear('cleaningdb'); $cmd = __DIR__ . '/../../install/cleaning.php'; $cmd .= ' >> ' . log::getPathToLog('cleaningdb') . ' 2>&1 &'; @@ -1738,7 +1700,7 @@ public static function cleanFileSystemRight() { } public static function checkSpaceLeft($_dir = null) { - if ($_dir == null) { + if ($_dir === null) { $path = __DIR__ . '/../../'; } else { $path = $_dir; @@ -1794,17 +1756,17 @@ public static function getHardwareName() { } } } - } else if (strpos($uname, 'cubox') !== false || strpos($uname, 'imx6') !== false) { + } elseif (strpos($uname, 'cubox') !== false || strpos($uname, 'imx6') !== false) { $result = 'miniplus'; - } else if (file_exists('/usr/bin/grille-pain')) { + } elseif (file_exists('/usr/bin/grille-pain')) { $result = 'freeboxDelta'; - } else if (file_exists('/media/boot/multiboot/meson64_odroidc2.dtb.linux')) { + } elseif (file_exists('/media/boot/multiboot/meson64_odroidc2.dtb.linux')) { $result = 'smart'; - } else if (file_exists('/etc/update-motd.d/10-armbian-header-jeedomatlas')) { + } elseif (file_exists('/etc/update-motd.d/10-armbian-header-jeedomatlas')) { $result = 'Atlas'; - } else if (strpos($hostname, 'Luna') !== false) { + } elseif (strpos($hostname, 'Luna') !== false) { $result = 'Luna'; - } else if (file_exists('/proc/1/sched') && strpos(shell_exec('cat /proc/1/sched | head -n 1'),'systemd') === false){ + } elseif (file_exists('/proc/1/sched') && strpos(shell_exec('cat /proc/1/sched | head -n 1'),'systemd') === false){ $result = 'docker'; } config::save('hardware_name', $result); @@ -1836,7 +1798,7 @@ public static function isCapable($_function, $_forceRefresh = false) { /* * ******************Benchmark*************************** */ - public static function benchmark() { + public static function benchmark(): array { $return = array(); $param = array('cache_write' => 5000, 'cache_read' => 5000, 'database_write_delete' => 1000, 'database_update' => 1000, 'database_replace' => 1000, 'database_read' => 50000, 'subprocess' => 200); From e9a21906ff80adfb2a929acdf4db21532ec1338a Mon Sep 17 00:00:00 2001 From: Luc SANCHEZ <4697568+ColonelMoutarde@users.noreply.github.com> Date: Thu, 3 Jul 2025 09:31:53 +0200 Subject: [PATCH 2/7] Update jeedom.class.php --- core/class/jeedom.class.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/core/class/jeedom.class.php b/core/class/jeedom.class.php index a567246a39..3ff8b000ec 100644 --- a/core/class/jeedom.class.php +++ b/core/class/jeedom.class.php @@ -137,7 +137,7 @@ public static function getThemeConfig() { return $return; } - public static function addRemoveHistory($_data): void { + public static function addRemoveHistory($_data) { try { $remove_history = array(); if (file_exists(__DIR__ . '/../../data/remove_history.json')) { @@ -819,7 +819,7 @@ public static function consistency() { /********************************************BACKUP*****************************************************************/ - public static function backup($_background = false): void { + public static function backup($_background = false) { if ($_background) { log::clear('backup'); $cmd = __DIR__ . '/../../install/backup.php'; @@ -844,7 +844,7 @@ public static function listBackup(): array { return $return; } - public static function removeBackup($_backup): void { + public static function removeBackup($_backup) { if (file_exists($_backup)) { unlink($_backup); } else { @@ -852,7 +852,7 @@ public static function removeBackup($_backup): void { } } - public static function restore($_backup = '', $_background = false): void { + public static function restore($_backup = '', $_background = false) { if ($_background) { log::clear('restore'); $cmd = __DIR__ . '/../../install/restore.php "backup=' . $_backup . '"'; @@ -867,7 +867,7 @@ public static function restore($_backup = '', $_background = false): void { /****************************UPDATE*****************************************************************/ - public static function update($_options = array()): void { + public static function update($_options = array()) { log::clear('update'); $params = ''; if (is_array($_options) && count($_options) > 0) { @@ -936,7 +936,7 @@ public static function version(): string { /**********************START AND DATE MANAGEMENT*************************************************************/ - public static function stop(): void { + public static function stop() { echo "Disable all task"; config::save('enableCron', 0); foreach ((cron::all()) as $cron) { @@ -977,7 +977,7 @@ public static function stop(): void { echo " OK\n"; } - public static function start(): void { + public static function start() { try { /* * *********Réactivation des scénarios**************** */ echo "Enable scenario : "; @@ -1036,7 +1036,7 @@ public static function isDateOk(): bool { return true; } - public static function event($_event, $_forceSyncMode = false, $_options = null): void { + public static function event($_event, $_forceSyncMode = false, $_options = null) { scenario::check($_event, $_forceSyncMode, null, null, null, $_options); } @@ -1072,7 +1072,7 @@ public static function cron10() { } } - public static function cron(): void { + public static function cron() { if (!self::isStarted()) { echo date('Y-m-d H:i:s') . ' starting Jeedom'; log::add('starting', 'debug', __('Démarrage de jeedom', __FILE__)); @@ -1259,7 +1259,7 @@ public static function cronHourly() { /*************************************************************************************/ - public static function replaceTag(array $_replaces): void { + public static function replaceTag(array $_replaces) { $datas = array(); foreach ($_replaces as $key => $value) { $cleanKey = str_replace('#', '', $key); @@ -1653,7 +1653,7 @@ public static function massReplace($_options = array(), $_eqlogics = array(), $_ /******************************SYSTEM MANAGEMENT**********************************************************/ - public static function haltSystem(): void { + public static function haltSystem() { plugin::stop(); cache::persist(); if (self::isCapable('sudo')) { @@ -1663,7 +1663,7 @@ public static function haltSystem(): void { } } - public static function rebootSystem(): void { + public static function rebootSystem() { plugin::stop(); cache::persist(); if (self::isCapable('sudo')) { @@ -1673,14 +1673,14 @@ public static function rebootSystem(): void { } } - public static function forceSyncHour(): void { + public static function forceSyncHour() { if (config::byKey('disable_ntp', 'core', 0) == 1) { return; } shell_exec(system::getCmdSudo() . 'service ntp stop;' . system::getCmdSudo() . 'ntpdate -s ' . config::byKey('ntp::optionalServer', 'core', '0.debian.pool.ntp.org') . ';' . system::getCmdSudo() . 'service ntp start'); } - public static function cleanDatabase(): void { + public static function cleanDatabase() { log::clear('cleaningdb'); $cmd = __DIR__ . '/../../install/cleaning.php'; $cmd .= ' >> ' . log::getPathToLog('cleaningdb') . ' 2>&1 &'; From ed17326b6d8daac51996efa3d70fde9ba7792bd6 Mon Sep 17 00:00:00 2001 From: Luc SANCHEZ <4697568+ColonelMoutarde@users.noreply.github.com> Date: Mon, 7 Jul 2025 11:12:53 +0200 Subject: [PATCH 3/7] Apply suggestions from code review --- core/class/jeedom.class.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/core/class/jeedom.class.php b/core/class/jeedom.class.php index 3ff8b000ec..ad029e7457 100644 --- a/core/class/jeedom.class.php +++ b/core/class/jeedom.class.php @@ -150,7 +150,10 @@ public static function addRemoveHistory($_data) { } } - public static function deadCmd(): array { + /** + * @return array + */ + public static function deadCmd() { global $JEEDOM_INTERNAL_CONFIG; $return = array(); $cmd = config::byKey('interact::warnme::defaultreturncmd', 'core', ''); @@ -944,7 +947,8 @@ public static function stop() { try { $cron->halt(); echo '.'; - } catch (Exception|Error $e) { + } catch (Throwable $e) { +`` sleep(5); $cron->halt(); } @@ -969,7 +973,7 @@ public static function stop() { try { $scenario->stop(); echo '.'; - } catch (Exception|Error $e) { + } catch (Throwable $e) { sleep(5); $scenario->stop(); } @@ -991,7 +995,7 @@ public static function start() { echo "Check Network Conf : "; network::checkConf('internal'); echo "OK\n"; - } catch (Exception|Error $e) { + } catch (Throwable $e) { if (!isset($_GET['mode']) || $_GET['mode'] != 'force') { throw $e; } @@ -1050,12 +1054,12 @@ public static function cron5() { $class::cron5(); } } - } catch (Exception|Error $e) { + } catch (Throwable $e) { log::add('jeedom', 'error', log::exception($e)); } try { eqLogic::checkAlive(); - } catch (Exception|Error $e) { + } catch (Throwable $e) { } } From aecd4359ac36304ac3bc8dd0db4366eb2305b5ed Mon Sep 17 00:00:00 2001 From: Luc SANCHEZ <4697568+ColonelMoutarde@users.noreply.github.com> Date: Mon, 7 Jul 2025 11:47:47 +0200 Subject: [PATCH 4/7] Update jeedom.class.php --- core/class/jeedom.class.php | 66 +++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 36 deletions(-) diff --git a/core/class/jeedom.class.php b/core/class/jeedom.class.php index ad029e7457..46a1a0548a 100644 --- a/core/class/jeedom.class.php +++ b/core/class/jeedom.class.php @@ -521,8 +521,8 @@ public static function health(): array { $return += array_merge($return, $class::health()); } - return $return; - } + return $return; + } public static function sick() { $cmd = __DIR__ . '/../../sick.php'; @@ -948,7 +948,6 @@ public static function stop() { $cron->halt(); echo '.'; } catch (Throwable $e) { -`` sleep(5); $cron->halt(); } @@ -1009,7 +1008,6 @@ public static function isStarted(): bool { } /** - * * @return boolean */ public static function isDateOk(): bool { @@ -1071,7 +1069,7 @@ public static function cron10() { $class::cron10(); } } - } catch (Exception|Error $e) { + } catch (Throwable $e) { log::add('jeedom', 'error', log::exception($e)); } } @@ -1086,26 +1084,26 @@ public static function cron() { if ($cron->running() && $cron->getClass() != 'jeedom' && $cron->getFunction() != 'cron') { try { $cron->halt(); - } catch (Exception|Error $e) { + } catch (Throwable $e) { log::add('starting', 'error', __('Erreur sur l\'arrêt d\'une tâche cron :', __FILE__) . ' ' . log::exception($e)); } } } - } catch (Exception|Error $e) { + } catch (Throwable $e) { log::add('starting', 'error', __('Erreur sur l\'arrêt des tâches crons :', __FILE__) . ' ' . log::exception($e)); } try { log::add('starting', 'debug', __('Restauration du cache', __FILE__)); cache::restore(); - } catch (Exception|Error $e) { + } catch (Throwable $e) { log::add('starting', 'error', __('Erreur sur la restauration du cache :', __FILE__) . ' ' . log::exception($e)); } try { log::add('starting', 'debug', __('Consolidation de l\'historique', __FILE__)); history::checkCurrentValueAndHistory(); - } catch (Exception|Error $e) { + } catch (Throwable $e) { log::add('starting', 'error', __('Erreur sur la consolidation de l\'historique :', __FILE__) . ' ' . log::exception($e)); } @@ -1113,7 +1111,7 @@ public static function cron() { log::add('starting', 'debug', __('Nettoyage du cache des péripheriques USB', __FILE__)); $cache = cache::byKey('jeedom::usbMapping'); $cache->remove(); - } catch (Exception|Error $e) { + } catch (Throwable $e) { log::add('starting', 'error', __('Erreur sur le nettoyage du cache des péripheriques USB :', __FILE__) . ' ' . log::exception($e)); } @@ -1121,14 +1119,14 @@ public static function cron() { log::add('starting', 'debug', __('Nettoyage du cache des péripheriques Bluetooth', __FILE__)); $cache = cache::byKey('jeedom::bluetoothMapping'); $cache->remove(); - } catch (Exception|Error $e) { + } catch (Throwable $e) { log::add('starting', 'error', __('Erreur sur le nettoyage du cache des péripheriques Bluetooth :', __FILE__) . ' ' . log::exception($e)); } try { log::add('starting', 'debug', __('Démarrage des processus Internet de Jeedom', __FILE__)); self::start(); - } catch (Exception|Error $e) { + } catch (Throwable $e) { log::add('starting', 'error', __('Erreur sur le démarrage interne de Jeedom :', __FILE__) . ' ' . log::exception($e)); } @@ -1137,7 +1135,7 @@ public static function cron() { if (file_put_contents(self::getTmpFolder() . '/started', date('Y-m-d H:i:s')) === false) { log::add('starting', 'error', __('Impossible d\'écrire', __FILE__) . ' ' . self::getTmpFolder() . '/started'); } - } catch (Exception|Error $e) { + } catch (Throwable $e) { log::add('starting', 'error', __('Impossible d\'écrire', __FILE__) . ' ' . self::getTmpFolder() . '/started : ' . log::exception($e)); } @@ -1151,23 +1149,21 @@ public static function cron() { if (!network::test('internal')) { network::checkConf('internal'); } - } catch (Exception|Error $e) { + } catch (Throwable $e) { log::add('starting', 'error', __('Erreur sur la configuration réseau interne :', __FILE__) . ' ' . log::exception($e)); } try { log::add('starting', 'debug', __('Envoi de l\'événement de démarrage', __FILE__)); self::event('start'); - } catch (Exception|Error $e) { + } catch (Throwable $e) { log::add('starting', 'error', __('Erreur sur l\'envoi de l\'événement de démarrage :', __FILE__) . ' ' . log::exception($e)); } try { log::add('starting', 'debug', __('Démarrage des plugins', __FILE__)); plugin::start(); - } catch (Exception $e) { - log::add('starting', 'error', __('Erreur sur le démarrage des plugins :', __FILE__) . ' ' . log::exception($e)); - } catch (Error $e) { + } catch (Throwable $e) { log::add('starting', 'error', __('Erreur sur la démarrage des plugins :', __FILE__) . ' ' . log::exception($e)); } @@ -1176,7 +1172,7 @@ public static function cron() { log::add('starting', 'debug', __('Test de connexion au market', __FILE__)); repo_market::test(); } - } catch (Exception|Error $e) { + } catch (Throwable $e) { log::add('starting', 'error', __('Erreur sur la connexion au market :', __FILE__) . ' ' . log::exception($e)); } log::add('starting', 'debug', __('Démarrage de jeedom fini avec succès', __FILE__)); @@ -1196,7 +1192,7 @@ public static function cronDaily() { user::regenerateHash(); jeeObject::cronDaily(); timeline::clean(false); - } catch (Exception|Error $e) { + } catch (Throwable $e) { log::add('jeedom', 'error', log::exception($e)); } try { @@ -1206,11 +1202,11 @@ public static function cronDaily() { $class::cronDaily(); } } - } catch (Exception|Error $e) { + } catch (Throwable $e) { log::add('jeedom', 'error', log::exception($e)); } $disk_space = self::checkSpaceLeft(); - if($disk_space < 10){ + if ($disk_space < 10) { log::add('jeedom', 'error',__('Espace disque disponible faible : ',__FILE__).$disk_space.'%.'.__('Veuillez faire de la place (suppression de backup, de video/capture du plugin camera, d\'historique...)',__FILE__)); } } @@ -1218,12 +1214,12 @@ public static function cronDaily() { public static function cronHourly() { try { cache::set('hour', strtotime('UTC')); - } catch (Exception|Error $e) { + } catch (Throwable $e) { log::add('jeedom', 'error', log::exception($e)); } try { cache::clean(); - } catch (Exception|Error $e) { + } catch (Throwable $e) { log::add('jeedom', 'error', log::exception($e)); } try { @@ -1246,17 +1242,17 @@ public static function cronHourly() { } } } - } catch (Exception|Error $e) { + } catch (Throwable $e) { log::add('jeedom', 'error', log::exception($e)); } try { - foreach ((update::listRepo()) as $name => $repo) { + foreach ((update::listRepo() as $name => $repo) { $class = 'repo_' . $name; if (class_exists($class) && method_exists($class, 'cronHourly') && config::byKey($name . '::enable') == 1) { $class::cronHourly(); } } - } catch (Exception|Error $e) { + } catch (Throwable $e) { log::add('jeedom', 'error', log::exception($e)); } } @@ -1312,7 +1308,7 @@ public static function replaceTag(array $_replaces) { } } $plans = plan::byLinkTypeLinkId('cmd', str_replace('#', '', $key)); - if (count($plans) > 0) { + if (count($plans) > 0) { foreach ($plans as $plan) { try { $plan->setLink_id(str_replace('#', '', $value)); @@ -1322,7 +1318,7 @@ public static function replaceTag(array $_replaces) { } } $plan3ds = plan3d::byLinkTypeLinkId('cmd', str_replace('#', '', $key)); - if (count($plan3ds) > 0) { + if (count($plan3ds) > 0) { foreach ($plan3ds as $plan3d) { try { $plan3d->setLink_id(str_replace('#', '', $value)); @@ -1345,7 +1341,9 @@ public static function retrievePidThread($_cmd) { } /******************************************UTILS******************************************************/ - + /** + * @return mixed|string + */ public static function versionAlias($_version, $_lightMode = true) { if ($_version == 'mview') { return 'mobile'; @@ -1704,11 +1702,7 @@ public static function cleanFileSystemRight() { } public static function checkSpaceLeft($_dir = null) { - if ($_dir === null) { - $path = __DIR__ . '/../../'; - } else { - $path = $_dir; - } + $path = $_dir ?? (__DIR__ . '/../../'); return round(disk_free_space($path) / disk_total_space($path) * 100); } @@ -1729,7 +1723,7 @@ public static function getTmpFolder($_plugin = '') { return $return; } - /* * ******************hardware management*************************** */ + /* * ******************hardware management*************************** */ public static function getHardwareKey() { $return = config::byKey('jeedom::installKey'); From d62b75a997709d32f5510e5998307eccf3a7b829 Mon Sep 17 00:00:00 2001 From: Luc SANCHEZ <4697568+ColonelMoutarde@users.noreply.github.com> Date: Mon, 7 Jul 2025 11:52:12 +0200 Subject: [PATCH 5/7] Update core/class/jeedom.class.php --- core/class/jeedom.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/class/jeedom.class.php b/core/class/jeedom.class.php index 46a1a0548a..b7300bbcab 100644 --- a/core/class/jeedom.class.php +++ b/core/class/jeedom.class.php @@ -1246,7 +1246,7 @@ public static function cronHourly() { log::add('jeedom', 'error', log::exception($e)); } try { - foreach ((update::listRepo() as $name => $repo) { + foreach ((update::listRepo() as $name) => $repo) { $class = 'repo_' . $name; if (class_exists($class) && method_exists($class, 'cronHourly') && config::byKey($name . '::enable') == 1) { $class::cronHourly(); From 76eec2453831095d1925cadb231de64e8f5e79b0 Mon Sep 17 00:00:00 2001 From: Luc SANCHEZ <4697568+ColonelMoutarde@users.noreply.github.com> Date: Mon, 7 Jul 2025 13:42:07 +0200 Subject: [PATCH 6/7] oups --- core/class/jeedom.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/class/jeedom.class.php b/core/class/jeedom.class.php index b7300bbcab..176f52ef84 100644 --- a/core/class/jeedom.class.php +++ b/core/class/jeedom.class.php @@ -1246,7 +1246,7 @@ public static function cronHourly() { log::add('jeedom', 'error', log::exception($e)); } try { - foreach ((update::listRepo() as $name) => $repo) { + foreach ((update::listRepo()) as $name => $repo) { $class = 'repo_' . $name; if (class_exists($class) && method_exists($class, 'cronHourly') && config::byKey($name . '::enable') == 1) { $class::cronHourly(); From eb028a67e2b882e59b41bc21f28eb6fb5ef97dab Mon Sep 17 00:00:00 2001 From: Luc SANCHEZ <4697568+ColonelMoutarde@users.noreply.github.com> Date: Mon, 7 Jul 2025 14:05:04 +0200 Subject: [PATCH 7/7] Optimize replaceTag() --- core/class/jeedom.class.php | 115 ++++++++++++++++++------------------ 1 file changed, 56 insertions(+), 59 deletions(-) diff --git a/core/class/jeedom.class.php b/core/class/jeedom.class.php index 176f52ef84..1fa8a4338f 100644 --- a/core/class/jeedom.class.php +++ b/core/class/jeedom.class.php @@ -1260,72 +1260,69 @@ public static function cronHourly() { /*************************************************************************************/ public static function replaceTag(array $_replaces) { - $datas = array(); - foreach ($_replaces as $key => $value) { - $cleanKey = str_replace('#', '', $key); - $searchExpressions = [ - cmd::searchConfiguration($key), - eqLogic::searchConfiguration($key), - jeeObject::searchConfiguration($key), - scenario::searchByUse([['action' => $key]]), - scenarioExpression::searchExpression($key, $key, false), - scenarioExpression::searchExpression("variable($cleanKey)"), - scenarioExpression::searchExpression('variable', $cleanKey, true), - scenarioExpression::searchExpression("genericType($cleanKey)"), - scenarioExpression::searchExpression('genericType', $cleanKey, true), - viewData::searchByConfiguration($key), - plan::searchByConfiguration($key), - plan3d::searchByConfiguration($key), - listener::searchEvent($key), - user::searchByOptions($key), - user::searchByRight($key), - ]; + $results = []; + foreach ($_replaces as $key => $value) { + $cleanKey = str_replace('#', '', $key); + $searchExpressions = [ + cmd::searchConfiguration($key), + eqLogic::searchConfiguration($key), + jeeObject::searchConfiguration($key), + scenario::searchByUse([['action' => $key]]), + scenarioExpression::searchExpression($key, $key, false), + scenarioExpression::searchExpression("variable($cleanKey)"), + scenarioExpression::searchExpression('variable', $cleanKey, true), + scenarioExpression::searchExpression("genericType($cleanKey)"), + scenarioExpression::searchExpression('genericType', $cleanKey, true), + viewData::searchByConfiguration($key), + plan::searchByConfiguration($key), + plan3d::searchByConfiguration($key), + listener::searchEvent($key), + user::searchByOptions($key), + user::searchByRight($key), + ]; foreach ($searchExpressions as $result) { - $datas = array_merge($datas, $result); - } - } - if (count($datas) > 0) { - foreach ($datas as $data) { - try { - if (method_exists($data, 'refresh')) { - $data->refresh(); - } - utils::a2o($data, json_decode(str_replace(array_keys($_replaces), $_replaces, json_encode(utils::o2a($data))), true)); - $data->save(true); - } catch (\Exception $e) { + if (is_array($result)) { + $results[] = $result; } } } - foreach ($_replaces as $key => $value) { - $viewDatas = viewData::byTypeLinkId('cmd', str_replace('#', '', $key)); - if (count($viewDatas) > 0) { - foreach ($viewDatas as $viewData) { - try { - $viewData->setLink_id(str_replace('#', '', $value)); - $viewData->save(); - } catch (\Exception $e) { - } + $datas = []; + if (!empty($results)) { + $datas = array_merge(...$results); + } + + foreach ($datas as $data) { + try { + if (method_exists($data, 'refresh')) { + $data->refresh(); } + utils::a2o($data, json_decode(str_replace(array_keys($_replaces), $_replaces, json_encode(utils::o2a($data))), true)); + $data->save(true); + } catch (\Exception $e) { } - $plans = plan::byLinkTypeLinkId('cmd', str_replace('#', '', $key)); - if (count($plans) > 0) { - foreach ($plans as $plan) { - try { - $plan->setLink_id(str_replace('#', '', $value)); - $plan->save(); - } catch (\Exception $e) { - } - } + } + + foreach ($_replaces as $key => $value) { + $cleanKey = str_replace('#', '', $key); + $cleanValue = str_replace('#', '', $value); + + foreach (viewData::byTypeLinkId('cmd', $cleanKey) as $viewData) { + try { + $viewData->setLink_id($cleanValue); + $viewData->save(); + } catch (\Exception $e) {} } - $plan3ds = plan3d::byLinkTypeLinkId('cmd', str_replace('#', '', $key)); - if (count($plan3ds) > 0) { - foreach ($plan3ds as $plan3d) { - try { - $plan3d->setLink_id(str_replace('#', '', $value)); - $plan3d->save(); - } catch (\Exception $e) { - } - } + foreach (plan::byLinkTypeLinkId('cmd', $cleanKey) as $plan) { + try { + $plan->setLink_id($cleanValue); + $plan->save(); + } catch (\Exception $e) {} + } + foreach (plan3d::byLinkTypeLinkId('cmd', $cleanKey) as $plan3d) { + try { + $plan3d->setLink_id($cleanValue); + $plan3d->save(); + } catch (\Exception $e) {} } } }