From 6268e218da6cf856b03ad1caf76239f5cb81d3b2 Mon Sep 17 00:00:00 2001 From: Stanislas Kita Date: Fri, 22 May 2026 14:50:16 +0200 Subject: [PATCH 1/3] Feat(Core): add collection scope --- inc/config.class.php | 14 ++++++++++++++ inc/sccm.class.php | 25 +++++++++++++++++++++---- templates/config.html.twig | 7 +++++++ 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/inc/config.class.php b/inc/config.class.php index b3fc832..4439ba7 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -106,6 +106,14 @@ public function rawSearchOptions(): array 'datatype' => 'string', ]; + $options[] = [ + 'id' => 8, + 'table' => $this->getTable(), + 'field' => 'sccm_collection_name', + 'name' => __('Collection name', 'sccm'), + 'datatype' => 'string', + ]; + $options[] = [ 'id' => 6, 'table' => $this->getTable(), @@ -205,6 +213,7 @@ public static function install(Migration $migration): bool `sccmdb_dbname` VARCHAR(255) NULL, `sccmdb_user` VARCHAR(255) NULL, `sccmdb_password` VARCHAR(255) NULL, + `sccm_collection_name` VARCHAR(255) NULL, `inventory_server_url` VARCHAR(255) NULL, `active_sync` tinyint NOT NULL DEFAULT '0', `verify_ssl_cert` tinyint NOT NULL DEFAULT '0', @@ -289,6 +298,11 @@ public static function install(Migration $migration): bool $migration->migrationOneTable($table); } + if (!$DB->fieldExists($table, 'sccm_collection_name')) { + $migration->addField($table, 'sccm_collection_name', 'string', ['after' => 'sccmdb_password', 'value' => '']); + $migration->migrationOneTable($table); + } + if (!$DB->fieldExists($table, 'use_lasthwscan')) { $migration->addField($table, "use_lasthwscan", "tinyint NOT NULL default '0'"); $migration->migrationOneTable($table); diff --git a/inc/sccm.class.php b/inc/sccm.class.php index 24633b6..6477e35 100644 --- a/inc/sccm.class.php +++ b/inc/sccm.class.php @@ -75,7 +75,11 @@ public function getDevices(int $config_id, $where = 0, $limit = 99999999): void ); } - $query = self::getcomputerQuery(); + $config = new PluginSccmConfig(); + $config->getFromDB($config_id); + $collection_name = (string) ($config->getField('sccm_collection_name') ?? ''); + + $query = self::getcomputerQuery($collection_name); if ($where != 0) { $query .= " WHERE csd.MachineID = '" . $where . "'"; @@ -504,9 +508,9 @@ public static function executeCollect($task): int return $retcode; } - public static function getcomputerQuery(): string + public static function getcomputerQuery(string $collection_name = ''): string { - return "SELECT csd.Description00 as \"CSD-Description\", + $query = "SELECT csd.Description00 as \"CSD-Description\", csd.Domain00 as \"CSD-Domain\", csd.Manufacturer00 as \"CSD-Manufacturer\", csd.Model00 as \"CSD-Model\", @@ -549,6 +553,18 @@ public static function getcomputerQuery(): string LEFT JOIN System_DATA sd ON csd.MachineID = sd.MachineID INNER JOIN v_R_System VrS ON csd.MachineID = VrS.ResourceID WHERE csd.MachineID is not null and csd.MachineID != ''"; + + if ($collection_name !== '') { + $safe_name = str_replace("'", "''", $collection_name); + $query .= " AND csd.MachineID IN ( + SELECT fcm.ResourceID + FROM v_FullCollectionMembership fcm + INNER JOIN v_Collection vc ON fcm.CollectionID = vc.CollectionID + WHERE vc.Name = N'{$safe_name}' + )"; + } + + return $query; } public static function executePush(CronTask $task): int @@ -588,8 +604,9 @@ public static function executePush(CronTask $task): int $config = new PluginSccmConfig(); $config->getFromDB($config_id); + $collection_name = (string) ($config->getField('sccm_collection_name') ?? ''); - $query = self::getcomputerQuery(); + $query = self::getcomputerQuery($collection_name); $result = $PluginSccmSccmdb->exec_query($query); while ($tab = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) { diff --git a/templates/config.html.twig b/templates/config.html.twig index 4ac5b0e..b415b0b 100644 --- a/templates/config.html.twig +++ b/templates/config.html.twig @@ -63,6 +63,13 @@ {'autocomplete': 'off'} ) }} + {{ fields.textField( + 'sccm_collection_name', + item.fields['sccm_collection_name'], + __('Collection name', 'sccm'), + {'helper': __('Leave empty to collect all devices', 'sccm')} + ) }} + {% set alert %} {{ url }} {% endset %} From ba59d3b5e04bf6adf794276196387ee186bc66b1 Mon Sep 17 00:00:00 2001 From: Stanislas Kita Date: Fri, 22 May 2026 14:50:40 +0200 Subject: [PATCH 2/3] adapt CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8d495d..ad9140c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Added - Handle multiple SCCM configuration +- Add `collection` scope + ## [2.5.1] - 2025-10-07 From 936488d754fecf989d1091ee0d3d77ec750ab65e Mon Sep 17 00:00:00 2001 From: Stanislas Kita Date: Fri, 22 May 2026 14:58:59 +0200 Subject: [PATCH 3/3] Fix CI --- inc/sccm.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/inc/sccm.class.php b/inc/sccm.class.php index 6477e35..7246c4c 100644 --- a/inc/sccm.class.php +++ b/inc/sccm.class.php @@ -77,6 +77,7 @@ public function getDevices(int $config_id, $where = 0, $limit = 99999999): void $config = new PluginSccmConfig(); $config->getFromDB($config_id); + $collection_name = (string) ($config->getField('sccm_collection_name') ?? ''); $query = self::getcomputerQuery($collection_name);