<commit_before><?php

/*
   ----------------------------------------------------------------------
   FusionInventory
   Copyright (C) 2010-2011 by the FusionInventory Development Team.

   http://www.fusioninventory.org/   http://forge.fusioninventory.org/
   ----------------------------------------------------------------------

   LICENSE

   This file is part of FusionInventory.

   FusionInventory is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 2 of the License, or
   any later version.

   FusionInventory is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with FusionInventory.  If not, see <http://www.gnu.org/licenses/>.

   ------------------------------------------------------------------------
   Original Author of file: <NAME>
   Co-authors of file:
   Purpose of file:
   ----------------------------------------------------------------------
 */

if (!defined('GLPI_ROOT')) {
	die("Sorry. You can't access directly to this file");
}

class PluginFusinvinventoryLib extends CommonDBTM {

   var $table = "glpi_plugin_fusinvinventory_libserialization";


   /**
   * Sarting create or update computer and get Entity
   *
   * @param $simpleXMLObj simplexml xmlobject of the computer
   * @param $items_id interger id of the computer
   * @param $new bool if 1 create a new computer
   *
   * @return nothing
   *
   **/
   function startAction($simpleXMLObj, $items_id, $new=0) {
      global $DB;

      $xml = simplexml_load_string($_SESSION['SOURCEXML'],'SimpleXMLElement', LIBXML_NOCDATA);
      
      if ($new == "0") {
         // Transfer if entity is different
         $Computer = new Computer();
         $Computer->getFromDB($items_id);
         $input = array();
         $input['id'] = $Computer->fields['id'];
         $input['autoupdatesystems_id'] = Dropdown::importExternal('AutoUpdateSystem', 'FusionInventory');
         $_SESSION['glpiactiveentities_string'] = $Computer->fields['entities_id'];
         $input['is_ocs_import'] = 0;
         $Computer->update($input);
         if ($_SESSION["plugin_fusinvinventory_entity"] == NOT_AVAILABLE) {
            $_SESSION["plugin_fusinvinventory_entity"] = $Computer->fields['entities_id'];
         }
         $PluginFusioninventoryConfig = new PluginFusioninventoryConfig();
         if ($Computer->getEntityID() != $_SESSION["plugin_fusinvinventory_entity"]) {
            $Transfer = new Transfer();
            // get value in Config ($config['transfers_id_auto'])
            $Transfer->getFromDB(
                $PluginFusioninventoryConfig->getValue($_SESSION["plugin_fusinvinventory_moduleid"],
                                                       'transfers_id_auto'));

            $item_to_transfer = array("Computer" => array($items_id=>$items_id));

            $Transfer->moveItems($item_to_transfer, $_SESSION["plugin_fusinvinventory_entity"], 
                                 $Transfer->fields);
         }

      //if ($internalId = $this->isMachineExist()) {
         // Get internal ID with $items_id
         $a_serialized = array();
         $query = "SELECT * FROM `glpi_plugin_fusinvinventory_libserialization`
                   WHERE `computers_id`='".$items_id."'
                   LIMIT 1";
         $result = $DB->query($query);
         if ($result) {
            if ($DB->numrows($result) == '1') {
               $a_serialized = $DB->fetch_assoc($result);
            }
         }
         $internalId = uniqid();
         if (isset($a_serialized['internal_id'])) {
            $internalId = $a_serialized['internal_id'];
         } else {
            // Importer les donnes de GLPI dans le xml
            $PluginFusinvinventoryInventory = new PluginFusinvinventoryInventory();
            $PluginFusinvinventoryInventory->createMachineInLib($items_id, $internalId);
         }

         // Link computer to agent FusionInventory
         $PluginFusioninventoryAgent = new PluginFusioninventoryAgent();
         $PluginFusioninventoryAgent->setAgentWithComputerid($items_id, addslashes_deep($xml->DEVICEID));

         // Transfer agent entity
         $PluginFusioninventoryAgent = new PluginFusioninventoryAgent();
         $agent_id = $PluginFusioninventoryAgent->getAgentWithComputerid($items_id);
         if ($agent_id) {
            $PluginFusioninventoryAgent->getFromDB($agent_id);
            if ($PluginFusioninventoryAgent->getEntityID() != $_SESSION["plugin_fusinvinventory_entity"]) {
               $input = array();
               $input['id'] = $PluginFusioninventoryAgent->fields['id'];
               $input['entities_id'] = $_SESSION["plugin_fusinvinventory_entity"];
               $PluginFusioninventoryAgent->update($input);
            }
         }

         //Sections update
         $xmlSections = $this->_getXMLSections($simpleXMLObj);
         $this->updateLibMachine($xmlSections, $internalId);
         
         $PluginFusinvinventoryLibhook = new PluginFusinvinventoryLibhook();
         $PluginFusinvinventoryLibhook->writeXMLFusion($items_id);
      } else {
         // New Computer
         if ($_SESSION["plugin_fusinvinventory_entity"] == NOT_AVAILABLE) {
            $_SESSION["plugin_fusinvinventory_entity"] = 0;
         }

         //We launch CreateMachine() hook and provide an InternalId
         $xmlSections = $this->_getXMLSections($simpleXMLObj);
         $internalId = uniqid();

         try {
            $PluginFusinvinventoryLibhook = new PluginFusinvinventoryLibhook();
            $PluginFusinvinventoryLibhook->createMachine($items_id);
            
            // Link computer to agent FusionInventory
            $PluginFusioninventoryAgent = new PluginFusioninventoryAgent();
            $PluginFusioninventoryAgent->setAgentWithComputerid($items_id, $xml->DEVICEID);

            // Link computer to agent FusionInventory
            $PluginFusioninventoryAgent = new PluginFusioninventoryAgent();
            $PluginFusioninventoryAgent->setAgentWithComputerid($items_id, addslashes_deep($xml->DEVICEID));

            // Transfer agent entity
            $PluginFusioninventoryAgent = new PluginFusioninventoryAgent();
            $agent_id = $PluginFusioninventoryAgent->getAgentWithComputerid($items_id);
            if ($agent_id) {
               $PluginFusioninventoryAgent->getFromDB($agent_id);
               if ($PluginFusioninventoryAgent->getEntityID() 
                     != $_SESSION["plugin_fusinvinventory_entity"]) {
                  $PluginFusioninventoryAgent->fields['entities_id'] 
                     = $_SESSION["plugin_fusinvinventory_entity"];
                  $PluginFusioninventoryAgent->update($PluginFusioninventoryAgent->fields);
               }
            }

            $this->addLibMachine($internalId, $items_id);

            $this->updateLibMachine($xmlSections, $internalId);

         } catch (MyException $e) {
             // $log->error('created machine stage: error');
         }
      }
   }


   
   /**
   * get all sections and convert to php array
   *
   * @param $simpleXMLObj simplexml XML object of the computer
   *
   * @return array XML sections into an array
   *
   **/
   private function _getXMLSections($simpleXMLObj) {

      $xmlSections = array();
      $PluginFusinvinventoryLibfilter = new PluginFusinvinventoryLibfilter();

      $sectionsToFilter = array();
      array_push ($sectionsToFilter,
      'USBDEVICES',
      'CONTROLLERS',
      'NETWORKS');

      foreach($simpleXMLObj->CONTENT->children() as $section) {

         if(in_array($section->getName(), $sectionsToFilter)) {
            $nofilter = $PluginFusinvinventoryLibfilter->filter($section);
            //if the folder for the filter doesn't exist, delete this element from array.
            if($nofilter){
               foreach($sectionsToFilter as $fKey => $fValue) {
                  if ($fValue == $nofilter) {
                     unset($sectionsToFilter[$fKey]);
                  }
               }
            }
         }

         $sectionData = array();
         foreach ($section->children() as $data) {
            if ($section->getName() == "VIRTUALMACHINES"
                    AND $data->getName() == "COMMENT") {
               $sectionData[$data->getName()] = addslashes_deep((string)$data);
            } else {
               $sectionData[$data->getName()] = (string)$data;
            }
         }

         //sectionId initialization, we will affect id after hook createSection return value.
         $serializedSectionData = serialize($sectionData);
         array_push($xmlSections, 
                    array("sectionId"        => 0,
                          "sectionName"      => $section->getName(),
                          "sectionDatawName" => $serializedSectionData.$section->getName(),
                          "sectionData"      => $serializedSectionData));
      }
      return $xmlSections;
   }



   /**
   * Create computer into lib
   *
   * @param $internalId value uniq id for internal lib
   * @param $externalId integer id of the GLPI computer
   *
   * @return nothing
   *
   */
   public function addLibMachine($internalId, $externalId) {

      $queryInsert = "INSERT INTO `glpi_plugin_fusinvinventory_libserialization` 
                      ( `internal_id` , `computers_id`)
                      VALUES ('" . $internalId . "' , '".$externalId."')";
      mysql_query($queryInsert);
  }




   /**
   * Determine if there are sections changements and update
   * Definition of the existant criteria in each section to known
   * if can be update or if it's a new section
   *
   * @param $xmlSections array XML sections in a php array
   * @param $internalId value uniq id of internal lib
   *
   * @return nothing
   *
   */
   public function updateLibMachine($xmlSections, $internalId) {
      global $DB;

      $a_sections   = array();
      $a_sections[] = "DRIVES";
      $a_sections[] = "SOFTWARES";
      $a_sections[] = "CONTROLLERS";
      $a_sections[] = "ENVS";
      $a_sections[] = "INPUTS";
      $a_sections[] = "MEMORIES";
      $a_sections[] = "MONITORS";
      $a_sections[] = "NETWORKS";
      $a_sections[] = "PORTS";
      $a_sections[] = "PRINTERS";
      $a_sections[] = "PROCESSES";
      $a_sections[] = "SOUNDS";
      $a_sections[] = "STORAGES";
      $a_sections[] = "USERS";
      $a_sections[] = "VIDEOS";
      $a_sections[] = "USBDEVICES";
      $a_sections[] = "VIRTUALMACHINES";
      $a_sections[] = "CPUS";
      $a_sections[] = "ANTIVIRUS";

      // Retrieve all sections stored in info file
      $infoSections = $this->_getInfoSections($internalId);
      // Retrieve all sections from xml file
      $serializedSectionsFromXML = array();
      
      foreach($xmlSections as $xmlSection) {
         array_push($serializedSectionsFromXML, $xmlSection["sectionDatawName"]);
      }
      //Retrieve changes, sections to Add and sections to Remove
      $sectionsToAdd    = array_diff($serializedSectionsFromXML, $infoSections["sections"]);
      $sectionsToRemove = array_diff($infoSections["sections"], $serializedSectionsFromXML);

      $classhook = "PluginFusinvinventoryLibhook";

      //updated section: process
      if($sectionsToRemove && $sectionsToAdd) {
         $datasToUpdate = array();
         $existUpdate = 0;
         foreach($sectionsToRemove as $sectionId => $serializedSectionToRemove) {
            $sectionName=substr(strrchr($infoSections["sections"][$sectionId], "}"), 1 );
            
            if (in_array($sectionName, $a_sections)) {
               foreach($sectionsToAdd as $arrayId => $serializedSectionToAdd) {
                  //check if we have the same section Name for an sectionToRemove and an sectionToAdd
                  if($xmlSections[$arrayId]['sectionName'] == $sectionName) {
                     //Finally, we have to determine if it's an update or not
                     $boolUpdate = false;
                     if (!unserialize($serializedSectionToAdd)) {
                        //logInFile('serialise', $serializedSectionToAdd);
                     }
                     $arrSectionToAdd = unserialize($serializedSectionToAdd);
                     if (!unserialize($serializedSectionToRemove)) {
                        //logInFile('serialise', $serializedSectionToRemove);
                     }
                     $arrSectionToRemove = unserialize($serializedSectionToRemove);
                     
                     //TODO: Traiter les notices sur les indices de tableau qui n'existent pas.
                     switch($sectionName) {

                        case "DRIVES":
                           if (((isset($arrSectionToAdd["SERIAL"]))
                                 AND (isset($arrSectionToRemove["SERIAL"]))
                                 AND ($arrSectionToAdd["SERIAL"] == $arrSectionToRemove["SERIAL"]))
                              OR (((isset($arrSectionToAdd["NAME"]))
                                 AND (isset($arrSectionToRemove["NAME"]))
                                 AND ($arrSectionToAdd["NAME"] == $arrSectionToRemove["NAME"])))
                              OR ((isset($arrSectionToAdd['VOLUMN'])
                                 AND (isset($arrSectionToRemove["VOLUMN"]))
                                 AND ($arrSectionToAdd["VOLUMN"] == $arrSectionToRemove["VOLUMN"])))) {

                              $boolUpdate = true;
                           }
                           break;
                           
                        case "SOFTWARES":
                           if ((isset($arrSectionToAdd["GUID"]) AND isset($arrSectionToRemove["GUID"])
                                 AND ($arrSectionToAdd["GUID"] == $arrSectionToRemove["GUID"])
                                 AND isset($arrSectionToAdd["VERSION"]) AND isset($arrSectionToRemove["VERSION"])
                                 AND $arrSectionToAdd["VERSION"] == $arrSectionToRemove["VERSION"])

                              OR (isset($arrSectionToAdd["GUID"]) AND isset($arrSectionToRemove["GUID"])
                                 AND ($arrSectionToAdd["GUID"] == $arrSectionToRemove["GUID"])
                                 AND !isset($arrSectionToAdd["VERSION"]))

                              OR (isset($arrSectionToAdd["NAME"]) AND isset($arrSectionToRemove["NAME"])
                                 AND $arrSectionToAdd["NAME"] == $arrSectionToRemove["NAME"]<commit_msg>FIx delete and recreate volumn for OCS agents. closes #1205<commit_after><?php

/*
   ----------------------------------------------------------------------
   FusionInventory
   Copyright (C) 2010-2011 by the FusionInventory Development Team.

   http://www.fusioninventory.org/   http://forge.fusioninventory.org/
   ----------------------------------------------------------------------

   LICENSE

   This file is part of FusionInventory.

   FusionInventory is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 2 of the License, or
   any later version.

   FusionInventory is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with FusionInventory.  If not, see <http://www.gnu.org/licenses/>.

   ------------------------------------------------------------------------
   Original Author of file: <NAME>
   Co-authors of file:
   Purpose of file:
   ----------------------------------------------------------------------
 */

if (!defined('GLPI_ROOT')) {
	die("Sorry. You can't access directly to this file");
}

class PluginFusinvinventoryLib extends CommonDBTM {

   var $table = "glpi_plugin_fusinvinventory_libserialization";


   /**
   * Sarting create or update computer and get Entity
   *
   * @param $simpleXMLObj simplexml xmlobject of the computer
   * @param $items_id interger id of the computer
   * @param $new bool if 1 create a new computer
   *
   * @return nothing
   *
   **/
   function startAction($simpleXMLObj, $items_id, $new=0) {
      global $DB;

      $xml = simplexml_load_string($_SESSION['SOURCEXML'],'SimpleXMLElement', LIBXML_NOCDATA);
      
      if ($new == "0") {
         // Transfer if entity is different
         $Computer = new Computer();
         $Computer->getFromDB($items_id);
         $input = array();
         $input['id'] = $Computer->fields['id'];
         $input['autoupdatesystems_id'] = Dropdown::importExternal('AutoUpdateSystem', 'FusionInventory');
         $_SESSION['glpiactiveentities_string'] = $Computer->fields['entities_id'];
         $input['is_ocs_import'] = 0;
         $Computer->update($input);
         if ($_SESSION["plugin_fusinvinventory_entity"] == NOT_AVAILABLE) {
            $_SESSION["plugin_fusinvinventory_entity"] = $Computer->fields['entities_id'];
         }
         $PluginFusioninventoryConfig = new PluginFusioninventoryConfig();
         if ($Computer->getEntityID() != $_SESSION["plugin_fusinvinventory_entity"]) {
            $Transfer = new Transfer();
            // get value in Config ($config['transfers_id_auto'])
            $Transfer->getFromDB(
                $PluginFusioninventoryConfig->getValue($_SESSION["plugin_fusinvinventory_moduleid"],
                                                       'transfers_id_auto'));

            $item_to_transfer = array("Computer" => array($items_id=>$items_id));

            $Transfer->moveItems($item_to_transfer, $_SESSION["plugin_fusinvinventory_entity"], 
                                 $Transfer->fields);
         }

      //if ($internalId = $this->isMachineExist()) {
         // Get internal ID with $items_id
         $a_serialized = array();
         $query = "SELECT * FROM `glpi_plugin_fusinvinventory_libserialization`
                   WHERE `computers_id`='".$items_id."'
                   LIMIT 1";
         $result = $DB->query($query);
         if ($result) {
            if ($DB->numrows($result) == '1') {
               $a_serialized = $DB->fetch_assoc($result);
            }
         }
         $internalId = uniqid();
         if (isset($a_serialized['internal_id'])) {
            $internalId = $a_serialized['internal_id'];
         } else {
            // Importer les donnes de GLPI dans le xml
            $PluginFusinvinventoryInventory = new PluginFusinvinventoryInventory();
            $PluginFusinvinventoryInventory->createMachineInLib($items_id, $internalId);
         }

         // Link computer to agent FusionInventory
         $PluginFusioninventoryAgent = new PluginFusioninventoryAgent();
         $PluginFusioninventoryAgent->setAgentWithComputerid($items_id, addslashes_deep($xml->DEVICEID));

         // Transfer agent entity
         $PluginFusioninventoryAgent = new PluginFusioninventoryAgent();
         $agent_id = $PluginFusioninventoryAgent->getAgentWithComputerid($items_id);
         if ($agent_id) {
            $PluginFusioninventoryAgent->getFromDB($agent_id);
            if ($PluginFusioninventoryAgent->getEntityID() != $_SESSION["plugin_fusinvinventory_entity"]) {
               $input = array();
               $input['id'] = $PluginFusioninventoryAgent->fields['id'];
               $input['entities_id'] = $_SESSION["plugin_fusinvinventory_entity"];
               $PluginFusioninventoryAgent->update($input);
            }
         }

         //Sections update
         $xmlSections = $this->_getXMLSections($simpleXMLObj);
         $this->updateLibMachine($xmlSections, $internalId);
         
         $PluginFusinvinventoryLibhook = new PluginFusinvinventoryLibhook();
         $PluginFusinvinventoryLibhook->writeXMLFusion($items_id);
      } else {
         // New Computer
         if ($_SESSION["plugin_fusinvinventory_entity"] == NOT_AVAILABLE) {
            $_SESSION["plugin_fusinvinventory_entity"] = 0;
         }

         //We launch CreateMachine() hook and provide an InternalId
         $xmlSections = $this->_getXMLSections($simpleXMLObj);
         $internalId = uniqid();

         try {
            $PluginFusinvinventoryLibhook = new PluginFusinvinventoryLibhook();
            $PluginFusinvinventoryLibhook->createMachine($items_id);
            
            // Link computer to agent FusionInventory
            $PluginFusioninventoryAgent = new PluginFusioninventoryAgent();
            $PluginFusioninventoryAgent->setAgentWithComputerid($items_id, $xml->DEVICEID);

            // Link computer to agent FusionInventory
            $PluginFusioninventoryAgent = new PluginFusioninventoryAgent();
            $PluginFusioninventoryAgent->setAgentWithComputerid($items_id, addslashes_deep($xml->DEVICEID));

            // Transfer agent entity
            $PluginFusioninventoryAgent = new PluginFusioninventoryAgent();
            $agent_id = $PluginFusioninventoryAgent->getAgentWithComputerid($items_id);
            if ($agent_id) {
               $PluginFusioninventoryAgent->getFromDB($agent_id);
               if ($PluginFusioninventoryAgent->getEntityID() 
                     != $_SESSION["plugin_fusinvinventory_entity"]) {
                  $PluginFusioninventoryAgent->fields['entities_id'] 
                     = $_SESSION["plugin_fusinvinventory_entity"];
                  $PluginFusioninventoryAgent->update($PluginFusioninventoryAgent->fields);
               }
            }

            $this->addLibMachine($internalId, $items_id);

            $this->updateLibMachine($xmlSections, $internalId);

         } catch (MyException $e) {
             // $log->error('created machine stage: error');
         }
      }
   }


   
   /**
   * get all sections and convert to php array
   *
   * @param $simpleXMLObj simplexml XML object of the computer
   *
   * @return array XML sections into an array
   *
   **/
   private function _getXMLSections($simpleXMLObj) {

      $xmlSections = array();
      $PluginFusinvinventoryLibfilter = new PluginFusinvinventoryLibfilter();

      $sectionsToFilter = array();
      array_push ($sectionsToFilter,
      'USBDEVICES',
      'CONTROLLERS',
      'NETWORKS');

      foreach($simpleXMLObj->CONTENT->children() as $section) {

         if(in_array($section->getName(), $sectionsToFilter)) {
            $nofilter = $PluginFusinvinventoryLibfilter->filter($section);
            //if the folder for the filter doesn't exist, delete this element from array.
            if($nofilter){
               foreach($sectionsToFilter as $fKey => $fValue) {
                  if ($fValue == $nofilter) {
                     unset($sectionsToFilter[$fKey]);
                  }
               }
            }
         }

         $sectionData = array();
         foreach ($section->children() as $data) {
            if ($section->getName() == "VIRTUALMACHINES"
                    AND $data->getName() == "COMMENT") {
               $sectionData[$data->getName()] = addslashes_deep((string)$data);
            } else {
               $sectionData[$data->getName()] = (string)$data;
            }
         }

         //sectionId initialization, we will affect id after hook createSection return value.
         $serializedSectionData = serialize($sectionData);
         array_push($xmlSections, 
                    array("sectionId"        => 0,
                          "sectionName"      => $section->getName(),
                          "sectionDatawName" => $serializedSectionData.$section->getName(),
                          "sectionData"      => $serializedSectionData));
      }
      return $xmlSections;
   }



   /**
   * Create computer into lib
   *
   * @param $internalId value uniq id for internal lib
   * @param $externalId integer id of the GLPI computer
   *
   * @return nothing
   *
   */
   public function addLibMachine($internalId, $externalId) {

      $queryInsert = "INSERT INTO `glpi_plugin_fusinvinventory_libserialization` 
                      ( `internal_id` , `computers_id`)
                      VALUES ('" . $internalId . "' , '".$externalId."')";
      mysql_query($queryInsert);
  }




   /**
   * Determine if there are sections changements and update
   * Definition of the existant criteria in each section to known
   * if can be update or if it's a new section
   *
   * @param $xmlSections array XML sections in a php array
   * @param $internalId value uniq id of internal lib
   *
   * @return nothing
   *
   */
   public function updateLibMachine($xmlSections, $internalId) {
      global $DB;

      $a_sections   = array();
      $a_sections[] = "DRIVES";
      $a_sections[] = "SOFTWARES";
      $a_sections[] = "CONTROLLERS";
      $a_sections[] = "ENVS";
      $a_sections[] = "INPUTS";
      $a_sections[] = "MEMORIES";
      $a_sections[] = "MONITORS";
      $a_sections[] = "NETWORKS";
      $a_sections[] = "PORTS";
      $a_sections[] = "PRINTERS";
      $a_sections[] = "PROCESSES";
      $a_sections[] = "SOUNDS";
      $a_sections[] = "STORAGES";
      $a_sections[] = "USERS";
      $a_sections[] = "VIDEOS";
      $a_sections[] = "USBDEVICES";
      $a_sections[] = "VIRTUALMACHINES";
      $a_sections[] = "CPUS";
      $a_sections[] = "ANTIVIRUS";

      // Retrieve all sections stored in info file
      $infoSections = $this->_getInfoSections($internalId);
      // Retrieve all sections from xml file
      $serializedSectionsFromXML = array();
      
      foreach($xmlSections as $xmlSection) {
         array_push($serializedSectionsFromXML, $xmlSection["sectionDatawName"]);
      }
      //Retrieve changes, sections to Add and sections to Remove
      $sectionsToAdd    = array_diff($serializedSectionsFromXML, $infoSections["sections"]);
      $sectionsToRemove = array_diff($infoSections["sections"], $serializedSectionsFromXML);

      $classhook = "PluginFusinvinventoryLibhook";

      //updated section: process
      if($sectionsToRemove && $sectionsToAdd) {
         $datasToUpdate = array();
         $existUpdate = 0;
         foreach($sectionsToRemove as $sectionId => $serializedSectionToRemove) {
            $sectionName=substr(strrchr($infoSections["sections"][$sectionId], "}"), 1 );
            
            if (in_array($sectionName, $a_sections)) {
               foreach($sectionsToAdd as $arrayId => $serializedSectionToAdd) {
                  //check if we have the same section Name for an sectionToRemove and an sectionToAdd
                  if($xmlSections[$arrayId]['sectionName'] == $sectionName) {
                     //Finally, we have to determine if it's an update or not
                     $boolUpdate = false;
                     if (!unserialize($serializedSectionToAdd)) {
                        //logInFile('serialise', $serializedSectionToAdd);
                     }
                     $arrSectionToAdd = unserialize($serializedSectionToAdd);
                     if (!unserialize($serializedSectionToRemove)) {
                        //logInFile('serialise', $serializedSectionToRemove);
                     }
                     $arrSectionToRemove = unserialize($serializedSectionToRemove);
                     
                     //TODO: Traiter les notices sur les indices de tableau qui n'existent pas.
                     switch($sectionName) {

                        case "DRIVES":
                           if (((isset($arrSectionToAdd["SERIAL"]))
                                 AND (isset($arrSectionToRemove["SERIAL"]))
                                 AND ($arrSectionToAdd["SERIAL"] == $arrSectionToRemove["SERIAL"]))
                              OR (((isset($arrSectionToAdd["NAME"]))
                                 AND (isset($arrSectionToRemove["NAME"]))
                                 AND ($arrSectionToAdd["NAME"] == $arrSectionToRemove["NAME"])))
                              OR ((isset($arrSectionToAdd['VOLUMN'])
                                 AND (isset($arrSectionToRemove["VOLUMN"]))
                                 AND ($arrSectionToAdd["VOLUMN"] == $arrSectionToRemove["VOLUMN"])))
                              OR ((isset($arrSectionToAdd['LETTER'])
                                 AND (isset($arrSectionToRemove["LETTER"]))
                                 AND ($arrSectionToAdd["LETTER"] == $arrSectionToRemove["LETTER"])))) {

                              $boolUpdate = true;
                           }
                           break;
                           
                        case "SOFTWARES":
                           if ((isset($arrSectionToAdd["GUID"]) AND isset($arrSectionToRemove["GUID"])
                                 AND ($arrSectionToAdd["GUID"] == $arrSectionToRemove["GUID"])
                                 AND isset($arrSectionToAdd["VERSION"]) AND isset($arrSectionToRemove["VERSION"])
                                 AND $arrSectionToAdd["VERSION"] == $arrSectionToRemove["VERSION"])

                              OR (isset($arrSectionToAdd["GUID"]) AND isset($arrSectionToRemove["GUID"])
                                 AND ($arrSectionToAdd["GUID"] == $arrSectionToRemove["GUID"])
                                 AND !isset($arrSectionToAdd["VERSION"]))

                              OR (isset($arrSectionToAdd["NAME"]) AND isset($arrSectionToRemove["NAME"])
                                 AND $arrSectionToAdd["NAME"] == $arrSectionToRemove["NAME"]
{'fraction_non_alphanumeric': 0.1319034852546917, 'fraction_numerical': 0.0014075067024128685, 'mean_word_length': 2.0603015075376883, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 129, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 46}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 43, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4287143', 'n_tokens_mistral': 8003, 'n_tokens_neox': 7756, 'n_words': 1625}