diff --git a/CHANGELOG.md b/CHANGELOG.md index 09b1d41ad37783390cddbc49b60b3152327eb6c7..c9f50c5bc65c34f0a30a655676e82c6450fb1b14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/inc/commondbchild.class.php b/inc/commondbchild.class.php index 2c5da1f793b4271e8ee2651cac2540f9b95fc9a1..03ad5153c1fdce4791a13daf18713993f87b957d 100644 --- a/inc/commondbchild.class.php +++ b/inc/commondbchild.class.php @@ -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 diff --git a/inc/commondbconnexity.class.php b/inc/commondbconnexity.class.php index 25becf289a108466991b810b587c5c80d503b925..3ffc0179b8287b3ac475c10003bd12e573715b1f 100644 --- a/inc/commondbconnexity.class.php +++ b/inc/commondbconnexity.class.php @@ -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] diff --git a/inc/commondbrelation.class.php b/inc/commondbrelation.class.php index 48bf7a5581a8825620fcb93d110f4a99cf2b088b..73d085e160d4977933d628df10658a0da6b4a7cc 100644 --- a/inc/commondbrelation.class.php +++ b/inc/commondbrelation.class.php @@ -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 * diff --git a/inc/commondbtm.class.php b/inc/commondbtm.class.php index 12e48912ca42234053cd69cb255d2711d3499e7f..34ee1913570d43837de9ff443dded73fb1761a1f 100644 --- a/inc/commondbtm.class.php +++ b/inc/commondbtm.class.php @@ -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; diff --git a/inc/db.function.php b/inc/db.function.php index 77335e95e36701d7eb82a7a807cc0b3f8b595fab..463154c9961cefce17e330e9a125f092cd6496d0 100644 --- a/inc/db.function.php +++ b/inc/db.function.php @@ -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 * diff --git a/inc/dbutils.class.php b/inc/dbutils.class.php index f6d2f5752f95e8cbd8e39ed96708f31ddbf26f16..e8bb55c7a7da169fe7a53e42ed8dbc0c7b7aff8b 100644 --- a/inc/dbutils.class.php +++ b/inc/dbutils.class.php @@ -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 * diff --git a/inc/dropdown.class.php b/inc/dropdown.class.php index efa92e52cb2825aaa59b781cdbb7ef80ba77212d..06771fb6539815fbc2def2aa380dffc9a6db4aca 100755 --- a/inc/dropdown.class.php +++ b/inc/dropdown.class.php @@ -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; diff --git a/inc/knowbaseitemcategory.class.php b/inc/knowbaseitemcategory.class.php index 7adfacd93ddc4b62798b13c9b7e823607011ae18..13387ef0d06f5a9663043e2b46da6a9bc2d91551 100755 --- a/inc/knowbaseitemcategory.class.php +++ b/inc/knowbaseitemcategory.class.php @@ -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 = "&item_items_id=".$options['item_items_id']."&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' - ] - ] - ], - 'WHERE' => $where + ['glpi_knowbaseitems.is_faq' => 1] - ]; - $criteria = array_merge( - $criteria, - KnowbaseItem::getVisibilityCriteria() - ); - - $iterator = $DB->request($criteria); - while ($data = $iterator->next()) { - if (!in_array($data['knowbaseitemcategories_id'], $categories)) { - $categories[] = $data['knowbaseitemcategories_id']; - $categories = array_merge( - $categories, - getAncestorsOf( - 'glpi_knowbaseitemcategories', - $data['knowbaseitemcategories_id'] - ) - ); - } - } - - $criteria = [ - 'SELECT' => 'glpi_knowbaseitemcategories.*', - 'DISTINCT' => true, - 'FROM' => 'glpi_knowbaseitemcategories', - 'WHERE' => [ - 'id' => $categories, - 'knowbaseitemcategories_id' => $params['knowbaseitemcategories_id'] - ] + $where, - 'ORDERBY' => 'name ASC' - ]; - } else { - if (!Session::haveRight("knowbase", READ)) { - return false; - } - $where = getEntitiesRestrictCriteria( - 'glpi_knowbaseitemcategories', - 'entities_id', - $_SESSION['glpiactiveentities'], - true - ); - - $criteria = [ - 'FROM' => 'glpi_knowbaseitemcategories', - 'WHERE' => [ - 'knowbaseitemcategories_id' => $params['knowbaseitemcategories_id'] - ] + $where, - 'ORDER' => 'name ASC' - ]; - } - $iterator = $DB->request($criteria); - - // Show category - echo "
"; - echo " " . __('Root category') . ""; - - // Display Category - if ($params["knowbaseitemcategories_id"]!=0) { - $tmpID = $params["knowbaseitemcategories_id"]; - $todisplay = ""; - - while ($tmpID != 0) { - $cat_iterator = $DB->request([ - 'FROM' => 'glpi_knowbaseitemcategories', - 'WHERE' => [ - 'knowbaseitemcategories_id' => $tmpID - ] + $where - ]); - - if (count($cat_iterator) == 1) { - $data = $cat_iterator->next(); - $tmpID = $data["knowbaseitemcategories_id"]; - $todisplay = "".$data["name"]."". - (empty($todisplay)?"":" > "). $todisplay; - } else { - $tmpID = 0; - } - } - echo " > ".$todisplay; - } - - if (count($iterator) > 0) { - $i = 0; - while ($row = $iterator->next()) { - // on affiche les résultats sur trois colonnes - if (($i%3) == 0) { - echo " | ||
";
- echo " ";
- echo "".
- "".
- $row["name"]."";
- echo " ".Html::resume_text($row['comment'], 60)." ";
-
- if (($i%3) == 2) {
- echo " | ||