N°6271 - Fix drop-down list not refreshed when adding an external key with a friendlyname built on an external key

This commit is contained in:
Eric Espie
2023-06-26 18:00:04 +02:00
parent a206af1813
commit db6e4137b1
5 changed files with 61 additions and 18 deletions

View File

@@ -7987,6 +7987,17 @@ class AttributeExternalField extends AttributeDefinition
return $oExtAttDef->MakeRealValue($proposedValue, $oHostObj);
}
/**
* @inheritDoc
* @since 3.1.0 N°6271 Delegate to remote attribute to ensure cascading computed values
*/
public function GetSQLValues($value)
{
$oExtAttDef = $this->GetExtAttDef();
return $oExtAttDef->GetSQLValues($value);
}
public function ScalarToSQL($value)
{
// This one could be used in case of filtering only

View File

@@ -2853,11 +2853,10 @@ abstract class DBObject implements iDisplay
$aHierarchicalKeys = array();
foreach(MetaModel::ListAttributeDefs($sTableClass) as $sAttCode=>$oAttDef)
{
foreach(MetaModel::ListAttributeDefs($sTableClass) as $sAttCode=>$oAttDef) {
// Skip this attribute if not defined in this table
if (!MetaModel::IsAttributeOrigin($sTableClass, $sAttCode) && !$oAttDef->CopyOnAllTables())
{
if ((!MetaModel::IsAttributeOrigin($sTableClass, $sAttCode) && !$oAttDef->CopyOnAllTables())
|| $oAttDef->IsExternalField()) {
continue;
}
$aAttColumns = $oAttDef->GetSQLValues($this->m_aCurrValues[$sAttCode]);
@@ -2981,10 +2980,13 @@ abstract class DBObject implements iDisplay
}
$aHierarchicalKeys = array();
foreach(MetaModel::ListAttributeDefs($sTableClass) as $sAttCode=>$oAttDef)
foreach(MetaModel::ListAttributeDefs($sTableClass) as $sAttCode => $oAttDef)
{
// Skip this attribute if not defined in this table
if (!MetaModel::IsAttributeOrigin($sTableClass, $sAttCode)) continue;
if ((!MetaModel::IsAttributeOrigin($sTableClass, $sAttCode))
|| $oAttDef->IsExternalField()) {
continue;
};
// Skip link set that can still be undefined though the object is 100% loaded
if ($oAttDef->IsLinkSet()) continue;
@@ -6011,11 +6013,8 @@ abstract class DBObject implements iDisplay
}
$oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode);
$aSQLValues = $oAttDef->GetSQLValues($this->m_aCurrValues[$sAttCode]);
$aSQLValues = $oAttDef->GetSQLValues($this->Get($sAttCode));
$value = reset($aSQLValues);
if ($oAttDef->IsNull($value)) {
return '';
}
$aArgs[$sFieldDesc] = $value;
}

View File

@@ -3526,6 +3526,7 @@ class CharConcatWSExpression extends CharConcatExpression
$aRes = array();
foreach ($this->m_aExpressions as $oExpr)
{
// TODO: Seems weird, this should rather be $aRes[] = $oExpr->Evaluate($aArgs);
$aRes .= $oExpr->Evaluate($aArgs);
}
return implode($this->m_separator, $aRes);

View File

@@ -218,8 +218,8 @@ class SQLObjectQueryBuilder
continue;
}
$oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
// Skip this attribute if not made of SQL columns
if (count($oAttDef->GetSQLExpressions()) == 0)
// Skip this attribute if not made of SQL columns nor in current table
if (count($oAttDef->GetSQLExpressions()) == 0 || $oAttDef->IsExternalField())
{
continue;
}

View File

@@ -140,7 +140,7 @@ class DBObjectTest extends ItopDataTestCase
* @covers DBObject::Get
* @covers DBObject::Set
*/
public function testAttributeRefresh_FriendlyName()
public function testAttributeRefresh_FriendlyNameWithoutCascade()
{
$oObject = \MetaModel::NewObject('Person', array('name' => 'Foo', 'first_name' => 'John', 'org_id' => 3, 'location_id' => 2));
@@ -149,6 +149,21 @@ class DBObjectTest extends ItopDataTestCase
static::assertEquals('John Who', $oObject->Get('friendlyname'));
}
/**
* @covers DBObject::NewObject
* @covers DBObject::Get
* @covers DBObject::Set
*/
public function testAttributeRefresh_FriendlyNameWithCascade()
{
$oServer = \MetaModel::NewObject('Server', ['name' => 'ServerTest', 'org_id' => 3]);
$oServer->DBInsert();
$oDBServer = \MetaModel::NewObject('DBServer', ['name' => 'DBServerTest', 'org_id' => 3, 'system_id' => $oServer]);
static::assertEquals('ServerTest', $oDBServer->Get('system_name'));
static::assertEquals('DBServerTest ServerTest', $oDBServer->Get('friendlyname'));
}
/**
* @covers MetaModel::GetObject
* @covers DBObject::Get
@@ -174,8 +189,7 @@ class DBObjectTest extends ItopDataTestCase
public function testPartialAttributeEvaluation()
{
$oObject = \MetaModel::NewObject('Person', array('name' => 'Foo', 'org_id' => 3, 'location_id' => 2));
static::assertEquals('', $oObject->Get('friendlyname'));
static::assertEquals(' Foo', $oObject->Get('friendlyname'));
}
/**
@@ -186,7 +200,7 @@ class DBObjectTest extends ItopDataTestCase
{
$oObject = \MetaModel::NewObject('Person', array('org_id' => 3, 'location_id' => 2));
static::assertEquals('', $oObject->Get('friendlyname'));
static::assertEquals(' ', $oObject->Get('friendlyname'));
}
/**
@@ -198,7 +212,7 @@ class DBObjectTest extends ItopDataTestCase
$oUserProfile = new \URP_UserProfile();
$oUserProfile->Set('profileid', 2);
static::assertEquals('', $oUserProfile->Get('friendlyname'));
static::assertEquals('Link between and Portal user', $oUserProfile->Get('friendlyname'));
}
/**
@@ -206,7 +220,7 @@ class DBObjectTest extends ItopDataTestCase
* @covers DBObject::Get
* @covers DBObject::Set
*/
public function testAttributeRefresh_ObsolescenceFlag()
public function testAttributeRefresh_ObsolescenceFlagWithoutCascade()
{
$oObject = \MetaModel::NewObject('Person', array('name' => 'Foo', 'first_name' => 'John', 'org_id' => 3, 'location_id' => 2));
@@ -215,6 +229,24 @@ class DBObjectTest extends ItopDataTestCase
static::assertEquals(true, (bool)$oObject->Get('obsolescence_flag'));
}
/**
* @covers DBObject::NewObject
* @covers DBObject::Get
* @covers DBObject::Set
*/
public function testAttributeRefresh_ObsolescenceFlagWithCascade()
{
$this->markTestSkipped('Postponed');
// Necessary ext. key for $oDBServer
$oServer = \MetaModel::NewObject('Server', ['name' => 'ServerTest', 'org_id' => 3]);
$oServer->DBInsert();
$oDBServer = \MetaModel::NewObject('DBServer', ['name' => 'DBServerTest', 'org_id' => 3, 'system_id' => $oServer, 'status' => 'inactive']);
$oDBServer->DBInsert();
$oDBSchema = \MetaModel::NewObject('DatabaseSchema', ['name' => 'DBSchemaTest', 'org_id' => 3, 'dbserver_id' => $oDBServer]);
static::assertEquals(true, $oDBSchema->Get('obsolescence_flag'));
}
/**
* @covers DBObject::NewObject
* @covers DBObject::Get