mirror of
https://github.com/getgrav/grav.git
synced 2026-06-27 20:09:01 +02:00
Fixed index updating on copyUploadedFile(), deleteFile() and renameFile()
This commit is contained in:
@@ -312,9 +312,9 @@ trait MediaUploadTrait
|
||||
// TODO: This overrides existing media sizes if used with multiple retina image sizes.
|
||||
$this->doAddUploadedMedium($name, $filename, $path);
|
||||
|
||||
// Force media index update.
|
||||
if (method_exists($this, 'saveIndex')) {
|
||||
$this->saveIndex($this->index);
|
||||
// Update media index.
|
||||
if (method_exists($this, 'updateIndex')) {
|
||||
$this->updateIndex();
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
@@ -364,9 +364,9 @@ trait MediaUploadTrait
|
||||
// Remove file and all all the associated metadata.
|
||||
$this->doRemove($name, $path);
|
||||
|
||||
// Force media index update.
|
||||
if (method_exists($this, 'saveIndex')) {
|
||||
$this->saveIndex($this->index);
|
||||
// Update media index.
|
||||
if (method_exists($this, 'updateIndex')) {
|
||||
$this->updateIndex();
|
||||
}
|
||||
|
||||
// Finally clear media cache.
|
||||
@@ -409,9 +409,9 @@ trait MediaUploadTrait
|
||||
|
||||
$this->doRename($from, $to, $path);
|
||||
|
||||
// Force media index update.
|
||||
if (method_exists($this, 'saveIndex')) {
|
||||
$this->saveIndex($this->index);
|
||||
// Update media index.
|
||||
if (method_exists($this, 'updateIndex')) {
|
||||
$this->updateIndex();
|
||||
}
|
||||
|
||||
// Finally clear media cache.
|
||||
|
||||
@@ -365,10 +365,10 @@ abstract class AbstractMedia implements ExportInterface, MediaCollectionInterfac
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $files
|
||||
* @param array|null $files
|
||||
* @return void
|
||||
*/
|
||||
public function updateIndex(array $files): void
|
||||
public function updateIndex(array $files = null): void
|
||||
{
|
||||
$mediaIndex = $this->getIndex();
|
||||
if (!$mediaIndex) {
|
||||
@@ -380,11 +380,17 @@ abstract class AbstractMedia implements ExportInterface, MediaCollectionInterfac
|
||||
$id = $this->getId();
|
||||
$index = $mediaIndex->get($id, true);
|
||||
|
||||
// Add new files and remove the old ones.
|
||||
$files += $index['files'] ?? [];
|
||||
$files = array_filter($files, static function($val) { return $val !== null; } );
|
||||
if ($files === null) {
|
||||
$files = $index['files'] ?? [];
|
||||
$timestamp = 0;
|
||||
} else {
|
||||
// Add new files and remove the old ones.
|
||||
$files += $index['files'] ?? [];
|
||||
$files = array_filter($files, static function($val) { return $val !== null; } );
|
||||
$timestamp = time();
|
||||
}
|
||||
|
||||
$index = $this->generateIndex($files);
|
||||
$index = $this->generateIndex($files, null, $timestamp);
|
||||
|
||||
$mediaIndex->save($id, $index);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user