Skip to content

chore(files_versions): Use new metadata API for versions - #44175

Merged
skjnldsv merged 1 commit into
masterfrom
artonge/chore/use_new_version_metadata_API
Mar 14, 2024
Merged

chore(files_versions): Use new metadata API for versions#44175
skjnldsv merged 1 commit into
masterfrom
artonge/chore/use_new_version_metadata_API

Conversation

@artonge

@artongeartonge commented Mar 13, 2024

Copy link
Copy Markdown
Collaborator

Use the new version metadata API for handling the label logic.

@emoral435 I also tweaked the API a bit, I left some comments to give some reasoning behind the changes.

As of: #44049

@artongeartonge self-assigned this Mar 13, 2024
Comment threadapps/files_versions/lib/Sabre/Plugin.php Fixed
Comment threadapps/files_versions/lib/Versions/LegacyVersionsBackend.php Fixed
if ($backend instanceof IMetadataVersionBackend) {
$backend->setMetadataValue($this->version, $key, $value);
return true;
} elseif ($key === 'label' && $backend instanceof INameableVersionBackend) {

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure compatibility with backends that are not migrated yet.

* @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;

@artongeartongeMar 13, 2024

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The metadata can already be retrieved from the IMetadataVersion. So this method seem unnecessary. @emoral435 does it make sense to remove it? Can still be added later if needed, but I don't see a reason for it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed 👍

Comment on lines -127 to -130
if ($this->backend instanceof IMetadataVersionBackend && $this->sourceFileInfo instanceof Node) {
return $this->backend->getMetadataValue($this->sourceFileInfo, "author");
}
return null;

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

The 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.

@artonge
artonge requested review from emoral435 and removed request for emoral435March 13, 2024 12:42
@artongeartonge added 2. developing Work in progress feature: versions technical debt 🧱 🤔🚀 php Pull requests that update Php code labels Mar 13, 2024
@artongeartonge added this to the Nextcloud 29 milestone Mar 13, 2024
@artonge
artongeforce-pushed the artonge/chore/use_new_version_metadata_API branch from d375386 to 28ee8afCompareMarch 13, 2024 12:44
@artonge
artonge marked this pull request as ready for review March 13, 2024 12:44
@artonge
artongeforce-pushed the artonge/chore/use_new_version_metadata_API branch from 28ee8af to cf75f46CompareMarch 13, 2024 12:49
artonge added a commit to nextcloud/groupfolders that referenced this pull request Mar 13, 2024
As of: nextcloud/server#44049
Server equivalent: nextcloud/server#44175
Signed-off-by: Louis Chemineau <louis@chmn.me>
@artonge
artongeforce-pushed the artonge/chore/use_new_version_metadata_API branch 2 times, most recently from 8aeb048 to 0fad147CompareMarch 13, 2024 13:54
public function getMetadataValue(string $key): ?string {
if ($this->version instanceof IMetadataVersion) {
return $this->version->getMetadataValue($key);
} elseif ($key === 'label' && $this->version instanceof INameableVersion) {

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure compatibility with backends that are not migrated yet.

* @since 29.0.0
*/
public function getMetadataValue(Node $node, string $key): ?string;
public function setMetadataValue(Node $node, int $revision, string $key, string $value): void;

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a $revision param to be able to target a specific version. @emoral435, ok with you?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this change! Ok with me.

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 notice

Code scanning / Psalm

ArgumentTypeCoercion

Argument 1 of OCA\Files_Versions\Versions\IMetadataVersionBackend::setMetadataValue expects OCP\Files\Node, but parent type OCP\Files\FileInfo provided
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 notice

Code scanning / Psalm

PossiblyInvalidArgument

Argument 2 of OCA\Files_Versions\Versions\IMetadataVersionBackend::setMetadataValue expects int, but possibly different type int|string provided
$backend->setMetadataValue($this->version->getSourceFile(), $this->version->getRevisionId(), $key, $value);
return true;
} elseif ($key === 'label' && $backend instanceof INameableVersionBackend) {
$backend->setVersionLabel($this->version, $value);

Check notice

Code scanning / Psalm

DeprecatedMethod

The method OCA\Files_Versions\Versions\INameableVersionBackend::setVersionLabel has been marked as deprecated
if ($this->version instanceof IMetadataVersion) {
return $this->version->getMetadataValue($key);
} elseif ($key === 'label' && $this->version instanceof INameableVersion) {
return $this->version->getLabel();

Check notice

Code scanning / Psalm

DeprecatedMethod

The method OCA\Files_Versions\Versions\INameableVersion::getLabel has been marked as deprecated
Signed-off-by: Louis Chemineau <louis@chmn.me>
@artonge
artongeforce-pushed the artonge/chore/use_new_version_metadata_API branch from 0fad147 to 9361a30CompareMarch 13, 2024 14:27
artonge added a commit to nextcloud/groupfolders that referenced this pull request Mar 13, 2024
As of: nextcloud/server#44049
Server equivalent: nextcloud/server#44175
Signed-off-by: Louis Chemineau <louis@chmn.me>

@emoral435emoral435 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the new changes. The capability to store whatever metadata we want and get whichever version's metadata seems really flexible :) I do not know if this PR is ready as I have not been marked down as a reviewer, though I approve the current changes. Ping me if you need me to approve!

* @since 29.0.0
*/
public function getMetadataValue(Node $node, string $key): ?string;
public function setMetadataValue(Node $node, int $revision, string $key, string $value): void;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this change! Ok with me.

* @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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed 👍

@artonge

Copy link
Copy Markdown
CollaboratorAuthor

I do not know if this PR is ready as I have not been marked down as a reviewer

I was waiting for CI to be green. Now it's ok, and your approval would be appreciated. :)

@artongeartonge added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Mar 13, 2024
@skjnldsv
skjnldsv merged commit 5764f03 into masterMar 14, 2024
@skjnldsv
skjnldsv deleted the artonge/chore/use_new_version_metadata_API branch March 14, 2024 07:23
@AltahrimAltahrim mentioned this pull request Mar 14, 2024
artonge added a commit to nextcloud/groupfolders that referenced this pull request Mar 18, 2024
As of: nextcloud/server#44049
Server equivalent: nextcloud/server#44175
Signed-off-by: Louis Chemineau <louis@chmn.me>
artonge added a commit to nextcloud/groupfolders that referenced this pull request Mar 18, 2024
As of: nextcloud/server#44049
Server equivalent: nextcloud/server#44175
Signed-off-by: Louis Chemineau <louis@chmn.me>
artonge added a commit to nextcloud/groupfolders that referenced this pull request Mar 18, 2024
As of: nextcloud/server#44049
Server equivalent: nextcloud/server#44175
Signed-off-by: Louis Chemineau <louis@chmn.me>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to reviewWaiting for reviewsfeature: versionsphpPull requests that update Php codetechnical debt🧱 🤔🚀

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@artonge@skjnldsv@github-advanced-security@emoral435