Commit 7a88fda8 authored by Johan Cwiklinski's avatar Johan Cwiklinski Committed by Johan Cwiklinski

Fix wrong methods names

Replace deprecated fetch_array
Replace deprecated fetch_row
Replace deprecated fetch_assoc
Replace deprectaed data_seek
Replace deprecated insert_id
Replace deprecated list_fields, num_field and field_name
Replace deprecated free_result, missing depreciations in iterator
Replace deprecated affected_rows
parent 0b2ef3f5
......@@ -5,10 +5,28 @@ The present file will list all changes made to the project; according to the
## [9.5] unreleased
#### Added
### Added
- encrypted file systems support
### API changes
#### Deprecated
- `DBMysql::fetch_array()`
- `DBMysql::fetch_row()`
- `DBMysql::fetch_assoc()`
- `DBMysql::fetch_object()`
- `DBMysql::data_seek()`
- `DBMysql::insert_id()`
- `DBMysql::num_fields()`
- `DBMysql::field_name()`
- `DBMysql::list_fields()`
- `DBMysql::affected_rows()`
- `DBMysql::free_result()`
- `DBMysql::isMySQLStrictMode()`
## [9.4.2] unreleased
### API changes
......
......@@ -87,7 +87,7 @@ if (class_exists($_POST["itemtype"])
$values = [];
if ($DB->numrows($result)) {
while ($data = $DB->fetch_assoc($result)) {
while ($data = $DB->fetchAssoc($result)) {
// Device name + port name
$output = $output_long = $data['cname'];
......
......@@ -66,7 +66,7 @@ if ($_POST['softwares_id'] > 0) {
$values = [];
if ($number) {
while ($data = $DB->fetch_assoc($result)) {
while ($data = $DB->fetchAssoc($result)) {
$ID = $data['id'];
$output = $data['name'];
......
......@@ -58,7 +58,7 @@ if ($_POST['softwares_id'] > 0) {
$values = [];
if ($number) {
while ($data = $DB->fetch_assoc($result)) {
while ($data = $DB->fetchAssoc($result)) {
$ID = $data['id'];
$output = $data['name'];
......
......@@ -88,7 +88,7 @@ if (isset($_GET['node'])) {
ORDER BY `name`";
if ($result = $DB->query($query)) {
while ($row = $DB->fetch_assoc($result)) {
while ($row = $DB->fetchAssoc($result)) {
$path = [
'id' => $row['id'],
'text' => $row['name']
......
......@@ -179,7 +179,7 @@ function get_def($DB, $table) {
$query = "SHOW CREATE TABLE `$table`";
$result = $DB->query($query);
$DB->query("SET SESSION sql_quote_show_create = 1");
$row = $DB->fetch_row($result);
$row = $DB->fetchRow($result);
$def .= preg_replace("/AUTO_INCREMENT=\w+/i", "", $row[1]);
$def .= ";";
......
......@@ -183,7 +183,7 @@ if (isset($query) && count($query)) {
echo "<th>".__('Start date')."</th>";
echo "<th>".__('End date')."</th>";
echo "</tr>";
while ($data = $DB->fetch_assoc($result)) {
while ($data = $DB->fetchAssoc($result)) {
echo "<tr class='tab_bg_1'>";
if ($data['itemname']) {
echo "<td> ".$data['itemname']." </td>";
......
......@@ -135,7 +135,7 @@ function display_infocoms_report($itemtype, $begin, $end) {
$valeurnettegraph = [];
$valeurgraph = [];
while ($line=$DB->fetch_assoc($result)) {
while ($line=$DB->fetchAssoc($result)) {
if ($itemtype == 'SoftwareLicense') {
$item->getFromDB($line["items_id"]);
......
......@@ -136,7 +136,7 @@ function display_infocoms_report($itemtype, $begin, $end) {
$valeurnettegraph = [];
$valeurgraph = [];
while ($line=$DB->fetch_assoc($result)) {
while ($line=$DB->fetchAssoc($result)) {
if (isset($line["is_global"]) && $line["is_global"]
&& $item->getFromDB($line["items_id"])) {
$line["value"] *= Computer_Item::countForItem($item);
......
......@@ -139,7 +139,7 @@ if (isset($query) && count($query)) {
echo "<th>".__('Start date')."</th>";
echo "<th>".__('End date')."</th></tr>";
while ($data = $DB->fetch_assoc($result)) {
while ($data = $DB->fetchAssoc($result)) {
echo "<tr class='tab_bg_1'>";
if ($data['itemname']) {
echo "<td> ".$data['itemname']."</td>";
......
......@@ -975,7 +975,7 @@ abstract class API extends CommonGLPI {
getEntitiesRestrictRequest("AND", "glpi_tickets")."
ORDER BY `glpi_tickets`.`date_mod` DESC";
if ($result = $DB->query($query)) {
while ($data = $DB->fetch_assoc($result)) {
while ($data = $DB->fetchAssoc($result)) {
$fields['_tickets'][] = $data;
}
}
......@@ -999,7 +999,7 @@ abstract class API extends CommonGLPI {
getEntitiesRestrictRequest("AND", "glpi_problems")."
ORDER BY `glpi_problems`.`date_mod` DESC";
if ($result = $DB->query($query)) {
while ($data = $DB->fetch_assoc($result)) {
while ($data = $DB->fetchAssoc($result)) {
$fields['_problems'][] = $data;
}
}
......@@ -1023,7 +1023,7 @@ abstract class API extends CommonGLPI {
getEntitiesRestrictRequest("AND", "glpi_changes")."
ORDER BY `glpi_changes`.`date_mod` DESC";
if ($result = $DB->query($query)) {
while ($data = $DB->fetch_assoc($result)) {
while ($data = $DB->fetchAssoc($result)) {
$fields['_changes'][] = $data;
}
}
......@@ -1268,7 +1268,7 @@ abstract class API extends CommonGLPI {
ORDER BY ".$params['sort']." ".$params['order']."
LIMIT ".$params['start'].", ".$params['list_limit'];
if ($result = $DB->query($query)) {
while ($data = $DB->fetch_assoc($result)) {
while ($data = $DB->fetchAssoc($result)) {
$found[] = $data;
}
}
......
......@@ -235,7 +235,7 @@ class Cartridge extends CommonDBChild {
'id' => $input['id']
]
);
if ($result && ($DB->affected_rows() > 0)) {
if ($result && ($DB->affectedRows() > 0)) {
return true;
}
return false;
......@@ -281,7 +281,7 @@ class Cartridge extends CommonDBChild {
'date_use' => null
]
);
if ($result && ($DB->affected_rows() > 0)) {
if ($result && ($DB->affectedRows() > 0)) {
$changes = [
'0',
'',
......@@ -326,7 +326,7 @@ class Cartridge extends CommonDBChild {
);
if ($result
&& ($DB->affected_rows() > 0)) {
&& ($DB->affectedRows() > 0)) {
$changes = [
'0',
'',
......
......@@ -162,7 +162,7 @@ class CartridgeItem extends CommonDBTM {
];
$result = $DB->insert('glpi_cartridgeitems_printermodels', $params);
if ($result && ($DB->affected_rows() > 0)) {
if ($result && ($DB->affectedRows() > 0)) {
return true;
}
}
......@@ -594,7 +594,7 @@ class CartridgeItem extends CommonDBTM {
$datas = [];
if ($result = $DB->query($query)) {
if ($DB->numrows($result)) {
while ($data= $DB->fetch_assoc($result)) {
while ($data= $DB->fetchAssoc($result)) {
$text = sprintf(__('%1$s - %2$s'), $data["name"], $data["ref"]);
$text = sprintf(__('%1$s (%2$s)'), $text, $data["cpt"]);
$text = sprintf(__('%1$s - %2$s'), $text, $data["location"]);
......
......@@ -1174,7 +1174,7 @@ class Change extends CommonITILObject {
if ($number > 0) {
self::commonListHeader(Search::HTML_OUTPUT);
while ($data = $DB->fetch_assoc($result)) {
while ($data = $DB->fetchAssoc($result)) {
Session::addToNavigateListItems('Problem', $data["id"]);
self::showShort($data["id"]);
}
......@@ -1216,7 +1216,7 @@ class Change extends CommonITILObject {
if ($number > 0) {
self::commonListHeader(Search::HTML_OUTPUT);
while ($data = $DB->fetch_assoc($result)) {
while ($data = $DB->fetchAssoc($result)) {
// Session::addToNavigateListItems(TRACKING_TYPE,$data["id"]);
self::showShort($data["id"]);
}
......
......@@ -495,7 +495,7 @@ class CommonDBTM extends CommonGLPI {
$data = [];
if ($result = $DB->query($query)) {
if ($DB->numrows($result)) {
while ($line = $DB->fetch_assoc($result)) {
while ($line = $DB->fetchAssoc($result)) {
$data[$line['id']] = $line;
}
}
......@@ -554,7 +554,7 @@ class CommonDBTM extends CommonGLPI {
$table = $this->getTable();
if (!empty($table) &&
($fields = $DB->list_fields($table))) {
($fields = $DB->listFields($table))) {
foreach (array_keys($fields) as $key) {
$this->fields[$key] = "";
......@@ -615,7 +615,7 @@ class CommonDBTM extends CommonGLPI {
[$field => $this->fields[$field]],
['id' => $this->fields['id']]
);
if ($DB->affected_rows() == 0) {
if ($DB->affectedRows() == 0) {
if (isset($oldvalues[$field])) {
unset($oldvalues[$field]);
}
......@@ -661,7 +661,7 @@ class CommonDBTM extends CommonGLPI {
if (!isset($this->fields['id'])
|| is_null($this->fields['id'])
|| ($this->fields['id'] == 0)) {
$this->fields['id'] = $DB->insert_id();
$this->fields['id'] = $DB->insertId();
}
return $this->fields['id'];
......@@ -1117,7 +1117,7 @@ class CommonDBTM extends CommonGLPI {
if ($this->input && is_array($this->input)) {
$this->fields = [];
$table_fields = $DB->list_fields($this->getTable());
$table_fields = $DB->listFields($this->getTable());
// fill array for add
foreach (array_keys($this->input) as $key) {
......
......@@ -1035,7 +1035,7 @@ abstract class CommonITILTask extends CommonDBTM {
$interv = [];
if ($DB->numrows($result) > 0) {
for ($i=0; $data=$DB->fetch_assoc($result); $i++) {
for ($i=0; $data=$DB->fetchAssoc($result); $i++) {
if ($item->getFromDB($data["id"])
&& $item->canViewItem()) {
if ($parentitem->getFromDBwithData($item->fields[$parentitem->getForeignKeyField()], 0)) {
......
......@@ -608,7 +608,7 @@ class Consumable extends CommonDBChild {
if ($result = $DB->query($query)) {
if ($DB->numrows($result)) {
while ($data = $DB->fetch_assoc($result)) {
while ($data = $DB->fetchAssoc($result)) {
$used[$data['itemtype'].'####'.$data['items_id']][$data["consumableitems_id"]]
= $data["count"];
}
......@@ -626,7 +626,7 @@ class Consumable extends CommonDBChild {
if ($result = $DB->query($query)) {
if ($DB->numrows($result)) {
while ($data = $DB->fetch_assoc($result)) {
while ($data = $DB->fetchAssoc($result)) {
$new[$data["consumableitems_id"]] = $data["count"];
}
}
......@@ -639,7 +639,7 @@ class Consumable extends CommonDBChild {
if ($result = $DB->query($query)) {
if ($DB->numrows($result)) {
while ($data = $DB->fetch_assoc($result)) {
while ($data = $DB->fetchAssoc($result)) {
$types[$data["id"]] = $data["name"];
}
}
......
......@@ -1542,7 +1542,7 @@ class Contract extends CommonDBTM {
$group = '';
$prev = -1;
$values = [];
while ($data = $DB->fetch_assoc($result)) {
while ($data = $DB->fetchAssoc($result)) {
if ($p['nochecklimit']
|| ($data["max_links_allowed"] == 0)
|| ($data["max_links_allowed"] > countElementsInTable('glpi_contracts_items',
......
......@@ -373,7 +373,7 @@ class ContractCost extends CommonDBChild {
Contract::getTypeName(1), $contract->getName()));
$total = 0;
while ($data = $DB->fetch_assoc($result)) {
while ($data = $DB->fetchAssoc($result)) {
echo "<tr class='tab_bg_2' ".
($canedit
? "style='cursor:pointer' onClick=\"viewEditCost".$data['contracts_id']."_".
......
......@@ -218,7 +218,7 @@ class CronTask extends CommonDBTM{
]
);
if ($DB->affected_rows($result)>0) {
if ($DB->affectedRows($result)>0) {
$this->timer = microtime(true);
$this->volume = 0;
$log = new CronTaskLog();
......@@ -283,7 +283,7 @@ class CronTask extends CommonDBTM{
]
);
if ($DB->affected_rows($result) > 0) {
if ($DB->affectedRows($result) > 0) {
// No gettext for log but add gettext line to be parsed for pot generation
// order is important for insertion in english in the database
if (is_null($retcode)) {
......@@ -410,7 +410,7 @@ class CronTask extends CommonDBTM{
if ($result = $DB->query($query)) {
if ($DB->numrows($result)>0) {
$this->fields = $DB->fetch_assoc($result);
$this->fields = $DB->fetchAssoc($result);
return true;
}
}
......@@ -934,7 +934,7 @@ class CronTask extends CommonDBTM{
$result = $DB->query($query);
if ($DB->numrows($result)) {
while ($data = $DB->fetch_assoc($result)) {
while ($data = $DB->fetchAssoc($result)) {
if (!$temp->delete($data)) {
$ret = false;
}
......@@ -992,7 +992,7 @@ class CronTask extends CommonDBTM{
AND `state` = '".CronTaskLog::STATE_STOP."'";
$result = $DB->query($query);
if ($data = $DB->fetch_assoc($result)) {
if ($data = $DB->fetchAssoc($result)) {
echo "<tr class='tab_bg_1'><td>".__('Start date')."</td>";
echo "<td class='right'>".Html::convDateTime($data['datemin'])."</td></tr>";
......@@ -1089,7 +1089,7 @@ class CronTask extends CommonDBTM{
LIMIT ".intval($start)."," . intval($_SESSION['glpilist_limit']);
if ($result = $DB->query($query)) {
if ($data = $DB->fetch_assoc($result)) {
if ($data = $DB->fetchAssoc($result)) {
echo "<table class='tab_cadrehov'>";
$header = "<tr>";
$header .= "<th>".__('Date')."</th>";
......@@ -1112,7 +1112,7 @@ class CronTask extends CommonDBTM{
// Use gettext to display
echo "<td>".__($data['content'])."</td>";
echo "</tr>\n";
} while ($data = $DB->fetch_assoc($result));
} while ($data = $DB->fetchAssoc($result));
echo $header;
echo "</table>";
......@@ -1147,7 +1147,7 @@ class CronTask extends CommonDBTM{
ORDER BY `id` ASC";
if ($result = $DB->query($query)) {
if ($data = $DB->fetch_assoc($result)) {
if ($data = $DB->fetchAssoc($result)) {
echo "<table class='tab_cadrehov'><tr>";
echo "<th>".__('Date')."</th>";
echo "<th>".__('Status')."</th>";
......@@ -1194,7 +1194,7 @@ class CronTask extends CommonDBTM{
echo "<td>".$content."</td>";
echo "</tr>\n";
$first = false;
} while ($data = $DB->fetch_assoc($result));
} while ($data = $DB->fetchAssoc($result));
echo "</table>";
......
......@@ -65,7 +65,7 @@ class CronTaskLog extends CommonDBTM{
AND UNIX_TIMESTAMP(date) < UNIX_TIMESTAMP()-$secs";
$DB->query($query_exp);
return $DB->affected_rows();
return $DB->affectedRows();
}
......
......@@ -287,13 +287,28 @@ class DBmysql {
/**
* Fetch array of the next row of a Mysql query
* Please prefer fetch_row or fetch_assoc
* Please prefer fetchRow or fetchAssoc
*
* @param mysqli_result $result MySQL result handler
*
* @return string[]|null array results
*
* @deprecated 9.5.0
*/
function fetch_array($result) {
Toolbox::deprecated('Use DBmysql::fetchArray()');
return $this->fetchArray($result);
}
/**
* Fetch array of the next row of a Mysql query
* Please prefer fetchRow or fetchAssoc
*
* @param mysqli_result $result MySQL result handler
*
* @return string[]|null array results
*/
function fetchArray($result) {
return $result->fetch_array();
}
......@@ -303,8 +318,22 @@ class DBmysql {
* @param mysqli_result $result MySQL result handler
*
* @return mixed|null result row
*
* @deprecated 9.5.0
*/
function fetch_row($result) {
Toolbox::deprecated('Use DBmysql::fetchRow()');
return $this->fetchRow($result);
}
/**
* Fetch row of the next row of a Mysql query
*
* @param mysqli_result $result MySQL result handler
*
* @return mixed|null result row
*/
function fetchRow($result) {
return $result->fetch_row();
}
......@@ -314,8 +343,22 @@ class DBmysql {
* @param mysqli_result $result MySQL result handler
*
* @return string[]|null result associative array
*
* @deprecated 9.5.0
*/
function fetch_assoc($result) {
Toolbox::deprecated('Use DBmysql::fetchAssoc()');
return $this->fetchAssoc($result);
}
/**
* Fetch assoc of the next row of a Mysql query
*
* @param mysqli_result $result MySQL result handler
*
* @return string[]|null result associative array
*/
function fetchAssoc($result) {
return $result->fetch_assoc();
}
......@@ -327,41 +370,98 @@ class DBmysql {
* @return object|null
*/
function fetch_object($result) {
Toolbox::deprecated('Use DBmysql::fetchObject()');
return $this->fetchObject();
}
/**
* Fetch object of the next row of an SQL query
*
* @param mysqli_result $result MySQL result handler
*
* @return object|null
*/
function fetchObject($result) {
return $result->fetch_object();
}
/**
* Move current pointer of a Mysql result to the specific row
*
* @deprecated 9.5.0
*
* @param mysqli_result $result MySQL result handler
* @param integer $num Row to move current pointer
*
* @return boolean
*/
function data_seek($result, $num) {
Toolbox::deprecated('Use DBmysql::dataSeek()');
return $this->dataSeek($result, $num);
}
/**
* Move current pointer of a Mysql result to the specific row
*
* @param mysqli_result $result MySQL result handler
* @param integer $num Row to move current pointer
*
* @return boolean
*/
function dataSeek($result, $num) {
return $result->data_seek($num);
}
/**
* Give ID of the last inserted item by Mysql
*
* @return mixed
*
* @deprecated 9.5.0
*/
function insert_id() {
Toolbox::deprecated('Use DBmysql::insertId()');
return $this->insertId();
}
/**
* Give ID of the last inserted item by Mysql
*
* @return mixed
*
* @deprecated 9.5.0
*/
function insertId() {
return $this->dbh->insert_id;
}
/**
* Give number of fields of a Mysql result
*
* @deprecated 9.5.0
*
* @param mysqli_result $result MySQL result handler
*
* @return int number of fields
*/
function num_fields($result) {
Toolbox::deprecated('Use DBmysql::numFields()');
return $this->numFields($result);
}
/**
* Give number of fields of a Mysql result
*
* @param mysqli_result $result MySQL result handler
*
* @return int number of fields
*/
function numFields($result) {
return $result->field_count;
}
/**
* Give name of a field of a Mysql result
*
......@@ -369,8 +469,25 @@ class DBmysql {
* @param integer $nb ID of the field
*
* @return string name of the field
*
* @deprecated 9.5.0
*/
function field_name($result, $nb) {
Toolbox::deprecated('Use DBmysql::fieldName()');
return $this->fieldName($result, $nb);
}
/**
* Give name of a field of a Mysql result
*
* @param mysqli_result $result MySQL result handler
* @param integer $nb ID of the field
*
* @return string name of the field
*
* @deprecated 9.5.0
*/
function fieldName($result, $nb) {
$finfo = $result->fetch_fields();
return $finfo[$nb]->name;
}
......@@ -397,12 +514,16 @@ class DBmysql {
return $iterator;
}
public function getMyIsamTables() {
/**
* Returns tables using "MyIsam" engine.
*
* @return DBmysqlIterator
*/
public function getMyIsamTables(): DBmysqlIterator {
$iterator = $this->listTables('glpi_%', ['engine' => 'MyIsam']);
return $iterator;
}
/**
* List fields of a table
*
......@@ -410,8 +531,24 @@ class DBmysql {
* @param boolean $usecache If use field list cache (default true)
*
* @return mixed list of fields
*
* @deprecated 9.5.0
*/
function list_fields($table, $usecache = true) {
Toolbox::deprecated('Use DBmysql::listFields()');
return $this->listFields($table, $usecache);
}
/**
* List fields of a table
*
* @param string $table Table name condition
* @param boolean $usecache If use field list cache (default true)
*
* @return mixed list of fields
*/
function listFields($table, $usecache = true) {
static $cache = [];
if (!$this->cache_disabled && $usecache && isset($cache[$table])) {
......@@ -421,7 +558,7 @@ class DBmysql {
if ($result) {
if ($this->numrows($result) > 0) {
$cache[$table] = [];
while ($data = $result->fetch_assoc()) {
while ($data = $this->fetchAssoc($result)) {
$cache[$table][$data["Field"]] = $data;
}
return $cache[$table];
......@@ -435,19 +572,46 @@ class DBmysql {
* Get number of affected rows in previous MySQL operation
*
* @return int number of affected rows on success, and -1 if the last query failed.
*
* @deprecated 9.5.0
*/
function affected_rows() {
Toolbox::deprecated('Use DBmysql::affectedRows()');
return $this->affectedRows();
}
/**
* Get number of affected rows in previous MySQL operation
*
* @return int number of affected rows on success, and -1 if the last query failed.
*/
function affectedRows() {
return $this->dbh->affected_rows;
}
/**
* Free result memory
*
* @param mysqli_result $result MySQL result handler
*
* @return boolean TRUE on success or FALSE on failure.
* @return boolean
*
* @deprecated 9.5.0
*/
function free_result($result) {
Toolbox::deprecated('Use DBmysql::freeResult()');
return $this->freeResult($result);
}
/**
* Free result memory
*
* @param mysqli_result $result MySQL result handler
*
* @return boolean
*/
function freeResult($result) {
return $result->free();
}
......@@ -606,15 +770,18 @@ class DBmysql {
/**