diff --git a/pandora_console/include/lib/Module.php b/pandora_console/include/lib/Module.php index 982dd24f27..f63f3e0492 100644 --- a/pandora_console/include/lib/Module.php +++ b/pandora_console/include/lib/Module.php @@ -207,7 +207,7 @@ class Module extends Entity if (is_numeric($id_agent_module) === true && $id_agent_module > 0 ) { - if ($nodeId !== null) { + if ($nodeId > 0) { $this->nodeId = $nodeId; } @@ -1022,12 +1022,13 @@ class Module extends Entity /** * Calculates cascade protection service value for this service. * - * @param integer|null $id_node Meta searching node will use this field. + * @param integer|null $id_node Meta searching node will use this field. + * @param boolean $connected Connected to a node. * * @return integer CPS value. * @throws \Exception On error. */ - public function calculateCPS(?int $id_node=null) + public function calculateCPS(?int $id_node=null, bool $connected=false) { if ($this->cps() < 0) { return $this->cps(); @@ -1047,6 +1048,7 @@ class Module extends Entity // Here could happen 2 things. // 1. Metaconsole service is using this method impersonating node DB. // 2. Node service is trying to find parents into metaconsole. + // 3. Impersonated node searching metaconsole. if (empty($id_node) === true && is_metaconsole() === false && has_metaconsole() === true @@ -1119,6 +1121,38 @@ class Module extends Entity if ($r !== NOERR) { throw new \Exception(__('Cannot connect to node %d', $r)); } + } else if (is_metaconsole() === true + // True in impersonated nodes. + && has_metaconsole() === false + && empty($id_node) === true + ) { + // Impersonated node checking metaconsole. + \enterprise_hook('metaconsole_restore_db'); + + $mc_parents = db_get_all_rows_sql( + sprintf( + 'SELECT id_service, + cps, + cascade_protection, + name + FROM `tservice_element` te + INNER JOIN `tservice` t ON te.id_service = t.id + WHERE te.id_agente_modulo = %d', + $this->id_agente_modulo() + ), + false, + false + ); + + // Restore impersonation. + \enterprise_include_once('include/functions_metaconsole.php'); + $r = \enterprise_hook( + 'metaconsole_connect', + [ + null, + $id_node, + ] + ); } $cps = 0; diff --git a/pandora_console/include/rest-api/models/VisualConsole/Item.php b/pandora_console/include/rest-api/models/VisualConsole/Item.php index 95ba132d03..7af3b76817 100644 --- a/pandora_console/include/rest-api/models/VisualConsole/Item.php +++ b/pandora_console/include/rest-api/models/VisualConsole/Item.php @@ -922,7 +922,8 @@ class Item extends CachedModel // Can't fetch an agent with an invalid Id. $agentId = static::extractAgentId($itemData); if ($agentId === null) { - throw new \InvalidArgumentException('invalid agent Id'); + $agentId = 0; + // throw new \InvalidArgumentException('invalid agent Id'); } // Staticgraph don't need to have an agent. @@ -956,7 +957,8 @@ class Item extends CachedModel $agent = \db_get_row_sql($sql); if ($agent === false) { - throw new \Exception('error fetching the data from the DB'); + return $agentData; + // throw new \Exception('error fetching the data from the DB'); } // The agent name should be a valid string or a null value. @@ -996,7 +998,8 @@ class Item extends CachedModel // Can't fetch an module with a invalid Id. $moduleId = static::extractModuleId($itemData); if ($moduleId === null) { - throw new \InvalidArgumentException('invalid module Id'); + $moduleId = 0; + // throw new \InvalidArgumentException('invalid module Id'); } // Staticgraph don't need to have a module. @@ -1037,7 +1040,8 @@ class Item extends CachedModel } if ($moduleName === false) { - throw new \Exception('error fetching the data from the DB'); + return $moduleData; + // throw new \Exception('error fetching the data from the DB'); } $moduleData['moduleName'] = $moduleName['nombre']; diff --git a/pandora_console/include/rest-api/models/VisualConsole/Items/Clock.php b/pandora_console/include/rest-api/models/VisualConsole/Items/Clock.php index 2bfd4d847b..af50e65db2 100644 --- a/pandora_console/include/rest-api/models/VisualConsole/Items/Clock.php +++ b/pandora_console/include/rest-api/models/VisualConsole/Items/Clock.php @@ -123,6 +123,11 @@ final class Clock extends Item */ protected function decode(array $data): array { + // Default values. + if (empty($data['height']) === true) { + $data['height'] = ($data['width'] / 2); + } + $clockData = parent::decode($data); $clockData['type'] = CLOCK; $clockData['clockType'] = static::extractClockType($data); diff --git a/pandora_console/include/rest-api/models/VisualConsole/Items/Label.php b/pandora_console/include/rest-api/models/VisualConsole/Items/Label.php index af53e7489d..203117a313 100644 --- a/pandora_console/include/rest-api/models/VisualConsole/Items/Label.php +++ b/pandora_console/include/rest-api/models/VisualConsole/Items/Label.php @@ -31,6 +31,25 @@ final class Label extends Item */ protected function decode(array $data): array { + $data['label'] = \preg_replace( + '/overflow: hidden;/', + '', + $data['label'] + ); + // Default values. + if ((empty($data['width']) === true) + && (empty($data['height']) === true) + ) { + preg_match( + '/visual_font_size_(.*)pt/', + $data['label'], + $matches + ); + + $data['width'] = (($matches[1] * 10) + 5); + $data['height'] = ($matches[1] * 2.5); + } + $return = parent::decode($data); $return['type'] = LABEL; return $return;