mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-12 23:14:18 +01:00
N°931: Rename Tag columns in database
This commit is contained in:
@@ -2170,8 +2170,8 @@ EOF
|
||||
foreach($aTagSetObjectData as $oTagSet)
|
||||
{
|
||||
$aTagSetKeyValData[] = [
|
||||
'code' => $oTagSet->Get('tag_code'),
|
||||
'label' => $oTagSet->Get('tag_label')
|
||||
'code' => $oTagSet->Get('code'),
|
||||
'label' => $oTagSet->Get('label')
|
||||
];
|
||||
}
|
||||
$aJson['possible_values'] = $aTagSetKeyValData;
|
||||
|
||||
@@ -6797,7 +6797,7 @@ class AttributeTagSet extends AttributeDBFieldVoid
|
||||
$aAllowedValues = array();
|
||||
foreach($aAllowedTags as $oAllowedTag)
|
||||
{
|
||||
$aAllowedValues[$oAllowedTag->Get('tag_code')] = $oAllowedTag->Get('tag_label');
|
||||
$aAllowedValues[$oAllowedTag->Get('code')] = $oAllowedTag->Get('label');
|
||||
}
|
||||
|
||||
return $aAllowedValues;
|
||||
@@ -7086,9 +7086,9 @@ class AttributeTagSet extends AttributeDBFieldVoid
|
||||
$sTagLabel = $sTagCode;
|
||||
foreach($aAllowedTags as $oTag)
|
||||
{
|
||||
if ($sTagCode === $oTag->Get('tag_code'))
|
||||
if ($sTagCode === $oTag->Get('code'))
|
||||
{
|
||||
$sTagLabel = $oTag->Get('tag_label');
|
||||
$sTagLabel = $oTag->Get('label');
|
||||
}
|
||||
}
|
||||
$aRemoved[] = $sTagLabel;
|
||||
@@ -7115,9 +7115,9 @@ class AttributeTagSet extends AttributeDBFieldVoid
|
||||
$sTagLabel = $sTagCode;
|
||||
foreach($aAllowedTags as $oTag)
|
||||
{
|
||||
if ($sTagCode === $oTag->Get('tag_code'))
|
||||
if ($sTagCode === $oTag->Get('code'))
|
||||
{
|
||||
$sTagLabel = $oTag->Get('tag_label');
|
||||
$sTagLabel = $oTag->Get('label');
|
||||
}
|
||||
}
|
||||
$aAdded[] = $sTagLabel;
|
||||
@@ -7153,7 +7153,7 @@ class AttributeTagSet extends AttributeDBFieldVoid
|
||||
{
|
||||
$sClass = MetaModel::GetAttributeOrigin($this->GetHostClass(), $this->GetCode());
|
||||
$sAttCode = $this->GetCode();
|
||||
$sTagCode = $oTag->Get('tag_code');
|
||||
$sTagCode = $oTag->Get('code');
|
||||
$oFilter = DBSearch::FromOQL("SELECT $sClass WHERE $sAttCode MATCHES '$sTagCode'");
|
||||
$oAppContext = new ApplicationContext();
|
||||
$sContext = $oAppContext->GetForLink();
|
||||
@@ -7161,7 +7161,7 @@ class AttributeTagSet extends AttributeDBFieldVoid
|
||||
$sFilter = urlencode($oFilter->serialize());
|
||||
$sUrl = utils::GetAbsoluteUrlAppRoot()."pages/$sUIPage?operation=search&filter=".$sFilter."&{$sContext}";
|
||||
|
||||
$sHtml .= '<a href="'.$sUrl.'" class="attribute-tag">'.$oTag->Get('tag_label').'</a>';
|
||||
$sHtml .= '<a href="'.$sUrl.'" class="attribute-tag">'.$oTag->Get('label').'</a>';
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -954,8 +954,8 @@ class ScalarExpression extends UnaryExpression
|
||||
$aTags = $oValue->GetTags();
|
||||
foreach($aTags as $oTag)
|
||||
{
|
||||
$aValue['label'] = $oTag->Get('tag_label');
|
||||
$aValue['value'] = $oTag->Get('tag_code');
|
||||
$aValue['label'] = $oTag->Get('label');
|
||||
$aValue['value'] = $oTag->Get('code');
|
||||
$aValues[] = $aValue;
|
||||
}
|
||||
$aCriterion['values'] = $aValues;
|
||||
|
||||
@@ -187,7 +187,7 @@ final class ormTagSet
|
||||
{
|
||||
try
|
||||
{
|
||||
$aTags[$sTagCode] = $oTag->Get('tag_label');
|
||||
$aTags[$sTagCode] = $oTag->Get('label');
|
||||
} catch (CoreException $e)
|
||||
{
|
||||
IssueLog::Error($e->getMessage());
|
||||
@@ -197,7 +197,7 @@ final class ormTagSet
|
||||
{
|
||||
try
|
||||
{
|
||||
$aTags[$sTagCode] = $oTag->Get('tag_label');
|
||||
$aTags[$sTagCode] = $oTag->Get('label');
|
||||
} catch (CoreException $e)
|
||||
{
|
||||
IssueLog::Error($e->getMessage());
|
||||
@@ -537,7 +537,7 @@ final class ormTagSet
|
||||
$aAllowedTags = $this->GetAllowedTags();
|
||||
foreach($aAllowedTags as $oAllowedTag)
|
||||
{
|
||||
if ($oAllowedTag->Get('tag_code') === $sTagCode)
|
||||
if ($oAllowedTag->Get('code') === $sTagCode)
|
||||
{
|
||||
return $oAllowedTag;
|
||||
}
|
||||
@@ -557,9 +557,9 @@ final class ormTagSet
|
||||
$aAllowedTags = $this->GetAllowedTags();
|
||||
foreach($aAllowedTags as $oAllowedTag)
|
||||
{
|
||||
if ($oAllowedTag->Get('tag_label') === $sTagLabel)
|
||||
if ($oAllowedTag->Get('label') === $sTagLabel)
|
||||
{
|
||||
return $oAllowedTag->Get('tag_code');
|
||||
return $oAllowedTag->Get('code');
|
||||
}
|
||||
}
|
||||
throw new CoreUnexpectedValue("{$sTagLabel} is not defined as a valid tag for {$this->sClass}:{$this->sAttCode}");
|
||||
|
||||
@@ -40,9 +40,9 @@ abstract class TagSetFieldData extends cmdbAbstractObject
|
||||
(
|
||||
'category' => 'bizmodel',
|
||||
'key_type' => 'autoincrement',
|
||||
'name_attcode' => array('tag_label'),
|
||||
'name_attcode' => array('label'),
|
||||
'state_attcode' => '',
|
||||
'reconc_keys' => array('tag_code'),
|
||||
'reconc_keys' => array('code'),
|
||||
'db_table' => 'priv_tagfielddata',
|
||||
'db_key_field' => 'id',
|
||||
'db_finalclass_field' => 'finalclass',
|
||||
@@ -51,54 +51,54 @@ abstract class TagSetFieldData extends cmdbAbstractObject
|
||||
MetaModel::Init_Params($aParams);
|
||||
MetaModel::Init_InheritAttributes();
|
||||
|
||||
MetaModel::Init_AddAttribute(new AttributeString("tag_code", array(
|
||||
MetaModel::Init_AddAttribute(new AttributeString("code", array(
|
||||
"allowed_values" => null,
|
||||
"sql" => 'tag_code',
|
||||
"sql" => 'code',
|
||||
"default_value" => '',
|
||||
"is_null_allowed" => false,
|
||||
"depends_on" => array()
|
||||
)));
|
||||
MetaModel::Init_AddAttribute(new AttributeString("tag_label", array(
|
||||
MetaModel::Init_AddAttribute(new AttributeString("label", array(
|
||||
"allowed_values" => null,
|
||||
"sql" => 'tag_label',
|
||||
"sql" => 'label',
|
||||
"default_value" => '',
|
||||
"is_null_allowed" => false,
|
||||
"depends_on" => array()
|
||||
)));
|
||||
MetaModel::Init_AddAttribute(new AttributeString("tag_description", array(
|
||||
MetaModel::Init_AddAttribute(new AttributeString("description", array(
|
||||
"allowed_values" => null,
|
||||
"sql" => 'tag_description',
|
||||
"sql" => 'description',
|
||||
"default_value" => '',
|
||||
"is_null_allowed" => true,
|
||||
"depends_on" => array()
|
||||
)));
|
||||
MetaModel::Init_AddAttribute(new AttributeString("tag_class", array(
|
||||
MetaModel::Init_AddAttribute(new AttributeString("obj_class", array(
|
||||
"allowed_values" => null,
|
||||
"sql" => 'tag_class',
|
||||
"sql" => 'obj_class',
|
||||
"default_value" => '',
|
||||
"is_null_allowed" => false,
|
||||
"depends_on" => array()
|
||||
)));
|
||||
MetaModel::Init_AddAttribute(new AttributeString("tag_attcode", array(
|
||||
MetaModel::Init_AddAttribute(new AttributeString("obj_attcode", array(
|
||||
"allowed_values" => null,
|
||||
"sql" => 'tag_attcode',
|
||||
"sql" => 'obj_attcode',
|
||||
"default_value" => '',
|
||||
"is_null_allowed" => false,
|
||||
"depends_on" => array()
|
||||
)));
|
||||
|
||||
|
||||
MetaModel::Init_SetZListItems('details', array('tag_code', 'tag_label', 'tag_description'));
|
||||
MetaModel::Init_SetZListItems('standard_search', array('tag_code', 'tag_label', 'tag_description'));
|
||||
MetaModel::Init_SetZListItems('list', array('tag_code', 'tag_label', 'tag_description'));
|
||||
MetaModel::Init_SetZListItems('details', array('code', 'label', 'description'));
|
||||
MetaModel::Init_SetZListItems('standard_search', array('code', 'label', 'description'));
|
||||
MetaModel::Init_SetZListItems('list', array('code', 'label', 'description'));
|
||||
}
|
||||
|
||||
public function ComputeValues()
|
||||
{
|
||||
$sClassName = get_class($this);
|
||||
$aRes = static::ExtractTagFieldName($sClassName);
|
||||
$this->_Set('tag_class', $aRes['tag_class']);
|
||||
$this->_Set('tag_attcode', $aRes['tag_attcode']);
|
||||
$this->_Set('obj_class', $aRes['obj_class']);
|
||||
$this->_Set('obj_attcode', $aRes['obj_attcode']);
|
||||
}
|
||||
|
||||
public static function GetTagDataClassName($sClass, $sAttCode)
|
||||
@@ -122,8 +122,8 @@ abstract class TagSetFieldData extends cmdbAbstractObject
|
||||
// Extract class and attcode from class name using pattern TagSetFieldDataFor_<class>_<attcode>>;
|
||||
if (preg_match('@^TagSetFieldDataFor_(?<class>\w+)__(?<attcode>\w+)$@', $sClassName, $aMatches))
|
||||
{
|
||||
$aRes['tag_class'] = $aMatches['class'];
|
||||
$aRes['tag_attcode'] = $aMatches['attcode'];
|
||||
$aRes['obj_class'] = $aMatches['class'];
|
||||
$aRes['obj_attcode'] = $aMatches['attcode'];
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -141,9 +141,9 @@ abstract class TagSetFieldData extends cmdbAbstractObject
|
||||
{
|
||||
parent::DoCheckToDelete($oDeletionPlan);
|
||||
|
||||
$sTagCode = $this->Get('tag_code');
|
||||
$sClass = $this->Get('tag_class');
|
||||
$sAttCode = $this->Get('tag_attcode');
|
||||
$sTagCode = $this->Get('code');
|
||||
$sClass = $this->Get('obj_class');
|
||||
$sAttCode = $this->Get('obj_attcode');
|
||||
$oSearch = DBSearch::FromOQL("SELECT $sClass WHERE $sAttCode MATCHES '$sTagCode'");
|
||||
$oSet = new DBObjectSet($oSearch);
|
||||
if ($oSet->CountExceeds(0))
|
||||
@@ -166,8 +166,8 @@ abstract class TagSetFieldData extends cmdbAbstractObject
|
||||
public function DoCheckToWrite()
|
||||
{
|
||||
$this->ComputeValues();
|
||||
$sClass = $this->Get('tag_class');
|
||||
$sAttCode = $this->Get('tag_attcode');
|
||||
$sClass = $this->Get('obj_class');
|
||||
$sAttCode = $this->Get('obj_attcode');
|
||||
$iMaxLen = 20;
|
||||
$oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
|
||||
if ($oAttDef instanceof AttributeTagSet)
|
||||
@@ -175,14 +175,14 @@ abstract class TagSetFieldData extends cmdbAbstractObject
|
||||
$iMaxLen = $oAttDef->GetTagCodeMaxLength();
|
||||
}
|
||||
|
||||
$sTagCode = $this->Get('tag_code');
|
||||
// Check tag_code syntax
|
||||
$sTagCode = $this->Get('code');
|
||||
// Check code syntax
|
||||
if (!preg_match("@^[a-zA-Z0-9]{3,$iMaxLen}$@", $sTagCode))
|
||||
{
|
||||
$this->m_aCheckIssues[] = Dict::Format('Core:TagSetFieldData:ErrorTagCodeSyntax', $iMaxLen);
|
||||
}
|
||||
|
||||
$sTagLabel = $this->Get('tag_label');
|
||||
$sTagLabel = $this->Get('label');
|
||||
$sSepItem = MetaModel::GetConfig()->Get('tag_set_item_separator');
|
||||
if (empty($sTagLabel) || (strpos($sTagLabel, $sSepItem) !== false))
|
||||
{
|
||||
@@ -195,11 +195,11 @@ abstract class TagSetFieldData extends cmdbAbstractObject
|
||||
$sClassName = get_class($this);
|
||||
if (empty($id))
|
||||
{
|
||||
$oSearch = DBSearch::FromOQL("SELECT $sClassName WHERE (tag_code = '$sTagCode' OR tag_label = '$sTagLabel')");
|
||||
$oSearch = DBSearch::FromOQL("SELECT $sClassName WHERE (code = '$sTagCode' OR label = '$sTagLabel')");
|
||||
}
|
||||
else
|
||||
{
|
||||
$oSearch = DBSearch::FromOQL("SELECT $sClassName WHERE id != $id AND (tag_code = '$sTagCode' OR tag_label = '$sTagLabel')");
|
||||
$oSearch = DBSearch::FromOQL("SELECT $sClassName WHERE id != $id AND (code = '$sTagCode' OR label = '$sTagLabel')");
|
||||
}
|
||||
$oSet = new DBObjectSet($oSearch);
|
||||
if ($oSet->CountExceeds(0))
|
||||
@@ -220,7 +220,7 @@ abstract class TagSetFieldData extends cmdbAbstractObject
|
||||
{
|
||||
parent::OnUpdate();
|
||||
$aChanges = $this->ListChanges();
|
||||
if (array_key_exists('tag_code', $aChanges))
|
||||
if (array_key_exists('code', $aChanges))
|
||||
{
|
||||
throw new CoreException(Dict::S('Core:TagSetFieldData:ErrorCodeUpdateNotAllowed'));
|
||||
}
|
||||
@@ -244,9 +244,9 @@ abstract class TagSetFieldData extends cmdbAbstractObject
|
||||
parent::DisplayBareRelations($oPage, $bEditMode);
|
||||
if (!$bEditMode)
|
||||
{
|
||||
$sClass = $this->Get('tag_class');
|
||||
$sAttCode = $this->Get('tag_attcode');
|
||||
$sTagCode = $this->Get('tag_code');
|
||||
$sClass = $this->Get('obj_class');
|
||||
$sAttCode = $this->Get('obj_attcode');
|
||||
$sTagCode = $this->Get('code');
|
||||
$oFilter = DBSearch::FromOQL("SELECT $sClass WHERE $sAttCode MATCHES '$sTagCode'");
|
||||
$oSet = new DBObjectSet($oFilter);
|
||||
$iCount = $oSet->Count();
|
||||
@@ -259,7 +259,7 @@ abstract class TagSetFieldData extends cmdbAbstractObject
|
||||
else
|
||||
{
|
||||
$aClassLabels = array();
|
||||
foreach(MetaModel::EnumChildClasses($sClass) as $sCurrentClass)
|
||||
foreach(MetaModel::EnumChildClasses($sClass, ENUM_CHILD_CLASSES_ALL) as $sCurrentClass)
|
||||
{
|
||||
$aClassLabels[$sCurrentClass] = MetaModel::GetName($sCurrentClass);
|
||||
}
|
||||
@@ -288,8 +288,8 @@ abstract class TagSetFieldData extends cmdbAbstractObject
|
||||
{
|
||||
return $sClass;
|
||||
}
|
||||
$sClassDesc = MetaModel::GetName($aTagFieldInfo['tag_class']);
|
||||
$sAttDesc = MetaModel::GetAttributeDef($aTagFieldInfo['tag_class'], $aTagFieldInfo['tag_attcode'])->GetLabel();
|
||||
$sClassDesc = MetaModel::GetName($aTagFieldInfo['obj_class']);
|
||||
$sAttDesc = MetaModel::GetAttributeDef($aTagFieldInfo['obj_class'], $aTagFieldInfo['obj_attcode'])->GetLabel();
|
||||
if (Dict::Exists("Class:$sClass"))
|
||||
{
|
||||
$sName = Dict::Format("Class:$sClass", $sClassDesc, $sAttDesc);
|
||||
@@ -317,8 +317,8 @@ abstract class TagSetFieldData extends cmdbAbstractObject
|
||||
if (!isset(self::$m_aAllowedValues[$sTagDataClass]))
|
||||
{
|
||||
$oSearch = new DBObjectSearch($sTagDataClass);
|
||||
$oSearch->AddCondition('tag_class', $sClass);
|
||||
$oSearch->AddCondition('tag_attcode', $sAttCode);
|
||||
$oSearch->AddCondition('obj_class', $sClass);
|
||||
$oSearch->AddCondition('obj_attcode', $sAttCode);
|
||||
$oSet = new DBObjectSet($oSearch);
|
||||
self::$m_aAllowedValues[$sTagDataClass] = $oSet->ToArray();
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ try
|
||||
|
||||
$sSearchHeaderForceDropdown = '<select id="select_class" name="class" onChange="this.form.submit();">';
|
||||
$aClassLabels = array();
|
||||
foreach(MetaModel::EnumChildClasses($sBaseClass) as $sCurrentClass)
|
||||
foreach(MetaModel::EnumChildClasses($sBaseClass, ENUM_CHILD_CLASSES_EXCLUDETOP) as $sCurrentClass)
|
||||
{
|
||||
$aClassLabels[$sCurrentClass] = MetaModel::GetName($sCurrentClass);
|
||||
}
|
||||
|
||||
@@ -1846,9 +1846,9 @@ EOF;
|
||||
(
|
||||
'category' => 'bizmodel',
|
||||
'key_type' => 'autoincrement',
|
||||
'name_attcode' => array('tag_label'),
|
||||
'name_attcode' => array('label'),
|
||||
'state_attcode' => '',
|
||||
'reconc_keys' => array('tag_code'),
|
||||
'reconc_keys' => array('code'),
|
||||
'db_table' => '', // no need to have a corresponding table : this class exists only for rights, no additional field
|
||||
'db_key_field' => 'id',
|
||||
'db_finalclass_field' => 'finalclass',
|
||||
|
||||
@@ -226,13 +226,13 @@ class ItopDataTestCase extends ItopTestCase
|
||||
{
|
||||
$sTagClass = TagSetFieldData::GetTagDataClassName($sClass, $sAttCode);
|
||||
$oTagData = $this->createObject($sTagClass, array(
|
||||
'tag_code' => $sTagCode,
|
||||
'tag_label' => $sTagLabel,
|
||||
'tag_class' => $sClass,
|
||||
'tag_attcode' => $sAttCode,
|
||||
'tag_description' => $sTagDescription,
|
||||
'code' => $sTagCode,
|
||||
'label' => $sTagLabel,
|
||||
'obj_class' => $sClass,
|
||||
'obj_attcode' => $sAttCode,
|
||||
'description' => $sTagDescription,
|
||||
));
|
||||
$this->debug("Created {$oTagData->Get('tag_code')} ({$oTagData->Get('tag_label')})");
|
||||
$this->debug("Created {$oTagData->Get('code')} ({$oTagData->Get('label')})");
|
||||
|
||||
/** @var \TagSetFieldData $oTagData */
|
||||
return $oTagData;
|
||||
@@ -250,7 +250,7 @@ class ItopDataTestCase extends ItopTestCase
|
||||
protected function RemoveTagData($sClass, $sAttCode, $sTagCode)
|
||||
{
|
||||
$sTagClass = TagSetFieldData::GetTagDataClassName($sClass, $sAttCode);
|
||||
$this->RemoveObjects($sTagClass, "SELECT $sTagClass WHERE tag_code = '$sTagCode'");
|
||||
$this->RemoveObjects($sTagClass, "SELECT $sTagClass WHERE code = '$sTagCode'");
|
||||
}
|
||||
|
||||
private function RemoveObjects($sClass, $sOQL)
|
||||
|
||||
@@ -131,13 +131,13 @@ class TagSetFieldDataTest extends ItopDataTestCase
|
||||
{
|
||||
$sTagClass = TagSetFieldData::GetTagDataClassName(TAG_CLASS, TAG_ATTCODE);
|
||||
$oTagData = $this->createObject($sTagClass, array(
|
||||
'tag_code' => 'tag1',
|
||||
'tag_label' => 'First',
|
||||
'code' => 'tag1',
|
||||
'label' => 'First',
|
||||
));
|
||||
$this->debug("Created {$oTagData->Get('tag_class')}::{$oTagData->Get('tag_attcode')}");
|
||||
$this->debug("Created {$oTagData->Get('obj_class')}::{$oTagData->Get('obj_attcode')}");
|
||||
|
||||
static::assertEquals(TAG_CLASS, $oTagData->Get('tag_class'));
|
||||
static::assertEquals(TAG_ATTCODE, $oTagData->Get('tag_attcode'));
|
||||
static::assertEquals(TAG_CLASS, $oTagData->Get('obj_class'));
|
||||
static::assertEquals(TAG_ATTCODE, $oTagData->Get('obj_attcode'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -193,7 +193,7 @@ class TagSetFieldDataTest extends ItopDataTestCase
|
||||
public function testUpdateCode()
|
||||
{
|
||||
$oTagData = $this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'tag1', 'First');
|
||||
$oTagData->Set('tag_code', 'tag2');
|
||||
$oTagData->Set('code', 'tag2');
|
||||
$oTagData->DBWrite();
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ class ormTagSetTest extends ItopDataTestCase
|
||||
public function testGetTagDataClass()
|
||||
{
|
||||
$oTagSet = new ormTagSet(TAG_CLASS, TAG_ATTCODE, MAX_TAGS);
|
||||
static::assertEquals($oTagSet->GetTagDataClass(), 'TagSetFieldDataFor_Ticket_tagfield');
|
||||
static::assertEquals($oTagSet->GetTagDataClass(), 'TagSetFieldDataFor_Ticket__tagfield');
|
||||
}
|
||||
|
||||
public function testGetValue()
|
||||
|
||||
Reference in New Issue
Block a user