mirror of
https://github.com/silverstripe/silverstripe-frameworktest
synced 2024-10-22 11:06:02 +02:00
Add new regenerate_on_build
This commit is contained in:
parent
be8b3923cc
commit
c754116963
@ -1,3 +1,13 @@
|
||||
---
|
||||
Name: frameworktest-extensions
|
||||
---
|
||||
SilverStripe\ORM\DataObject:
|
||||
extensions:
|
||||
- DevBuildGeneratorExtension
|
||||
SilverStripe\Assets\File:
|
||||
extensions:
|
||||
- BasicFieldsTestFileExtension
|
||||
|
||||
---
|
||||
Only:
|
||||
classexists: 'DNADesign\Elemental\Extensions\ElementalPageExtension'
|
@ -1,6 +0,0 @@
|
||||
---
|
||||
Name: frameworktestpages
|
||||
---
|
||||
SilverStripe\Assets\File:
|
||||
extensions:
|
||||
- BasicFieldsTestFileExtension
|
@ -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);
|
||||
|
@ -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];
|
||||
|
14
code/DevBuildGeneratorExtension.php
Normal file
14
code/DevBuildGeneratorExtension.php
Normal 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;
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user