Skip to content

Commit

Permalink
feat: reduce number of created versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Severin Hauser committed Mar 21, 2023
1 parent 3e29da1 commit 6f255f4
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vendor/
composer.lock
resources/
24 changes: 20 additions & 4 deletions src/PageElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,20 @@ public function onAfterWrite()
if (Versioned::get_stage() == Versioned::DRAFT && $this->isChanged("__Counter", DataObject::CHANGE_VALUE)) {
foreach ($this->PageSections() as $section) {
$section->__Counter++;
$section->write();
if ($section->isLiveVersion()) {
$section->write();
} else {
$section->writeWithoutVersion();
}
}

foreach ($this->Parents() as $parent) {
$parent->__Counter++;
$parent->write();
if ($parent->isLiveVersion()) {
$parent->write();
} else {
$parent->writeWithoutVersion();
}
}
}
}
Expand All @@ -148,7 +156,11 @@ public function onAfterDelete()
if (Versioned::get_stage() == Versioned::DRAFT) {
foreach ($this->PageSections() as $section) {
$section->__Counter++;
$section->write();
if ($section->isLiveVersion()) {
$section->write();
} else {
$section->writeWithoutVersion();
}
}
}
}
Expand All @@ -158,7 +170,11 @@ public function onAfterArchive()
if (Versioned::get_stage() == Versioned::DRAFT) {
foreach ($this->PageSections() as $section) {
$section->__Counter++;
$section->write();
if ($section->isLiveVersion()) {
$section->write();
} else {
$section->writeWithoutVersion();
}
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions src/PageElementSelfRel.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ public function onAfterWrite()

if (!$this->__NewOrder && Versioned::get_stage() == Versioned::DRAFT) {
$this->Parent()->__Counter++;
$this->Parent()->write();
if ($this->Parent()->isLiveVersion()) {
$this->Parent()->write();
} else {
$this->Parent()->writeWithoutVersion();
}
}
}

Expand All @@ -46,7 +50,11 @@ public function onAfterDelete()

if (Versioned::get_stage() == Versioned::DRAFT) {
$this->Parent()->__Counter++;
$this->Parent()->write();
if ($this->Parent()->isLiveVersion()) {
$this->Parent()->write();
} else {
$this->Parent()->writeWithoutVersion();
}
}
}
}
7 changes: 6 additions & 1 deletion src/PageSection.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ public function onAfterWrite()

if (!$this->__isNew && Versioned::get_stage() == Versioned::DRAFT && $this->isChanged("__Counter", DataObject::CHANGE_VALUE)) {
$this->Parent()->__PageSectionCounter++;
$this->Parent()->write();
// Only create a new version when the previous one is <th></th>e published one.
if ($this->Parent()->isLiveVersion()) {
$this->Parent()->write();
} else {
$this->Parent()->writeWithoutVersion();
}
}
}

Expand Down
12 changes: 10 additions & 2 deletions src/PageSectionPageElementRel.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ public function onAfterWrite()

if (!$this->__NewOrder && Versioned::get_stage() == Versioned::DRAFT) {
$this->PageSection()->__Counter++;
$this->PageSection()->write();
if ($this->PageSection()->isLiveVersion()) {
$this->PageSection()->write();
} else {
$this->PageSection()->writeWithoutVersion();
}
}
}

Expand All @@ -46,7 +50,11 @@ public function onAfterDelete()

if (Versioned::get_stage() == Versioned::DRAFT) {
$this->PageSection()->__Counter++;
$this->PageSection()->write();
if ($this->PageSection()->isLiveVersion()) {
$this->PageSection()->write();
} else {
$this->PageSection()->writeWithoutVersion();
}
}
}
}

0 comments on commit 6f255f4

Please sign in to comment.