Skip to content

fix(node): emit hooks on Node::copy() #52996

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

Merged
merged 2 commits into from
May 28, 2025
Merged

fix(node): emit hooks on Node::copy() #52996

merged 2 commits into from
May 28, 2025

Conversation

mejo-
Copy link
Member

@mejo- mejo- commented May 20, 2025

When calling Files\Node\Node::copy(), Files\View::copy() gets called, but Files\View::fakeRoot is empty so the hooks are not emitted if no path is given to Files\View::shouldEmitHooks().

This results in node-related events like NodeCopiedEvent not being fired when copying files via Files\Node\Node::copy().

Files\View::shouldEmitHooks() is given a path as parameter in almost all places except when called from the copy() function. This commit changes it and passes the copy target path.

Fixes: nextcloud/collectives#1756

Checklist

@mejo- mejo- self-assigned this May 20, 2025
@mejo- mejo- requested a review from a team as a code owner May 20, 2025 15:16
@mejo- mejo- added the bug label May 20, 2025
@mejo- mejo- requested review from skjnldsv and removed request for a team May 20, 2025 15:16
@github-project-automation github-project-automation bot moved this to 🧭 Planning evaluation (don't pick) in 📝 Office team May 20, 2025
@mejo- mejo- moved this from 🧭 Planning evaluation (don't pick) to 👀 In review in 📝 Office team May 20, 2025
@come-nc
Copy link
Contributor

come-nc commented May 20, 2025

@icewind1991
Hello, I debugged this with @mejo- .
We came to the conclusion that the shouldEmitHooks call was missing the path. Because most other calls give a path to it.

When copying through dav, fakeRoot is set to the files folder, and that matches the default root, and thanks to that the hook is emitted.
But when copying from somewhere else (collectives in this case) through the node API, fakeRoot is empty.

Do you thing this is the right fix? Do you think we should give the path of source, target, or both?

Copy link
Member

@skjnldsv skjnldsv left a comment

Choose a reason for hiding this comment

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

Seems logical

Copy link
Member

@icewind1991 icewind1991 left a comment

Choose a reason for hiding this comment

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

Makes sense

@mejo- mejo- force-pushed the fix/emit_hooks_on_copy branch from b6c76a3 to bf67d8f Compare May 26, 2025 16:30
@mejo-
Copy link
Member Author

mejo- commented May 26, 2025

/backport to stable31

@mejo-
Copy link
Member Author

mejo- commented May 26, 2025

/backport to stable30

@mejo- mejo- force-pushed the fix/emit_hooks_on_copy branch 2 times, most recently from e427f00 to 1dd0ec8 Compare May 27, 2025 08:39
Copy link
Contributor

@artonge artonge left a comment

Choose a reason for hiding this comment

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

Overall, maybe just look into what the handleMove method is doing, as it seems to be doing something very similar.

@mejo- mejo- force-pushed the fix/emit_hooks_on_copy branch from 1dd0ec8 to f77ae68 Compare May 27, 2025 09:23
@mejo- mejo- requested a review from artonge May 27, 2025 09:24
mejo- added 2 commits May 27, 2025 12:14
When calling `Files\Node\Node::copy()`, `Files\View::copy()` gets called,
but `Files\View::fakeRoot` is empty so the hooks are not emitted if no
path is given to `Files\View::shouldEmitHooks()`.

This results in node-related events like `NodeCopiedEvent` not being
fired when copying files via `Files\Node\Node::copy()`.

`Files\View::shouldEmitHooks()` is given a path as parameter in almost
all places except when called from the `copy()` function. This commit
changes it and passes the copy target path.

Fixes: nextcloud/collectives#1756

Signed-off-by: Jonas <[email protected]>
Running $peerFile->copy() causes a second BeforeNodeCopiedEvent now,
which we don't want to handle.

Signed-off-by: Jonas <[email protected]>
@mejo- mejo- force-pushed the fix/emit_hooks_on_copy branch from f77ae68 to e5b4ae4 Compare May 27, 2025 10:14
@mejo- mejo- merged commit f833e2d into master May 28, 2025
192 checks passed
@mejo- mejo- deleted the fix/emit_hooks_on_copy branch May 28, 2025 11:49
@github-project-automation github-project-automation bot moved this from 👀 In review to ☑️ Done in 📝 Office team May 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ☑️ Done
Development

Successfully merging this pull request may close these issues.

Attachments get lost when copying a page
5 participants