pluginsGLPI / ocsinventoryng

Plugin ocsinventoryng for GLPI
GNU General Public License v2.0
68 stars 52 forks source link

If software has only one version the force sync delete the software, all licenses and information was lost #311

Closed fgendorf closed 2 years ago

fgendorf commented 2 years ago

-OCS version: 2.9.2 -GLPI version: 9.5.7

Hi, we have some softwares that is installed once in a unique machine, so just have one version of this software. If I force a syncronization the follow part of code DELETE complete the software and all information registred in it is lost, including license, management information, etc.

software.class.php: line 510

if ($DB->result($result2, 0, 0) == 1) {
               $vers = new SoftwareVersion();
               $vers->getFromDB($data['softwareversions_id']);
               $query3  = "SELECT COUNT(*)
                          FROM `glpi_softwareversions`
                          WHERE `softwares_id`= " . $vers->fields['softwares_id'];
               $result3 = $DB->query($query3);

               if ($DB->result($result3, 0, 0) == 1) {
                  $soft = new Software();
                  $soft->delete(['id'          => $vers->fields['softwares_id'],
                                 '_no_history' => !$uninstall_history],
                                true,
                                $uninstall_history);
               }
               $vers->delete(["id"          => $data['softwareversions_id'],
                              '_no_history' => !$uninstall_history],
                             true,
                             $uninstall_history);
            }

Special this code:

if ($DB->result($result3, 0, 0) == 1) {
                  $soft = new Software();
                  $soft->delete(['id'          => $vers->fields['softwares_id'],
                                 '_no_history' => !$uninstall_history],
                                true,
                                $uninstall_history);
               }

Why delete THE SOFTWARE, I understand the force delete all link between computer and software, but the software should be deleted?

ajavor commented 2 years ago

I think the fixes made by @tsmr apply to the GLPI10 beta. I applied the above changes to GLPI9.5.7 and the ocsinventoryng plugin stopped synchronizing with ocs server.