N°4718 - Remove "FilterCodes"

This commit is contained in:
Anne-Cath
2025-07-29 17:26:15 +02:00
parent 048aaeb854
commit 6cb10ab13a
7 changed files with 21 additions and 409 deletions

View File

@@ -955,16 +955,6 @@ abstract class AttributeDefinition
//abstract protected GetBasicFilterHTMLInput();
abstract public function GetBasicFilterSQLExpr($sOpCode, $value);
/**
* since 3.1.0 return has changed (N°4690 - Deprecate "FilterCodes")
*
* @return array filtercode => attributecode
*/
public function GetFilterDefinitions()
{
return array();
}
public function GetEditValue($sValue, $oHostObj = null)
{
return (string)$sValue;
@@ -2788,11 +2778,6 @@ class AttributeDBFieldVoid extends AttributeDefinition
return $aColumns;
}
public function GetFilterDefinitions()
{
return array($this->GetCode() => $this->GetCode());
}
public function GetBasicFilterOperators()
{
return array("=" => "equals", "!=" => "differs from");
@@ -4260,13 +4245,6 @@ class AttributePassword extends AttributeString implements iAttributeNoGroupBy
return 64;
}
public function GetFilterDefinitions()
{
// Note: due to this, you will get an error if a password is being declared as a search criteria (see ZLists)
// not allowed to search on passwords!
return array();
}
public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
{
if (utils::IsNullOrEmptyString($sValue))
@@ -4307,13 +4285,6 @@ class AttributeEncryptedString extends AttributeString implements iAttributeNoGr
return 255;
}
public function GetFilterDefinitions()
{
// Note: due to this, you will get an error if a an encrypted field is declared as a search criteria (see ZLists)
// not allowed to search on encrypted fields !
return array();
}
public function MakeRealValue($proposedValue, $oHostObj)
{
if (is_null($proposedValue))
@@ -7986,11 +7957,6 @@ class AttributeExternalField extends AttributeDefinition
return true;
}
public function GetFilterDefinitions()
{
return array($this->GetCode() => $this->GetCode());
}
public function GetBasicFilterOperators()
{
$oExtAttDef = $this->GetExtAttDef();
@@ -8479,11 +8445,6 @@ class AttributeBlob extends AttributeDefinition
return $aColumns;
}
public function GetFilterDefinitions()
{
return array();
}
public function GetBasicFilterOperators()
{
return array();
@@ -9123,25 +9084,6 @@ class AttributeStopWatch extends AttributeDefinition
return $aColumns;
}
public function GetFilterDefinitions()
{
$aRes = array(
$this->GetCode() => $this->GetCode(),
$this->GetCode().'_started' => $this->GetCode(),
$this->GetCode().'_laststart' => $this->GetCode(),
$this->GetCode().'_stopped' => $this->GetCode(),
);
foreach ($this->ListThresholds() as $iThreshold => $aFoo) {
$sPrefix = $this->GetCode().'_'.$iThreshold;
$aRes[$sPrefix.'_deadline'] = $this->GetCode();
$aRes[$sPrefix.'_passed'] = $this->GetCode();
$aRes[$sPrefix.'_triggered'] = $this->GetCode();
$aRes[$sPrefix.'_overrun'] = $this->GetCode();
}
return $aRes;
}
public function GetBasicFilterOperators()
{
return array();
@@ -9912,11 +9854,6 @@ class AttributeSubItem extends AttributeDefinition
return array();
}
public function GetFilterDefinitions()
{
return array($this->GetCode() => $this->GetCode());
}
public function GetBasicFilterOperators()
{
return array();
@@ -10199,12 +10136,6 @@ class AttributeOneWayPassword extends AttributeDefinition implements iAttributeN
return $oPassword;
}
public function GetFilterDefinitions()
{
return array();
// still not working... see later...
}
public function GetBasicFilterOperators()
{
return array();
@@ -12652,11 +12583,6 @@ class AttributeFriendlyName extends AttributeDefinition
return '';
}
public function GetFilterDefinitions()
{
return array($this->GetCode() => $this->GetCode());
}
public function GetBasicFilterOperators()
{
return array("=" => "equals", "!=" => "differs from");

View File

@@ -39,7 +39,6 @@ require_once('kpi.class.inc.php');
require_once('dict.class.inc.php');
require_once('attributedef.class.inc.php');
require_once('filterdef.class.inc.php');
require_once('stimulus.class.inc.php');
require_once('valuesetdef.class.inc.php');
require_once('MyHelpers.class.inc.php');

View File

@@ -417,8 +417,17 @@ class DBObjectSearch extends DBSearch
*/
public function AddCondition($sFilterCode, $value, $sOpCode = null, $bParseSearchString = false)
{
MyHelpers::CheckKeyInArray('filter code in class: '.$this->GetClass(), $sFilterCode, MetaModel::GetFilterAttribList($this->GetClass()));
if (MetaModel::IsValidFilterCode($this->GetClass(),$sFilterCode) == false){
/* $sArrayDesc = if (count($aData) == 0)
{
$sArrayDesc = "{}";
}
else
{
$sArrayDesc = "{".implode(", ", $aData)."}";
}*/
throw new CoreException("Wrong value for '".$this->GetClass()."', found '$sFilterCode'");// while expecting a value in $sArrayDesc");
}
$oField = new FieldExpression($sFilterCode, $this->GetClassAlias());
if (empty($sOpCode)) {
if ($sFilterCode == 'id') {

View File

@@ -1,216 +0,0 @@
<?php
// Copyright (C) 2010-2024 Combodo SAS
//
// This file is part of iTop.
//
// iTop is free software; you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// iTop is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with iTop. If not, see <http://www.gnu.org/licenses/>
/**
* Definition of a filter
* Most of the time, a filter corresponds to an attribute, but we could imagine other search criteria
*
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
require_once('MyHelpers.class.inc.php');
/**
* Definition of a filter (could be made out of an existing attribute, or from an expression)
*
* @deprecated 3.1.0 not used N°4690 - Deprecate "FilterCodes"
* @package iTopORM
*/
abstract class FilterDefinition
{
abstract public function GetType();
abstract public function GetTypeDesc();
protected $m_sCode;
private $m_aParams = array();
protected function Get($sParamName) {return $this->m_aParams[$sParamName];}
public function __construct($sCode, $aParams = array())
{
DeprecatedCallsLog::NotifyDeprecatedPhpMethod("Deprecated class ".$this->GetClass().". Do not use. Will be removed in next version.");
$this->m_sCode = $sCode;
$this->m_aParams = $aParams;
$this->ConsistencyCheck();
}
// to be overloaded
static protected function ListExpectedParams()
{
return array();
}
private function ConsistencyCheck()
{
// Check that any mandatory param has been specified
//
$aExpectedParams = $this->ListExpectedParams();
foreach($aExpectedParams as $sParamName)
{
if (!array_key_exists($sParamName, $this->m_aParams))
{
$aBacktrace = debug_backtrace();
$sTargetClass = $aBacktrace[2]["class"];
$sCodeInfo = $aBacktrace[1]["file"]." - ".$aBacktrace[1]["line"];
throw new CoreException("ERROR missing parameter '$sParamName' in ".get_class($this)." declaration for class $sTargetClass ($sCodeInfo)");
}
}
}
public function GetCode() {return $this->m_sCode;}
abstract public function GetLabel();
abstract public function GetValuesDef();
// returns an array of opcode=>oplabel (e.g. "differs from")
abstract public function GetOperators();
// returns an opcode
abstract public function GetLooseOperator();
abstract public function GetSQLExpressions();
// Wrapper - no need for overloading this one
public function GetOpDescription($sOpCode)
{
$aOperators = $this->GetOperators();
if (!array_key_exists($sOpCode, $aOperators))
{
throw new CoreException("Unknown operator '$sOpCode'");
}
return $aOperators[$sOpCode];
}
}
/**
* Match against the object unique identifier
*
* @deprecated 3.1.0 N°4690 - Deprecate "FilterCodes"
* @package iTopORM
*/
class FilterPrivateKey extends FilterDefinition
{
static protected function ListExpectedParams()
{
return array_merge(parent::ListExpectedParams(), array("id_field"));
}
public function GetType() {return "PrivateKey";}
public function GetTypeDesc() {return "Match against object identifier";}
public function GetLabel()
{
return "Object Private Key";
}
public function GetValuesDef()
{
return null;
}
public function GetOperators()
{
return array(
"="=>"equals",
"!="=>"differs from",
"IN"=>"in",
"NOTIN"=>"not in"
);
}
public function GetLooseOperator()
{
return "IN";
}
public function GetSQLExpressions()
{
return array(
'' => $this->Get("id_field"),
);
}
}
/**
* Match against an existing attribute (the attribute type will determine the available operators)
*
* @deprecated 3.1.0 N°4690 - Deprecate "FilterCodes"
* @package iTopORM
*/
class FilterFromAttribute extends FilterDefinition
{
static protected function ListExpectedParams()
{
return array_merge(parent::ListExpectedParams(), array("refattribute"));
}
public function __construct($oRefAttribute, $sSuffix = '')
{
// In this very specific case, the code is the one of the attribute
// (this to get a very very simple syntax upon declaration)
$aParam = array();
$aParam["refattribute"] = $oRefAttribute;
parent::__construct($oRefAttribute->GetCode().$sSuffix, $aParam);
}
public function GetType() {return "Basic";}
public function GetTypeDesc() {return "Match against field contents";}
public function __GetRefAttribute() // for checking purposes only !!!
{
return $oAttDef = $this->Get("refattribute");
}
public function GetLabel()
{
$oAttDef = $this->Get("refattribute");
return $oAttDef->GetLabel();
}
public function GetValuesDef()
{
$oAttDef = $this->Get("refattribute");
return $oAttDef->GetValuesDef();
}
public function GetAllowedValues($aArgs = array(), $sContains = '')
{
$oAttDef = $this->Get("refattribute");
return $oAttDef->GetAllowedValues($aArgs, $sContains);
}
public function GetOperators()
{
$oAttDef = $this->Get("refattribute");
return $oAttDef->GetBasicFilterOperators();
}
public function GetLooseOperator()
{
$oAttDef = $this->Get("refattribute");
return $oAttDef->GetBasicFilterLooseOperator();
}
public function GetSQLExpressions()
{
$oAttDef = $this->Get("refattribute");
return $oAttDef->GetSQLExpressions();
}
}
?>

View File

@@ -1134,22 +1134,6 @@ abstract class MetaModel
return self::$m_aAttribOrigins[$sClass][$sAttCode];
}
/** *
* @param string $sClass
* @param string $sAttCode
*
* @return mixed
* @throws \CoreException
*/
final public static function GetFilterCodeOrigin($sClass, $sAttCode)
{
if ($sAttCode == 'id') {
return MetaModel::GetRootClass($sClass);
}
return MetaModel::GetAttributeOrigin($sClass, self::$m_aFilterAttribList[$sClass][$sAttCode]);
}
/**
* @param string $sClass
* @param string $sAttCode
@@ -1508,9 +1492,9 @@ abstract class MetaModel
*/
final public static function GetFiltersList($sClass)
{
self::_check_subclass($sClass);
return array_keys(self::$m_aFilterAttribList[$sClass]);
$aFilterList = MetaModel::GetAttributesList($sClass);
$aFilterList[] = 'id';
return $aFilterList;
}
/**
@@ -1613,11 +1597,11 @@ abstract class MetaModel
*/
final public static function IsValidFilterCode($sClass, $sFilterCode)
{
if (!array_key_exists($sClass, self::$m_aFilterAttribList)) {
return false;
if ($sFilterCode == 'id') {
return true;
}
return (array_key_exists($sFilterCode, self::$m_aFilterAttribList[$sClass]));
return self::IsValidAttCode($sClass, $sFilterCode);
}
/**
@@ -1898,56 +1882,6 @@ abstract class MetaModel
return "";
}
/**
* @var array array of (FilterCode => AttributeCode)
*/
private static $m_aFilterAttribList = array();
/**
* @deprecated 3.0.0 do not use : dead code, will be removed in the future N°4690 - Deprecate "FilterCodes"
* instead of array_keys(MetaModel::GetClassFilterDefs($sClass)); use MetaModel::GetFiltersList($sClass)
*
* @param string $sClass
*
* @return mixed
* @throws \CoreException
*/
public static function GetClassFilterDefs($sClass)
{
// cannot notify depreciation for now as this is still MASSIVELY used in iTop core !
DeprecatedCallsLog::NotifyDeprecatedPhpMethod('do not use MetaModel::GetClassFilterDefs: dead code, will be removed in the future. Use MetaModel::GetFiltersList or MetaModel::GetFiltersAttributes');
return self::$m_aFilterAttribList[$sClass];
}
/**
*
* @param string $sClass
*
* @return array ($sFilterCode=>$sAttributeCode) + id=>id
* @throws \CoreException
*/
public static function GetFilterAttribList($sClass)
{
return self::$m_aFilterAttribList[$sClass];
}
/**
* @deprecated 3.0.0 do not use : dead code, will be removed in the future use GetLabel instead N°4690 - Deprecate "FilterCodes"
*
* @param string $sClass
* @param string $sFilterCode
*
* @return string
* @throws \CoreException
*/
public static function GetFilterLabel($sClass, $sFilterCode)
{
DeprecatedCallsLog::NotifyDeprecatedPhpMethod('do not use MetaModel::GetFilterLabel : dead code, will be removed in the future. Use MetaModel::GetLabel instead');
return this::GetLabel($sClass, $sFilterCode);
}
/**
* @var array array of ("listcode" => various info on the list, common to every classes)
*/
@@ -2820,25 +2754,6 @@ abstract class MetaModel
return $oAttDef->GetAllowedValues($aArgs, $sContains);
}
/**
* @deprecated 3.1.0 use GetAllowedValues_att N°4690 - Deprecate "FilterCodes"
*
* @param string $sClass
* @param string $sFltCode
* @param array $aArgs
* @param string $sContains
*
* @return mixed
* @throws \CoreException
*/
public static function GetAllowedValues_flt($sClass, $sFltCode, $aArgs = array(), $sContains = '')
{
DeprecatedCallsLog::NotifyDeprecatedPhpMethod('do not use MetaModel::GetAllowedValues_flt: dead code, will be removed in the future. Use MetaModel::GetAllowedValues');
return self::GetAllowedValues_att($sClass, $sFltCode);
}
/**
* @param string $sClass
* @param string $sAttCode
@@ -2911,8 +2826,6 @@ abstract class MetaModel
$oAttribute->SetHostClass($sTargetClass);
self::$m_aAttribDefs[$sTargetClass][$sCode] = $oAttribute;
self::$m_aAttribOrigins[$sTargetClass][$sCode] = $sOriginClass;
self::$m_aFilterAttribList[$sTargetClass][$sCode] = $sCode;
}
/**
@@ -3076,9 +2989,6 @@ abstract class MetaModel
if (array_key_exists('finalclass', self::$m_aAttribDefs[$sChildClass])) {
throw new CoreException("Class $sChildClass, 'finalclass' is a reserved keyword, it cannot be used as an attribute code");
}
if (array_key_exists('finalclass', self::$m_aFilterAttribList[$sChildClass])) {
throw new CoreException("Class $sChildClass, 'finalclass' is a reserved keyword, it cannot be used as a filter code");
}
$oCloned = clone $oClassAtt;
$oCloned->SetFixedValue($sChildClass);
self::AddMagicAttribute($oCloned, $sChildClass, $sRootClass);
@@ -3140,12 +3050,6 @@ abstract class MetaModel
// Add magic attributes to external keys (finalclass, friendlyname, archive_flag, obsolescence_flag)
foreach (self::GetClasses() as $sClass) {
foreach (self::$m_aAttribDefs[$sClass] as $sAttCode => $oAttDef) {
// Compute the filter codes
//
foreach ($oAttDef->GetFilterDefinitions() as $sFilterCode => $sCode) {
self::$m_aFilterAttribList[$sClass][$sFilterCode] = $sCode;
}
// Compute the fields that will be used to display a pointer to another object
//
if ($oAttDef->IsExternalKey(EXTKEY_ABSOLUTE)) {
@@ -3252,7 +3156,6 @@ abstract class MetaModel
if (array_key_exists('id', self::$m_aAttribDefs[$sClass])) {
throw new CoreException("Class $sClass, 'id' is a reserved keyword, it cannot be used as an attribute code");
}
self::$m_aFilterAttribList[$sClass]['id'] = 'id';
}
}
@@ -3412,7 +3315,6 @@ abstract class MetaModel
self::$m_aAttribDefs[$sClass] = array();
self::$m_aAttribOrigins[$sClass] = array();
self::$m_aFilterAttribList[$sClass] = array();
}
/**
@@ -6512,7 +6414,6 @@ abstract class MetaModel
self::$m_aAttribDefs = $result['m_aAttribDefs'];
self::$m_aAttribOrigins = $result['m_aAttribOrigins'];
self::$m_aIgnoredAttributes = $result['m_aIgnoredAttributes'];
self::$m_aFilterAttribList = $result['m_aFilterList'];
self::$m_aListInfos = $result['m_aListInfos'];
self::$m_aListData = $result['m_aListData'];
self::$m_aRelationInfos = $result['m_aRelationInfos'];
@@ -6548,7 +6449,6 @@ abstract class MetaModel
$aCache['m_aAttribDefs'] = self::$m_aAttribDefs; // array of ("classname" => array of attributes)
$aCache['m_aAttribOrigins'] = self::$m_aAttribOrigins; // array of ("classname" => array of ("attcode"=>"sourceclass"))
$aCache['m_aIgnoredAttributes'] = self::$m_aIgnoredAttributes; //array of ("classname" => array of ("attcode")
$aCache['m_aFilterList'] = self::$m_aFilterAttribList; // array of ("classname" => array filterdef)
$aCache['m_aListInfos'] = self::$m_aListInfos; // array of ("listcode" => various info on the list, common to every classes)
$aCache['m_aListData'] = self::$m_aListData; // array of ("classname" => array of "listcode" => list)
$aCache['m_aRelationInfos'] = self::$m_aRelationInfos; // array of ("relcode" => various info on the list, common to every classes)

View File

@@ -71,16 +71,11 @@ class OQLActualClassTreeResolver
}
// Attributes can be stored in attributes list or for magic ones into filter codes list.
$sOriginClass = null;
if (MetaModel::IsValidAttCode($sClass, $sAttCode))
{
if (MetaModel::IsValidAttCode($sClass, $sAttCode)) {
$sOriginClass = MetaModel::GetAttributeOrigin($sClass, $sAttCode);
}
else if (MetaModel::IsValidFilterCode($sClass, $sAttCode))
{
$sOriginClass = MetaModel::GetFilterCodeOrigin($sClass, $sAttCode);
}
else
{
} else if ($sAttCode == 'id') {
$sOriginClass = $sClass;
} else {
continue;
}
if (!isset($aClassAndAncestorsNodes[$sOriginClass]) || is_null($aClassAndAncestorsNodes[$sOriginClass]))

View File

@@ -25,7 +25,6 @@
require_once(APPROOT.'/core/attributedef.class.inc.php');
require_once(APPROOT.'/core/filterdef.class.inc.php');
require_once(APPROOT.'/core/stimulus.class.inc.php');
require_once(APPROOT.'/core/MyHelpers.class.inc.php');