Commit 7e889a05 authored by Johan Cwiklinski's avatar Johan Cwiklinski Committed by Johan Cwiklinski
Browse files

Remove methods that have been deprecated in 9.4.0

parent 89f6b75c
......@@ -32,6 +32,26 @@ The present file will list all changes made to the project; according to the
- `getAllDatasFromTable` renamed to `getAllDataFromTable()`
- Usage of `$order` parameter in `getAllDataFromTable()` (`DbUtils::getAllDataFromTable()`)
#### Removed
- Usage of string `$condition` parameter in `CommonDBTM::find()`
- Usage of string `$condition` parameter in `Dropdown::addNewCondition()`
- Usage of string in `$option['condition']` parameter in `Dropdown::show()`
- `KnowbaseItemCategory::showFirstLevel()`
- `Ticket::getTicketActors()`
- `NotificationTarget::getProfileJoinSql()`
- `NotificationTarget::getDistinctUserSql()`
- `NotificationTargetCommonITILObject::getProfileJoinSql()`
- `RuleCollection::getRuleListQuery()`
- `getNextItem()`
- `getPreviousItem()`
- `CommonDBChild::getSQLRequestToSearchForItem()`
- `CommonDBConnexity::getSQLRequestToSearchForItem()`
- `CommonDBRelation::getSQLRequestToSearchForItem()`
- `Project::addVisibility()`
- `Project::addVisibilityJoins()`
## [9.4.2] unreleased
### API changes
......
......@@ -52,42 +52,6 @@ abstract class CommonDBChild extends CommonDBConnexity {
static public $log_history_lock = Log::HISTORY_LOCK_SUBITEM;
static public $log_history_unlock = Log::HISTORY_UNLOCK_SUBITEM;
/**
* @since 0.84
*
* @deprecated 9.4
*
* @param $itemtype
* @param $items_id
*
* @return string
**/
static function getSQLRequestToSearchForItem($itemtype, $items_id) {
Toolbox::deprecated('Use getSQLCriteriaToSearchForItem');
$fields = ['`'.static::getIndexName().'`'];
// Check item 1 type
$condition_id = "`".static::$items_id."` = '$items_id'";
$fields[] = "`".static::$items_id."` as items_id";
if (preg_match('/^itemtype/', static::$itemtype)) {
$fields[] = "`".static::$itemtype."` AS itemtype";
$condition = "($condition_id AND `".static::$itemtype."` = '$itemtype')";
} else {
$fields[] = "'".static::$itemtype."' AS itemtype";
if (($itemtype == static::$itemtype)
|| is_subclass_of($itemtype, static::$itemtype)) {
$condition = $condition_id;
}
}
if (isset($condition)) {
return "SELECT ".implode(', ', $fields)."
FROM `".static::getTable()."`
WHERE $condition";
}
return '';
}
/**
* Get request cirteria to search for an item
......
......@@ -89,23 +89,6 @@ abstract class CommonDBConnexity extends CommonDBTM {
/// Disable auto forwarding information about entities ?
static public $disableAutoEntityForwarding = false;
/**
* Return the SQL request to get all the connexities corresponding to $itemtype[$items_id]
* That is used by cleanDBOnItem : the only interesting field is static::getIndexName()
* But CommonDBRelation also use it to get more complex result
*
* @deprecated 9.4
*
* @param string $itemtype the type of the item to look for
* @param integer $items_id the id of the item to look for
*
* @return string the SQL request of '' if it is not possible
**/
static function getSQLRequestToSearchForItem($itemtype, $items_id) {
Toolbox::deprecated('Use getSQLCriteriaToSearchForItem');
return '';
}
/**
* Return the SQL request to get all the connexities corresponding to $itemtype[$items_id]
......
......@@ -80,72 +80,6 @@ abstract class CommonDBRelation extends CommonDBConnexity {
public $no_form_page = true;
/**
* @since 0.84
*
* @deprecated 9.4
*
* @param $itemtype
* @param $items_id
*
* @return string
**/
static function getSQLRequestToSearchForItem($itemtype, $items_id) {
Toolbox::deprecated('Use getSQLCriteriaToSearchForItem');
$conditions = [];
$fields = ['`'.static::getIndexName().'`'];
// Check item 1 type
$condition_id_1 = "`".static::$items_id_1."` = '$items_id'";
$fields[] = "`".static::$items_id_1."` as items_id_1";
if (preg_match('/^itemtype/', static::$itemtype_1)) {
$fields[] = "`".static::$itemtype_1."` AS itemtype_1";
$condition_1 = "($condition_id_1 AND `".static::$itemtype_1."` = '$itemtype')";
} else {
$fields[] = "'".static::$itemtype_1."' AS itemtype_1";
if (($itemtype == static::$itemtype_1)
|| is_subclass_of($itemtype, static::$itemtype_1)) {
$condition_1 = $condition_id_1;
}
}
if (isset($condition_1)) {
$conditions[] = $condition_1;
$fields[] = "IF($condition_1, 1, 0) AS is_1";
} else {
$fields[] = "0 AS is_1";
}
// Check item 2 type
$condition_id_2 = "`".static::$items_id_2."` = '$items_id'";
$fields[] = "`".static::$items_id_2."` as items_id_2";
if (preg_match('/^itemtype/', static::$itemtype_2)) {
$fields[] = "`".static::$itemtype_2."` AS itemtype_2";
$condition_2 = "($condition_id_2 AND `".static::$itemtype_2."` = '$itemtype')";
} else {
$fields[] = "'".static::$itemtype_2."' AS itemtype_2";
if (($itemtype == static::$itemtype_2)
|| is_subclass_of($itemtype, static::$itemtype_2)) {
$condition_2 = $condition_id_2;
}
}
if (isset($condition_2)) {
$conditions[] = $condition_2;
$fields[] = "IF($condition_2, 2, 0) AS is_2";
} else {
$fields[] = "0 AS is_2";
}
if (count($conditions) != 0) {
return "SELECT ".implode(', ', $fields)."
FROM `".static::getTable()."`
WHERE ".implode(' OR ', $conditions)."";
}
return '';
}
/**
* Get request cirteria to search for an item
*
......
......@@ -108,7 +108,7 @@ class CommonDBTM extends CommonGLPI {
protected $fkfield = "";
/**
* Search option of item. Initialized on first call to `self::getOptions()` and used as cache.
* Search option of item. Initialized on first call to self::getOptions() and used as cache.
*
* @var array
*
......@@ -472,60 +472,30 @@ class CommonDBTM extends CommonGLPI {
**/
function find($condition = [], $order = [], $limit = null) {
global $DB;
// Make new database object and fill variables
if (!is_array($condition)) {
Toolbox::deprecated('Using string condition in find is deprecated!');
$query = "SELECT *
FROM `".$this->getTable()."`";
if (!empty($condition)) {
$query .= " WHERE $condition";
}
if (!empty($order)) {
$query .= " ORDER BY $order";
}
if (!empty($limit)) {
$query .= " LIMIT ".intval($limit);
}
$data = [];
if ($result = $DB->query($query)) {
if ($DB->numrows($result)) {
while ($line = $DB->fetchAssoc($result)) {
$data[$line['id']] = $line;
}
}
}
} else {
//@since 9.4: use iterator
$criteria = [
'FROM' => $this->getTable()
];
$criteria = [
'FROM' => $this->getTable()
];
if (count($condition)) {
$criteria['WHERE'] = $condition;
}
if (count($condition)) {
$criteria['WHERE'] = $condition;
}
if (!is_array($order)) {
$order = [$order];
}
if (count($order)) {
$criteria['ORDERBY'] = $order;
}
if (!is_array($order)) {
$order = [$order];
}
if (count($order)) {
$criteria['ORDERBY'] = $order;
}
if ((int)$limit > 0) {
$criteria['LIMIT'] = (int)$limit;
}
if ((int)$limit > 0) {
$criteria['LIMIT'] = (int)$limit;
}
$data = [];
$iterator = $DB->request($criteria);
while ($line = $iterator->next()) {
$data[$line['id']] = $line;
}
$data = [];
$iterator = $DB->request($criteria);
while ($line = $iterator->next()) {
$data[$line['id']] = $line;
}
return $data;
......
......@@ -425,42 +425,6 @@ function regenerateTreeCompleteName($table) {
}
/**
* Get the ID of the next Item
*
* @deprecated 9.4
*
* @param string $table table to search next item
* @param integer $ID current ID
* @param string $condition condition to add to the search (default ='')
* @param string $nextprev_item field used to sort (default ='name')
*
* @return integer the next ID, -1 if not exist
*/
function getNextItem($table, $ID, $condition = "", $nextprev_item = "name") {
$dbu = new DbUtils();
return $dbu->getNextItem($table, $ID, $condition, $nextprev_item);
}
/**
* Get the ID of the previous Item
*
* @deprecated 9.4
*
* @param string $table table to search next item
* @param integer $ID current ID
* @param string $condition condition to add to the search (default ='')
* @param string $nextprev_item field used to sort (default ='name')
*
* @return integer the previous ID, -1 if not exist
*/
function getPreviousItem($table, $ID, $condition = "", $nextprev_item = "name") {
$dbu = new DbUtils();
return $dbu->getPreviousItem($table, $ID, $condition, $nextprev_item);
}
/**
* Format a user name
*
......
......@@ -1350,190 +1350,6 @@ final class DbUtils {
}
/**
* Get the ID of the next Item
*
* @deprecated 9.4
*
* @param string $table table to search next item
* @param integer $ID current ID
* @param string $condition condition to add to the search (default ='')
* @param string $nextprev_item field used to sort (default ='name')
*
* @return integer the next ID, -1 if not exist
*/
public function getNextItem($table, $ID, $condition = "", $nextprev_item = "name") {
global $DB;
Toolbox::deprecated();
if (empty($nextprev_item)) {
return false;
}
$itemtype = $this->getItemTypeForTable($table);
$item = new $itemtype();
$search = $ID;
if ($nextprev_item != "id") {
$iterator = $DB->request([
'SELECT' => $nextprev_item,
'FROM' => $table,
'WHERE' => ['id' => $ID]
]);
if (count($iterator) > 0) {
$search = addslashes($iterator->next()[$nextprev_item]);
} else {
$nextprev_item = "id";
}
}
$LEFTJOIN = '';
if ($table == "glpi_users") {
$LEFTJOIN = " LEFT JOIN `glpi_profiles_users`
ON (`glpi_users`.`id` = `glpi_profiles_users`.`users_id`)";
}
$query = "SELECT `$table`.`id`
FROM `$table`
$LEFTJOIN
WHERE (`$table`.`$nextprev_item` > '$search' ";
// Same name case
if ($nextprev_item != "id") {
$query .= " OR (`$table`.`".$nextprev_item."` = '$search'
AND `$table`.`id` > '$ID') ";
}
$query .= ") ";
if (!empty($condition)) {
$query .= " AND $condition ";
}
if ($item->maybeDeleted()) {
$query .= " AND `$table`.`is_deleted` = 0 ";
}
if ($item->maybeTemplate()) {
$query .= " AND `$table`.`is_template` = 0 ";
}
// Restrict to active entities
if ($table == "glpi_entities") {
$query .= $this->getEntitiesRestrictRequest("AND", $table, '', '', true);
} else if ($item->isEntityAssign()) {
$query .= $this->getEntitiesRestrictRequest("AND", $table, '', '', $item->maybeRecursive());
} else if ($table == "glpi_users") {
$query .= $this->getEntitiesRestrictRequest("AND", "glpi_profiles_users");
}
$query .= " ORDER BY `$table`.`$nextprev_item` ASC,
`$table`.`id` ASC";
$result = $DB->query($query);
if ($result
&& ($DB->numrows($result) > 0)) {
return $DB->result($result, 0, "id");
}
return -1;
}
/**
* Get the ID of the previous Item
*
* @deprecated 9.4
*
* @param string $table table to search next item
* @param integer $ID current ID
* @param string $condition condition to add to the search (default ='')
* @param string $nextprev_item field used to sort (default ='name')
*
* @return integer the previous ID, -1 if not exist
*/
public function getPreviousItem($table, $ID, $condition = "", $nextprev_item = "name") {
global $DB;
Toolbox::deprecated();
if (empty($nextprev_item)) {
return false;
}
$itemtype = $this->getItemTypeForTable($table);
$item = new $itemtype();
$search = $ID;
if ($nextprev_item != "id") {
$iterator = $DB->request([
'SELECT' => $nextprev_item,
'FROM' => $table,
'WHERE' => ['id' => $ID]
]);
if (count($iterator) > 0) {
$search = addslashes($iterator->next()[$nextprev_item]);
} else {
$nextprev_item = "id";
}
}
$LEFTJOIN = '';
if ($table == "glpi_users") {
$LEFTJOIN = " LEFT JOIN `glpi_profiles_users`
ON (`glpi_users`.`id` = `glpi_profiles_users`.`users_id`)";
}
$query = "SELECT `$table`.`id`
FROM `$table`
$LEFTJOIN
WHERE (`$table`.`$nextprev_item` < '$search' ";
// Same name case
if ($nextprev_item != "id") {
$query .= " OR (`$table`.`$nextprev_item` = '$search'
AND `$table`.`id` < '$ID') ";
}
$query .= ") ";
if (!empty($condition)) {
$query .= " AND $condition ";
}
if ($item->maybeDeleted()) {
$query .= "AND `$table`.`is_deleted` = 0";
}
if ($item->maybeTemplate()) {
$query .= "AND `$table`.`is_template` = 0";
}
// Restrict to active entities
if ($table == "glpi_entities") {
$query .= $this->getEntitiesRestrictRequest("AND", $table, '', '', true);
} else if ($item->isEntityAssign()) {
$query .= $this->getEntitiesRestrictRequest("AND", $table, '', '', $item->maybeRecursive());
} else if ($table == "glpi_users") {
$query .= $this->getEntitiesRestrictRequest("AND", "glpi_profiles_users");
}
$query .= " ORDER BY `$table`.`$nextprev_item` DESC,
`$table`.`id` DESC";
$result = $DB->query($query);
if ($result
&& ($DB->numrows($result) > 0)) {
return $DB->result($result, 0, "id");
}
return -1;
}
/**
* Format a user name
*
......
......@@ -75,15 +75,11 @@ class Dropdown {
*
* @return boolean : false if error and random id if OK
*
* @since 9.4.0 Usage of string in condition option is deprecated
* @since 9.5.0 Usage of string in condition option is removed
**/
static function show($itemtype, $options = []) {
global $DB, $CFG_GLPI;
if (array_key_exists('condition', $options) && !is_array($options['condition'])) {
Toolbox::deprecated('Using a string in condition option is deprecated.');
}
if ($itemtype && !($item = getItemForItemtype($itemtype))) {
return false;
}
......@@ -280,14 +276,7 @@ class Dropdown {
* @return string
*/
static function addNewCondition($condition) {
if (!is_array($condition)) {
Toolbox::deprecated('Using a string in dropdown condition is deprecated.');
$condition = Toolbox::cleanNewLines($condition);
$sha1 = sha1($condition);
} else {
$sha1 = sha1(serialize($condition));
}
$sha1 = sha1(serialize($condition));
$_SESSION['glpicondition'][$sha1] = $condition;
return $sha1;
}
......@@ -2316,12 +2305,7 @@ class Dropdown {
}
if (isset($post['condition']) && ($post['condition'] != '')) {
if (!is_array($post['condition']) && $post['condition'] != '') {
Toolbox::deprecated('Please no longer use raw SQL for conditions!');
$where[] = new \QueryExpression($post['condition']);
} else if (count($post['condition'])) {
$where = array_merge($where, $post['condition']);
}
$where = array_merge($where, $post['condition']);
}
$one_item = -1;
......
......@@ -44,183 +44,7 @@ class KnowbaseItemCategory extends CommonTreeDropdown {
static $rightname = 'knowbasecategory';
static function getTypeName($nb = 0) {
return _n('Knowledge base category', 'Knowledge base categories', $nb);
}
/**
* Show KB categories
*
* @param $options $_GET
*
* @return nothing (display the form)
*
* @deprecated 9.4.0
**/
static function showFirstLevel($options) {
global $DB, $CFG_GLPI;
Toolbox::deprecated();
$faq = !Session::haveRight("knowbase", READ);
// Default values of parameters
$params["knowbaseitemcategories_id"] = "0";
$params["target"] = KnowbaseItem::getSearchURL();
if (is_array($options) && count($options)) {
foreach ($options as $key => $val) {
$params[$key]=$val;
}
}
$parameters = '';
// Manage search solution
if (isset($options['item_itemtype'])
&& isset($options['item_items_id'])) {
$parameters = "&amp;item_items_id=".$options['item_items_id']."&amp;item_itemtype=".
$options['item_itemtype'];
}
if ($faq) {
if (!$CFG_GLPI["use_public_faq"]
&& !Session::haveRight('knowbase', KnowbaseItem::READFAQ)) {
return false;
}
$where = [];
if (Session::getLoginUserID()) {
$where = getEntitiesRestrictCriteria('glpi_knowbaseitemcategories', '', '', true);
} else {
// Anonymous access
if (Session::isMultiEntitiesMode()) {
$where['glpi_knowbaseitemcategories.entities_id'] = 0;
$where['glpi_knowbaseitemcategories.is_recursive'] = 1;
}
}
// Get All FAQ categories
$categories = [];
$criteria = [
'SELECT' => 'glpi_knowbaseitems.knowbaseitemcategories_id',
'DISTINCT' => true,
'FROM' => 'glpi_knowbaseitems',
'LEFT JOIN' => [
'glpi_knowbaseitemcategories', [
'ON' => [
'glpi_knowbaseitemcategories' => 'id',
'glpi_knowbaseitems' => 'knowbaseitemcategories_id'
]
]
],