Skip to content

fix: set createdAt timestamp for local attachments#11966

Merged
kesselb merged 1 commit intomainfrom
bug/5901/set-created-at-on-insert
Mar 24, 2026
Merged

fix: set createdAt timestamp for local attachments#11966
kesselb merged 1 commit intomainfrom
bug/5901/set-created-at-on-insert

Conversation

@kesselb
Copy link
Copy Markdown
Contributor

@kesselb kesselb commented Oct 23, 2025

Local copy of #11943 with squashed commits.

  • Inject ITimeFactory into AttachmentService constructor
  • Set createdAt using timeFactory.getTime() when creating attachments
  • Update unit tests to mock ITimeFactory and expect createdAt value
  • Update integration tests to pass ITimeFactory dependency

@kesselb kesselb self-assigned this Oct 23, 2025
@kesselb kesselb marked this pull request as draft October 23, 2025 22:53
@kesselb kesselb force-pushed the bug/5901/set-created-at-on-insert branch from 5ac547c to 4f09d8c Compare November 7, 2025 11:13
@kesselb kesselb force-pushed the bug/5901/set-created-at-on-insert branch 2 times, most recently from 2f91323 to 24fd083 Compare March 20, 2026 12:26
@kesselb kesselb requested a review from Copilot March 20, 2026 12:26
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates local attachment creation to always set a createdAt timestamp via ITimeFactory, and aligns tests and wiring to the new dependency.

Changes:

  • Inject ITimeFactory into AttachmentService and set createdAt on new local attachments.
  • Update unit/integration tests to provide a time factory and assert createdAt.
  • Add a DB migration related to mail_attachments.created_at and bump app/package versions.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
lib/Service/Attachment/AttachmentService.php Injects ITimeFactory and sets createdAt during attachment creation
tests/Unit/Service/Attachment/AttachmentServiceTest.php Mocks ITimeFactory and asserts createdAt in expected attachments
tests/Integration/Service/OutboxServiceIntegrationTest.php Passes ITimeFactory to service construction in integration setup
tests/Integration/Service/DraftServiceIntegrationTest.php Passes ITimeFactory to service construction in integration setup
lib/Migration/Version5008Date20260320000001.php Adds migration adjusting mail_attachments.created_at default
package.json Updates package version to 5.8.0-alpha.1
appinfo/info.xml Updates app version to 5.8.0-alpha.1

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

/**
* @param Closure(): ISchemaWrapper $schemaClosure
*/
#[\Override]
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

#[\\Override] is a PHP 8.3+ built-in attribute; if this app supports PHP 8.1/8.2 (common for Nextcloud apps), loading this file will fatal with Attribute class \"Override\" not found. To keep compatibility, remove the attribute (or use a project-provided override attribute if the codebase has one) and rely on the method signature/interface contract.

Suggested change
#[\Override]

Copilot uses AI. Check for mistakes.
Comment thread package.json Outdated
{
"name": "nextcloud-mail",
"version": "5.7.0-rc.1",
"version": "5.8.0-alpha.1",
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

The PR description focuses on setting createdAt and updating tests/wiring, but this change also bumps the app/package version (and appinfo/info.xml does the same). Either update the PR description to explicitly call out the version bump (and why it’s needed for this change/migration), or avoid changing versions in this PR to keep the scope aligned.

Copilot uses AI. Check for mistakes.
Comment on lines +58 to +59
/** @var ITimeFactory|MockObject */
private $timeFactory;
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

This mock property is untyped, which weakens static analysis/autocomplete and can hide type mistakes. If the project’s PHP version allows it, prefer an intersection type on the property (e.g., private ITimeFactory&MockObject $timeFactory;) and drop the phpdoc, or at least add a concrete property type plus phpdoc for the mock interface.

Suggested change
/** @var ITimeFactory|MockObject */
private $timeFactory;
private ITimeFactory&MockObject $timeFactory;

Copilot uses AI. Check for mistakes.
@kesselb kesselb marked this pull request as ready for review March 20, 2026 12:50
@kesselb kesselb requested a review from DerDreschner March 20, 2026 12:50
@kesselb kesselb force-pushed the bug/5901/set-created-at-on-insert branch from ba1d2f9 to 3228e8d Compare March 23, 2026 13:03
- Inject ITimeFactory into AttachmentService constructor
- Set createdAt using timeFactory.getTime() when creating attachments
- Update unit tests to mock ITimeFactory and expect createdAt value
- Update integration tests to pass ITimeFactory dependency

Signed-off-by: dhairyasquad73 <dhairya.jangir.s73@kalvium.community>
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
@kesselb kesselb force-pushed the bug/5901/set-created-at-on-insert branch from 3228e8d to 29f84a6 Compare March 24, 2026 21:26
@kesselb kesselb merged commit 20311a5 into main Mar 24, 2026
41 of 42 checks passed
@kesselb kesselb deleted the bug/5901/set-created-at-on-insert branch March 24, 2026 21:42
@ChristophWurst
Copy link
Copy Markdown
Member

Backport or is it too risky?

@kesselb
Copy link
Copy Markdown
Contributor Author

kesselb commented Mar 25, 2026

Not really necessary, I'd say.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants