Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion install/migration/update_1.0.0_to_1.0.1.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* -------------------------------------------------------------------------
*/

function update100to101(Migration $migration)
function update100to101(Migration $migration): bool
{
/** @var DBmysql $DB */
global $DB;
Expand Down
2 changes: 1 addition & 1 deletion install/migration/update_1.0.1_to_1.1.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* -------------------------------------------------------------------------
*/

function update101to110(Migration $migration)
function update101to110(Migration $migration): bool
{
/** @var DBmysql $DB */
global $DB;
Expand Down
2 changes: 1 addition & 1 deletion install/migration/update_1.1.1_to_1.2.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* -------------------------------------------------------------------------
*/

function update111to120(Migration $migration)
function update111to120(Migration $migration): bool
{
/** @var DBmysql $DB */
global $DB;
Expand Down
8 changes: 8 additions & 0 deletions install/mysql/plugin_carbon_empty.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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';
Expand Down
83 changes: 83 additions & 0 deletions src/Datacenter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

/**
* -------------------------------------------------------------------------
* Carbon plugin for GLPI
*
* @copyright Copyright (C) 2024-2025 Teclib' and contributors.
* @license https://www.gnu.org/licenses/gpl-3.0.txt GPLv3+
* @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 <https://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/

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;
}
}
42 changes: 42 additions & 0 deletions templates/datacenter.html.twig
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
#
# -------------------------------------------------------------------------
#}

{% 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 %}
Loading