11<?php
2+
23/*
34 * @version $Id: HEADER 15930 2011-10-30 15:47:55Z tsmr $
45 -------------------------------------------------------------------------
3435use GlpiPlugin \Ocsinventoryng \Server ;
3536use GlpiPlugin \Ocsinventoryng \Thread ;
3637
38+ define ("GLPI_DIR_ROOT " , "../../../.. " );
39+ require_once GLPI_DIR_ROOT . '/src/Glpi/Application/ResourcesChecker.php ' ;
40+ (new \Glpi \Application \ResourcesChecker (GLPI_DIR_ROOT ))->checkResources ();
41+
42+ include GLPI_DIR_ROOT . '/vendor/autoload.php ' ;
43+ $ kernel = new \Glpi \Kernel \Kernel ($ options ['env ' ] ?? null );
44+ $ application = new \Glpi \Console \Application ($ kernel );
45+
3746set_time_limit (0 );
3847ini_set ('mysql.connect_timeout ' , '0 ' );
3948ini_set ("memory_limit " , "-1 " );
5564 }
5665}
5766
58- // Can't run on MySQL replicate
59- $ USEDBREPLICATE = 0 ;
60- $ DBCONNECTION_REQUIRED = 1 ;
61-
62- // MASS IMPORT for OCSNG
63-
64-
6567$ _SESSION ["glpicronuserrunning " ] = $ _SESSION ["glpiname " ] = 'ocsinventoryng ' ;
6668// Check PHP Version - sometime (debian) cli version != module version
6769if (phpversion () < "5 " ) {
8284$ thread_nbr = '' ;
8385$ threadid = '' ;
8486$ ocsservers_id = -1 ;
85- $ fields = array () ;
87+ $ fields = [] ;
8688
8789//Get script configuration
8890$ config = new Config ();
@@ -218,11 +220,11 @@ function FirstPass($ocsservers_id)
218220 $ ocsClient = OcsServer::getDBocs ($ ocsservers_id );
219221
220222 // Compute lastest new computer
221- $ ocsResult = $ ocsClient ->getComputers (array (
222- 'COMPLETE ' => '0 ' ,
223- 'MAX_RECORDS ' => 1 ,
224- 'ORDER ' => 'ID DESC ' ,
225- ) );
223+ $ ocsResult = $ ocsClient ->getComputers ([
224+ 'COMPLETE ' => '0 ' ,
225+ 'MAX_RECORDS ' => 1 ,
226+ 'ORDER ' => 'ID DESC ' ,
227+ ] );
226228
227229 if (count ($ ocsResult ['COMPUTERS ' ])) {
228230 $ max_id = key ($ ocsResult ['COMPUTERS ' ]);
@@ -345,15 +347,15 @@ function plugin_ocsinventoryng_importFromOcsServer(
345347
346348 $ ocsServerId = $ cfg_ocs ['id ' ];
347349 $ ocsClient = OcsServer::getDBocs ($ ocsServerId );
348- $ ocsComputers = array () ;
350+ $ ocsComputers = [] ;
349351
350352 // Build common options
351353 //$inventoriedBefore = new DateTime('@'.(time() - 180));
352354
353- $ computerOptions = array (
354- 'COMPLETE ' => '0 ' ,
355- 'ORDER ' => 'LASTDATE ' ,
356- ) ;
355+ $ computerOptions = [
356+ 'COMPLETE ' => '0 ' ,
357+ 'ORDER ' => 'LASTDATE ' ,
358+ ] ;
357359
358360 // Limit the number of imported records according to config
359361 if ($ config ->fields ["import_limit " ] > 0 ) {
@@ -372,7 +374,7 @@ function plugin_ocsinventoryng_importFromOcsServer(
372374 // Get newly inventoried computers
373375 $ firstQueryOptions = $ computerOptions ;
374376 // if ($server->fields["max_glpidate"] != '0000-00-00 00:00:00') {
375- // $firstQueryOptions['FILTER']['INVENTORIED_BEFORE'] = $server->fields["max_glpidate"];
377+ // $firstQueryOptions['FILTER']['INVENTORIED_BEFORE'] = $server->fields["max_glpidate"];
376378 // }
377379
378380 $ firstQueryOptions ['FILTER ' ]['CHECKSUM ' ] = intval ($ cfg_ocs ["checksum " ]);
@@ -386,17 +388,17 @@ function plugin_ocsinventoryng_importFromOcsServer(
386388 // Some conditions can't be sent to OCS, so we have to do this in a loop
387389 // Maybe add this to SOAP ?
388390 // if (isset($ocsResult['COMPUTERS'])) {
389- // $excludeIds = array();
390- // foreach ($ocsResult['COMPUTERS'] as $ID => $computer) {
391- // if ($ID <= intval($server->fields["max_ocsid"]) and (!$multiThread or ($ID % $thread_nbr) == ($threadid - 1))) {
392- // $ocsComputers[$ID] = $computer;
393- // }
394- // $excludeIds [] = $ID;
395- // }
396- //
397- // $secondQueryOptions['FILTER']['EXCLUDE_IDS'] = $excludeIds;
391+ // $excludeIds = array();
392+ // foreach ($ocsResult['COMPUTERS'] as $ID => $computer) {
393+ // if ($ID <= intval($server->fields["max_ocsid"]) and (!$multiThread or ($ID % $thread_nbr) == ($threadid - 1))) {
394+ // $ocsComputers[$ID] = $computer;
395+ // }
396+ // $excludeIds [] = $ID;
397+ // }
398+ //
399+ // $secondQueryOptions['FILTER']['EXCLUDE_IDS'] = $excludeIds;
398400 // }
399- //
401+ //
400402 // $secondQueryOptions['FILTER']['CHECKSUM'] = intval($cfg_ocs["checksum"]);
401403
402404 // $ocsResult = $ocsClient->getComputers($secondQueryOptions);
@@ -461,9 +463,9 @@ function plugin_ocsinventoryng_importFromOcsServer(
461463 echo ". " ;
462464 $ entities_id = 0 ;
463465 $ process_params = ['ocsid ' => $ ID ,
464- 'plugin_ocsinventoryng_ocsservers_id ' => $ ocsServerId ,
465- 'lock ' => 1 ,
466- 'force ' => 1 ];
466+ 'plugin_ocsinventoryng_ocsservers_id ' => $ ocsServerId ,
467+ 'lock ' => 1 ,
468+ 'force ' => 1 ];
467469
468470 $ action = OcsProcess::processComputer ($ process_params );
469471 OcsProcess::manageImportStatistics ($ fields , $ action ['status ' ]);
0 commit comments