mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
API exists() no longer true for nullifyIfEmpty if empty string
Optimise DBString::exists() to skip shortcodes
This commit is contained in:
parent
2c5e482de0
commit
9be22701fd
@ -242,4 +242,12 @@ class DBHTMLText extends DBText
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function exists()
|
||||
{
|
||||
// Optimisation: don't process shortcode just for ->exists()
|
||||
$value = $this->getValue();
|
||||
// All truthy values and non-empty strings exist ('0' but not (int)0)
|
||||
return $value || (is_string($value) && strlen($value));
|
||||
}
|
||||
}
|
||||
|
@ -141,4 +141,12 @@ class DBHTMLVarchar extends DBVarchar
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function exists()
|
||||
{
|
||||
// Optimisation: don't process shortcode just for ->exists()
|
||||
$value = $this->getValue();
|
||||
// All truthy values and non-empty strings exist ('0' but not (int)0)
|
||||
return $value || (is_string($value) && strlen($value));
|
||||
}
|
||||
}
|
||||
|
@ -96,9 +96,8 @@ abstract class DBString extends DBField
|
||||
public function exists()
|
||||
{
|
||||
$value = $this->RAW();
|
||||
return $value // All truthy values exist
|
||||
|| (is_string($value) && strlen($value)) // non-empty strings exist ('0' but not (int)0)
|
||||
|| (!$this->getNullifyEmpty() && $value === ''); // Remove this stupid exemption in 4.0
|
||||
// All truthy values and non-empty strings exist ('0' but not (int)0)
|
||||
return $value || (is_string($value) && strlen($value));
|
||||
}
|
||||
|
||||
public function prepValueForDB($value)
|
||||
|
@ -205,7 +205,7 @@ class DBFieldTest extends SapphireTest
|
||||
$varcharField->setValue('abc');
|
||||
$this->assertTrue($varcharField->exists());
|
||||
$varcharField->setValue('');
|
||||
$this->assertTrue($varcharField->exists());
|
||||
$this->assertFalse($varcharField->exists());
|
||||
$varcharField->setValue(null);
|
||||
$this->assertFalse($varcharField->exists());
|
||||
|
||||
@ -223,7 +223,7 @@ class DBFieldTest extends SapphireTest
|
||||
$textField->setValue('abc');
|
||||
$this->assertTrue($textField->exists());
|
||||
$textField->setValue('');
|
||||
$this->assertTrue($textField->exists());
|
||||
$this->assertFalse($textField->exists());
|
||||
$textField->setValue(null);
|
||||
$this->assertFalse($textField->exists());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user