API / Minn\Content / Comments

Comments final readonly class

Minn\Content\Comments · public/minn/src/Minn/Content/Comments.php · 245 lines

Reads and writes over the comments table.

Constants and properties

privateUPDATABLE = array ( 0 => 'comment_post_ID', 1 => 'comment_author', 2 => 'comment_author_email', 3 => 'comment_author_url', 4 => 'comment_author_IP', 5 => 'comment_date', 6 => 'comment_date_gmt', 7 => 'comment_content', 8 => 'comment_karma', 9 => 'comment_approved', 10 => 'comment_agent', 11 => 'comment_type', 12 => 'comment_parent', 13 => 'user_id', )
privateFIELD_LENGTHS = array ( 'comment_author' => 245, 'comment_author_email' => 100, 'comment_author_url' => 200, 'comment_content' => 65525, )

The comment form fields whose length the table limits, with the length a stock table gives each.

privatereadonly Minn\Db $db

Promoted from the constructor.

Public

new__construct(Minn\Db $db)#
methodfind(int $id): ?Minn\Content\CommentRecord#

The comment with this id, or null.

methodmeta(int $id, string $key): ?string#

One meta value of a comment, or null when it has none.

methodaddMeta(int $id, string $key, string $value): void#

Adds a meta row; a second row with the same key is allowed, as the reference allows it.

methodduplicate(int $postId, string $author, string $email, string $content, int $userId): bool#

The same words on the same post from the same person, in any status but trash or spam.

methodduplicateId(int $postId, string $author, string $email, string $content, int $userId): ?int#

The id of a comment this one would repeat (same post, same author, same words, not spam or trash), or null.

methodlastCommentTime(int $userId, string $address, string $email, string $sinceGmt): ?int#

When the commenter last commented since the GMT time given, as a Unix time: matched by user id when signed in, else by address, or by email either way. Null when they have not.

methodpendingCounts(array $postIds): array#

Held comments per post, for the ids given (a post without any reads 0).

methodpreviouslyApproved(string $author, string $email): bool#

True when this name and email already have an approved comment.

methodinsert(array $columns): int#

Inserts a row from column => value pairs and returns the new id.

$columnsarray<string, mixed>
methodupdate(int $id, array $columns): void#

Sets the given columns on one comment.

$columnsarray<string, mixed>
methodfieldLengths(): array#

How long each comment form field may be, read from the table as it is: a character column allows its declared length, a text column ten bytes fewer than it holds. A column the schema does not describe keeps the stock table's length.

@return array<string, int>
methodidsOf(int $postId): array#

The ids of every comment on a post, whatever its status, oldest first. @return list<int>

@return list<int>
methodstatusesOf(int $postId): array#

Every comment on a post as id => status, which the trash keeps to give back. @return array<int, string>

@return array<int, string>
methodsetStatusOf(array $ids, string $status): void#

Sets one status on the given comments. @param list<int> $ids

$idslist<int>
methodorphanReplies(int $id, int $parent): void#

A deleted comment's replies move up to its parent.

methoddelete(int $id): void#

Removes the comment and its meta; the post's count is the caller's to recount.

methodrecount(int $postId): void#

Recomputes a post's stored comment_count (approved comments only).

staticstatusOf(string $approved): string#

DB approval token to the wp/v2 status string.

statictokensFor(string $status): ?array#

wp/v2 status parameter to DB token(s); null for an unknown status.

@return list<string>|null
staticchangedColumns(array $data, array $current): array#

The columns an update really changes, compared as strings against the stored row; the approval shorthands hold/approve become the stored 0/1.

$dataarray<string, mixed>
$currentarray<string, mixed>
@return array<string, mixed>