Skip to content

Commit

Permalink
Improved backward compatibility for Contao 3.1 file IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
ausi committed Nov 19, 2013
1 parent 84033c0 commit b1947a5
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/MadeYourDay/Contao/CustomElements.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,28 @@ public function loadCallback($value, $dc)
$GLOBALS['TL_DCA'][$dc->table]['fields'][$dc->field]['inputType'] === 'rsce_file_tree' &&
$value
) {
if (strlen($value) === 36) {
$value = \String::uuidToBin($value);
// Multiple files
if (substr($value, 0, 2) === 'a:') {
$value = serialize(array_map(function($value) {
if (strlen($value) === 36) {
$value = \String::uuidToBin($value);
}
else if (is_numeric($value) && $file = \FilesModel::findByPk($value)) {
// Convert 3.1 format into 3.2 format
$value = $file->uuid;
}
return $value;
}, deserialize($value)));
}
// Single file
else {
$value = serialize(array_map('String::uuidToBin', deserialize($value)));
if (strlen($value) === 36) {
$value = \String::uuidToBin($value);
}
else if (is_numeric($value) && $file = \FilesModel::findByPk($value)) {
// Convert 3.1 format into 3.2 format
$value = $file->uuid;
}
}
}

Expand Down

0 comments on commit b1947a5

Please sign in to comment.