Skip to content

Commit e5bffae

Browse files
authored
[5.3] Prevent null ordering on item restore from version history (#45783)
1 parent 0e88af4 commit e5bffae

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

libraries/src/Versioning/VersionableModelTrait.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ public function loadHistory($versionId, Table $table)
7979
$table->load($rowArray[$key]);
8080
}
8181

82+
// Fix null ordering when restoring history
83+
if (\array_key_exists('ordering', $rowArray) && $rowArray['ordering'] === null) {
84+
$rowArray['ordering'] = 0;
85+
}
86+
8287
return $table->bind($rowArray);
8388
}
8489
}

libraries/src/Versioning/Versioning.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,17 @@ public static function store($typeAlias, $id, $data, $note = '')
123123
Factory::getApplication()->getDispatcher()->dispatch('onContentVersioningPrepareTable', $event);
124124
}
125125

126+
// Fix for null ordering - set to 0 if null
127+
if (\is_object($data)) {
128+
if (property_exists($data, 'ordering') && $data->ordering === null) {
129+
$data->ordering = 0;
130+
}
131+
} elseif (\is_array($data)) {
132+
if (\array_key_exists('ordering', $data) && $data['ordering'] === null) {
133+
$data['ordering'] = 0;
134+
}
135+
}
136+
126137
$historyTable->version_data = json_encode($data);
127138
$historyTable->version_note = $note;
128139

0 commit comments

Comments
 (0)