diff --git a/core/class/jeedom.class.php b/core/class/jeedom.class.php index d090860d81..1fa8a4338f 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']; } @@ -151,15 +150,16 @@ public static function addRemoveHistory($_data) { } } + /** + * @return array + */ public static function deadCmd() { 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 +172,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 +499,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__), @@ -521,8 +521,8 @@ public static function health() { $return += array_merge($return, $class::health()); } - return $return; - } + return $return; + } public static function sick() { $cmd = __DIR__ . '/../../sick.php'; @@ -575,7 +575,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 +626,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); @@ -833,7 +833,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 { @@ -924,13 +924,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')); } @@ -947,14 +947,11 @@ public static function stop() { try { $cron->halt(); echo '.'; - } catch (Exception $e) { - sleep(5); - $cron->halt(); - } catch (Error $e) { + } catch (Throwable $e) { sleep(5); $cron->halt(); } - } + } } echo " OK\n"; @@ -975,14 +972,11 @@ public static function stop() { try { $scenario->stop(); echo '.'; - } catch (Exception $e) { - sleep(5); - $scenario->stop(); - } catch (Error $e) { + } catch (Throwable $e) { sleep(5); $scenario->stop(); } - } + } echo " OK\n"; } @@ -1000,30 +994,23 @@ public static function start() { echo "Check Network Conf : "; network::checkConf('internal'); echo "OK\n"; - } catch (Exception $e) { + } catch (Throwable $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'); } /** - * * @return boolean */ - public static function isDateOk() { + public static function isDateOk(): bool { if (config::byKey('ignoreHourCheck') == 1) { return true; } @@ -1040,10 +1027,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; } @@ -1065,17 +1052,14 @@ public static function cron5() { $class::cron5(); } } - } catch (Exception $e) { - log::add('jeedom', 'error', log::exception($e)); - } catch (Error $e) { + } catch (Throwable $e) { log::add('jeedom', 'error', log::exception($e)); } - try { + try { eqLogic::checkAlive(); - } catch (Exception $e) { - } catch (Error $e) { + } catch (Throwable $e) { } - } + } public static function cron10() { try { @@ -1085,12 +1069,10 @@ public static function cron10() { $class::cron10(); } } - } catch (Exception $e) { - log::add('jeedom', 'error', log::exception($e)); - } catch (Error $e) { + } catch (Throwable $e) { log::add('jeedom', 'error', log::exception($e)); } - } + } public static function cron() { if (!self::isStarted()) { @@ -1102,78 +1084,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 (Throwable $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 (Throwable $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 (Throwable $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 (Throwable $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 (Throwable $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 (Throwable $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 (Throwable $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 (Throwable $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,27 +1149,21 @@ 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 (Throwable $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 (Throwable $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) { - 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)); } @@ -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 (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__)); + log::add('starting', 'debug', __('Démarrage de jeedom fini avec succès', __FILE__)); } self::isDateOk(); } @@ -1234,25 +1192,21 @@ 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 (Throwable $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 (Throwable $e) { log::add('jeedom', 'error', log::exception($e)); } - $disk_space = self::checkSpaceLeft(); - if($disk_space < 10){ + $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 (Throwable $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 (Throwable $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,88 +1242,87 @@ public static function cronHourly() { } } } - } catch (Exception $e) { - log::add('jeedom', 'error', log::exception($e)); - } catch (Error $e) { + } catch (Throwable $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 (Throwable $e) { log::add('jeedom', 'error', log::exception($e)); } - } + } /*************************************************************************************/ public static function replaceTag(array $_replaces) { - $datas = array(); + $results = []; 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)); - } - 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) { + $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) { + 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) {} } } } @@ -1389,7 +1338,9 @@ public static function retrievePidThread($_cmd) { } /******************************************UTILS******************************************************/ - + /** + * @return mixed|string + */ public static function versionAlias($_version, $_lightMode = true) { if ($_version == 'mview') { return 'mobile'; @@ -1567,8 +1518,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 +1532,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 +1578,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 +1595,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 +1605,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 +1617,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 +1631,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 +1640,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; } @@ -1738,11 +1699,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); } @@ -1763,7 +1720,7 @@ public static function getTmpFolder($_plugin = '') { return $return; } - /* * ******************hardware management*************************** */ + /* * ******************hardware management*************************** */ public static function getHardwareKey() { $return = config::byKey('jeedom::installKey'); @@ -1794,17 +1751,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 +1793,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);