Skip to content

Commit 9684b76

Browse files
authored
[6.0] Remaining fixes for Version History (#46276)
1 parent d4ca800 commit 9684b76

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

libraries/src/MVC/Model/AdminModel.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,12 @@ public function delete(&$pks)
936936
return false;
937937
}
938938

939+
if ($this instanceof VersionableModelInterface) {
940+
$typeAlias = $this->typeAlias ?: $this->option . '.' . $this->name;
941+
942+
$this->deleteHistory($typeAlias, $pk);
943+
}
944+
939945
// Trigger the after event.
940946
$dispatcher->dispatch($this->event_after_delete, new Model\AfterDeleteEvent($this->event_after_delete, [
941947
'context' => $context,

libraries/src/Versioning/VersionableModelInterface.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,16 @@ public function loadHistory(int $historyId);
4343
* @since 6.0.0
4444
*/
4545
public function saveHistory(array $data, string $context);
46+
47+
/**
48+
* Method to delete the history for an item.
49+
*
50+
* @param string $typeAlias Typealias of the content type
51+
* @param integer $id ID of the content item to delete
52+
*
53+
* @return boolean true on success, otherwise false.
54+
*
55+
* @since __DEPLOY_VERSION__
56+
*/
57+
public function deleteHistory($typeAlias, $id);
4658
}

libraries/src/Versioning/VersionableModelTrait.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,10 @@ public function setConvertToInt(array $convertToInt): void
299299
*/
300300
public function saveHistory(array $data, string $context)
301301
{
302+
if (!$this->versionHistoryEnabled($context)) {
303+
return false;
304+
}
305+
302306
$id = $this->getState($this->getName() . '.id');
303307

304308
/**
@@ -470,4 +474,20 @@ protected function markVersionAsCurrent(int $versionId, string $itemId): void
470474
$db->setQuery($query);
471475
$db->execute();
472476
}
477+
478+
/**
479+
* Method to check if version history is enabled for a specific context.
480+
*
481+
* @param string $context The model context.
482+
*
483+
* @return boolean True if version history is enabled, false otherwise.
484+
*
485+
* @since __DEPLOY_VERSION__
486+
*/
487+
protected function versionHistoryEnabled(string $context): bool
488+
{
489+
[$extension, $type] = explode('.', $context);
490+
491+
return (bool) ComponentHelper::getParams($extension)->get('save_history', 0);
492+
}
473493
}

0 commit comments

Comments
 (0)