Skip to content

Commit

Permalink
Merge pull request #18 from ticgal/glpi-10-compatibility
Browse files Browse the repository at this point in the history
GLPI 10 compatibility
  • Loading branch information
inesmv committed Jul 7, 2022
2 parents c31e525 + c8e90b3 commit 5ae9e7a
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 71 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
10 changes: 7 additions & 3 deletions inc/config.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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([
Expand Down
20 changes: 13 additions & 7 deletions inc/entity.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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')) {
Expand Down
110 changes: 57 additions & 53 deletions inc/task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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]);
}

}
}
}
Expand All @@ -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();
Expand Down
16 changes: 11 additions & 5 deletions inc/ticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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')) {
Expand Down
6 changes: 3 additions & 3 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down

0 comments on commit 5ae9e7a

Please sign in to comment.