Skip to content

Commit 08f861c

Browse files
Rom1-BstonebuzzMyvTsv
authored
feature/glpi-12.0 (#37)
* feature/glpi-12.0 Co-authored-by: Stanislas <skita@teclib.com> * lint --------- Co-authored-by: Stanislas <skita@teclib.com> Co-authored-by: MyuTsu <gaetan.langlois31@gmail.com>
1 parent 4feaecf commit 08f861c

29 files changed

Lines changed: 141 additions & 166 deletions

‎.github/workflows/continuous-integration.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
name: "Generate CI matrix"
2121
uses: "glpi-project/plugin-ci-workflows/.github/workflows/generate-ci-matrix.yml@v1"
2222
with:
23-
glpi-version: "11.0.x"
23+
glpi-version: "12.0.x"
2424
ci:
2525
name: "GLPI ${{ matrix.glpi-version }} - php:${{ matrix.php-version }} - ${{ matrix.db-image }}"
2626
needs: "generate-ci-matrix"

‎CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [UNRELEASED]
44

5+
### Added
6+
7+
- GLPI 12 compatibility
8+
59
### Fixed
610

711
- Fix mobile devices duplication during mobile sync

‎ajax/cron.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
Html::header_nocache();
4242

43-
Session::checkRight('config', UPDATE);
43+
Session::checkRight(Config::$rightname, UPDATE);
4444

4545
/** @var DBmysql $DB */
4646
global $DB;

‎front/menu.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464

6565
TemplateRenderer::getInstance()->display('@jamf/menu.html.twig', [
6666
'links' => $links,
67-
'can_configure' => Session::haveRight('config', UPDATE),
67+
'can_configure' => Session::haveRight(Config::$rightname, UPDATE),
6868
'config_url' => Config::getFormURL() . '?forcetab=PluginJamfConfig$1',
6969
]);
7070

‎hook.php‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function plugin_jamf_getAddSearchOptions($itemtype)
7575
$opt = [];
7676
$plugin = new Plugin();
7777
if ($plugin->isActivated('jamf') && ($itemtype === 'Computer' || $itemtype === 'Phone')) {
78-
$opt = [
78+
return [
7979
'22002' => [
8080
'table' => 'glpi_plugin_jamf_devices',
8181
'field' => 'last_inventory',
@@ -236,9 +236,7 @@ function plugin_jamf_getAddSearchOptions($itemtype)
236236

237237
function plugin_jamf_dashboardCards($cards = [])
238238
{
239-
if (is_null($cards)) {
240-
$cards = [];
241-
}
239+
$cards ??= [];
242240

243241
$cards = array_merge($cards, PluginJamfExtensionAttribute::dashboardCards());
244242

‎inc/abstractdevice.class.php‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@
3535
*/
3636
abstract class PluginJamfAbstractDevice extends CommonDBChild
3737
{
38-
public static $itemtype = 'itemtype';
38+
public static string $itemtype = 'itemtype';
3939

40-
public static $items_id = 'items_id';
40+
public static string $items_id = 'items_id';
4141

4242
public static $jamftype_name;
4343

44-
public static $mustBeAttached = false;
44+
public static bool $mustBeAttached = false;
4545

4646
/**
4747
* Display the extra information for Jamf devices on the main Computer or Phone tab.
@@ -67,7 +67,7 @@ private static function purgeItemCommon(CommonDBTM $item)
6767
/** @var DBmysql $DB */
6868
global $DB;
6969

70-
$jamf_class = static::getJamfItemClassForGLPIItem($item::getType(), $item->getID());
70+
$jamf_class = static::getJamfItemClassForGLPIItem($item::class, $item->getID());
7171
if (!is_string($jamf_class)) {
7272
return;
7373
}
@@ -108,7 +108,7 @@ public static function plugin_jamf_purgePhone(Phone $item)
108108

109109
self::purgeItemCommon($item);
110110
$DB->delete(Item_OperatingSystem::getTable(), [
111-
'itemtype' => $item::getType(),
111+
'itemtype' => $item::class,
112112
'items_id' => $item->getID(),
113113
]);
114114
}
@@ -176,7 +176,7 @@ public static function getJamfItemForGLPIItem(CommonDBTM $item, $limit_to_type =
176176
],
177177
],
178178
'WHERE' => [
179-
'itemtype' => $item::getType(),
179+
'itemtype' => $item::class,
180180
'items_id' => $item->getID(),
181181
],
182182
]);
@@ -256,7 +256,7 @@ public function getExtensionAttributes()
256256
],
257257
],
258258
'WHERE' => [
259-
$item_ext_table . '.itemtype' => static::getType(),
259+
$item_ext_table . '.itemtype' => static::class,
260260
'items_id' => $this->getID(),
261261
],
262262
]);

‎inc/computer.class.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*/
3838
class PluginJamfComputer extends PluginJamfAbstractDevice
3939
{
40-
public static $rightname = 'plugin_jamf_computer';
40+
public static string $rightname = 'plugin_jamf_computer';
4141

4242
public static $jamftype_name = 'Computer';
4343

‎inc/computersync.class.php‎

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ protected function syncOS(): PluginJamfDeviceSync
133133
'operatingsystemversions_id' => $os_version->getID(),
134134
'date_creation' => $_SESSION['glpi_currenttime'],
135135
], [
136-
'itemtype' => $this->item::getType(),
136+
'itemtype' => $this->item::class,
137137
'items_id' => $this->item->getID(),
138138
]);
139139
} catch (Exception) {
@@ -186,11 +186,11 @@ protected function syncSoftware(): PluginJamfDeviceSync
186186
'is_recursive' => $this->item->fields['is_recursive'],
187187
]);
188188
$this->applyDesiredState('Item_SoftwareVersion', [
189-
'itemtype' => $this->item::getType(),
189+
'itemtype' => $this->item::class,
190190
'items_id' => $this->item->getID(),
191191
'softwareversions_id' => $software_version->getID(),
192192
], [
193-
'itemtype' => $this->item::getType(),
193+
'itemtype' => $this->item::class,
194194
'items_id' => $this->item->getID(),
195195
'softwareversions_id' => $software_version->getID(),
196196
'entities_id' => $this->item->fields['entities_id'],
@@ -206,7 +206,7 @@ protected function syncSoftware(): PluginJamfDeviceSync
206206
foreach ($to_remove_software as $to_remove) {
207207
$DB->delete(Item_SoftwareVersion::getTable(), [
208208
SoftwareVersion::getTable() . '.softwares_id' => $to_remove['softwares_id'],
209-
'itemtype' => $this->item::getType(),
209+
'itemtype' => $this->item::class,
210210
'items_id' => $this->item->getID(),
211211
], [
212212
'LEFT JOIN' => [
@@ -294,7 +294,7 @@ protected function syncPurchasing(): PluginJamfDeviceSync
294294
}
295295

296296
$this->db->updateOrInsert(Infocom::getTable(), $infocom_changes, [
297-
'itemtype' => $this->item::getType(),
297+
'itemtype' => $this->item::class,
298298
'items_id' => $this->item->getID(),
299299
]);
300300
} catch (Exception) {
@@ -312,11 +312,11 @@ protected function syncExtensionAttributes(): PluginJamfDeviceSync
312312
{
313313
if (!$this->config['sync_general'] || !isset($this->data['extension_attributes'])) {
314314
$this->status['syncExtensionAttributes'] = self::STATUS_SKIPPED;
315-
316315
return $this;
317-
} elseif ($this->config['sync_general'] && $this->jamfplugin_device === null) {
318-
$this->status['syncExtensionAttributes'] = self::STATUS_DEFERRED;
316+
}
319317

318+
if ($this->jamfplugin_device === null) {
319+
$this->status['syncExtensionAttributes'] = self::STATUS_DEFERRED;
320320
return $this;
321321
}
322322

@@ -336,7 +336,7 @@ protected function syncExtensionAttributes(): PluginJamfDeviceSync
336336
$this->db->updateOrInsert(PluginJamfItem_ExtensionAttribute::getTable(), ['value' => $attr['value']], [
337337
'glpi_plugin_jamf_extensionattributes_id' => $attr_match['id'],
338338
'items_id' => $this->jamfplugin_device->getID(),
339-
'itemtype' => $this->jamfplugin_device::getType(),
339+
'itemtype' => $this->jamfplugin_device::class,
340340
]);
341341
}
342342
}
@@ -398,11 +398,11 @@ protected function syncNetwork(): PluginJamfDeviceSync
398398
'comment' => 'Created by Jamf Plugin for GLPI',
399399
]);
400400
$item_wifi = $this->createOrGetItem('Item_DeviceNetworkCard', [
401-
'itemtype' => $this->item->getType(),
401+
'itemtype' => $this->item::class,
402402
'items_id' => $this->item->getID(),
403403
'devicenetworkcards_id' => $wifi->getID(),
404404
], [
405-
'itemtype' => $this->item->getType(),
405+
'itemtype' => $this->item::class,
406406
'items_id' => $this->item->getID(),
407407
'devicenetworkcards_id' => $wifi->getID(),
408408
'is_dynamic' => 1,
@@ -411,12 +411,12 @@ protected function syncNetwork(): PluginJamfDeviceSync
411411
]);
412412

413413
$netport = $this->createOrGetItem('NetworkPort', [
414-
'itemtype' => $this->item->getType(),
414+
'itemtype' => $this->item::class,
415415
'items_id' => $this->item->getID(),
416416
'instantiation_type' => 'NetworkPortWifi',
417417
'logical_number' => 0,
418418
], [
419-
'itemtype' => $this->item->getType(),
419+
'itemtype' => $this->item::class,
420420
'items_id' => $this->item->getID(),
421421
'instantiation_type' => 'NetworkPortWifi',
422422
'logical_number' => 0,
@@ -442,7 +442,7 @@ protected function syncNetwork(): PluginJamfDeviceSync
442442
'entities_id' => $this->item->fields['entities_id'],
443443
'itemtype' => 'NetworkName',
444444
'items_id' => $network_name->getID(),
445-
'mainitemtype' => $this->item->getType(),
445+
'mainitemtype' => $this->item::class,
446446
'mainitems_id' => $this->item->getID(),
447447
'is_dynamic' => 1,
448448
]);
@@ -451,7 +451,7 @@ protected function syncNetwork(): PluginJamfDeviceSync
451451
'entities_id' => $this->item->fields['entities_id'],
452452
'itemtype' => 'NetworkName',
453453
'items_id' => $network_name->getID(),
454-
'mainitemtype' => $this->item->getType(),
454+
'mainitemtype' => $this->item::class,
455455
'mainitems_id' => $this->item->getID(),
456456
'is_dynamic' => 1,
457457
'name' => $general['ip_address'],
@@ -500,7 +500,7 @@ protected function syncGeneralJamfPluginItem(): PluginJamfDeviceSync
500500
$this->commondevice_changes['enroll_date'] = $enroll_date;
501501
}
502502

503-
$this->commondevice_changes['itemtype'] = $this->item::getType();
503+
$this->commondevice_changes['itemtype'] = $this->item::class;
504504
$this->commondevice_changes['items_id'] = $this->item->getID();
505505
$this->commondevice_changes['jamf_items_id'] = $general['id'];
506506
$this->commondevice_changes['udid'] = $general['udid'];
@@ -538,11 +538,11 @@ protected function syncComponents(): PluginJamfDeviceSync
538538
'is_recursive' => '1',
539539
]);
540540
$this->applyDesiredState('Item_DeviceFirmware', [
541-
'itemtype' => $this->item::getType(),
541+
'itemtype' => $this->item::class,
542542
'items_id' => $this->item->getID(),
543543
'devicefirmwares_id' => $boot_rom->getID(),
544544
], [
545-
'itemtype' => $this->item::getType(),
545+
'itemtype' => $this->item::class,
546546
'items_id' => $this->item->getID(),
547547
'devicefirmwares_id' => $boot_rom->getID(),
548548
'is_deleted' => 0,
@@ -558,12 +558,12 @@ protected function syncComponents(): PluginJamfDeviceSync
558558
foreach ($disk['partitions'] as $partition) {
559559
// Volume
560560
$this->applyDesiredState(Item_Disk::class, [
561-
'itemtype' => $this->item::getType(),
561+
'itemtype' => $this->item::class,
562562
'items_id' => $this->item->getID(),
563563
'mountpoint' => '',
564564
'name' => $partition['name'],
565565
], [
566-
'itemtype' => $this->item::getType(),
566+
'itemtype' => $this->item::class,
567567
'items_id' => $this->item->getID(),
568568
'name' => $partition['name'],
569569
'mountpoint' => '',
@@ -712,7 +712,7 @@ public static function import(string $itemtype, int $jamf_items_id, $use_transac
712712
if ($items_id) {
713713
// Link
714714
$r = $DB->insert('glpi_plugin_jamf_devices', [
715-
'itemtype' => $item::getType(),
715+
'itemtype' => $item::class,
716716
'items_id' => $items_id,
717717
'udid' => $jamf_item['general']['udid'],
718718
'jamf_type' => static::$jamf_itemtype,

‎inc/config.class.php‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@
3636
*/
3737
class PluginJamfConfig extends CommonDBTM
3838
{
39-
protected static $notable = true;
39+
protected static bool $notable = true;
4040

4141
public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
4242
{
43-
if (!$withtemplate && $item::getType() === Config::class) {
44-
return self::createTabEntry(__s("Jamf", "jamf"), 0, $item::getType(), self::getIcon());
43+
if (!$withtemplate && $item::class === Config::class) {
44+
return self::createTabEntry(__s("Jamf", "jamf"), 0, $item::class, self::getIcon());
4545
}
4646

4747
return '';
4848
}
4949

5050
public function showForm($ID = -1, array $options = [])
5151
{
52-
if (!Session::haveRight('config', UPDATE)) {
52+
if (!Session::haveRight(Config::$rightname, UPDATE)) {
5353
return false;
5454
}
5555

@@ -73,7 +73,7 @@ public function showForm($ID = -1, array $options = [])
7373

7474
public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
7575
{
76-
if ($item::getType() === Config::class) {
76+
if ($item::class === Config::class) {
7777
return (new self())->showForm();
7878
}
7979

@@ -95,9 +95,7 @@ public static function undiscloseConfigValue($fields)
9595
public static function getConfig(bool $force_all = false): array
9696
{
9797
static $config = null;
98-
if ($config === null) {
99-
$config = Config::getConfigurationValues('plugin:Jamf');
100-
}
98+
$config ??= Config::getConfigurationValues('plugin:Jamf');
10199

102100
if (!$force_all) {
103101
return self::undiscloseConfigValue($config);

‎inc/connection.class.php‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ public function setConnectionConfig($jssserver, $jssuser, $jsspassword)
9090
public function getServerVersion()
9191
{
9292
static $version = null;
93-
if (is_null($version)) {
94-
$version = PluginJamfAPI::getJamfProVersion();
95-
}
93+
$version ??= PluginJamfAPI::getJamfProVersion();
9694

9795
return $version;
9896
}

0 commit comments

Comments
 (0)