diff --git a/pandora_console/include/rest-api/models/VisualConsole/Container.php b/pandora_console/include/rest-api/models/VisualConsole/Container.php index ffc0746d97..720fa2f556 100644 --- a/pandora_console/include/rest-api/models/VisualConsole/Container.php +++ b/pandora_console/include/rest-api/models/VisualConsole/Container.php @@ -62,7 +62,7 @@ final class Container extends Model ); } - $this->extractGroupId($data); + static::extractGroupId($data); } @@ -80,13 +80,13 @@ final class Container extends Model return [ 'id' => (int) $data['id'], 'name' => $data['name'], - 'groupId' => $this->extractGroupId($data), - 'backgroundImage' => $this->extractBackgroundImage($data), - 'backgroundColor' => $this->extractBackgroundColor($data), - 'isFavorite' => $this->extractFavorite($data), + 'groupId' => static::extractGroupId($data), + 'backgroundImage' => static::extractBackgroundImage($data), + 'backgroundColor' => static::extractBackgroundColor($data), + 'isFavorite' => static::extractFavorite($data), 'width' => (int) $data['width'], 'height' => (int) $data['height'], - 'backgroundURL' => $this->extractBackgroundUrl($data), + 'backgroundURL' => static::extractBackgroundUrl($data), 'relationLineWidth' => (int) $data['relationLineWidth'], ]; } @@ -101,7 +101,7 @@ final class Container extends Model * * @throws \InvalidArgumentException When a valid group Id can't be found. */ - private function extractGroupId(array $data): int + private static function extractGroupId(array $data): int { $groupId = static::parseIntOr( static::issetInArray($data, ['id_group', 'groupId']), @@ -125,7 +125,7 @@ final class Container extends Model * * @return mixed String representing the image name (not empty) or null. */ - private function extractBackgroundImage(array $data) + private static function extractBackgroundImage(array $data) { $backgroundImage = static::notEmptyStringOr( static::issetInArray($data, ['background', 'backgroundURL']), @@ -143,7 +143,7 @@ final class Container extends Model * * @return mixed String representing the image url (not empty) or null. */ - private function extractBackgroundUrl(array $data) + private static function extractBackgroundUrl(array $data) { return static::notEmptyStringOr( static::issetInArray($data, ['backgroundURL']), @@ -159,7 +159,7 @@ final class Container extends Model * * @return mixed String representing the color (not empty) or null. */ - private function extractBackgroundColor(array $data) + private static function extractBackgroundColor(array $data) { return static::notEmptyStringOr( static::issetInArray( @@ -181,7 +181,7 @@ final class Container extends Model * * @return boolean If the item is favorite or not. */ - private function extractFavorite(array $data): bool + private static function extractFavorite(array $data): bool { return static::parseBool( static::issetInArray($data, ['is_favourite', 'isFavorite']) @@ -383,7 +383,7 @@ final class Container extends Model $class = static::getItemClass($itemType); try { - \array_push($items, $class::fromDB(['id' => $itemId])); + array_push($items, $class::fromDB(['id' => $itemId])); } catch (\Throwable $e) { // TODO: Log this? } diff --git a/pandora_console/include/rest-api/models/VisualConsole/Item.php b/pandora_console/include/rest-api/models/VisualConsole/Item.php index f064bd8d07..122a9549b6 100644 --- a/pandora_console/include/rest-api/models/VisualConsole/Item.php +++ b/pandora_console/include/rest-api/models/VisualConsole/Item.php @@ -667,7 +667,7 @@ class Item extends Model if (isset($data['encodedHtml']) === true) { return $data['encodedHtml']; } else if (isset($data['html']) === true) { - return \base64_encode($data['html']); + return base64_encode($data['html']); } return ''; @@ -686,6 +686,10 @@ class Item extends Model */ protected static function fetchDataFromDB(array $filter): array { + // Load side libraries. + global $config; + include_once $config['homedir'].'/include/functions_io.php'; + // Due to this DB call, this function cannot be unit tested without // a proper mock. $row = \db_get_row_filter('tlayout_data', $filter); @@ -698,11 +702,6 @@ class Item extends Model global $config; include_once $config['homedir'].'/include/functions_io.php'; - if (\is_metaconsole()) { - \enterprise_include_once('include/functions_metaconsole.php'); - \enterprise_include_once('meta/include/functions_ui_meta.php'); - } - // Clean up to two levels of HTML entities. $row = \io_safe_output(\io_safe_output($row)); @@ -712,9 +711,9 @@ class Item extends Model // The linked module includes the agent data. if (static::$useLinkedModule === true) { - $row = \array_merge($row, static::fetchModuleDataFromDB($row)); + $row = array_merge($row, static::fetchModuleDataFromDB($row)); } else if (static::$useLinkedAgent === true) { - $row = \array_merge($row, static::fetchAgentDataFromDB($row)); + $row = array_merge($row, static::fetchAgentDataFromDB($row)); } // Build the item link if needed. @@ -806,6 +805,11 @@ class Item extends Model */ protected static function fetchModuleDataFromDB(array $itemData): array { + // Load side libraries. + if (\is_metaconsole()) { + \enterprise_include_once('include/functions_metaconsole.php'); + } + // Initialize with the agent data. $moduleData = static::fetchAgentDataFromDB($itemData); @@ -830,7 +834,9 @@ class Item extends Model $moduleName = false; // Connect to node. - if (\is_metaconsole() && \metaconsole_connect(null, $metaconsoleId) !== NOERR) { + if (\is_metaconsole() + && \metaconsole_connect(null, $metaconsoleId) !== NOERR + ) { throw new \InvalidArgumentException( 'error connecting to the node' ); @@ -874,8 +880,10 @@ class Item extends Model global $config; // Load side libraries. - \enterprise_include_once('include/functions_metaconsole.php'); - \enterprise_include_once('meta/include/functions_ui_meta.php'); + if (\is_metaconsole()) { + \enterprise_include_once('include/functions_metaconsole.php'); + \enterprise_include_once('meta/include/functions_ui_meta.php'); + } $linkedVisualConsole = static::extractLinkedVisualConsole($data); $linkedModule = static::extractLinkedModule($data);