BUG Fix displayrule versioning

This commit is contained in:
Damian Mooyman 2015-09-18 11:07:58 +12:00
parent 14365c963d
commit 1bf826d34e
4 changed files with 48 additions and 11 deletions

View File

@ -409,6 +409,11 @@ class UserDefinedForm_Controller extends Page_Controller {
// Get the field which is effected
$formFieldWatch = EditableFormField::get()->byId($rule->ConditionFieldID);
// Skip deleted fields
if(!$formFieldWatch) {
continue;
}
$fieldToWatch = $formFieldWatch->getSelectorField($rule);
$fieldToWatchOnLoad = $formFieldWatch->getSelectorField($rule, true);

View File

@ -353,17 +353,20 @@ class EditableFormField extends DataObject {
}
/**
* Delete this form from a given stage
* Delete this field from a given stage
*
* Wrapper for the {@link Versioned} deleteFromStage function
*/
public function doDeleteFromStage($stage) {
$this->deleteFromStage($stage);
// Don't forget to delete the related custom rules...
foreach ($this->DisplayRules() as $rule) {
// Remove custom rules in this stage
$rules = Versioned::get_by_stage('EditableCustomRule', $stage)
->filter('ParentID', $this->ID);
foreach ($rules as $rule) {
$rule->deleteFromStage($stage);
}
// Remove record
$this->deleteFromStage($stage);
}
/**

View File

@ -95,7 +95,7 @@ class EditableMultipleOptionField extends EditableFormField {
}
}
$this->publish($fromStage, $toStage, $createNewVersion);
parent::doPublish($fromStage, $toStage, $createNewVersion);
}
/**
@ -106,13 +106,14 @@ class EditableMultipleOptionField extends EditableFormField {
* @return void
*/
public function doDeleteFromStage($stage) {
if($this->Options()) {
foreach($this->Options() as $option) {
$option->deleteFromStage($stage);
}
// Remove options
$options = Versioned::get_by_stage('EditableOption', $stage)
->filter('ParentID', $this->ID);
foreach($options as $option) {
$option->deleteFromStage($stage);
}
$this->deleteFromStage($stage);
parent::doDeleteFromStage($stage);
}
/**

View File

@ -188,6 +188,34 @@ class UserDefinedFormTest extends FunctionalTest {
$liveText = Versioned::get_one_by_stage("EditableFormField", "Live", "\"EditableFormField_Live\".\"ID\" = $text->ID");
$this->assertTrue($liveText->Title == $text->Title);
// Add a display rule to the dropdown
$displayRule = new EditableCustomRule();
$displayRule->ParentID = $dropdown->ID;
$displayRule->ConditionFieldID = $text->ID;
$displayRule->write();
$ruleID = $displayRule->ID;
// Not live
$liveRule = Versioned::get_one_by_stage("EditableCustomRule", "Live", "\"EditableCustomRule_Live\".\"ID\" = $ruleID");
$this->assertEmpty($liveRule);
// Publish form, it's now live
$form->doPublish();
$liveRule = Versioned::get_one_by_stage("EditableCustomRule", "Live", "\"EditableCustomRule_Live\".\"ID\" = $ruleID");
$this->assertNotEmpty($liveRule);
// Remove rule
$displayRule->delete();
// Live rule still exists
$liveRule = Versioned::get_one_by_stage("EditableCustomRule", "Live", "\"EditableCustomRule_Live\".\"ID\" = $ruleID");
$this->assertNotEmpty($liveRule);
// Publish form, it should remove this rule
$form->doPublish();
$liveRule = Versioned::get_one_by_stage("EditableCustomRule", "Live", "\"EditableCustomRule_Live\".\"ID\" = $ruleID");
$this->assertEmpty($liveRule);
}
function testUnpublishing() {