Skip to content

Commit 4655139

Browse files
authored
Admin: move benchmark functions to new component (#10258)
https://docu.ilias.de/go/wiki/wpage_8648_1357
1 parent ecda3d6 commit 4655139

File tree

13 files changed

+394
-233
lines changed

13 files changed

+394
-233
lines changed

components/ILIAS/Administration/GlobalScreen/classes/AdministrationMainBarProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ private function getGroups(): array
209209
// admin menu layout
210210
$layout = array(
211211
"maintenance" =>
212-
array("adm", "cron", "lngf", "hlps", "wfe", 'fils', 'logs', 'sysc', "recf", "root"),
212+
array("adm", "cron", "bnmk", "lngf", "hlps", "wfe", 'fils', 'logs', 'sysc', "recf", "root"),
213213
"layout_and_navigation" =>
214214
array("mme", "gsfo", "dshs", "stys", "adve"),
215215
"repository_and_objects" =>

components/ILIAS/Administration/classes/class.ilAdministrationGUI.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function __construct()
9494
$ilCtrl = $DIC->ctrl();
9595

9696
$this->lng = $lng;
97-
$this->lng->loadLanguageModule('administration');
97+
$this->lng->loadLanguageModule('benchmark');
9898
$this->tpl = $tpl;
9999
$this->tree = $tree;
100100
$this->rbacsystem = $rbacsystem;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
/**
4+
* This file is part of ILIAS, a powerful learning management system
5+
* published by ILIAS open source e-Learning e.V.
6+
*
7+
* ILIAS is licensed with the GPL-3.0,
8+
* see https://www.gnu.org/licenses/gpl-3.0.en.html
9+
* You should have received a copy of said license along with the
10+
* source code, too.
11+
*
12+
* If this is not the case or you just want to try ILIAS, you'll find
13+
* us at:
14+
* https://www.ilias.de
15+
* https://github.com/ILIAS-eLearning
16+
*
17+
*********************************************************************/
18+
19+
declare(strict_types=1);
20+
21+
namespace ILIAS;
22+
23+
class Benchmark implements Component\Component
24+
{
25+
public function init(
26+
array | \ArrayAccess &$define,
27+
array | \ArrayAccess &$implement,
28+
array | \ArrayAccess &$use,
29+
array | \ArrayAccess &$contribute,
30+
array | \ArrayAccess &$seek,
31+
array | \ArrayAccess &$provide,
32+
array | \ArrayAccess &$pull,
33+
array | \ArrayAccess &$internal,
34+
): void {
35+
$contribute[\ILIAS\Setup\Agent::class] = fn() =>
36+
new \ILIAS\Benchmark\Setup\Agent(
37+
$pull[\ILIAS\Refinery\Factory::class]
38+
);
39+
}
40+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
/**
4+
* This file is part of ILIAS, a powerful learning management system
5+
* published by ILIAS open source e-Learning e.V.
6+
*
7+
* ILIAS is licensed with the GPL-3.0,
8+
* see https://www.gnu.org/licenses/gpl-3.0.en.html
9+
* You should have received a copy of said license along with the
10+
* source code, too.
11+
*
12+
* If this is not the case or you just want to try ILIAS, you'll find
13+
* us at:
14+
* https://www.ilias.de
15+
* https://github.com/ILIAS-eLearning
16+
*
17+
*********************************************************************/
18+
19+
declare(strict_types=1);
20+
21+
namespace ILIAS\Benchmark\Setup;
22+
23+
use ILIAS\Refinery\Factory as Refinery;
24+
use ILIAS\Refinery\Transformation;
25+
use ILIAS\Setup\Objective;
26+
use ILIAS\Setup\Config;
27+
use ILIAS\Setup\Metrics\Storage;
28+
use ILIAS\Setup\Objective\NullObjective;
29+
use ILIAS\Setup\Agent as AgentInterface;
30+
use ilTreeAdminNodeAddedObjective;
31+
32+
class Agent implements AgentInterface
33+
{
34+
public function __construct(private readonly Refinery $refinery)
35+
{
36+
}
37+
38+
public function hasConfig(): bool
39+
{
40+
return false;
41+
}
42+
43+
public function getArrayToConfigTransformation(): Transformation
44+
{
45+
return $this->refinery->identity();
46+
}
47+
48+
public function getInstallObjective(?Config $config = null): Objective
49+
{
50+
return new NullObjective();
51+
}
52+
53+
public function getUpdateObjective(?Config $config = null): Objective
54+
{
55+
return new ilTreeAdminNodeAddedObjective('bnmk', 'Benchmark');
56+
}
57+
58+
public function getBuildObjective(): Objective
59+
{
60+
return new NullObjective();
61+
}
62+
63+
public function getStatusObjective(Storage $storage): Objective
64+
{
65+
return new NullObjective();
66+
}
67+
68+
public function getMigrations(): array
69+
{
70+
return [];
71+
}
72+
73+
public function getNamedObjectives(?Config $config = null): array
74+
{
75+
return [];
76+
}
77+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/**
4+
* This file is part of ILIAS, a powerful learning management system
5+
* published by ILIAS open source e-Learning e.V.
6+
*
7+
* ILIAS is licensed with the GPL-3.0,
8+
* see https://www.gnu.org/licenses/gpl-3.0.en.html
9+
* You should have received a copy of said license along with the
10+
* source code, too.
11+
*
12+
* If this is not the case or you just want to try ILIAS, you'll find
13+
* us at:
14+
* https://www.ilias.de
15+
* https://github.com/ILIAS-eLearning
16+
*
17+
*********************************************************************/
18+
19+
declare(strict_types=1);
20+
21+
final class ilObjBenchmark extends ilObject2
22+
{
23+
public const string TYPE = 'bnmk';
24+
25+
protected function initType(): void
26+
{
27+
$this->type = self::TYPE;
28+
}
29+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/**
4+
* This file is part of ILIAS, a powerful learning management system
5+
* published by ILIAS open source e-Learning e.V.
6+
*
7+
* ILIAS is licensed with the GPL-3.0,
8+
* see https://www.gnu.org/licenses/gpl-3.0.en.html
9+
* You should have received a copy of said license along with the
10+
* source code, too.
11+
*
12+
* If this is not the case or you just want to try ILIAS, you'll find
13+
* us at:
14+
* https://www.ilias.de
15+
* https://github.com/ILIAS-eLearning
16+
*
17+
*********************************************************************/
18+
19+
declare(strict_types=1);
20+
21+
final class ilObjBenchmarkAccess extends ilObjectAccess
22+
{
23+
}
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
<?php
2+
3+
/**
4+
* This file is part of ILIAS, a powerful learning management system
5+
* published by ILIAS open source e-Learning e.V.
6+
*
7+
* ILIAS is licensed with the GPL-3.0,
8+
* see https://www.gnu.org/licenses/gpl-3.0.en.html
9+
* You should have received a copy of said license along with the
10+
* source code, too.
11+
*
12+
* If this is not the case or you just want to try ILIAS, you'll find
13+
* us at:
14+
* https://www.ilias.de
15+
* https://github.com/ILIAS-eLearning
16+
*
17+
*********************************************************************/
18+
19+
declare(strict_types=1);
20+
21+
use ILIAS\HTTP\Wrapper\WrapperFactory as WrapperFactoryAlias;
22+
23+
/**
24+
* @ilCtrl_isCalledBy ilObjBenchmarkGUI: ilAdministrationGUI
25+
* @ilCtrl_Calls ilObjBenchmarkGUI: ilPermissionGUI
26+
*/
27+
class ilObjBenchmarkGUI extends ilObject2GUI
28+
{
29+
private ilPropertyFormGUI $form;
30+
private ilBenchmark $bench;
31+
private WrapperFactoryAlias $wrapper;
32+
33+
public function __construct(int $id = 0, int $id_type = self::REPOSITORY_NODE_ID, int $parent_node_id = 0)
34+
{
35+
parent::__construct($id, $id_type, $parent_node_id);
36+
37+
global $DIC;
38+
$this->wrapper = $DIC->http()->wrapper();
39+
$this->bench = $DIC["ilBench"];
40+
}
41+
42+
public function getType(): string
43+
{
44+
return ilObjBenchmark::TYPE;
45+
}
46+
47+
public function executeCommand(): void
48+
{
49+
$this->checkPermission('read');
50+
51+
$this->lng->loadLanguageModule($this->getType());
52+
$this->prepareOutput();
53+
54+
switch ($this->ctrl->getNextClass($this)) {
55+
case strtolower(ilPermissionGUI::class):
56+
$this->tabs_gui->activateTab('permissions');
57+
$perm_gui = new ilPermissionGUI($this);
58+
$this->ctrl->forwardCommand($perm_gui);
59+
break;
60+
61+
default:
62+
$cmd = $this->ctrl->getCmd("view");
63+
switch ($cmd) {
64+
case 'settings':
65+
case 'update':
66+
$this->tabs_gui->activateTab('settings');
67+
$this->checkPermission('write');
68+
$this->$cmd();
69+
break;
70+
71+
case 'view':
72+
case 'slowest_first':
73+
case 'sorted_by_sql':
74+
case 'by_first_table':
75+
$this->getViewSubtabs();
76+
$this->tabs_gui->activateTab('view');
77+
$this->tabs_gui->activateSubTab($cmd);
78+
$this->view();
79+
break;
80+
}
81+
}
82+
}
83+
84+
public function getAdminTabs(): void
85+
{
86+
$this->tabs_gui->addTab(
87+
'view',
88+
$this->lng->txt('view'),
89+
$this->ctrl->getLinkTarget($this, 'view')
90+
);
91+
92+
if ($this->checkPermissionBool('write')) {
93+
$this->tabs_gui->addTab(
94+
'settings',
95+
$this->lng->txt('settings'),
96+
$this->ctrl->getLinkTarget($this, 'settings')
97+
);
98+
}
99+
if ($this->checkPermissionBool('edit_permission')) {
100+
$this->tabs_gui->addTab(
101+
'permissions',
102+
$this->lng->txt('perm_settings'),
103+
$this->ctrl->getLinkTargetByClass([self::class, ilPermissionGUI::class], 'perm')
104+
);
105+
}
106+
}
107+
108+
private function getViewSubtabs(): void
109+
{
110+
$this->tabs_gui->addSubTab(
111+
'view',
112+
$this->lng->txt('adm_db_bench_chronological'),
113+
$this->ctrl->getLinkTarget($this, 'view')
114+
);
115+
116+
$this->tabs_gui->addSubTab(
117+
'slowest_first',
118+
$this->lng->txt('adm_db_bench_slowest_first'),
119+
$this->ctrl->getLinkTarget($this, 'slowest_first')
120+
);
121+
122+
$this->tabs_gui->addSubTab(
123+
'sorted_by_sql',
124+
$this->lng->txt('adm_db_bench_sorted_by_sql'),
125+
$this->ctrl->getLinkTarget($this, 'sorted_by_sql')
126+
);
127+
128+
$this->tabs_gui->addSubTab(
129+
'by_first_table',
130+
$this->lng->txt('adm_db_bench_by_first_table'),
131+
$this->ctrl->getLinkTarget($this, 'by_first_table')
132+
);
133+
}
134+
135+
private function settings(): void
136+
{
137+
$this->form = new ilPropertyFormGUI();
138+
139+
// Activate DB Benchmark
140+
$cb = new ilCheckboxInputGUI($this->lng->txt("adm_activate_db_benchmark"), ilBenchmark::ENABLE_DB_BENCH);
141+
$cb->setChecked((bool) $this->settings->get(ilBenchmark::ENABLE_DB_BENCH));
142+
$cb->setInfo($this->lng->txt("adm_activate_db_benchmark_desc"));
143+
$this->form->addItem($cb);
144+
145+
// DB Benchmark User
146+
$ti = new ilTextInputGUI($this->lng->txt("adm_db_benchmark_user"), ilBenchmark::DB_BENCH_USER);
147+
$login = ilObjUser::_lookupLogin((int) ($this->settings->get(ilBenchmark::DB_BENCH_USER)));
148+
$ti->setValue($login);
149+
$ti->setInfo($this->lng->txt("adm_db_benchmark_user_desc"));
150+
$this->form->addItem($ti);
151+
152+
$this->form->setTitle($this->lng->txt("adm_db_benchmark"));
153+
$this->form->setFormAction($this->ctrl->getFormAction($this));
154+
$this->form->addCommandButton('update', $this->lng->txt('save'));
155+
156+
$this->tpl->setContent($this->form->getHTML());
157+
}
158+
159+
public function update(): void
160+
{
161+
if ($this->wrapper->post()->has(ilBenchmark::ENABLE_DB_BENCH)
162+
&& $this->wrapper->post()->has(ilBenchmark::DB_BENCH_USER)) {
163+
$activate = $this->wrapper->post()->retrieve(ilBenchmark::ENABLE_DB_BENCH, $this->refinery->kindlyTo()->bool());
164+
if ($activate) {
165+
$user_name = $this->wrapper->post()->retrieve(ilBenchmark::DB_BENCH_USER, $this->refinery->kindlyTo()->string());
166+
$this->bench->clearData();
167+
$this->bench->enableDbBenchmarkForUserName($user_name);
168+
}
169+
} else {
170+
$this->bench->clearData();
171+
$this->bench->disableDbBenchmark();
172+
}
173+
174+
$this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_obj_modified"), true);
175+
$this->ctrl->redirect($this, 'settings');
176+
}
177+
178+
public function view(): void
179+
{
180+
$cmd = $this->ctrl->getCmd("view");
181+
$mode = $cmd === 'view' ? 'chronological' : $cmd;
182+
183+
$table = new ilBenchmarkTableGUI($this, $cmd, $this->bench->getDbBenchRecords(), $mode);
184+
$this->tpl->setContent($table->getHTML());
185+
}
186+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version = "1.0" encoding = "UTF-8"?>
2+
<service xmlns="http://www.w3.org" version="$Id$" id="bnmk">
3+
<baseclasses>
4+
</baseclasses>
5+
<objects>
6+
<object id="bnmk" class_name="Benchmark" dir="classes" checkbox="0" inherit="0" translate="sys" rbac="1" system="1" administration="1">
7+
<parent id="adm" max="1">adm</parent>
8+
</object>
9+
</objects>
10+
<logging />
11+
</service>

0 commit comments

Comments
 (0)