Hello, I have made 3 modifications of structure (Patch 0001 to 0003) with using PHP CONSTANTS to use lib with external program with other folders, etc...
For patch 0004, it's a patch when you use only one criteria (because it return an error but no error in this case) So now, we can use lib in GLPI ;) Enjoy ^^ Best regards, David DURIEUX Tel : +33 (0)4.74.04.81.34 Port : +33 (0)6.34.99.45.18 Mail : [email protected] Site Web : http://www.siprossii.com/ SIPROSSII 847 route de Frans (Créacité) 69400 Villefranche sur Saône FRANCE
>From 55962a66cedf2a20cc6cb146811a2edfe378d35c Mon Sep 17 00:00:00 2001 From: David Durieux <[email protected]> Date: Fri, 20 Aug 2010 21:37:20 +0200 Subject: [PATCH 1/4] Modify log path/filename with global variable --- Classes/Action/InventoryAction.class.php | 2 +- Classes/Action/PingAction.class.php | 2 +- Classes/FusionLibServer.class.php | 2 +- Classes/Logger.class.php | 11 +++++------ Classes/MyException.class.php | 2 +- Classes/Storage/Inventory/DataFilter.class.php | 2 +- .../Inventory/DirectoryStorageInventory.class.php | 2 +- user/main.php | 3 +++ 8 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Classes/Action/InventoryAction.class.php b/Classes/Action/InventoryAction.class.php index 6596d55..5bf5f04 100644 --- a/Classes/Action/InventoryAction.class.php +++ b/Classes/Action/InventoryAction.class.php @@ -89,7 +89,7 @@ class InventoryAction extends Action */ public function startAction($simpleXMLObj) { - $log = new Logger('logs'); + $log = new Logger(); $libData = StorageInventoryFactory::createStorage($this->_applicationName, $this->_config, $simpleXMLObj); diff --git a/Classes/Action/PingAction.class.php b/Classes/Action/PingAction.class.php index 5d70a19..bd4334e 100644 --- a/Classes/Action/PingAction.class.php +++ b/Classes/Action/PingAction.class.php @@ -19,7 +19,7 @@ class PingAction extends Action */ public function startAction($simpleXMLObj) { - $log = new Logger('logs'); + $log = new Logger(); $log->notifyDebugMessage("-- PING ACTION START --"); diff --git a/Classes/FusionLibServer.class.php b/Classes/FusionLibServer.class.php index d2a45b6..e7ddb6e 100644 --- a/Classes/FusionLibServer.class.php +++ b/Classes/FusionLibServer.class.php @@ -84,7 +84,7 @@ class FusionLibServer $simpleXMLObj = simplexml_load_string(@gzuncompress($GLOBALS["HTTP_RAW_POST_DATA"])); //$simpleXMLObj = simplexml_load_file(dirname(__FILE__) ."/../data/aofr.ocs"); - $log = new Logger('logs'); + $log = new Logger(); if($simpleXMLObj->QUERY == "PROLOG") { diff --git a/Classes/Logger.class.php b/Classes/Logger.class.php index c702085..2236144 100644 --- a/Classes/Logger.class.php +++ b/Classes/Logger.class.php @@ -14,17 +14,16 @@ class Logger private $_fileHandle; - public function __construct($fileName) + public function __construct() { - $filePath = dirname(__FILE__)."/../data/logs/"; - if(!file_exists(dirname(__FILE__)."/../data/logs/")) + if(!file_exists(LIBSERVERFUSIONINVENTORY_LOG_FILE)) { - mkdir(dirname(__FILE__)."/../data/logs/",0777,true); + mkdir(LIBSERVERFUSIONINVENTORY_LOG_FILE,0777,true); } - $this->_fileHandle = fopen($filePath.$fileName, "a"); + $this->_fileHandle = fopen(LIBSERVERFUSIONINVENTORY_LOG_FILE, "a"); - if (!is_writable($filePath.$fileName)) + if (!is_writable(LIBSERVERFUSIONINVENTORY_LOG_FILE)) { throw new Exception("$filePath.$fileName isn't writable. Check permissions."); } diff --git a/Classes/MyException.class.php b/Classes/MyException.class.php index 985bb7f..45d2e99 100644 --- a/Classes/MyException.class.php +++ b/Classes/MyException.class.php @@ -4,7 +4,7 @@ class MyException extends Exception { function __construct($msg) { - $log = new Logger('logs'); + $log = new Logger(); $log->notifyExceptionMessage($msg); parent::__construct($msg); } diff --git a/Classes/Storage/Inventory/DataFilter.class.php b/Classes/Storage/Inventory/DataFilter.class.php index 41c5c38..cf2e6ef 100644 --- a/Classes/Storage/Inventory/DataFilter.class.php +++ b/Classes/Storage/Inventory/DataFilter.class.php @@ -14,7 +14,7 @@ class DataFilter */ public static function filter($section) { - $log = new Logger('logs'); + $log = new Logger(); switch($section->getName()) { case 'CONTROLLERS': diff --git a/Classes/Storage/Inventory/DirectoryStorageInventory.class.php b/Classes/Storage/Inventory/DirectoryStorageInventory.class.php index 2eb502c..8905cff 100644 --- a/Classes/Storage/Inventory/DirectoryStorageInventory.class.php +++ b/Classes/Storage/Inventory/DirectoryStorageInventory.class.php @@ -306,7 +306,7 @@ INFOCONTENT; */ public function updateLibMachine($xmlSections, $internalId) { - $log = new Logger('logs'); + $log = new Logger(); // Retrieve all sections stored in info file $iniSections = $this->_getINISections($internalId); diff --git a/user/main.php b/user/main.php index cd89583..2e202de 100644 --- a/user/main.php +++ b/user/main.php @@ -6,6 +6,9 @@ require_once dirname(__FILE__) ."/../Classes/Logger.class.php"; $configs = parse_ini_file(dirname(__FILE__) ."/configs.ini", true); +define("LIBSERVERFUSIONINVENTORY_LOG_FILE",dirname(__FILE__)."/../data/logs"); + + if (file_exists ($path=dirname(__FILE__) ."/applications/{$configs['application']['name']}/FusInvHooks.class.php")) { require_once $path; -- 1.7.1
>From 5d12cf02e7c74559eda34a44f572298e1206619c Mon Sep 17 00:00:00 2001 From: David Durieux <[email protected]> Date: Fri, 20 Aug 2010 22:35:40 +0200 Subject: [PATCH 2/4] Add Constant for Hools classnma because program using this lib can have already Hooks classname --- Classes/Action/InventoryAction.class.php | 3 ++- .../Inventory/DirectoryStorageInventory.class.php | 7 ++++--- user/main.php | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Classes/Action/InventoryAction.class.php b/Classes/Action/InventoryAction.class.php index 5bf5f04..a2c88b0 100644 --- a/Classes/Action/InventoryAction.class.php +++ b/Classes/Action/InventoryAction.class.php @@ -115,7 +115,8 @@ class InventoryAction extends Action $internalId = uniqid(); try { - $externalId = Hooks::createMachine(); + $classhook = LIBSERVERFUSIONINVENTORY_HOOKS_CLASSNAME; + $externalId = $classhook::createMachine(); $libData->addLibMachine($internalId, $externalId); $libData->addLibCriteriasMachine($internalId); diff --git a/Classes/Storage/Inventory/DirectoryStorageInventory.class.php b/Classes/Storage/Inventory/DirectoryStorageInventory.class.php index 8905cff..cb7b908 100644 --- a/Classes/Storage/Inventory/DirectoryStorageInventory.class.php +++ b/Classes/Storage/Inventory/DirectoryStorageInventory.class.php @@ -320,7 +320,7 @@ INFOCONTENT; //Retrieve changes, sections to Add and sections to Remove $sectionsToAdd = array_diff($xmlHashSections, $iniSections["sections"]); $sectionsToRemove = array_diff($iniSections["sections"], $xmlHashSections); - + $classhook = LIBSERVERFUSIONINVENTORY_HOOKS_CLASSNAME; if ($sectionsToRemove) { $sectionsId = array(); @@ -330,7 +330,8 @@ INFOCONTENT; unset($iniSections["sections"][$sectionId]); array_push($sectionsId, $sectionId); } - Hooks::removeSections($sectionsId, $iniSections["externalId"][0]); + + $classhook::removeSections($sectionsId, $iniSections["externalId"][0]); $log->notifyDebugMessage(count($sectionsToRemove)." section(s) removed"); } @@ -348,7 +349,7 @@ INFOCONTENT; } - $sectionsId = Hooks::addSections($data, $iniSections["externalId"][0]); + $sectionsId = $classhook::addSections($data, $iniSections["externalId"][0]); $log->notifyDebugMessage(count($sectionsToAdd)." section(s) added"); diff --git a/user/main.php b/user/main.php index 2e202de..f77fcdf 100644 --- a/user/main.php +++ b/user/main.php @@ -7,7 +7,7 @@ require_once dirname(__FILE__) ."/../Classes/Logger.class.php"; $configs = parse_ini_file(dirname(__FILE__) ."/configs.ini", true); define("LIBSERVERFUSIONINVENTORY_LOG_FILE",dirname(__FILE__)."/../data/logs"); - +define("LIBSERVERFUSIONINVENTORY_HOOKS_CLASSNAME","Hooks"); if (file_exists ($path=dirname(__FILE__) ."/applications/{$configs['application']['name']}/FusInvHooks.class.php")) { -- 1.7.1
>From 41d6b7d60ab41f905957ede389afffe4e755716b Mon Sep 17 00:00:00 2001 From: David Durieux <[email protected]> Date: Fri, 20 Aug 2010 22:46:15 +0200 Subject: [PATCH 3/4] Add STORAGELOCATION in coplete path in a constant --- .../Inventory/DirectoryStorageInventory.class.php | 10 ++++------ user/main.php | 1 + 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Classes/Storage/Inventory/DirectoryStorageInventory.class.php b/Classes/Storage/Inventory/DirectoryStorageInventory.class.php index cb7b908..d3263b6 100644 --- a/Classes/Storage/Inventory/DirectoryStorageInventory.class.php +++ b/Classes/Storage/Inventory/DirectoryStorageInventory.class.php @@ -253,9 +253,8 @@ INFOCONTENT; */ private function _getCriteriaDSN($criteriaName, $criteriaValue) { - $dsn = sprintf('%s/../../../%s/%s/%s/%s/%s', - dirname(__FILE__), - $this->_configs["storageLocation"], + $dsn = sprintf('%s/%s/%s', + LIBSERVERFUSIONINVENTORY_STORAGELOCATION, "criterias", $criteriaName, $this->_applicationName, @@ -270,9 +269,8 @@ INFOCONTENT; */ private function _getInfoPathDSN($internalId) { - $dsn = sprintf('%s/../../../%s/%s/%s', - dirname(__FILE__), - $this->_configs["storageLocation"], + $dsn = sprintf('%s/%s/%s', + LIBSERVERFUSIONINVENTORY_STORAGELOCATION, "machines", $internalId); return $dsn; diff --git a/user/main.php b/user/main.php index f77fcdf..2bfe481 100644 --- a/user/main.php +++ b/user/main.php @@ -7,6 +7,7 @@ require_once dirname(__FILE__) ."/../Classes/Logger.class.php"; $configs = parse_ini_file(dirname(__FILE__) ."/configs.ini", true); define("LIBSERVERFUSIONINVENTORY_LOG_FILE",dirname(__FILE__)."/../data/logs"); +define("LIBSERVERFUSIONINVENTORY_STORAGELOCATION",dirname(__FILE__)."/".$configs['storageLocation']); define("LIBSERVERFUSIONINVENTORY_HOOKS_CLASSNAME","Hooks"); if (file_exists ($path=dirname(__FILE__) ."/applications/{$configs['application']['name']}/FusInvHooks.class.php")) -- 1.7.1
>From 139d3e33c9141f1a6424c5b89e24ff6f262684ae Mon Sep 17 00:00:00 2001 From: David Durieux <[email protected]> Date: Fri, 20 Aug 2010 23:05:52 +0200 Subject: [PATCH 4/4] Fix bug when have only one criteria --- .../Inventory/DirectoryStorageInventory.class.php | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/Classes/Storage/Inventory/DirectoryStorageInventory.class.php b/Classes/Storage/Inventory/DirectoryStorageInventory.class.php index d3263b6..48a4c10 100644 --- a/Classes/Storage/Inventory/DirectoryStorageInventory.class.php +++ b/Classes/Storage/Inventory/DirectoryStorageInventory.class.php @@ -109,6 +109,10 @@ class DirectoryStorageInventory extends StorageInventory } } } + if($falseCriteriaNb == $this->_configs["maxFalse"]) + { + return false; + } if (isset($internalId[2])) { return $internalId[2]; -- 1.7.1
_______________________________________________ Fusioninventory-devel mailing list [email protected] http://lists.alioth.debian.org/mailman/listinfo/fusioninventory-devel
