@@ -50,6 +50,10 @@ static function canView() {
5050 return Session::haveRight ('config ' , UPDATE );
5151 }
5252
53+ static function canPurge () {
54+ return Session::haveRight ('config ' , UPDATE );
55+ }
56+
5357 static function getTypeName ($ nb = 0 ) {
5458 return __ ("SCCM " , "sccm " );
5559 }
@@ -130,29 +134,15 @@ function getAllConfigurations() {
130134 return getAllDataFromTable (self ::getTable ());
131135 }
132136
133- function loadFirstConfiguration () {
134- $ configurations = $ this ->getAllConfigurations ();
135- if (empty ($ configurations )) {
136- return false ;
137- }
138- $ this ->getFromDB (array_values ($ configurations )[0 ]['id ' ]);
139-
140- return true ;
137+ public function prepareInputForUpdate ($ input ) {
138+ return self ::handleInput ($ input );
141139 }
142140
143- function prepareInputForUpdate ($ input ) {
144- if (isset ($ input ["sccmdb_password " ]) AND !empty ($ input ["sccmdb_password " ])) {
145- $ input ["sccmdb_password " ] = (new GLPIKey ())->encrypt ($ input ["sccmdb_password " ]);
146- }
147-
148- if (array_key_exists ('inventory_server_url ' , $ input ) && !empty ($ input ['inventory_server_url ' ])) {
149- $ input ['inventory_server_url ' ] = trim ($ input ['inventory_server_url ' ], '/ ' );
150- }
151-
152- return $ input ;
141+ public function prepareInputForAdd ($ input ) {
142+ return self ::handleInput ($ input );
153143 }
154144
155- function prepareInputForAdd ($ input ) {
145+ public static function handleInput ($ input ) {
156146 if (isset ($ input ["sccmdb_password " ]) AND !empty ($ input ["sccmdb_password " ])) {
157147 $ input ["sccmdb_password " ] = (new GLPIKey ())->encrypt ($ input ["sccmdb_password " ]);
158148 }
@@ -167,10 +157,8 @@ function prepareInputForAdd($input) {
167157 static function isIdAutoIncrement ()
168158 {
169159 global $ DB ;
170-
171160 $ columns = $ DB ->query ("SHOW COLUMNS FROM glpi_plugin_sccm_configs WHERE FIELD = 'id' " );
172161 $ data = $ columns ->fetch_assoc ();
173- Toolbox::logInFile ('sccm ' , "Auto increment ... " . $ data ["Extra " ] . " \n" , true );
174162 return str_contains ($ data ["Extra " ], "auto_increment " );
175163 }
176164
@@ -181,12 +169,12 @@ static function install(Migration $migration) {
181169 $ default_collation = DBConnection::getDefaultCollation ();
182170 $ default_key_sign = DBConnection::getDefaultPrimaryKeySignOption ();
183171
184- $ table = 'glpi_plugin_sccm_configs ' ;
185- Toolbox::logInFile ('sccm ' , "Installing ... \n" , true );
172+ $ table = self ::getTable ();
186173
187174 if (!$ DB ->tableExists ($ table )) {
188175
189- Toolbox::logInFile ('sccm ' , "Table not exists, creating ... \n" , true );
176+ $ migration ->displayMessage ("Installing SCCM plugin ... " );
177+ $ migration ->displayMessage ("Table not exists, creating ... " );
190178
191179 $ query = "CREATE TABLE ` " . $ table ."`(
192180 `id` int {$ default_key_sign } NOT NULL AUTO_INCREMENT,
@@ -210,34 +198,32 @@ static function install(Migration $migration) {
210198 PRIMARY KEY (`id`)
211199 ) ENGINE=InnoDB DEFAULT CHARSET= {$ default_charset } COLLATE= {$ default_collation } ROW_FORMAT=DYNAMIC; " ;
212200
213- $ DB ->queryOrDie ($ query , __ ("Error when using glpi_plugin_sccm_configs table. " , "sccm " )
214- . "<br /> " .$ DB ->error ());
215-
216- $ query = "INSERT INTO ` $ table`
217- (date_mod, sccmdb_host, sccmdb_dbname,
218- sccmdb_user, sccmdb_password, inventory_server_url)
219- VALUES (NOW(), 'srv_sccm','bdd_sccm','user_sccm','',
220- NULL) " ;
201+ $ DB ->queryOrDie ($ query , $ DB ->error ());
221202
222- $ DB -> queryOrDie ( $ query , __ ( " Error when using glpi_plugin_sccm_configs table. " , " sccm " )
223- . " <br /> " . $ DB -> error () );
203+ // Update display preferences
204+ $ migration -> updateDisplayPrefs ([PluginSccmConfig::class => [ 1 , 2 , 3 , 4 , 5 , 6 ]] );
224205
225206 } else {
226- if (!self ::isIdAutoIncrement ())
227- {
228- Toolbox::logInFile ('sccm ' , "Changing to Auto increment ... \n" , true );
207+
208+ $ migration ->displayMessage ("Updating SCCM plugin ... " );
209+
210+ // Need to move ID column to auto increment.
211+ if (!self ::isIdAutoIncrement ()) {
229212 $ migration ->changeField ("glpi_plugin_sccm_configs " , "id " , "id " , "autoincrement " );
230213 $ migration ->migrationOneTable ('glpi_plugin_sccm_configs ' );
214+ // Update display preferences
215+ $ migration ->updateDisplayPrefs ([PluginSccmConfig::class => [1 , 2 , 3 , 4 , 5 , 6 ]]);
231216 }
217+
232218 if (!$ DB ->fieldExists ($ table , 'sccm_config_name ' )) {
233219 $ migration ->addField ("glpi_plugin_sccm_configs " , "sccm_config_name " , "VARCHAR(255) " );
234220 $ migration ->migrationOneTable ('glpi_plugin_sccm_configs ' );
235- }
221+ }
236222
237223 if (!$ DB ->fieldExists ($ table , 'sccm_collection_name ' )) {
238224 $ migration ->addField ("glpi_plugin_sccm_configs " , "sccm_collection_name " , "VARCHAR(255) " );
239225 $ migration ->migrationOneTable ('glpi_plugin_sccm_configs ' );
240- }
226+ }
241227
242228 if (!$ DB ->fieldExists ($ table , 'verify_ssl_cert ' )) {
243229 $ migration ->addField ("glpi_plugin_sccm_configs " , "verify_ssl_cert " , "tinyint NOT NULL default '0' " );
@@ -327,21 +313,23 @@ static function install(Migration $migration) {
327313 ]
328314 );
329315 }
316+
330317 }
331318
332319 return true ;
333320 }
334321
335-
336322 static function uninstall () {
323+ /** @var \DBmysql $DB */
337324 global $ DB ;
338-
339- if ($ DB ->tableExists ('glpi_plugin_sccm_configs ' )) {
340-
341- $ query = "DROP TABLE `glpi_plugin_sccm_configs` " ;
342- $ DB ->queryOrDie ($ query , $ DB ->error ());
325+ $ table = self ::getTable ();
326+ if ($ DB ->tableExists ($ table )) {
327+ $ DB ->queryOrDie ("DROP TABLE IF EXISTS ` " . self ::getTable () . "` " ) or die ($ DB ->error ());
328+ $ displayPref = new DisplayPreference ();
329+ foreach ($ displayPref ->find (['itemtype ' => PluginSccmConfig::class]) as $ pref ) {
330+ $ displayPref ->delete ($ pref );
331+ }
343332 }
344- return true ;
345333 }
346334
347335 static function searchUrl () {
@@ -363,7 +351,7 @@ function showForm($ID, $options = []) {
363351
364352 if (!$ this ->getFromDB ($ ID )) {
365353 $ this ->getEmpty ();
366- }
354+ }
367355
368356 $ this ->initForm ($ ID , $ options );
369357 $ this ->showFormHeader ($ options );
@@ -451,13 +439,10 @@ function showForm($ID, $options = []) {
451439 echo "</td></tr> \n" ;
452440
453441 $ this ->showFormButtons ($ options );
454- //$this->showFormButtons(['candel'=>false]);
455-
456442 return false ;
457443 }
458444
459- static function canPurge () {
460- return Session:: haveRight ( ' config ' , UPDATE ) ;
445+ public static function getIcon () {
446+ return " fa-solid fa-dice-d20 " ;
461447 }
462-
463448}
0 commit comments