Skip to content
Merged
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 .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
name: "Generate CI matrix"
uses: "glpi-project/plugin-ci-workflows/.github/workflows/generate-ci-matrix.yml@v1"
with:
glpi-version: "11.0.x"
glpi-version: "12.0.x"
ci:
name: "GLPI ${{ matrix.glpi-version }} - php:${{ matrix.php-version }} - ${{ matrix.db-image }}"
needs: "generate-ci-matrix"
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [UNRELEASED]

### Added

- GLPI 12 compatibility

### Fixed

- Fix mobile devices duplication during mobile sync
Expand Down
2 changes: 1 addition & 1 deletion ajax/cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

Html::header_nocache();

Session::checkRight('config', UPDATE);
Session::checkRight(Config::$rightname, UPDATE);

/** @var DBmysql $DB */
global $DB;
Expand Down
2 changes: 1 addition & 1 deletion front/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

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

Expand Down
6 changes: 2 additions & 4 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function plugin_jamf_getAddSearchOptions($itemtype)
$opt = [];
$plugin = new Plugin();
if ($plugin->isActivated('jamf') && ($itemtype === 'Computer' || $itemtype === 'Phone')) {
$opt = [
return [
'22002' => [
'table' => 'glpi_plugin_jamf_devices',
'field' => 'last_inventory',
Expand Down Expand Up @@ -236,9 +236,7 @@ function plugin_jamf_getAddSearchOptions($itemtype)

function plugin_jamf_dashboardCards($cards = [])
{
if (is_null($cards)) {
$cards = [];
}
$cards ??= [];

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

Expand Down
14 changes: 7 additions & 7 deletions inc/abstractdevice.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
*/
abstract class PluginJamfAbstractDevice extends CommonDBChild
{
public static $itemtype = 'itemtype';
public static string $itemtype = 'itemtype';

public static $items_id = 'items_id';
public static string $items_id = 'items_id';

public static $jamftype_name;

public static $mustBeAttached = false;
public static bool $mustBeAttached = false;

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

$jamf_class = static::getJamfItemClassForGLPIItem($item::getType(), $item->getID());
$jamf_class = static::getJamfItemClassForGLPIItem($item::class, $item->getID());
if (!is_string($jamf_class)) {
return;
}
Expand Down Expand Up @@ -108,7 +108,7 @@ public static function plugin_jamf_purgePhone(Phone $item)

self::purgeItemCommon($item);
$DB->delete(Item_OperatingSystem::getTable(), [
'itemtype' => $item::getType(),
'itemtype' => $item::class,
'items_id' => $item->getID(),
]);
}
Expand Down Expand Up @@ -176,7 +176,7 @@ public static function getJamfItemForGLPIItem(CommonDBTM $item, $limit_to_type =
],
],
'WHERE' => [
'itemtype' => $item::getType(),
'itemtype' => $item::class,
'items_id' => $item->getID(),
],
]);
Expand Down Expand Up @@ -256,7 +256,7 @@ public function getExtensionAttributes()
],
],
'WHERE' => [
$item_ext_table . '.itemtype' => static::getType(),
$item_ext_table . '.itemtype' => static::class,
'items_id' => $this->getID(),
],
]);
Expand Down
2 changes: 1 addition & 1 deletion inc/computer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*/
class PluginJamfComputer extends PluginJamfAbstractDevice
{
public static $rightname = 'plugin_jamf_computer';
public static string $rightname = 'plugin_jamf_computer';

public static $jamftype_name = 'Computer';

Expand Down
42 changes: 21 additions & 21 deletions inc/computersync.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ protected function syncOS(): PluginJamfDeviceSync
'operatingsystemversions_id' => $os_version->getID(),
'date_creation' => $_SESSION['glpi_currenttime'],
], [
'itemtype' => $this->item::getType(),
'itemtype' => $this->item::class,
'items_id' => $this->item->getID(),
]);
} catch (Exception) {
Expand Down Expand Up @@ -186,11 +186,11 @@ protected function syncSoftware(): PluginJamfDeviceSync
'is_recursive' => $this->item->fields['is_recursive'],
]);
$this->applyDesiredState('Item_SoftwareVersion', [
'itemtype' => $this->item::getType(),
'itemtype' => $this->item::class,
'items_id' => $this->item->getID(),
'softwareversions_id' => $software_version->getID(),
], [
'itemtype' => $this->item::getType(),
'itemtype' => $this->item::class,
'items_id' => $this->item->getID(),
'softwareversions_id' => $software_version->getID(),
'entities_id' => $this->item->fields['entities_id'],
Expand All @@ -206,7 +206,7 @@ protected function syncSoftware(): PluginJamfDeviceSync
foreach ($to_remove_software as $to_remove) {
$DB->delete(Item_SoftwareVersion::getTable(), [
SoftwareVersion::getTable() . '.softwares_id' => $to_remove['softwares_id'],
'itemtype' => $this->item::getType(),
'itemtype' => $this->item::class,
'items_id' => $this->item->getID(),
], [
'LEFT JOIN' => [
Expand Down Expand Up @@ -294,7 +294,7 @@ protected function syncPurchasing(): PluginJamfDeviceSync
}

$this->db->updateOrInsert(Infocom::getTable(), $infocom_changes, [
'itemtype' => $this->item::getType(),
'itemtype' => $this->item::class,
'items_id' => $this->item->getID(),
]);
} catch (Exception) {
Expand All @@ -312,11 +312,11 @@ protected function syncExtensionAttributes(): PluginJamfDeviceSync
{
if (!$this->config['sync_general'] || !isset($this->data['extension_attributes'])) {
$this->status['syncExtensionAttributes'] = self::STATUS_SKIPPED;

return $this;
} elseif ($this->config['sync_general'] && $this->jamfplugin_device === null) {
$this->status['syncExtensionAttributes'] = self::STATUS_DEFERRED;
}

if ($this->jamfplugin_device === null) {
$this->status['syncExtensionAttributes'] = self::STATUS_DEFERRED;
return $this;
}

Expand All @@ -336,7 +336,7 @@ protected function syncExtensionAttributes(): PluginJamfDeviceSync
$this->db->updateOrInsert(PluginJamfItem_ExtensionAttribute::getTable(), ['value' => $attr['value']], [
'glpi_plugin_jamf_extensionattributes_id' => $attr_match['id'],
'items_id' => $this->jamfplugin_device->getID(),
'itemtype' => $this->jamfplugin_device::getType(),
'itemtype' => $this->jamfplugin_device::class,
]);
}
}
Expand Down Expand Up @@ -398,11 +398,11 @@ protected function syncNetwork(): PluginJamfDeviceSync
'comment' => 'Created by Jamf Plugin for GLPI',
]);
$item_wifi = $this->createOrGetItem('Item_DeviceNetworkCard', [
'itemtype' => $this->item->getType(),
'itemtype' => $this->item::class,
'items_id' => $this->item->getID(),
'devicenetworkcards_id' => $wifi->getID(),
], [
'itemtype' => $this->item->getType(),
'itemtype' => $this->item::class,
'items_id' => $this->item->getID(),
'devicenetworkcards_id' => $wifi->getID(),
'is_dynamic' => 1,
Expand All @@ -411,12 +411,12 @@ protected function syncNetwork(): PluginJamfDeviceSync
]);

$netport = $this->createOrGetItem('NetworkPort', [
'itemtype' => $this->item->getType(),
'itemtype' => $this->item::class,
'items_id' => $this->item->getID(),
'instantiation_type' => 'NetworkPortWifi',
'logical_number' => 0,
], [
'itemtype' => $this->item->getType(),
'itemtype' => $this->item::class,
'items_id' => $this->item->getID(),
'instantiation_type' => 'NetworkPortWifi',
'logical_number' => 0,
Expand All @@ -442,7 +442,7 @@ protected function syncNetwork(): PluginJamfDeviceSync
'entities_id' => $this->item->fields['entities_id'],
'itemtype' => 'NetworkName',
'items_id' => $network_name->getID(),
'mainitemtype' => $this->item->getType(),
'mainitemtype' => $this->item::class,
'mainitems_id' => $this->item->getID(),
'is_dynamic' => 1,
]);
Expand All @@ -451,7 +451,7 @@ protected function syncNetwork(): PluginJamfDeviceSync
'entities_id' => $this->item->fields['entities_id'],
'itemtype' => 'NetworkName',
'items_id' => $network_name->getID(),
'mainitemtype' => $this->item->getType(),
'mainitemtype' => $this->item::class,
'mainitems_id' => $this->item->getID(),
'is_dynamic' => 1,
'name' => $general['ip_address'],
Expand Down Expand Up @@ -500,7 +500,7 @@ protected function syncGeneralJamfPluginItem(): PluginJamfDeviceSync
$this->commondevice_changes['enroll_date'] = $enroll_date;
}

$this->commondevice_changes['itemtype'] = $this->item::getType();
$this->commondevice_changes['itemtype'] = $this->item::class;
$this->commondevice_changes['items_id'] = $this->item->getID();
$this->commondevice_changes['jamf_items_id'] = $general['id'];
$this->commondevice_changes['udid'] = $general['udid'];
Expand Down Expand Up @@ -538,11 +538,11 @@ protected function syncComponents(): PluginJamfDeviceSync
'is_recursive' => '1',
]);
$this->applyDesiredState('Item_DeviceFirmware', [
'itemtype' => $this->item::getType(),
'itemtype' => $this->item::class,
'items_id' => $this->item->getID(),
'devicefirmwares_id' => $boot_rom->getID(),
], [
'itemtype' => $this->item::getType(),
'itemtype' => $this->item::class,
'items_id' => $this->item->getID(),
'devicefirmwares_id' => $boot_rom->getID(),
'is_deleted' => 0,
Expand All @@ -558,12 +558,12 @@ protected function syncComponents(): PluginJamfDeviceSync
foreach ($disk['partitions'] as $partition) {
// Volume
$this->applyDesiredState(Item_Disk::class, [
'itemtype' => $this->item::getType(),
'itemtype' => $this->item::class,
'items_id' => $this->item->getID(),
'mountpoint' => '',
'name' => $partition['name'],
], [
'itemtype' => $this->item::getType(),
'itemtype' => $this->item::class,
'items_id' => $this->item->getID(),
'name' => $partition['name'],
'mountpoint' => '',
Expand Down Expand Up @@ -712,7 +712,7 @@ public static function import(string $itemtype, int $jamf_items_id, $use_transac
if ($items_id) {
// Link
$r = $DB->insert('glpi_plugin_jamf_devices', [
'itemtype' => $item::getType(),
'itemtype' => $item::class,
'items_id' => $items_id,
'udid' => $jamf_item['general']['udid'],
'jamf_type' => static::$jamf_itemtype,
Expand Down
14 changes: 6 additions & 8 deletions inc/config.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,20 @@
*/
class PluginJamfConfig extends CommonDBTM
{
protected static $notable = true;
protected static bool $notable = true;

public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
{
if (!$withtemplate && $item::getType() === Config::class) {
return self::createTabEntry(__s("Jamf", "jamf"), 0, $item::getType(), self::getIcon());
if (!$withtemplate && $item::class === Config::class) {
return self::createTabEntry(__s("Jamf", "jamf"), 0, $item::class, self::getIcon());
}

return '';
}

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

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

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

Expand All @@ -95,9 +95,7 @@ public static function undiscloseConfigValue($fields)
public static function getConfig(bool $force_all = false): array
{
static $config = null;
if ($config === null) {
$config = Config::getConfigurationValues('plugin:Jamf');
}
$config ??= Config::getConfigurationValues('plugin:Jamf');

if (!$force_all) {
return self::undiscloseConfigValue($config);
Expand Down
4 changes: 1 addition & 3 deletions inc/connection.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ public function setConnectionConfig($jssserver, $jssuser, $jsspassword)
public function getServerVersion()
{
static $version = null;
if (is_null($version)) {
$version = PluginJamfAPI::getJamfProVersion();
}
$version ??= PluginJamfAPI::getJamfProVersion();

return $version;
}
Expand Down
14 changes: 1 addition & 13 deletions inc/dbutil.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,7 @@ public static function dropTableOrDie(string $table, string $message = '')
return true;
}

$res = $DB->doQuery('DROP TABLE' . $DB::quoteName($table));
if (!$res) {
//TRANS: %1$s is the description, %2$s is the query, %3$s is the error message
$message = sprintf(
_x('error', '%1$s - Error during the drop of the table %2$s - Error is %3$s', 'jamf'),
$message,
$table,
$DB->error(),
);
throw new RuntimeException($message);
}

return $res;
return $DB->doQuery('DROP TABLE' . $DB::quoteName($table));
}

public static function truncate($table)
Expand Down
10 changes: 5 additions & 5 deletions inc/devicesync.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,12 @@ protected function finalizeSync()
'id' => $this->item->getID(),
] + $this->item_changes);
foreach ($this->extitem_changes as $key => $value) {
PluginJamfExtField::setValue($this->item::getType(), $this->item->getID(), $key, $value);
PluginJamfExtField::setValue($this->item::class, $this->item->getID(), $key, $value);
}

// Update or Add Jamf Item
$this->db->updateOrInsert('glpi_plugin_jamf_devices', $this->commondevice_changes, [
'itemtype' => $this->item::getType(),
'itemtype' => $this->item::class,
'items_id' => $this->item->getID(),
]);
$device_id = -1;
Expand All @@ -328,7 +328,7 @@ protected function finalizeSync()
'SELECT' => ['id'],
'FROM' => 'glpi_plugin_jamf_devices',
'WHERE' => [
'itemtype' => $this->item::getType(),
'itemtype' => $this->item::class,
'items_id' => $this->item->getID(),
],
]);
Expand All @@ -340,7 +340,7 @@ protected function finalizeSync()
'glpi_plugin_jamf_devices_id' => $device_id,
]);

if ($this->jamfplugin_device === null || empty($this->jamfplugin_device->fields)) {
if ($this->jamfplugin_device === null || $this->jamfplugin_device->fields === []) {

if (!is_a(static::$jamfplugin_itemtype, CommonDBTM::class, true)) {
throw new RuntimeException('Invalid jamfplugin_itemtype: ' . static::$jamfplugin_itemtype);
Expand All @@ -351,7 +351,7 @@ protected function finalizeSync()
'SELECT' => ['id'],
'FROM' => static::$jamfplugin_itemtype::getTable(),
'WHERE' => [
'itemtype' => $this->item::getType(),
'itemtype' => $this->item::class,
'items_id' => $this->item->getID(),
],
'LEFT JOIN' => [
Expand Down
Loading
Loading