diff --git a/install/migration/update_1.0.0_to_1.0.1.php b/install/migration/update_1.0.0_to_1.0.1.php index ba4ba692..ec109f8c 100644 --- a/install/migration/update_1.0.0_to_1.0.1.php +++ b/install/migration/update_1.0.0_to_1.0.1.php @@ -30,7 +30,7 @@ * ------------------------------------------------------------------------- */ -function update100to101(Migration $migration) +function update100to101(Migration $migration): bool { /** @var DBmysql $DB */ global $DB; diff --git a/install/migration/update_1.0.1_to_1.1.0.php b/install/migration/update_1.0.1_to_1.1.0.php index 19714136..21ad5f48 100644 --- a/install/migration/update_1.0.1_to_1.1.0.php +++ b/install/migration/update_1.0.1_to_1.1.0.php @@ -30,7 +30,7 @@ * ------------------------------------------------------------------------- */ -function update101to110(Migration $migration) +function update101to110(Migration $migration): bool { /** @var DBmysql $DB */ global $DB; diff --git a/install/migration/update_1.1.1_to_1.2.0.php b/install/migration/update_1.1.1_to_1.2.0.php index fd3d0e80..61fd9bf6 100644 --- a/install/migration/update_1.1.1_to_1.2.0.php +++ b/install/migration/update_1.1.1_to_1.2.0.php @@ -30,7 +30,7 @@ * ------------------------------------------------------------------------- */ -function update111to120(Migration $migration) +function update111to120(Migration $migration): bool { /** @var DBmysql $DB */ global $DB; diff --git a/install/mysql/plugin_carbon_empty.sql b/install/mysql/plugin_carbon_empty.sql index 48a78f46..7cc1d78e 100644 --- a/install/mysql/plugin_carbon_empty.sql +++ b/install/mysql/plugin_carbon_empty.sql @@ -181,6 +181,14 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_carbon_computerusageprofiles` ( PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +CREATE TABLE IF NOT EXISTS `glpi_plugin_carbon_datacenters` ( + `id` int unsigned NOT NULL AUTO_INCREMENT, + `datacenters_id` int unsigned NOT NULL DEFAULT '0', + `pue` float DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `unicity` (`datacenters_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + CREATE TABLE IF NOT EXISTS `glpi_plugin_carbon_embodiedimpacts` ( `id` int unsigned NOT NULL AUTO_INCREMENT, `itemtype` varchar(255) DEFAULT NULL, diff --git a/setup.php b/setup.php index 15a45e9e..77c65863 100644 --- a/setup.php +++ b/setup.php @@ -32,9 +32,11 @@ use Config as GlpiConfig; use CronTask as GlpiCronTask; +use Datacenter as GlpiDatacenter; use Glpi\Plugin\Hooks; use GlpiPlugin\Carbon\Config; use GlpiPlugin\Carbon\CronTask; +use GlpiPlugin\Carbon\Datacenter; use GlpiPlugin\Carbon\Dashboard\Grid; use GlpiPlugin\Carbon\Dashboard\Widget; use GlpiPlugin\Carbon\DataSource\CarbonIntensity\ClientFactory as CarbonIntensityClientFactory; @@ -152,6 +154,7 @@ function plugin_carbon_registerClasses() Plugin::registerClass(Profile::class, ['addtabon' => GlpiProfile::class]); Plugin::registerClass(Location::class, ['addtabon' => GlpiLocation::class]); Plugin::registerClass(CronTask::class, ['addtabon' => GlpiCronTask::class]); + Plugin::registerClass(Datacenter::class, ['addtabon' => GlpiDatacenter::class]); foreach (PLUGIN_CARBON_TYPES as $itemtype) { $core_type_class = $itemtype . 'Type'; diff --git a/src/Datacenter.php b/src/Datacenter.php new file mode 100644 index 00000000..8bc9d2f2 --- /dev/null +++ b/src/Datacenter.php @@ -0,0 +1,83 @@ +. + * + * ------------------------------------------------------------------------- + */ + +namespace GlpiPlugin\Carbon; + +use CommonDBChild; +use CommonGLPI; +use Datacenter as GlpiDatacenter; +use Glpi\Application\View\TemplateRenderer; +use Override; + +class Datacenter extends CommonDBChild +{ + // From CommonDBRelation + public static $itemtype = GlpiDatacenter::class; + public static $items_id = 'datacenters_id'; + + #[Override] + public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) + { + if ($item instanceof GlpiDatacenter) { + return self::createTabEntry(__('Environmental impact', 'carbon'), 0); + } + return ''; + } + + #[Override] + public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) + { + if ($item instanceof GlpiDatacenter) { + /** @var GlpiDatacenter $item */ + $location = new self(); + $location->showForDatacenter($item); + } + return true; + } + + public function showForDatacenter(GlpiDatacenter $item, array $options = []) + { + $this->getFromDBByCrit(['datacenters_id' => $item->getID()]); + if ($this->isNewItem()) { + $this->add(['datacenters_id' => $item->getID()]); + } + + TemplateRenderer::getInstance()->display('@carbon/datacenter.html.twig', [ + 'item' => $this, + 'params' => [ + 'candel' => false, + ], + ]); + + return true; + } +} diff --git a/templates/datacenter.html.twig b/templates/datacenter.html.twig new file mode 100644 index 00000000..649d94cd --- /dev/null +++ b/templates/datacenter.html.twig @@ -0,0 +1,42 @@ +{# + # ------------------------------------------------------------------------- + # Carbon plugin for GLPI + # + # @copyright Copyright (C) 2024-2025 Teclib' and contributors. + # @license https://www.gnu.org/licenses/gpl-3.0.txt GPLv3+ + # @license MIT https://opensource.org/licenses/mit-license.php + # @link https://github.com/pluginsGLPI/carbon + # + # ------------------------------------------------------------------------- + # + # LICENSE + # + # This file is part of Carbon plugin for GLPI. + # + # This program is free software: you can redistribute it and/or modify + # it under the terms of the GNU General Public License as published by + # the Free Software Foundation, either version 3 of the License, or + # (at your option) any later version. + # + # This program is distributed in the hope that it will be useful, + # but WITHOUT ANY WARRANTY; without even the implied warranty of + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + # GNU General Public License for more details. + # + # You should have received a copy of the GNU General Public License + # along with this program. If not, see . + # + # ------------------------------------------------------------------------- + #} + +{% extends "generic_show_form.html.twig" %} +{% import "components/form/fields_macros.html.twig" as fields %} + +{% block form_fields %} + {{ fields.numberField('pue', + item.fields['pue'] ?? '', + __('Power Usage Effectiveness (PUE)', 'carbon'), + { + + }) }} +{% endblock %}