-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
chore(files_versions): Use new metadata API for versions #44175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ | |
|
|
||
| use OCA\Files_Versions\Versions\IDeletableVersionBackend; | ||
| use OCA\Files_Versions\Versions\IMetadataVersion; | ||
| use OCA\Files_Versions\Versions\IMetadataVersionBackend; | ||
| use OCA\Files_Versions\Versions\INameableVersion; | ||
| use OCA\Files_Versions\Versions\INameableVersionBackend; | ||
| use OCA\Files_Versions\Versions\IVersion; | ||
|
|
@@ -38,15 +39,10 @@ | |
| use Sabre\DAV\IFile; | ||
|
|
||
| class VersionFile implements IFile { | ||
| /** @var IVersion */ | ||
| private $version; | ||
|
|
||
| /** @var IVersionManager */ | ||
| private $versionManager; | ||
|
|
||
| public function __construct(IVersion $version, IVersionManager $versionManager) { | ||
| $this->version = $version; | ||
| $this->versionManager = $versionManager; | ||
| public function __construct( | ||
| private IVersion $version, | ||
| private IVersionManager $versionManager | ||
| ) { | ||
| } | ||
|
|
||
| public function put($data) { | ||
|
|
@@ -93,17 +89,14 @@ public function setName($name) { | |
| throw new Forbidden(); | ||
| } | ||
|
|
||
| public function getLabel(): ?string { | ||
| if ($this->version instanceof INameableVersion && $this->version->getSourceFile()->getSize() > 0) { | ||
| return $this->version->getLabel(); | ||
| } else { | ||
| return null; | ||
| } | ||
| } | ||
| public function setMetadataValue(string $key, string $value): bool { | ||
| $backend = $this->version->getBackend(); | ||
|
|
||
| public function setLabel($label): bool { | ||
| if ($this->versionManager instanceof INameableVersionBackend) { | ||
| $this->versionManager->setVersionLabel($this->version, $label); | ||
| if ($backend instanceof IMetadataVersionBackend) { | ||
| $backend->setMetadataValue($this->version->getSourceFile(), $this->version->getRevisionId(), $key, $value); | ||
Check noticeCode scanning / Psalm PossiblyInvalidArgument
Argument 2 of OCA\Files_Versions\Versions\IMetadataVersionBackend::setMetadataValue expects int, but possibly different type int|string provided
|
||
| return true; | ||
| } elseif ($key === 'label' && $backend instanceof INameableVersionBackend) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure compatibility with backends that are not migrated yet. |
||
| $backend->setVersionLabel($this->version, $value); | ||
Check noticeCode scanning / Psalm DeprecatedMethod
The method OCA\Files_Versions\Versions\INameableVersionBackend::setVersionLabel has been marked as deprecated
|
||
| return true; | ||
| } else { | ||
| return false; | ||
|
|
@@ -113,6 +106,8 @@ public function setLabel($label): bool { | |
| public function getMetadataValue(string $key): ?string { | ||
| if ($this->version instanceof IMetadataVersion) { | ||
| return $this->version->getMetadataValue($key); | ||
| } elseif ($key === 'label' && $this->version instanceof INameableVersion) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure compatibility with backends that are not migrated yet. |
||
| return $this->version->getLabel(); | ||
Check noticeCode scanning / Psalm DeprecatedMethod
The method OCA\Files_Versions\Versions\INameableVersion::getLabel has been marked as deprecated
|
||
| } | ||
| return null; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,18 +35,10 @@ interface IMetadataVersionBackend { | |
| * Sets a key value pair in the metadata column corresponding to the node's version. | ||
| * | ||
| * @param Node $node the node that triggered the Metadata event listener, aka, the file version | ||
| * @param int $revision the key for the json value of the metadata column | ||
| * @param string $key the key for the json value of the metadata column | ||
| * @param string $value the value that corresponds to the key in the metadata column | ||
| * @since 29.0.0 | ||
| */ | ||
| public function setMetadataValue(Node $node, string $key, string $value): void; | ||
|
|
||
| /** | ||
| * Retrieves a corresponding value from the metadata column using the key. | ||
| * | ||
| * @param Node $node the node that triggered the Metadata event listener, aka, the file version | ||
| * @param string $key the key for the json value of the metadata column | ||
| * @since 29.0.0 | ||
| */ | ||
| public function getMetadataValue(Node $node, string $key): ?string; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The metadata can already be retrieved from the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed 👍 |
||
| public function setMetadataValue(Node $node, int $revision, string $key, string $value): void; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this change! Ok with me. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,61 +26,21 @@ | |
| namespace OCA\Files_Versions\Versions; | ||
|
|
||
| use OCP\Files\FileInfo; | ||
| use OCP\Files\Node; | ||
| use OCP\IUser; | ||
|
|
||
| class Version implements IVersion, INameableVersion, IMetadataVersion { | ||
| /** @var int */ | ||
| private $timestamp; | ||
|
|
||
| /** @var int|string */ | ||
| private $revisionId; | ||
|
|
||
| /** @var string */ | ||
| private $name; | ||
|
|
||
| private string $label; | ||
|
|
||
| /** @var int|float */ | ||
| private $size; | ||
|
|
||
| /** @var string */ | ||
| private $mimetype; | ||
|
|
||
| /** @var string */ | ||
| private $path; | ||
|
|
||
| /** @var FileInfo */ | ||
| private $sourceFileInfo; | ||
|
|
||
| /** @var IVersionBackend */ | ||
| private $backend; | ||
|
|
||
| /** @var IUser */ | ||
| private $user; | ||
|
|
||
| class Version implements IVersion, IMetadataVersion { | ||
| public function __construct( | ||
| int $timestamp, | ||
| $revisionId, | ||
| string $name, | ||
| int|float $size, | ||
| string $mimetype, | ||
| string $path, | ||
| FileInfo $sourceFileInfo, | ||
| IVersionBackend $backend, | ||
| IUser $user, | ||
| string $label = '' | ||
| private int $timestamp, | ||
| private int|string $revisionId, | ||
| private string $name, | ||
| private int|float $size, | ||
| private string $mimetype, | ||
| private string $path, | ||
| private FileInfo $sourceFileInfo, | ||
| private IVersionBackend $backend, | ||
| private IUser $user, | ||
| private array $metadata = [], | ||
| ) { | ||
| $this->timestamp = $timestamp; | ||
| $this->revisionId = $revisionId; | ||
| $this->name = $name; | ||
| $this->label = $label; | ||
| $this->size = $size; | ||
| $this->mimetype = $mimetype; | ||
| $this->path = $path; | ||
| $this->sourceFileInfo = $sourceFileInfo; | ||
| $this->backend = $backend; | ||
| $this->user = $user; | ||
| } | ||
|
|
||
| public function getBackend(): IVersionBackend { | ||
|
|
@@ -107,10 +67,6 @@ public function getSourceFileName(): string { | |
| return $this->name; | ||
| } | ||
|
|
||
| public function getLabel(): string { | ||
| return $this->label; | ||
| } | ||
|
|
||
| public function getMimeType(): string { | ||
| return $this->mimetype; | ||
| } | ||
|
|
@@ -124,9 +80,6 @@ public function getUser(): IUser { | |
| } | ||
|
|
||
| public function getMetadataValue(string $key): ?string { | ||
| if ($this->backend instanceof IMetadataVersionBackend && $this->sourceFileInfo instanceof Node) { | ||
| return $this->backend->getMetadataValue($this->sourceFileInfo, "author"); | ||
| } | ||
| return null; | ||
|
Comment on lines
-127
to
-130
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The constructor now receives the metadata, so we can simplify the logic here. |
||
| return $this->metadata[$key] ?? null; | ||
| } | ||
| } | ||
Check notice
Code scanning / Psalm
ArgumentTypeCoercion