Add new regenerate_on_build

This commit is contained in:
Aaron Carlino 2021-05-27 15:25:38 +12:00
parent be8b3923cc
commit c754116963
7 changed files with 39 additions and 10 deletions

View File

@ -1,3 +1,13 @@
---
Name: frameworktest-extensions
---
SilverStripe\ORM\DataObject:
extensions:
- DevBuildGeneratorExtension
SilverStripe\Assets\File:
extensions:
- BasicFieldsTestFileExtension
---
Only:
classexists: 'DNADesign\Elemental\Extensions\ElementalPageExtension'

View File

@ -1,6 +0,0 @@
---
Name: frameworktestpages
---
SilverStripe\Assets\File:
extensions:
- BasicFieldsTestFileExtension

View File

@ -110,11 +110,10 @@ class BasicFieldsTestPage extends TestPage
{
parent::requireDefaultRecords();
if ($inst = DataObject::get_one('BasicFieldsTestPage')) {
if ($inst = DataObject::get_one('BasicFieldsTestPage') && static::config()->get('regenerate_on_build')) {
$data = $this->getDefaultData();
$inst->update($data);
$inst->write();
TestCategory::create()->requireDefaultRecords();
$cats = TestCategory::get();
$firstCat = $cats->offsetGet(0);

View File

@ -6,10 +6,10 @@ use SilverStripe\Assets\Image;
use SilverStripe\Forms\DropdownField;
use SilverStripe\ORM\HasManyList;
use SilverStripe\ORM\ManyManyList;
use SilverStripe\ORM\ValidationResult;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB;
use SilverStripe\AssetAdmin\Forms\UploadField;
use SilverStripe\Versioned\RecursivePublishable;
use SilverStripe\Versioned\Versioned;
use RelationFieldsTestPage;
use GridFieldTestPage;
@ -120,11 +120,15 @@ class Company extends DataObject
{
parent::requireDefaultRecords();
$companySet = static::get();
$data = $this->data();
if ($companySet->exists() && !static::config()->get('regenerate_on_build')) {
return;
}
foreach ($companySet as $company) {
$company->delete();
}
foreach ($this->data() as $companyData) {
foreach ($data as $companyData) {
$company = new Company();
$company->Name = $companyData[0];
$company->Category = $companyData[1];

View File

@ -0,0 +1,14 @@
<?php
use SilverStripe\Core\Config\Configurable;
use SilverStripe\ORM\DataExtension;
/**
* There is no good place to put this setting, so it gets a class.
*/
class DevBuildGeneratorExtension extends DataExtension
{
use Configurable;
private static $regenerate_on_build = false;
}

View File

@ -99,6 +99,10 @@ class Employee extends DataObject
{
parent::requireDefaultRecords();
$employeeSet = DataObject::get(Employee::class);
if ($employeeSet->exists() && !static::config()->get('regenerate_on_build')) {
return;
}
foreach ($employeeSet as $employee) {
$employee->delete();
}

View File

@ -851,6 +851,10 @@ class TestRegistryDataObject extends DataObject implements RegistryDataInterface
/** @var DataObject[] $all */
$all = static::get();
if ($all->exists() && !static::config()->get('regenerate_on_build')) {
return;
}
foreach ($all as $one) {
$one->delete();
}