InitialConfirmationTrait
Confirmation of a new record by its author through an e-mail link.
Shared by adverts (Bazaar, module 5), company profiles (Comcat, module 6) and discussion
posts (Discussion, module 8). Called from beforeSave() on insert only (front, external
Api and admin).
Whether confirmation is required depends on the author kind
(EmailConfirmationSetting::isRequiredFor()): a record with an owner ($ownerUserId:
insertUserId for adverts, userId for posts; on the external path the server takes it
from the JWT and the client value is dropped as #[ExternalReadonly]) has a logged-in
author, a record without one has a guest.
- not required:
confirmedAtis set to now (unless already filled) and no key is issued; only the insert notice is sent after commit, - required: a key is issued (the digest is stored, the plain key travels in
$metato the e-mail),confirmedAtstays null and the record stays hidden until the author clicks the link, - required, but an admin ticked "confirmed" on creation (
confirmedAtfilled): nothing is issued, - required, but the record has no e-mail (front forms require it; an empty one can only come from the external Api or an import): there is nowhere to send the link, so the record is confirmed at once, otherwise it would stay hidden forever.
IMPORTANT: visibility depends only on confirmedAt IS NOT NULL (for adverts also inside the
generated active column), so a record that needs no confirmation must get confirmedAt
immediately; otherwise it never becomes visible.
The decision is stored in $meta[self::META_CONFIRMATION_REQUIRED] so that the e-mail sent
after commit (completedSave) follows the state at insert time, not a setting read again
later.
Tags
Table of Contents
Constants
- META_CONFIRMATION_REQUIRED : string = '__confirmationRequired'
- `$meta` key: bool, whether author confirmation was required at insert.
Methods
- applyInitialConfirmation() : bool
- initialConfirmationEmailKind() : string|null
- Returns the e-mail kind to send the author after insert commit: `'activation'` (with the confirmation link), `'insert'` (insert notice only) or `null` for nothing (confirmation was required but no key was issued: an admin confirmed or the e-mail is missing).
Constants
META_CONFIRMATION_REQUIRED
`$meta` key: bool, whether author confirmation was required at insert.
private
string
META_CONFIRMATION_REQUIRED
= '__confirmationRequired'
Methods
applyInitialConfirmation()
private
applyInitialConfirmation(Advert|Advert|Message<mixed, mixed> $entity, int $module, int|null $ownerUserId, array<string, mixed> &$meta) : bool
Parameters
- $entity : Advert|Advert|Message<mixed, mixed>
- $module : int
-
5 = Bazaar, 6 = Comcat, 8 = Discussion
- $ownerUserId : int|null
- $meta : array<string, mixed>
Return values
bool —true when a key was issued and the record awaits author confirmation
initialConfirmationEmailKind()
Returns the e-mail kind to send the author after insert commit: `'activation'` (with the confirmation link), `'insert'` (insert notice only) or `null` for nothing (confirmation was required but no key was issued: an admin confirmed or the e-mail is missing).
private
initialConfirmationEmailKind(array<string, mixed> $meta) : string|null
Parameters
- $meta : array<string, mixed>