enh(metadata): store current file etagtags/v29.0.0beta2
$metadata->setArray($metadataKey, $value); | $metadata->setArray($metadataKey, $value); | ||||
break; | break; | ||||
case IMetadataValueWrapper::TYPE_STRING_LIST: | case IMetadataValueWrapper::TYPE_STRING_LIST: | ||||
$metadata->setStringList( | |||||
$metadataKey, $value, $knownMetadata->isIndex($metadataKey) | |||||
); | |||||
$metadata->setStringList($metadataKey, $value, $knownMetadata->isIndex($metadataKey)); | |||||
break; | break; | ||||
case IMetadataValueWrapper::TYPE_INT_LIST: | case IMetadataValueWrapper::TYPE_INT_LIST: | ||||
$metadata->setIntList( | |||||
$metadataKey, $value, $knownMetadata->isIndex($metadataKey) | |||||
); | |||||
$metadata->setIntList($metadataKey, $value, $knownMetadata->isIndex($metadataKey)); | |||||
break; | break; | ||||
} | } | ||||
return; | return; | ||||
} | } | ||||
$currentEtag = $file->getEtag(); | |||||
$metadata = $event->getMetadata(); | |||||
if ($metadata->getEtag('blurhash') === $currentEtag) { | |||||
return; | |||||
} | |||||
// too heavy to run on the live thread, request a rerun as a background job | // too heavy to run on the live thread, request a rerun as a background job | ||||
if ($event instanceof MetadataLiveEvent) { | if ($event instanceof MetadataLiveEvent) { | ||||
$event->requestBackgroundJob(); | $event->requestBackgroundJob(); | ||||
return; | return; | ||||
} | } | ||||
$metadata = $event->getMetadata(); | |||||
$metadata->setString('blurhash', $this->generateBlurHash($image)); | |||||
$metadata->setString('blurhash', $this->generateBlurHash($image)) | |||||
->setEtag('blurhash', $currentEtag); | |||||
} | } | ||||
/** | /** |
$this->metadata[$key]->setEditPermission($permission); | $this->metadata[$key]->setEditPermission($permission); | ||||
} | } | ||||
public function getEtag(string $key): string { | |||||
if (!array_key_exists($key, $this->metadata)) { | |||||
throw new FilesMetadataNotFoundException(); | |||||
} | |||||
return $this->metadata[$key]->getEtag(); | |||||
} | |||||
public function setEtag(string $key, string $etag): void { | |||||
if (!array_key_exists($key, $this->metadata)) { | |||||
throw new FilesMetadataNotFoundException(); | |||||
} | |||||
$this->metadata[$key]->setEtag($etag); | |||||
} | |||||
/** | /** | ||||
* @param string $key metadata key | * @param string $key metadata key | ||||
* | * |
private string $type; | private string $type; | ||||
/** @var string|int|float|bool|array|string[]|int[] */ | /** @var string|int|float|bool|array|string[]|int[] */ | ||||
private mixed $value = null; | private mixed $value = null; | ||||
private string $etag = ''; | |||||
private bool $indexed = false; | private bool $indexed = false; | ||||
private int $editPermission = self::EDIT_FORBIDDEN; | private int $editPermission = self::EDIT_FORBIDDEN; | ||||
return $this->value; | return $this->value; | ||||
} | } | ||||
/** | |||||
* @inheritDoc | |||||
* @return string stored etag | |||||
* @since 29.0.0 | |||||
*/ | |||||
public function getEtag(): string { | |||||
return $this->etag; | |||||
} | |||||
/** | |||||
* @param string $etag etag value | |||||
* | |||||
* @inheritDoc | |||||
* @return self | |||||
* @since 29.0.0 | |||||
*/ | |||||
public function setEtag(string $etag): self { | |||||
$this->etag = $etag; | |||||
return $this; | |||||
} | |||||
/** | /** | ||||
* @param bool $indexed TRUE to set the stored value as an indexed value | * @param bool $indexed TRUE to set the stored value as an indexed value | ||||
* | * | ||||
public function import(array $data): self { | public function import(array $data): self { | ||||
$this->value = $data['value'] ?? null; | $this->value = $data['value'] ?? null; | ||||
$this->type = $data['type'] ?? ''; | $this->type = $data['type'] ?? ''; | ||||
$this->setEtag($data['etag'] ?? ''); | |||||
$this->setIndexed($data['indexed'] ?? false); | $this->setIndexed($data['indexed'] ?? false); | ||||
$this->setEditPermission($data['editPermission'] ?? self::EDIT_FORBIDDEN); | $this->setEditPermission($data['editPermission'] ?? self::EDIT_FORBIDDEN); | ||||
return $this; | return $this; | ||||
return [ | return [ | ||||
'value' => ($emptyValues) ? null : $this->value, | 'value' => ($emptyValues) ? null : $this->value, | ||||
'type' => $this->getType(), | 'type' => $this->getType(), | ||||
'etag' => $this->getEtag(), | |||||
'indexed' => $this->isIndexed(), | 'indexed' => $this->isIndexed(), | ||||
'editPermission' => $this->getEditPermission() | 'editPermission' => $this->getEditPermission() | ||||
]; | ]; |
try { | try { | ||||
$qb = $this->dbConnection->getQueryBuilder(); | $qb = $this->dbConnection->getQueryBuilder(); | ||||
$qb->select('json', 'sync_token')->from(self::TABLE_METADATA); | $qb->select('json', 'sync_token')->from(self::TABLE_METADATA); | ||||
$qb->where( | |||||
$qb->expr()->eq('file_id', $qb->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)) | |||||
); | |||||
$qb->where($qb->expr()->eq('file_id', $qb->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))); | |||||
$result = $qb->executeQuery(); | $result = $qb->executeQuery(); | ||||
$data = $result->fetch(); | $data = $result->fetch(); | ||||
$result->closeCursor(); | $result->closeCursor(); | ||||
} catch (Exception $e) { | } catch (Exception $e) { | ||||
$this->logger->warning( | |||||
'exception while getMetadataFromDatabase()', ['exception' => $e, 'fileId' => $fileId] | |||||
); | |||||
$this->logger->warning('exception while getMetadataFromDatabase()', ['exception' => $e, 'fileId' => $fileId]); | |||||
throw new FilesMetadataNotFoundException(); | throw new FilesMetadataNotFoundException(); | ||||
} | } | ||||
/** | /** | ||||
* returns metadata for multiple file ids | * returns metadata for multiple file ids | ||||
* | * | ||||
* If | |||||
* | |||||
* @param array $fileIds file ids | * @param array $fileIds file ids | ||||
* | * | ||||
* @return array File ID is the array key, files without metadata are not returned in the array | * @return array File ID is the array key, files without metadata are not returned in the array | ||||
public function getMetadataFromFileIds(array $fileIds): array { | public function getMetadataFromFileIds(array $fileIds): array { | ||||
$qb = $this->dbConnection->getQueryBuilder(); | $qb = $this->dbConnection->getQueryBuilder(); | ||||
$qb->select('file_id', 'json', 'sync_token')->from(self::TABLE_METADATA); | $qb->select('file_id', 'json', 'sync_token')->from(self::TABLE_METADATA); | ||||
$qb->where( | |||||
$qb->expr()->in('file_id', $qb->createNamedParameter($fileIds, IQueryBuilder::PARAM_INT_ARRAY)) | |||||
); | |||||
$qb->where($qb->expr()->in('file_id', $qb->createNamedParameter($fileIds, IQueryBuilder::PARAM_INT_ARRAY))); | |||||
$list = []; | $list = []; | ||||
$result = $qb->executeQuery(); | $result = $qb->executeQuery(); |
* "mymeta": { | * "mymeta": { | ||||
* "value": "this is a test", | * "value": "this is a test", | ||||
* "type": "string", | * "type": "string", | ||||
* "etag": "abcd1234", | |||||
* "indexed": false, | * "indexed": false, | ||||
* "editPermission": 1 | * "editPermission": 1 | ||||
* }, | * }, | ||||
* "myapp-anothermeta": { | * "myapp-anothermeta": { | ||||
* "value": 42, | * "value": 42, | ||||
* "type": "int", | * "type": "int", | ||||
* "etag": "0987zyxw", | |||||
* "indexed": true, | * "indexed": true, | ||||
* "editPermission": 0 | * "editPermission": 0 | ||||
* } | * } | ||||
*/ | */ | ||||
public function isIndex(string $key): bool; | public function isIndex(string $key): bool; | ||||
/** | |||||
* returns file etag stored during the last update of the metadata key | |||||
* | |||||
* @param string $key metadata key | |||||
* @return string | |||||
* @since 29.0.0 | |||||
*/ | |||||
public function getEtag(string $key): string; | |||||
/** | |||||
* set file etag | |||||
* | |||||
* @param string $key metadata key | |||||
* @since 29.0.0 | |||||
*/ | |||||
public function setEtag(string $key, string $etag): void; | |||||
/** | /** | ||||
* set remote edit permission | * set remote edit permission | ||||
* (Webdav PROPPATCH) | * (Webdav PROPPATCH) |
*/ | */ | ||||
public function getValueAny(): mixed; | public function getValueAny(): mixed; | ||||
/** | |||||
* get stored etag value | |||||
* | |||||
* @return string stored etag | |||||
* @since 29.0.0 | |||||
*/ | |||||
public function getEtag(): string; | |||||
/** | |||||
* set etag value | |||||
* | |||||
* @param string $etag etag value | |||||
* | |||||
* @return self | |||||
* @since 29.0.0 | |||||
*/ | |||||
public function setEtag(string $etag): self; | |||||
/** | /** | ||||
* @param bool $indexed TRUE to set the stored value as an indexed value | * @param bool $indexed TRUE to set the stored value as an indexed value | ||||
* | * |