Skip to content

Conversation

@artonge
Copy link
Contributor

@artonge artonge commented Mar 13, 2024

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

@artonge artonge self-assigned this Mar 13, 2024
if ($backend instanceof IMetadataVersionBackend) {
$backend->setMetadataValue($this->version, $key, $value);
return true;
} elseif ($key === 'label' && $backend instanceof INameableVersionBackend) {
Copy link
Contributor Author

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;
Copy link
Contributor Author

@artonge artonge Mar 13, 2024

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
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
Contributor Author

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 emoral435 March 13, 2024 12:42
@artonge artonge added 2. developing Work in progress feature: versions technical debt php Pull requests that update Php code labels Mar 13, 2024
@artonge artonge added this to the Nextcloud 29 milestone Mar 13, 2024
@artonge artonge force-pushed the artonge/chore/use_new_version_metadata_API branch from d375386 to 28ee8af Compare March 13, 2024 12:44
@artonge artonge marked this pull request as ready for review March 13, 2024 12:44
@artonge artonge force-pushed the artonge/chore/use_new_version_metadata_API branch from 28ee8af to cf75f46 Compare March 13, 2024 12:49
artonge added a commit to nextcloud/groupfolders that referenced this pull request Mar 13, 2024
@artonge artonge force-pushed the artonge/chore/use_new_version_metadata_API branch 2 times, most recently from 8aeb048 to 0fad147 Compare March 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
Contributor Author

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
Contributor Author

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
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
@artonge artonge force-pushed the artonge/chore/use_new_version_metadata_API branch from 0fad147 to 9361a30 Compare March 13, 2024 14:27
artonge added a commit to nextcloud/groupfolders that referenced this pull request Mar 13, 2024
Copy link
Contributor

@emoral435 emoral435 left a comment

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
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
Contributor

Choose a reason for hiding this comment

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

Agreed 👍

@artonge artonge requested review from come-nc and icewind1991 March 13, 2024 15:29
@artonge
Copy link
Contributor Author

artonge commented Mar 13, 2024

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. :)

@artonge artonge added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Mar 13, 2024
@skjnldsv skjnldsv merged commit 5764f03 into master Mar 14, 2024
@skjnldsv skjnldsv deleted the artonge/chore/use_new_version_metadata_API branch March 14, 2024 07:23
@Altahrim Altahrim mentioned this pull request Mar 14, 2024
artonge added a commit to nextcloud/groupfolders that referenced this pull request Mar 18, 2024
artonge added a commit to nextcloud/groupfolders that referenced this pull request Mar 18, 2024
artonge added a commit to nextcloud/groupfolders that referenced this pull request Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews feature: versions php Pull requests that update Php code technical debt

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants