mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX: Disable DataObject validation temporarily while importing yaml fixtures
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@71642 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
bec773db22
commit
4cbf0d60ae
@ -105,6 +105,29 @@ class DataObject extends ViewableData implements DataObjectInterface,i18nEntityP
|
||||
* @todo Define the options that can be set here
|
||||
*/
|
||||
static $api_access = false;
|
||||
|
||||
/**
|
||||
* Should dataobjects be validated before they are written?
|
||||
*/
|
||||
private static $validation_enabled = true;
|
||||
|
||||
/**
|
||||
* Returns when validation on DataObjects is enabled.
|
||||
* @return bool
|
||||
*/
|
||||
static function get_validation_enabled() {
|
||||
return self::$validation_enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether DataObjects should be validated before they are written.
|
||||
* @param $enable bool
|
||||
* @see DataObject::validate()
|
||||
*/
|
||||
static function set_validation_enabled($enable) {
|
||||
self::$validation_enabled = (bool) $enable;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new DataObject.
|
||||
@ -683,10 +706,12 @@ class DataObject extends ViewableData implements DataObjectInterface,i18nEntityP
|
||||
$this->brokenOnWrite = true;
|
||||
$isNewRecord = false;
|
||||
|
||||
$valid = $this->validate();
|
||||
if(!$valid->valid()) {
|
||||
throw new ValidationException($valid, "Validation error writing a $this->class object: " . $valid->message() . ". Object not written.", E_USER_WARNING);
|
||||
return false;
|
||||
if(self::get_validation_enabled()) {
|
||||
$valid = $this->validate();
|
||||
if(!$valid->valid()) {
|
||||
throw new ValidationException($valid, "Validation error writing a $this->class object: " . $valid->message() . ". Object not written.", E_USER_WARNING);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$this->onBeforeWrite();
|
||||
|
@ -66,9 +66,15 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
$dbadmin = new DatabaseAdmin();
|
||||
$dbadmin->clearAllData();
|
||||
|
||||
|
||||
// We have to disable validation while we import the fixtures, as the order in
|
||||
// which they are imported doesnt guarantee valid relations until after the
|
||||
// import is complete.
|
||||
$validationenabled = DataObject::get_validation_enabled();
|
||||
DataObject::set_validation_enabled(false);
|
||||
$this->fixture = new YamlFixture($fixtureFile);
|
||||
$this->fixture->saveIntoDatabase();
|
||||
DataObject::set_validation_enabled($validationenabled);
|
||||
}
|
||||
|
||||
// Set up email
|
||||
@ -230,4 +236,4 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user