Skip to content

Commit bcf8f55

Browse files
authored
Fix(Cron): fix SQL query error (#213)
* Fix(Cron): fix SQL query error * fix CS * fix header * fixrector
1 parent ec5828c commit bcf8f55

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## [UNRELEASED]
9+
10+
### Fixed
11+
12+
- Fix SQL error for `lowcredits` task
13+
814
## [1.15.1] - 2025-11-18
915

1016
### Fixed

inc/entity.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ public static function cronLowCredits($task)
457457
'glpi_plugin_credit_entities.is_active' => 1,
458458
],
459459
'GROUPBY' => 'glpi_plugin_credit_entities.id',
460-
'HAVING' => new QueryExpression('glpi_plugin_credit_entities.quantity - quantity_consumed <= (glpi_plugin_credit_entities.quantity * glpi_plugin_credit_entities.low_credit_alert) / 100'),
460+
'HAVING' => [new QueryExpression('glpi_plugin_credit_entities.quantity - quantity_consumed <= (glpi_plugin_credit_entities.quantity * glpi_plugin_credit_entities.low_credit_alert) / 100')],
461461
],
462462
);
463463

inc/notificationtargetentity.class.php

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,36 @@
11
<?php
22

3+
/**
4+
* -------------------------------------------------------------------------
5+
* Credit plugin for GLPI
6+
* -------------------------------------------------------------------------
7+
*
8+
* LICENSE
9+
*
10+
* This file is part of Credit.
11+
*
12+
* Credit is free software; you can redistribute it and/or modify
13+
* it under the terms of the GNU General Public License as published by
14+
* the Free Software Foundation; either version 3 of the License, or
15+
* (at your option) any later version.
16+
*
17+
* Credit is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU General Public License
23+
* along with Credit. If not, see <http://www.gnu.org/licenses/>.
24+
* -------------------------------------------------------------------------
25+
* @author François Legastelois
26+
* @copyright Copyright (C) 2017-2023 by Credit plugin team.
27+
* @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
28+
* @link https://github.com/pluginsGLPI/credit
29+
* -------------------------------------------------------------------------
30+
*/
31+
32+
33+
334
/**
435
* -------------------------------------------------------------------------
536
* Credit plugin for GLPI
@@ -44,6 +75,10 @@ public function addDataForTemplate($event, $options = [])
4475
/** @var DBmysql $DB */
4576
global $DB;
4677

78+
if (!($this->obj instanceof CommonDBTM)) {
79+
return;
80+
}
81+
4782
$this->data['##credit.name##'] = $this->obj->getField('name');
4883
$this->data['##credit.quantity_sold##'] = $this->obj->getField('quantity');
4984
$this->data['##credit.begindate##'] = $this->obj->getField('begin_date');
@@ -63,8 +98,8 @@ public function addDataForTemplate($event, $options = [])
6398
],
6499
);
65100
$data = $req->current();
66-
$this->data['##credit.quantity_remaining##'] = (int) $this->obj->getField('quantity') - (int) $data['consumed_total'];
67-
$this->data['##credit.quantity_consumed##'] = (int) $data['consumed_total'];
101+
$this->data['##credit.quantity_remaining##'] = (string) ((int) $this->obj->getField('quantity') - (int) $data['consumed_total']);
102+
$this->data['##credit.quantity_consumed##'] = (string) $data['consumed_total'];
68103

69104
$this->data['##credit.entity##'] = Dropdown::getDropdownName(
70105
'glpi_entities',

0 commit comments

Comments
 (0)