mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
FIX Improve publish performance for formfields (#538)
* FIX Improve publish performance for formfields * FIX Travis builds broken with external code coverage
This commit is contained in:
parent
efcd85fcbe
commit
2f710d6518
@ -27,7 +27,9 @@ before_script:
|
||||
|
||||
script:
|
||||
- vendor/bin/phpunit --coverage-clover coverage.clover userforms/tests
|
||||
|
||||
after_script:
|
||||
- mv coverage.clover ~/build/$TRAVIS_REPO_SLUG/
|
||||
- cd ~/build/$TRAVIS_REPO_SLUG
|
||||
- wget https://scrutinizer-ci.com/ocular.phar
|
||||
- git remote rm origin
|
||||
- git remote add origin git@github.com:silverstripe/silverstripe-userforms.git
|
||||
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover
|
||||
|
@ -136,18 +136,32 @@ class UserFormFieldEditorExtension extends DataExtension {
|
||||
* @return void
|
||||
*/
|
||||
public function onAfterPublish($original) {
|
||||
// Remove fields on the live table which could have been orphaned.
|
||||
$live = Versioned::get_by_stage("EditableFormField", "Live")
|
||||
->filter('ParentID', $original->ID);
|
||||
|
||||
if($live) {
|
||||
foreach($live as $field) {
|
||||
$field->doDeleteFromStage('Live');
|
||||
}
|
||||
}
|
||||
// store IDs of fields we've published
|
||||
$seenIDs = array();
|
||||
|
||||
foreach ($this->owner->Fields() as $field) {
|
||||
// store any IDs of fields we publish so we don't unpublish them
|
||||
$seenIDs[] = $field->ID;
|
||||
$field->doPublish('Stage', 'Live');
|
||||
$field->destroy();
|
||||
}
|
||||
|
||||
// fetch any orphaned live records
|
||||
$live = Versioned::get_by_stage("EditableFormField", "Live")
|
||||
->filter(array(
|
||||
'ParentID' => $original->ID,
|
||||
));
|
||||
|
||||
if (!empty($seenIDs)) {
|
||||
$live = $live->exclude(array(
|
||||
'ID' => $seenIDs,
|
||||
));
|
||||
}
|
||||
|
||||
// delete orphaned records
|
||||
foreach ($live as $field) {
|
||||
$field->doDeleteFromStage('Live');
|
||||
$field->destroy();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -474,9 +474,25 @@ class EditableFormField extends DataObject {
|
||||
public function doPublish($fromStage, $toStage, $createNewVersion = false) {
|
||||
$this->publish($fromStage, $toStage, $createNewVersion);
|
||||
|
||||
$seenIDs = array();
|
||||
|
||||
// Don't forget to publish the related custom rules...
|
||||
foreach ($this->DisplayRules() as $rule) {
|
||||
$seenIDs[] = $rule->ID;
|
||||
$rule->doPublish($fromStage, $toStage, $createNewVersion);
|
||||
$rule->destroy();
|
||||
}
|
||||
|
||||
// remove any orphans from the "fromStage"
|
||||
$rules = Versioned::get_by_stage('EditableCustomRule', $toStage)
|
||||
->filter('ParentID', $this->ID);
|
||||
|
||||
if (!empty($seenIDs)) {
|
||||
$rules = $rules->exclude('ID', $seenIDs);
|
||||
}
|
||||
|
||||
foreach ($rules as $rule) {
|
||||
$rule->deleteFromStage($toStage);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user