Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when using with Generic Object plugin - PHP fatal error #3

Open
Rafit77 opened this issue Apr 14, 2017 · 1 comment
Open

when using with Generic Object plugin - PHP fatal error #3

Rafit77 opened this issue Apr 14, 2017 · 1 comment

Comments

@Rafit77
Copy link

Rafit77 commented Apr 14, 2017

when try to search anything, nothing shows, and apache log error:

PHP Fatal error: Call to a member function fetch_array() on boolean in /var/www/html/inc/dbmysql.class.php on line 282, referer: http ://xx.xx.xx.xx/plugins/physicalinv/front/inventory.php

problem:
file: /plugins/physicalinv/inc/inventory.class.php

code:

         $result = $DB->query($query);
         while ($data = $DB->fetch_array($result)) {
            if ($item->canEdit($data['id'])) {
               $id_list[$itemtype][$data['id']] = $data['id'];
            }
         }

fixed code:

         $result = $DB->query($query);
         if ($DB->numrows($result)>0) {
             while ($data = $DB->fetch_array($result)) {
                if ($item->canEdit($data['id'])) {
                   $id_list[$itemtype][$data['id']] = $data['id'];
                }
             }
         }

I hope this helps (it worked for me).

EDIT: I investigated further, using Generic Object plugin caused error. To make both plugins work together few more changes need to be done. Reason: not all object need to have dustbin and template fields.

   /**
    * Search and get list of devices have the 'number' in serial number or
    * inventory number
    *
    * @param string $number
    * @return array
    */
   function searchItemWithNumber($number) {
      global $DB, $CFG_GLPI;

      $id_list = array();

      // search in inventory have serial number or inventory number
      foreach($CFG_GLPI["asset_types"] as $itemtype) {
         $where_fields = array();
         $table = getTableForItemType($itemtype);
         $item = new $itemtype();

         if (FieldExists($table, 'serial')) {
            $where_fields[] = 'serial';
         }
         if (FieldExists($table, 'otherserial')) {
            $where_fields[] = 'otherserial';
         }
         if (count($where_fields) == 0) {
            continue;
         }
         $query = "SELECT *
                   FROM `".$table."` WHERE (";
         $first = True;
         foreach ($where_fields as $field) {
            if (!$first) {
               $query .= " OR ";
            }
            $query .= " `$field`='$number'";
            $first = False;
         }
         $query .= ")";
         if (FieldExists($table, 'is_deleted')) { // only if dust bin enabled
            $query .= " AND `is_deleted`='0'";
         }
         if (FieldExists($table, 'is_template')) { // only if templates are in use
            $query .= " AND `is_template`='0'";
         }

         $result = $DB->query($query);
         if ($DB->numrows($result)>0) {
             while ($data = $DB->fetch_array($result)) {
                if ($item->canEdit($data['id'])) {
                   $id_list[$itemtype][$data['id']] = $data['id'];
                }
             }
         }
      }
      return $id_list;
   }

Regards
Rafal

@Rafit77 Rafit77 changed the title when using with GLPI 9.1.2 (latest) - PHP fatal error when using with Generic Object plugin - PHP fatal error Mar 7, 2019
@Rafit77
Copy link
Author

Rafit77 commented Sep 8, 2019

The problem should be resolved with provided pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant