Skip to content

Commit 501e1db

Browse files
committed
feat: prepare tab for cache management
1 parent 677305a commit 501e1db

3 files changed

Lines changed: 53 additions & 27 deletions

File tree

src/CronTask.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,19 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $
7070
if ($item instanceof GlpiCronTask) {
7171
/** @var GlpiCronTask $item */
7272
$cron_task = new self();
73-
$cron_task->showForCronTask($item);
73+
$cron_task->showForCronTask($item, $tabnum);
7474
}
7575
return true;
7676
}
7777

78-
public function showForCronTask(CommonDBTM $item)
78+
public function showForCronTask(CommonDBTM $item, int $tabnum)
7979
{
8080
$itemtype = $item->fields['itemtype'];
8181
if (!in_array($itemtype, CronTaskProvider::getCronTaskTypes())) {
8282
return;
8383
}
8484
$crontask = new $itemtype();
85-
$crontask->showForCronTask($item);
85+
$crontask->showForCronTask($item, $tabnum);
8686
}
8787

8888
/**

src/DataSource/CarbonIntensity/ElectricityMaps/CronTask.php

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,20 @@
4545

4646
class CronTask extends AbstractCronTask implements CronTaskInterface
4747
{
48+
private const TAB_DIAGNOSIS = 0;
49+
private const TAB_CACHE = 1;
50+
4851
public static function getIcon()
4952
{
5053
return 'fa-solid fa-gears';
5154
}
5255

5356
public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
5457
{
55-
return self::createTabEntry(__('Resource diagnosis', 'carbon'), 0);
58+
return [
59+
self::TAB_DIAGNOSIS => self::createTabEntry(__('Resource diagnosis', 'carbon'), 0),
60+
// self::TAB_CACHE => self::createTabEntry(__('Cache', 'carbon'), 0),
61+
];
5662
}
5763

5864
public static function enumerateTasks(): array
@@ -103,19 +109,26 @@ public static function cronDownloadElectricityMap(GlpiCronTask $task): int
103109
return CarbonCronTask::downloadCarbonIntensityFromSource($task, $client, new CarbonIntensity());
104110
}
105111

106-
public function showForCronTask(CommonDBTM $item)
112+
public function showForCronTask(CommonDBTM $item, int $tabnum)
107113
{
108-
switch ($item->fields['name']) {
109-
case 'DownloadElectricityMap':
110-
$client = new Client(new RestApiClient());
111-
$source_name = ($client)->getSourceName();
112-
foreach ($client->getSupportedZones() as $zone_name) {
113-
$source_zone = new Source_Zone();
114-
if (!$source_zone->getFromDbBySourceAndZone($source_name, $zone_name)) {
115-
continue;
114+
if ($tabnum === self::TAB_DIAGNOSIS) {
115+
switch ($item->fields['name']) {
116+
case 'DownloadElectricityMap':
117+
$client = new Client(new RestApiClient());
118+
$source_name = ($client)->getSourceName();
119+
foreach ($client->getSupportedZones() as $zone_name) {
120+
$source_zone = new Source_Zone();
121+
if (!$source_zone->getFromDbBySourceAndZone($source_name, $zone_name)) {
122+
continue;
123+
}
124+
$source_zone->showGaps();
116125
}
117-
$source_zone->showGaps();
118-
}
126+
}
127+
} elseif ($tabnum === self::TAB_CACHE) {
128+
switch ($item->fields['name']) {
129+
case 'DownloadElectricityMap':
130+
// TODO: implement tab to clear cached data in files/ folder
131+
}
119132
}
120133
}
121134
}

src/DataSource/CarbonIntensity/Rte/CronTask.php

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,29 +45,42 @@
4545

4646
class CronTask extends AbstractCronTask implements CronTaskInterface
4747
{
48+
private const TAB_DIAGNOSIS = 0;
49+
private const TAB_CACHE = 1;
50+
4851
public static function getIcon()
4952
{
5053
return 'fa-solid fa-gears';
5154
}
5255

5356
public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
5457
{
55-
return self::createTabEntry(__('Resource diagnosis', 'carbon'), 0);
58+
return [
59+
self::TAB_DIAGNOSIS => self::createTabEntry(__('Resource diagnosis', 'carbon'), 0),
60+
// self::TAB_CACHE => self::createTabEntry(__('Cache', 'carbon'), 0),
61+
];
5662
}
5763

58-
public function showForCronTask(CommonDBTM $item)
64+
public function showForCronTask(CommonDBTM $item, int $tabnum)
5965
{
60-
switch ($item->fields['name']) {
61-
case 'DownloadRte':
62-
$client = new Client(new RestApiClient());
63-
$source_name = ($client)->getSourceName();
64-
foreach ($client->getSupportedZones() as $zone_name) {
65-
$source_zone = new Source_Zone();
66-
if (!$source_zone->getFromDbBySourceAndZone($source_name, $zone_name)) {
67-
continue;
66+
if ($tabnum === self::TAB_DIAGNOSIS) {
67+
switch ($item->fields['name']) {
68+
case 'DownloadRte':
69+
$client = new Client(new RestApiClient());
70+
$source_name = ($client)->getSourceName();
71+
foreach ($client->getSupportedZones() as $zone_name) {
72+
$source_zone = new Source_Zone();
73+
if (!$source_zone->getFromDbBySourceAndZone($source_name, $zone_name)) {
74+
continue;
75+
}
76+
$source_zone->showGaps();
6877
}
69-
$source_zone->showGaps();
70-
}
78+
}
79+
} elseif ($tabnum === self::TAB_CACHE) {
80+
switch ($item->fields['name']) {
81+
case 'DownloadElectricityMap':
82+
// TODO: implement tab to clear cached data in files/ folder
83+
}
7184
}
7285
}
7386

0 commit comments

Comments
 (0)