diff --git a/CHANGELOG.md b/CHANGELOG.md index efabfcc..bd465e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Costs The cost plugin for GLPI + +## 3.0.0 - 2022-07-07 +### Features +- GLPI 10 compatibility #10398 + ## 2.2.3 ### Bugfixes - Don't show Billable to self-service users. diff --git a/inc/config.class.php b/inc/config.class.php index fb297a6..572a3d1 100644 --- a/inc/config.class.php +++ b/inc/config.class.php @@ -115,6 +115,10 @@ static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtem public static function install(Migration $migration) { global $DB; + $default_charset = DBConnection::getDefaultCharset(); + $default_collation = DBConnection::getDefaultCollation(); + $default_key_sign = DBConnection::getDefaultPrimaryKeySignOption(); + $table = self::getTable(); $config = new self(); @@ -123,10 +127,10 @@ public static function install(Migration $migration) { //Install $query = "CREATE TABLE `$table` ( - `id` int(11) NOT NULL auto_increment, - `taskdescription` tinyint(1) NOT NULL default '0', + `id` int {$default_key_sign} NOT NULL auto_increment, + `taskdescription` tinyint NOT NULL default '0', PRIMARY KEY (`id`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;"; + ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; $DB->query($query) or die ($DB->error()); $config->add([ diff --git a/inc/entity.class.php b/inc/entity.class.php index e89fd4e..7f7f6f9 100644 --- a/inc/entity.class.php +++ b/inc/entity.class.php @@ -68,7 +68,9 @@ public function getFromDBByEntity($entities_id) { $req=$DB->request(['FROM' => self::getTable(),'WHERE' => ['entities_id' => $entities_id]]); if (count($req)) { - $this->fields=$req->next($req); + foreach ($req as $result){ + $this->fields=$result; + } return true; } else { if ($entities_id>0) { @@ -188,22 +190,26 @@ static function getConfigID($entities_id){ static function install(Migration $migration) { global $DB; + $default_charset = DBConnection::getDefaultCharset(); + $default_collation = DBConnection::getDefaultCollation(); + $default_key_sign = DBConnection::getDefaultPrimaryKeySignOption(); + $table=self::getTable(); if (!$DB->tableExists($table)) { $migration->displayMessage("Installing $table"); $query="CREATE TABLE IF NOT EXISTS $table ( - id int(11) NOT NULL auto_increment, - entities_id int(11) NOT NULL DEFAULT '0', + id int {$default_key_sign} NOT NULL auto_increment, + entities_id int {$default_key_sign} NOT NULL DEFAULT '0', fixed_cost float NOT NULL default '0', time_cost float NOT NULL default '0', - cost_private tinyint(1) NOT NULL DEFAULT '0', - auto_cost tinyint(1) NOT NULL DEFAULT '0', - inheritance tinyint(1) NOT NULL DEFAULT '0', + cost_private tinyint NOT NULL DEFAULT '0', + auto_cost tinyint NOT NULL DEFAULT '0', + inheritance tinyint NOT NULL DEFAULT '0', PRIMARY KEY (id), KEY entities_id (entities_id) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; + ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; $DB->query($query) or die($DB->error()); }else{ if (!$DB->fieldExists($table, 'auto_cost')) { diff --git a/inc/task.class.php b/inc/task.class.php index 5b87a0b..5e3ae36 100644 --- a/inc/task.class.php +++ b/inc/task.class.php @@ -17,7 +17,7 @@ static function taskAdd(TicketTask $task){ if (array_key_exists('state', $task->input)) { if ($task->fields['state']==Planning::DONE) { $cost_config=new PluginCostsEntity(); - $cost_config->getFromDBByEntity($ticket->fields['entities_id']); + $cost_config->getFromDBByCrit(["entities_id"=>$ticket->fields['entities_id']]); if ($cost_config->fields['inheritance']) { $parent_id=PluginCostsEntity::getConfigID($ticket->fields['entities_id']); $cost_config->getFromDB($parent_id); @@ -121,59 +121,63 @@ static function preTaskUpdate(TicketTask $task){ ] ]; $req=$DB->request($query); - if ($row=$req->next()) { - $cost_id=$row['costs_id']; - - $config=PluginCostsConfig::getConfig(); - $comment=__('Automatically generated by GLPI').' -> Costs Plugin'; - if ($config->fields['taskdescription']) { - $comment=$content." \n".__('Automatically generated by GLPI').' -> Costs Plugin'; - } - $input=[ - 'id'=>$cost_id, - 'comment'=>$comment, - 'actiontime'=>$actiontime, - ]; - if (array_key_exists('begin', $task->input)) { - $input['begin_date']=$task->input['begin']; - } - if (array_key_exists('end', $task->input)) { - $input['end_date']=$task->input['end']; - } - - $cost=new TicketCost(); - $cost->update($input); - }else{ - $config=PluginCostsConfig::getConfig(); - $comment=__('Automatically generated by GLPI').' -> Costs Plugin'; - if ($config->fields['taskdescription']) { - $comment=$content." \n".__('Automatically generated by GLPI').' -> Costs Plugin'; - } - $cost=new TicketCost(); - $input=[ - 'tickets_id'=>$task->fields['tickets_id'], - 'name'=>$task->fields['id']."_".$users_id_tech, - 'comment'=>$comment, - 'actiontime'=>$actiontime, - 'cost_time'=>$cost_time, - 'cost_fixed'=>$cost_fixed, - 'entities_id'=>$ticket->fields['entities_id'], - ]; - if (array_key_exists('begin', $task->input)) { - $input['begin_date']=$task->input['begin']; + + if(count($req)){ + foreach($req as $row) { + $cost_id=$row['costs_id']; + + $config=PluginCostsConfig::getConfig(); + $comment=__('Automatically generated by GLPI').' -> Costs Plugin'; + if ($config->fields['taskdescription']) { + $comment=$content." \n".__('Automatically generated by GLPI').' -> Costs Plugin'; + } + $input=[ + 'id'=>$cost_id, + 'comment'=>$comment, + 'actiontime'=>$actiontime, + ]; + if (array_key_exists('begin', $task->input)) { + $input['begin_date']=$task->input['begin']; + } + if (array_key_exists('end', $task->input)) { + $input['end_date']=$task->input['end']; + } + + $cost=new TicketCost(); + $cost->update($input); + } }else{ - $input['begin_date']=$task->fields['begin']; + $config=PluginCostsConfig::getConfig(); + $comment=__('Automatically generated by GLPI').' -> Costs Plugin'; + if ($config->fields['taskdescription']) { + $comment=$content." \n".__('Automatically generated by GLPI').' -> Costs Plugin'; + } + $cost=new TicketCost(); + $input=[ + 'tickets_id'=>$task->fields['tickets_id'], + 'name'=>$task->fields['id']."_".$users_id_tech, + 'comment'=>$comment, + 'actiontime'=>$actiontime, + 'cost_time'=>$cost_time, + 'cost_fixed'=>$cost_fixed, + 'entities_id'=>$ticket->fields['entities_id'], + ]; + if (array_key_exists('begin', $task->input)) { + $input['begin_date']=$task->input['begin']; + }else{ + $input['begin_date']=$task->fields['begin']; + } + if (array_key_exists('end', $task->input)) { + $input['end_date']=$task->input['end']; + }else{ + $input['end_date']=$task->fields['end']; + } + $cost_id=$cost->add($input); + + $taskcost=new self(); + $taskcost->add(['tasks_id'=>$task->fields['id'],'costs_id'=>$cost_id]); } - if (array_key_exists('end', $task->input)) { - $input['end_date']=$task->input['end']; - }else{ - $input['end_date']=$task->fields['end']; - } - $cost_id=$cost->add($input); - - $taskcost=new self(); - $taskcost->add(['tasks_id'=>$task->fields['id'],'costs_id'=>$cost_id]); - } + } } } @@ -190,7 +194,7 @@ static function taskPurge(TicketTask $task){ ] ]; $req=$DB->request($query); - if ($row=$req->next()) { + foreach ($req as $row) { $cost = new TicketCost(); $cost->delete(['id'=>$row['costs_id']], 1); $taskcost=new self(); diff --git a/inc/ticket.class.php b/inc/ticket.class.php index 701438b..68c034f 100644 --- a/inc/ticket.class.php +++ b/inc/ticket.class.php @@ -87,7 +87,9 @@ public function getFromDBByTicket($ticket_id) { $req=$DB->request(['FROM' => self::getTable(),'WHERE' => ['tickets_id' => $ticket_id]]); if (count($req)) { - $this->fields=$req->next($req); + foreach ($req as $result){ + $this->fields=$result; + } return true; } else { $ticket=new Ticket(); @@ -166,19 +168,23 @@ static function ticketUpdate(Ticket $ticket){ static function install(Migration $migration) { global $DB; + $default_charset = DBConnection::getDefaultCharset(); + $default_collation = DBConnection::getDefaultCollation(); + $default_key_sign = DBConnection::getDefaultPrimaryKeySignOption(); + $table = self::getTable(); if (!$DB->tableExists($table)) { $migration->displayMessage("Installing $table"); $query = "CREATE TABLE IF NOT EXISTS `$table` ( - `id` int(11) NOT NULL auto_increment, - `tickets_id` int(11) NOT NULL, - `billable` tinyint(1) NOT NULL DEFAULT '0', + `id` int {$default_key_sign} NOT NULL auto_increment, + `tickets_id` int {$default_key_sign} NOT NULL, + `billable` tinyint NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `tickets_id` (`tickets_id`), KEY `billable` (`billable`) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci"; + ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; $DB->query($query) or die($DB->error()); }else{ if ($DB->fieldExists($table, 'costs_id')) { diff --git a/setup.php b/setup.php index 79bc2f5..122fe30 100755 --- a/setup.php +++ b/setup.php @@ -32,11 +32,11 @@ @link https://tic.gal @since 2018 ---------------------------------------------------------------------- */ -define ('PLUGIN_COSTS_VERSION', '2.2.3'); +define ('PLUGIN_COSTS_VERSION', '3.0.0'); // Minimal GLPI version, inclusive -define("PLUGIN_COSTS_MIN_GLPI", "9.5"); +define("PLUGIN_COSTS_MIN_GLPI", "10.0"); // Maximum GLPI version, exclusive -define("PLUGIN_COSTS_MAX_GLPI", "9.6"); +define("PLUGIN_COSTS_MAX_GLPI", "11.0"); global $CFG_GLPI; if (!defined('PLUGIN_COSTS_NUMBER_STEP')) {