Fixed Flex User Avatar not fully backwards compatible with old user

This commit is contained in:
Matias Griese
2019-10-03 22:11:13 +03:00
parent 8ac3451fbc
commit ae41b6f5ff
2 changed files with 30 additions and 10 deletions

View File

@@ -7,6 +7,7 @@
* Support customizable null character replacement in `CSVFormatter::decode()`
1. [](#bugfix)
* Fixed wrong Grav param separator when using `Route` class
* Fixed Flex User Avatar not fully backwards compatible with old user
* Grav 1.7: Fixed prev/next page missing pages if pagination was turned on in page header
* Grav 1.7: Reverted setting language for every page during initialization
* Grav 1.7: Fixed numeric language inconsistencies

View File

@@ -29,6 +29,7 @@ use Grav\Framework\Form\FormFlashFile;
use Grav\Framework\Media\Interfaces\MediaManipulationInterface;
use Psr\Http\Message\UploadedFileInterface;
use RocketTheme\Toolbox\File\FileInterface;
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
/**
* Flex User
@@ -567,7 +568,7 @@ class User extends FlexObject implements UserInterface, MediaManipulationInterfa
$folder = $this->getFlexMediaFolder();
if (!$folder) {
// Shared media!
$this->loadMedia = false;
$this->_loadMedia = false;
$folder = $this->getBlueprint()->fields()['avatar']['destination'] ?? 'user://accounts/avatars';
}
@@ -610,7 +611,30 @@ class User extends FlexObject implements UserInterface, MediaManipulationInterfa
$list_original = [];
foreach ($files as $field => $group) {
foreach ($group as $filename => $file) {
if (strpos($field, '/original')) {
if ($file) {
$filename = $file->getClientFilename();
/** @var FormFlashFile $file */
$data = $file->jsonSerialize();
unset($data['tmp_name'], $data['path']);
} else {
$data = null;
}
// For shared media folder we need to keep path for backwards compatibility.
$folder = $this->getMediaFolder();
if ($this->_loadMedia) {
$filepath = $filename;
} else {
/** @var UniformResourceLocator $locator */
$locator = Grav::instance()['locator'];
$filepath = $locator->findResource($folder, false, true) . '/' . $filename;
if ($data) {
$data['path'] = $filepath;
}
}
if ($this->_loadMedia && strpos($field, '/original')) {
// Special handling for original images.
$list_original[$filename] = $file;
continue;
@@ -618,15 +642,10 @@ class User extends FlexObject implements UserInterface, MediaManipulationInterfa
$list[$filename] = $file;
if ($file) {
/** @var FormFlashFile $file */
$data = $file->jsonSerialize();
$path = $file->getClientFilename();
unset($data['tmp_name'], $data['path']);
$this->setNestedProperty("{$field}\n{$path}", $data, "\n");
if ($data) {
$this->setNestedProperty("{$field}\n{$filepath}", $data, "\n");
} else {
$this->unsetNestedProperty("{$field}\n{$filename}", "\n");
$this->unsetNestedProperty("{$field}\n{$filepath}", "\n");
}
}
}