Commit d3db2649 authored by Johan Cwiklinski's avatar Johan Cwiklinski Committed by Johan Cwiklinski

Rename getAllDatasFromTable and deprecate raw order

parent 083f73c2
......@@ -29,6 +29,8 @@ The present file will list all changes made to the project; according to the
- `DBMysql::affected_rows()`
- `DBMysql::free_result()`
- `DBMysql::isMySQLStrictMode()`
- `getAllDatasFromTable` renamed to `getAllDataFromTable()`
- Usage of `$order` parameter in `getAllDataFromTable()` (`DbUtils::getAllDataFromTable()`)
## [9.4.2] unreleased
......
......@@ -553,7 +553,7 @@ abstract class API extends CommonGLPI {
&& in_array($itemtype, Item_Devices::getConcernedItems())) {
$all_devices = [];
foreach (Item_Devices::getItemAffinities($item->getType()) as $device_type) {
$found_devices = getAllDatasFromTable(
$found_devices = getAllDataFromTable(
$device_type::getTable(), [
'items_id' => $item->getID(),
'itemtype' => $item->getType(),
......@@ -1048,7 +1048,7 @@ abstract class API extends CommonGLPI {
if (!Session::haveRight($itemtype::$rightname, READNOTE)) {
$fields['_logs'] = self::arrayRightError();
} else {
$fields['_logs'] = getAllDatasFromTable(
$fields['_logs'] = getAllDataFromTable(
"glpi_logs", [
'items_id' => $item->getID(),
'itemtype' => $item->getType()
......
......@@ -568,8 +568,8 @@ class Auth extends CommonGLPI {
//Return all the authentication methods in an array
$this->authtypes = [
'ldap' => getAllDatasFromTable('glpi_authldaps'),
'mail' => getAllDatasFromTable('glpi_authmails')
'ldap' => getAllDataFromTable('glpi_authldaps'),
'mail' => getAllDataFromTable('glpi_authmails')
];
}
......@@ -654,7 +654,7 @@ class Auth extends CommonGLPI {
$ldapservers[] = $authldap->fields;
}
} else { // User has never beeen authenticated : try all active ldap server to find the right one
foreach (getAllDatasFromTable('glpi_authldaps', ['is_active' => 1]) as $ldap_config) {
foreach (getAllDataFromTable('glpi_authldaps', ['is_active' => 1]) as $ldap_config) {
$ldapservers[] = $ldap_config;
}
}
......
......@@ -2641,7 +2641,7 @@ class AuthLDAP extends CommonDBTM {
* @return array
*/
static function getLdapServers() {
return getAllDatasFromTable('glpi_authldaps', [], false, '`is_default` DESC');
return getAllDataFromTable('glpi_authldaps', ['ORDER' => 'is_default DESC']);
}
......
......@@ -247,10 +247,10 @@ class Blacklist extends CommonDropdown {
**/
static function getBlacklistedItems($type) {
$datas = getAllDatasFromTable('glpi_blacklists', ['type' => $type]);
$data = getAllDataFromTable('glpi_blacklists', ['type' => $type]);
$items = [];
if (count($datas)) {
foreach ($datas as $val) {
if (count($data)) {
foreach ($data as $val) {
$items[] = $val['value'];
}
}
......
......@@ -828,7 +828,7 @@ class Budget extends CommonDropdown{
echo "</tr>";
// get all entities ordered by names
$allentities = getAllDatasFromTable('glpi_entities', [], true, 'completename');
$allentities = getAllDataFromTable('glpi_entities', ['ORDER' => 'completename'], true);
foreach (array_keys($allentities) as $entity) {
if (isset($entities_values[$entity])) {
......
......@@ -135,7 +135,7 @@ class CalendarSegment extends CommonDBChild {
static function getSegmentsBetween($calendars_id, $begin_day, $begin_time, $end_day, $end_time) {
// Do not check hour if day before the end day of after the begin day
return getAllDatasFromTable(
return getAllDataFromTable(
'glpi_calendarsegments', [
'calendars_id' => $calendars_id,
['day' => ['>=', $begin_day]],
......
......@@ -4241,7 +4241,7 @@ class CommonDBTM extends CommonGLPI {
$message[$field] = $this->input[$field];
}
$doubles = getAllDatasFromTable($this->getTable(), $where);
$doubles = getAllDataFromTable($this->getTable(), $where);
$message_text = $this->getUnicityErrorMessage($message, $fields, $doubles);
if ($p['unicity_error_message']) {
if (!$fields['action_refuse']) {
......
......@@ -3789,7 +3789,7 @@ abstract class CommonITILObject extends CommonDBTM {
? $options['entities_id']: $options['entity_restrict'])];
//only for active ldap and corresponding right
$ldap_methods = getAllDatasFromTable('glpi_authldaps', ['is_active' => 1]);
$ldap_methods = getAllDataFromTable('glpi_authldaps', ['is_active' => 1]);
if (count($ldap_methods)
&& Session::haveRight('user', User::IMPORTEXTAUTHUSERS)) {
$params['ldap_import'] = true;
......
......@@ -1391,7 +1391,7 @@ abstract class CommonITILValidation extends CommonDBChild {
$statuses = [self::ACCEPTED => 0,
self::WAITING => 0,
self::REFUSED => 0];
$validations = getAllDatasFromTable(
$validations = getAllDataFromTable(
static::getTable(), [
static::$items_id => $item->getID()
]
......
......@@ -244,7 +244,7 @@ class ComputerVirtualMachine extends CommonDBChild {
echo "<div class='center'>";
if (isset($comp->fields['uuid']) && ($comp->fields['uuid'] != '')) {
$hosts = getAllDatasFromTable(
$hosts = getAllDataFromTable(
self::getTable(), [
'RAW' => [
'LOWER(uuid)' => self::getUUIDRestrictCriteria($comp->fields['uuid'])
......@@ -323,13 +323,14 @@ class ComputerVirtualMachine extends CommonDBChild {
echo "<div class='center'>";
$virtualmachines = getAllDatasFromTable(
$virtualmachines = getAllDataFromTable(
self::getTable(), [
'computers_id' => $ID,
'is_deleted' => 0
],
false,
'name'
'WHERE' => [
'computers_id' => $ID,
'is_deleted' => 0
],
'ORDER' => 'name'
]
);
echo "<table class='tab_cadre_fixehov'>";
......
......@@ -223,7 +223,7 @@ function countElementsInTableForEntity($table, $entity, $condition = [], $recurs
/**
* Get datas from a table in an array :
* Get data from a table in an array :
* CAUTION TO USE ONLY FOR SMALL TABLES OR USING A STRICT CONDITION
*
* @param string $table table name
......@@ -232,12 +232,31 @@ function countElementsInTableForEntity($table, $entity, $condition = [], $recurs
* @param string $order result order (default '')
*
* @return array containing all the datas
*
* @deprecated 9.5.0
**/
function getAllDatasFromTable($table, $condition = [], $usecache = false, $order = '') {
$dbu = new DbUtils();
return $dbu->getAllDataFromTable($table, $condition, $usecache, $order);
Toolbox::deprecated('Use getAllDataFromTable()');
return getAllDataFromTable($table, $condition, $usecache, $order);
}
/**
* Get data from a table in an array :
* CAUTION TO USE ONLY FOR SMALL TABLES OR USING A STRICT CONDITION
*
* @param string $table table name
* @param array $criteria condition to use (default [])
* @param boolean $usecache Use cache (false by default)
* @param string $order result order (default '')
*
* @return array containing all the datas
*
* @since 9.5.0
**/
function getAllDataFromTable($table, $criteria = [], $usecache = false, $order = '') {
$dbu = new DbUtils();
return $dbu->getAllDataFromTable($table, $criteria, $usecache, $order);
}
/**
* Get the Name of the element of a Dropdown Tree table
*
......
......@@ -399,45 +399,46 @@ final class DbUtils {
}
/**
* Get datas from a table in an array :
* Get data from a table in an array :
* CAUTION TO USE ONLY FOR SMALL TABLES OR USING A STRICT CONDITION
*
* @param string $table Table name
* @param array $condition Condition to use (default '') or array of criteria
* @param boolean $usecache Use cache (false by default)
* @param string $order Result order (default '')
* @param string $table Table name
* @param array $criteria Request criteria
* @param boolean $usecache Use cache (false by default)
* @param string $order Result order (default '')
*
* @return array containing all the datas
*/
public function getAllDataFromTable($table, $condition = [], $usecache = false, $order = '') {
public function getAllDataFromTable($table, $criteria = [], $usecache = false, $order = '') {
global $DB;
static $cache = [];
if (empty($condition) && empty($order) && $usecache && isset($cache[$table])) {
if (empty($criteria) && empty($order) && $usecache && isset($cache[$table])) {
return $cache[$table];
}
$data = [];
if (!is_array($condition)) {
if (empty($condition)) {
$condition = [];
if (!is_array($criteria)) {
Toolbox::Deprecated('Criteria must be an array!');
if (empty($criteria)) {
$criteria = [];
}
}
if (!empty($order)) {
//Toolbox::Deprecated('Order should be defined in condition!');
$condition['ORDER'] = $order; // Deprecated use case
Toolbox::Deprecated('Order should be defined in criteria!');
$criteria['ORDER'] = $order; // Deprecated use case
}
$iterator = $DB->request($table, $condition);
$iterator = $DB->request($table, $criteria);
while ($row = $iterator->next()) {
$data[$row['id']] = $row;
}
if (empty($condition) && empty($order) && $usecache) {
if (empty($criteria) && empty($order) && $usecache) {
$cache[$table] = $data;
}
return $data;
......
......@@ -1490,7 +1490,8 @@ class Entity extends CommonTreeDropdown {
$options[self::CONFIG_PARENT] = __('Inheritance of the parent entity');
}
foreach (getAllDatasFromTable('glpi_states') as $state) {
$states = getAllDataFromTable('glpi_states');
foreach ($states as $state) {
$options[Infocom::ON_STATUS_CHANGE.'_'.$state['id']]
//TRANS: %s is the name of the state
= sprintf(__('Fill when shifting to state %s'), $state['name']);
......@@ -1558,7 +1559,7 @@ class Entity extends CommonTreeDropdown {
$options[self::CONFIG_PARENT] = __('Inheritance of the parent entity');
}
foreach (getAllDatasFromTable('glpi_states') as $state) {
foreach ($states as $state) {
$options[Infocom::ON_STATUS_CHANGE.'_'.$state['id']]
//TRANS: %s is the name of the state
= sprintf(__('Fill when shifting to state %s'), $state['name']);
......@@ -2782,7 +2783,8 @@ class Entity extends CommonTreeDropdown {
case 'autofill_decommission_date' :
$tab[0] = __('No autofill');
$tab[self::CONFIG_PARENT] = __('Inheritance of the parent entity');
foreach (getAllDatasFromTable('glpi_states') as $state) {
$states = getAllDataFromTable('glpi_states');
foreach ($states as $state) {
$tab[Infocom::ON_STATUS_CHANGE.'_'.$state['id']]
//TRANS: %s is the name of the state
= sprintf(__('Fill when shifting to state %s'), $state['name']);
......
......@@ -411,7 +411,7 @@ class Item_Ticket extends CommonDBRelation{
self::dropdownMyDevices($dev_user_id, $ticket->fields["entities_id"], null, 0, ['tickets_id' => $instID]);
}
$data = array_keys(getAllDatasFromTable('glpi_items_tickets'));
$data = array_keys(getAllDataFromTable('glpi_items_tickets'));
$used = [];
if (!empty($data)) {
foreach ($data as $val) {
......@@ -1045,11 +1045,12 @@ class Item_Ticket extends CommonDBRelation{
* Return used items for a ticket
*
* @param type $tickets_id
*
* @return type
*/
static function getUsedItems($tickets_id) {
$data = getAllDatasFromTable('glpi_items_tickets', ['tickets_id' => $tickets_id]);
$data = getAllDataFromTable('glpi_items_tickets', ['tickets_id' => $tickets_id]);
$used = [];
if (!empty($data)) {
foreach ($data as $val) {
......
......@@ -1946,7 +1946,7 @@ class MailCollector extends CommonDBTM {
$buttons["notimportedemail.php"] = __('List of not imported emails');
}
$errors = getAllDatasFromTable($this->getTable(), ['errors' => ['>', 0]]);
$errors = getAllDataFromTable($this->getTable(), ['errors' => ['>', 0]]);
$message = '';
if (count($errors)) {
$servers = [];
......
......@@ -70,7 +70,7 @@ abstract class NotificationEventAbstract {
}
$notprocessed = [];
$targets = getAllDatasFromTable(
$targets = getAllDataFromTable(
'glpi_notificationtargets',
['notifications_id' => $data['id']]
);
......
......@@ -330,7 +330,7 @@ class NotificationTarget extends CommonDBChild {
list($type,$id) = explode('_', $key);
$values[$key] = $this->notification_targets_labels[$type][$id];
}
$targets = getAllDatasFromTable(
$targets = getAllDataFromTable(
self::getTable(), [
'notifications_id' => $notifications_id
]
......@@ -376,7 +376,7 @@ class NotificationTarget extends CommonDBChild {
if (!isset($input['notifications_id'])) {
return;
}
$targets = getAllDatasFromTable(
$targets = getAllDataFromTable(
self::getTable(), [
'notifications_id' => $input['notifications_id']
]
......
......@@ -89,7 +89,7 @@ class NotificationTargetChange extends NotificationTargetCommonITILObject {
// Complex mode
if (!$simple) {
$restrict = ['changes_id' => $item->getField('id')];
$tickets = getAllDatasFromTable('glpi_changes_tickets', $restrict);
$tickets = getAllDataFromTable('glpi_changes_tickets', $restrict);
$data['tickets'] = [];
if (count($tickets)) {
......@@ -111,7 +111,7 @@ class NotificationTargetChange extends NotificationTargetCommonITILObject {
$data['##change.numberoftickets##'] = count($data['tickets']);
$problems = getAllDatasFromTable('glpi_changes_problems', $restrict);
$problems = getAllDataFromTable('glpi_changes_problems', $restrict);
$data['problems'] = [];
if (count($problems)) {
......@@ -138,7 +138,7 @@ class NotificationTargetChange extends NotificationTargetCommonITILObject {
$data['##change.numberofproblems##'] = count($data['problems']);
$items = getAllDatasFromTable('glpi_changes_items', $restrict);
$items = getAllDataFromTable('glpi_changes_items', $restrict);
$data['items'] = [];
if (count($items)) {
......@@ -199,11 +199,11 @@ class NotificationTargetChange extends NotificationTargetCommonITILObject {
$restrict['glpi_changevalidations.id'] = $options['validation_id'];
}
$validations = getAllDatasFromTable(
'glpi_changevalidations',
$restrict,
false,
['submission_date DESC', 'id ASC']
$validations = getAllDataFromTable(
'glpi_changevalidations', [
'WHERE' => $restrict,
'ORDER' => ['submission_date DESC', 'id ASC']
]
);
$data['validations'] = [];
foreach ($validations as $validation) {
......
......@@ -1207,7 +1207,12 @@ abstract class NotificationTargetCommonITILObject extends NotificationTarget {
$followup_restrict['itemtype'] = $objettype;
//Followup infos
$followups = getAllDatasFromTable('glpi_itilfollowups', $followup_restrict, false, ['date_mod DESC', 'id ASC']);
$followups = getAllDataFromTable(
'glpi_itilfollowups', [
'WHERE' => $followup_restrict,
'ORDER' => ['date_mod DESC', 'id ASC']
]
);
$data['followups'] = [];
foreach ($followups as $followup) {
$tmp = [];
......@@ -1316,12 +1321,11 @@ abstract class NotificationTargetCommonITILObject extends NotificationTarget {
$data["##$objettype.costtime##"] = $costs['costtime'];
$data["##$objettype.totalcost##"] = $costs['totalcost'];
$costs = getAllDatasFromTable(
getTableForItemType($costtype),
[$item->getForeignKeyField() => $item->getField('id')],
false,
['begin_date DESC', 'id ASC']
$costs = getAllDataFromTable(
getTableForItemType($costtype), [
'WHERE' => [$item->getForeignKeyField() => $item->getField('id')],
'ORDER' => ['begin_date DESC', 'id ASC']
]
);
$data['costs'] = [];
foreach ($costs as $cost) {
......@@ -1354,11 +1358,11 @@ abstract class NotificationTargetCommonITILObject extends NotificationTarget {
$restrict['is_private'] = 0;
}
$tasks = getAllDatasFromTable(
$taskobj->getTable(),
$restrict,
false,
['date_mod DESC', 'id ASC']
$tasks = getAllDataFromTable(
$taskobj->getTable(), [
'WHERE' => $restrict,
'ORDER' => ['date_mod DESC', 'id ASC']
]
);
$data['tasks'] = [];
foreach ($tasks as $task) {
......
......@@ -72,7 +72,7 @@ class NotificationTargetProblem extends NotificationTargetCommonITILObject {
// Complex mode
if (!$simple) {
$restrict = ['problems_id' => $item->getField('id')];
$tickets = getAllDatasFromTable('glpi_problems_tickets', $restrict);
$tickets = getAllDataFromTable('glpi_problems_tickets', $restrict);
$data['tickets'] = [];
if (count($tickets)) {
......@@ -100,7 +100,7 @@ class NotificationTargetProblem extends NotificationTargetCommonITILObject {
$data['##problem.numberoftickets##'] = count($data['tickets']);
$changes = getAllDatasFromTable('glpi_changes_problems', $restrict);
$changes = getAllDataFromTable('glpi_changes_problems', $restrict);
$data['changes'] = [];
if (count($changes)) {
......@@ -127,7 +127,7 @@ class NotificationTargetProblem extends NotificationTargetCommonITILObject {
$data['##problem.numberofchanges##'] = count($data['changes']);
$items = getAllDatasFromTable('glpi_items_problems', $restrict);
$items = getAllDataFromTable('glpi_items_problems', $restrict);
$data['items'] = [];
if (count($items)) {
......
......@@ -314,7 +314,7 @@ class NotificationTargetProject extends NotificationTarget {
}
// Team infos
$restrict = ['projects_id' => $item->getField('id')];
$items = getAllDatasFromTable('glpi_projectteams', $restrict);
$items = getAllDataFromTable('glpi_projectteams', $restrict);
$this->data['teammembers'] = [];
if (count($items)) {
......@@ -333,7 +333,12 @@ class NotificationTargetProject extends NotificationTarget {
$this->data['##project.numberofteammembers##'] = count($this->data['teammembers']);
// Task infos
$tasks = getAllDatasFromTable('glpi_projecttasks', $restrict, false, ['date DESC', 'id ASC']);
$tasks = getAllDataFromTable(
'glpi_projecttasks', [
'WHERE' => $restrict,
'ORDER' => ['date DESC', 'id ASC']
]
);
$this->data['tasks'] = [];
foreach ($tasks as $task) {
$tmp = [];
......@@ -372,7 +377,12 @@ class NotificationTargetProject extends NotificationTarget {
$this->data["##project.numberoftasks##"] = count($this->data['tasks']);
//costs infos
$costs = getAllDatasFromTable('glpi_projectcosts', $restrict, false, ['begin_date DESC', 'id ASC']);
$costs = getAllDataFromTable(
'glpi_projectcosts', [
'WHERE' => $restrict,
'ORDER' => ['begin_date DESC', 'id ASC']
]
);
$this->data['costs'] = [];
$this->data["##project.totalcost##"] = 0;
foreach ($costs as $cost) {
......@@ -414,7 +424,7 @@ class NotificationTargetProject extends NotificationTarget {
'projects_id' => $item->getField('id'),
'itemtype' => $itemtype,
];
$link_items = getAllDatasFromTable(Itil_Project::getTable(), $restrict);
$link_items = getAllDataFromTable(Itil_Project::getTable(), $restrict);
if (count($link_items)) {
$nitem = new $itemtype();
foreach ($link_items as $data) {
......@@ -488,7 +498,7 @@ class NotificationTargetProject extends NotificationTarget {
= count($this->data['documents']);
// Items infos
$items = getAllDatasFromTable('glpi_items_projects', $restrict);
$items = getAllDataFromTable('glpi_items_projects', $restrict);
$this->data['items'] = [];
if (count($items)) {
......
......@@ -290,7 +290,7 @@ class NotificationTargetProjectTask extends NotificationTarget {
// Team infos
$restrict = ['projecttasks_id' => $item->getField('id')];
$order = ['date DESC', 'id ASC'];
$items = getAllDatasFromTable('glpi_projecttaskteams', $restrict);
$items = getAllDataFromTable('glpi_projecttaskteams', $restrict);
$this->data['teammembers'] = [];
if (count($items)) {
......@@ -309,7 +309,12 @@ class NotificationTargetProjectTask extends NotificationTarget {
$this->data['##projecttask.numberofteammembers##'] = count($this->data['teammembers']);
// Task infos
$tasks = getAllDatasFromTable('glpi_projecttasks', $restrict, false, $order);
$tasks = getAllDataFromTable(
'glpi_projecttasks', [
'WHERE' => $restrict,
'ORDER' => $order
]
);
$this->data['tasks'] = [];
foreach ($tasks as $task) {
$tmp = [];
......@@ -363,7 +368,7 @@ class NotificationTargetProjectTask extends NotificationTarget {
$this->data["##projecttask.numberoflogs##"] = count($this->data['log']);
// Tickets infos
$tickets = getAllDatasFromTable('glpi_projecttasks_tickets', $restrict);
$tickets = getAllDataFromTable('glpi_projecttasks_tickets', $restrict);
$this->data['tickets'] = [];
if (count($tickets)) {
......@@ -439,7 +444,7 @@ class NotificationTargetProjectTask extends NotificationTarget {
= count($this->data['documents']);
// Items infos
$items = getAllDatasFromTable('glpi_items_projects', $restrict);
$items = getAllDataFromTable('glpi_items_projects', $restrict);
$this->getTags();
foreach ($this->tag_descriptions[NotificationTarget::TAG_LANGUAGE] as $tag => $values) {
......
......@@ -391,7 +391,7 @@ class NotificationTargetTicket extends NotificationTargetCommonITILObject {
$data['##ticket.numberoflinkedtickets##'] = count($data['linkedtickets']);
$restrict = ['tickets_id' => $item->getField('id')];
$problems = getAllDatasFromTable('glpi_problems_tickets', $restrict);
$problems = getAllDataFromTable('glpi_problems_tickets', $restrict);
$data['problems'] = [];
if (count($problems)) {
$problem = new Problem();
......@@ -418,7 +418,7 @@ class NotificationTargetTicket extends NotificationTargetCommonITILObject {
$data['##ticket.numberofproblems##'] = count($data['problems']);
$changes = getAllDatasFromTable('glpi_changes_tickets', $restrict);
$changes = getAllDataFromTable('glpi_changes_tickets', $restrict);
$data['changes'] = [];
if (count($changes)) {
$change = new Change();
......@@ -450,7 +450,12 @@ class NotificationTargetTicket extends NotificationTargetCommonITILObject {
'itemtype' => 'Ticket',
'items_id' => $item->getField('id')
];
$replysolved = getAllDatasFromTable('glpi_itilfollowups', $solution_restrict, false, ['date_mod DESC', 'id ASC']);
$replysolved = getAllDataFromTable(
'glpi_itilfollowups', [
'WHERE' => $solution_restrict,
'ORDER' => ['date_mod DESC', 'id ASC']
]
);
$current = current($replysolved);
$data['##ticket.solution.approval.description##'] = $current['content'];
$data['##ticket.solution.approval.date##'] = Html::convDateTime($current['date']);
......@@ -463,7 +468,13 @@ class NotificationTargetTicket extends NotificationTargetCommonITILObject {
$restrict['glpi_ticketvalidations.id'] = $options['validation_id'];
}
$validations = getAllDatasFromTable('glpi_ticketvalidations', $restrict, false, ['submission_date DESC', 'id ASC']);
$validations = getAllDataFromTable(
'glpi_ticketvalidations', [
'WHERE' => $restrict,
'ORDER' => ['submission_date DESC', 'id ASC']
],
false
);
$data['validations'] = [];
foreach ($validations as $validation) {
$tmp = [];
......
......@@ -324,7 +324,7 @@ class NotificationTemplateTranslation extends CommonDBChild {
**/
static function getAllUsedLanguages($language_id) {
$used_languages = getAllDatasFromTable(
$used_languages = getAllDataFromTable(
'glpi_notificationtemplatetranslations', [
'notificationtemplates_id' => $language_id
]
......
......@@ -625,7 +625,7 @@ class ObjectLock extends CommonDBTM {
$actionCode = 0; // by default
$task->setVolume(0); // start with zero
$lockedItems = getAllDatasFromTable(
$lockedItems = getAllDataFromTable(
getTableForItemType(__CLASS__), [