Skip to content

Commit

Permalink
PR feedback: Execute validation on flush.
Browse files Browse the repository at this point in the history
  • Loading branch information
mfendeksilverstripe committed Oct 20, 2021
1 parent ce576ca commit 07aff3a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
13 changes: 11 additions & 2 deletions src/Dev/Validation/RelationValidationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use ReflectionException;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Config\Configurable;
use SilverStripe\Core\Flushable;
use SilverStripe\Core\Injector\Injectable;
use SilverStripe\Core\Resettable;
use SilverStripe\ORM\DataObject;
Expand All @@ -19,7 +20,7 @@
* This tool runs automatically via dev/build and outputs notices
* For strict validation it is recommended to hook this up to your unit test suite
*/
class RelationValidationService implements Resettable
class RelationValidationService implements Flushable, Resettable
{

use Configurable;
Expand Down Expand Up @@ -80,6 +81,14 @@ public static function reset(): void
$service->ignoreConfig = false;
}

/**
* @throws ReflectionException
*/
public static function flush(): void
{
self::singleton()->executeValidation();
}

/**
* Hook this into your unit tests and assert for empty array like this
*
Expand All @@ -100,7 +109,7 @@ public function validateRelations(): array
/**
* @throws ReflectionException
*/
public function devBuildCheck(): void
public function executeValidation(): void
{
$errors = $this->validateRelations();
$count = count($errors);
Expand Down
6 changes: 0 additions & 6 deletions src/ORM/DataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use SilverStripe\Core\Resettable;
use SilverStripe\Dev\Debug;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Dev\Validation\RelationValidationService;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\FormField;
use SilverStripe\Forms\FormScaffolder;
Expand Down Expand Up @@ -3651,11 +3650,6 @@ public function requireDefaultRecords()
}
}

// Validate relations (this needs to be triggered only once)
if (static::class === \Page::class) {
RelationValidationService::singleton()->devBuildCheck();
}

// Let any extensions make their own database default data
$this->extend('requireDefaultRecords', $dummy);
}
Expand Down

0 comments on commit 07aff3a

Please sign in to comment.