File_Content_Service implements Registerable, Standard_Service

Injects parsed attachment content into DVE indexing and manages cache storage.

Tags
author

Barn2 Plugins [email protected]

license

GPL-3.0

copyright

Barn2 Media Ltd

Interfaces, Classes and Traits

Registerable
Standard_Service

Table of Contents

ATTACHED_FILE_META  = '_wp_attached_file'
File attachment path metadata key.
ATTACHMENT_ID_META  = '_dlp_attached_file_id'
Metadata key storing attached file ID.
ATTRIBUTE_KEY  = 'file_content'
Search index attribute key.
ATTRIBUTE_WEIGHT  = 70
Relevance weight for file content attribute.
LINK_TYPE_META  = '_dlp_document_link_type'
Metadata key storing document link type.
PLUGIN_PREFIX  = 'dlp'
Plugin prefix used by DVE.
$recovering  : bool
Bypass parser upgrades during metadata-only recovery.
$active_parse_context  : array<string|int, mixed>|null
Metadata retained while a parser is active for fatal recovery diagnostics.
$failures  : array<int, string>
Failures encountered in this batch.
$table  : File_Content_Table
Table helper.
$table_available  : bool|null
Cached table existence check.
__construct()  : mixed
Constructor.
add_attribute_weight()  : array<string|int, mixed>
Add relevance weight for file content attribute.
add_file_content_attribute()  : array<string|int, mixed>
Add file content to searchable attributes for document posts.
adjust_batch_size_for_file_content()  : int
Reduce DVE batch size for safer document parsing runs.
classify_fatal_indexing_error()  : bool
Approve quarantine only while the active DLP PDF is being parsed.
cleanup_on_delete()  : mixed
Remove cache row when document post is deleted.
clear_failed_rows()  : mixed
Clear successful PDF caches in scope when a full reindex is requested.
on_attachment_change()  : mixed
Queue affected documents when an attachment changes.
on_attachment_delete()  : mixed
Cleanup cache and queue affected documents when an attachment is deleted.
on_attachment_meta_change()  : mixed
Queue affected documents when attachment file path metadata changes.
prepare_failed_item_retry()  : void
Clear only failed extraction caches before DVE retries a document.
record_recovered_fatal()  : mixed
Persist the parser-side diagnostic after DVE quarantines a fatal document.
recover_checkpoint()  : bool
Validate a failed scheduled parse against the current document before recovery.
register()  : mixed
{@inheritdoc}
retain_failure()  : void
The batch runner has now finished content, filters and sorting.
retry_failed_items_label()  : string
Customize the engine's Site Health action for documents.
retry_failed_items_notice_title()  : string
Use document wording in the retry progress notice.
retry_failed_items_progress_text()  : string
Describe per-document retry progress.
apply_content_limits()  : string
Apply optional extracted-content byte limit.
delete_cache_by_attachment_id()  : mixed
Delete cache rows by attachment ID.
delete_cache_by_post_id()  : mixed
Delete cache rows by document post ID.
encounter_failure()  : void
Remember failures without interrupting the remaining indexes.
generic_cache_version()  : string
Ignore backend suffixes written by earlier PDF caches.
get_cache_row()  : array<string|int, mixed>|null
Fetch cache row by document post ID.
get_document_ids_for_attachment()  : array<string|int, int>
Get document IDs that reference a given attachment.
has_fast_sticky_error()  : bool
Determine if sticky error can be respected without recomputing file hash.
has_sticky_error()  : bool
Determine if we should skip retry because error is sticky.
is_attachment_modified_since_parse()  : bool
Check if attachment post has been modified since the cache row was parsed.
is_cache_hit()  : bool
Determine if the cache row is reusable.
is_fast_cache_hit()  : bool
Determine if cache can be reused without recomputing file hash.
is_fast_cache_validation_enabled()  : bool
Determine whether fast cache validation is enabled.
is_file_skipped_by_size()  : bool
Apply optional file size-based parse skip.
is_table_available()  : bool
Check if cache table is available.
log_parse_error()  : mixed
Log parser failures.
maybe_refresh_cache_metadata()  : mixed
Refresh cached metadata when a cache hit still points to old attachment details.
normalize_content()  : string
Normalize content to valid UTF-8 text.
queue_documents_for_reindex()  : mixed
Queue documents for DVE reindex.
resolve_mime_type()  : string
Resolve parse MIME type.
store_cache_error()  : mixed
Store parser failure row.
store_cache_success()  : mixed
Store successful parse row.
upsert_row()  : mixed
Insert or replace a row by post ID.

Constants

ATTACHED_FILE_META

File attachment path metadata key.

public mixed ATTACHED_FILE_META = '_wp_attached_file'
Tags

ATTACHMENT_ID_META

Metadata key storing attached file ID.

public mixed ATTACHMENT_ID_META = '_dlp_attached_file_id'
Tags

ATTRIBUTE_KEY

Search index attribute key.

public mixed ATTRIBUTE_KEY = 'file_content'
Tags

ATTRIBUTE_WEIGHT

Relevance weight for file content attribute.

public mixed ATTRIBUTE_WEIGHT = 70
Tags

Metadata key storing document link type.

public mixed LINK_TYPE_META = '_dlp_document_link_type'
Tags

Properties

$recovering

Bypass parser upgrades during metadata-only recovery.

public static bool $recovering = false
Tags

$active_parse_context

Metadata retained while a parser is active for fatal recovery diagnostics.

private array<string|int, mixed>|null $active_parse_context = null
Tags

$failures

Failures encountered in this batch.

private array<int, string> $failures = []
Tags

$table_available

Cached table existence check.

private bool|null $table_available = null
Tags

Methods

add_attribute_weight()

Add relevance weight for file content attribute.

public add_attribute_weight(array<string|int, mixed> $weights[, string $plugin_prefix = '' ]) : array<string|int, mixed>
Parameters
$weights : array<string|int, mixed>

Attribute weights.

$plugin_prefix : string = ''

Plugin prefix.

Tags
Return values
array<string|int, mixed> —

add_file_content_attribute()

Add file content to searchable attributes for document posts.

public add_file_content_attribute(array<string|int, mixed> $attributes, WP_Post $post) : array<string|int, mixed>
Parameters
$attributes : array<string|int, mixed>

Existing searchable attributes.

$post : WP_Post

Current post.

Tags
throws
RuntimeException

When checkpoint or cache persistence fails.

Return values
array<string|int, mixed> —

adjust_batch_size_for_file_content()

Reduce DVE batch size for safer document parsing runs.

public adjust_batch_size_for_file_content(int $batch_size) : int
Parameters
$batch_size : int

Incoming batch size.

Tags
Return values
int —

classify_fatal_indexing_error()

Approve quarantine only while the active DLP PDF is being parsed.

public classify_fatal_indexing_error(bool $quarantine, array<string|int, mixed> $_error, int $post_id, string $plugin_prefix) : bool
Parameters
$quarantine : bool

Existing decision.

$_error : array<string|int, mixed>

PHP fatal details.

$post_id : int

Active document ID.

$plugin_prefix : string

DVE plugin prefix.

Tags
Return values
bool —

cleanup_on_delete()

Remove cache row when document post is deleted.

public cleanup_on_delete(int $post_id) : mixed
Parameters
$post_id : int

Post ID.

Tags
Return values
mixed —

clear_failed_rows()

Clear successful PDF caches in scope when a full reindex is requested.

public clear_failed_rows([array<string|int, mixed> $args = [] ]) : mixed

Failed PDFs retain their cache evidence and skipped status. Other formats retain the existing full-reindex cache-clearing behavior.

Parameters
$args : array<string|int, mixed> = []

Requested index scope.

Tags
Return values
mixed —

on_attachment_change()

Queue affected documents when an attachment changes.

public on_attachment_change(int $attachment_id) : mixed
Parameters
$attachment_id : int

Attachment ID.

Tags
Return values
mixed —

on_attachment_delete()

Cleanup cache and queue affected documents when an attachment is deleted.

public on_attachment_delete(int $attachment_id) : mixed
Parameters
$attachment_id : int

Attachment ID.

Tags
Return values
mixed —

on_attachment_meta_change()

Queue affected documents when attachment file path metadata changes.

public on_attachment_meta_change(int $meta_id, int $object_id, string $meta_key, mixed $meta_value) : mixed
Parameters
$meta_id : int

Meta ID.

$object_id : int

Object ID.

$meta_key : string

Meta key.

$meta_value : mixed

Meta value.

Tags
Return values
mixed —

prepare_failed_item_retry()

Clear only failed extraction caches before DVE retries a document.

public prepare_failed_item_retry(int $post_id, string $plugin_prefix) : void
Parameters
$post_id : int

Post ID.

$plugin_prefix : string

Engine consumer prefix.

Tags
throws
RuntimeException

When preparation fails, preserving DVE's failure diagnostic.

Return values
void —

record_recovered_fatal()

Persist the parser-side diagnostic after DVE quarantines a fatal document.

public record_recovered_fatal(int $post_id, string $diagnostic, array<string|int, mixed> $_error, string $plugin_prefix) : mixed
Parameters
$post_id : int

Quarantined document ID.

$diagnostic : string

Normalized fatal diagnostic.

$_error : array<string|int, mixed>

Original PHP fatal details.

$plugin_prefix : string

DVE plugin prefix.

Tags
Return values
mixed —

recover_checkpoint()

Validate a failed scheduled parse against the current document before recovery.

public recover_checkpoint(bool $recovered, array<string|int, mixed> $record, string $prefix) : bool
Parameters
$recovered : bool

Existing consumer result.

$record : array<string|int, mixed>

Persisted attempt.

$prefix : string

Engine prefix.

Tags
Return values
bool —

True only after persistence and metadata scheduling succeed.

retain_failure()

The batch runner has now finished content, filters and sorting.

public retain_failure(int $post_id) : void
Parameters
$post_id : int

Document ID.

Tags
Return values
void —

retry_failed_items_label()

Customize the engine's Site Health action for documents.

public retry_failed_items_label(string $label, string $plugin_prefix) : string
Parameters
$label : string

Default label.

$plugin_prefix : string

Engine consumer prefix.

Tags
Return values
string —

retry_failed_items_notice_title()

Use document wording in the retry progress notice.

public retry_failed_items_notice_title(string $title, string $plugin_prefix) : string
Parameters
$title : string

Default notice title.

$plugin_prefix : string

Plugin prefix.

Tags
Return values
string —

retry_failed_items_progress_text()

Describe per-document retry progress.

public retry_failed_items_progress_text(string $template, string $plugin_prefix) : string
Parameters
$template : string

Default progress text.

$plugin_prefix : string

Plugin prefix.

Tags
Return values
string —

apply_content_limits()

Apply optional extracted-content byte limit.

private apply_content_limits(string $content, int $post_id, int $attachment_id) : string
Parameters
$content : string

Extracted content.

$post_id : int

Document post ID.

$attachment_id : int

Attachment ID.

Tags
Return values
string —

delete_cache_by_attachment_id()

Delete cache rows by attachment ID.

private delete_cache_by_attachment_id(int $attachment_id) : mixed
Parameters
$attachment_id : int

Attachment ID.

Tags
Return values
mixed —

delete_cache_by_post_id()

Delete cache rows by document post ID.

private delete_cache_by_post_id(int $post_id) : mixed
Parameters
$post_id : int

Post ID.

Tags
Return values
mixed —

encounter_failure()

Remember failures without interrupting the remaining indexes.

private encounter_failure(array<string|int, mixed> $row) : void
Parameters
$row : array<string|int, mixed>

Cached failure.

Tags
Return values
void —

generic_cache_version()

Ignore backend suffixes written by earlier PDF caches.

private static generic_cache_version(array<string|int, mixed> $row) : string
Parameters
$row : array<string|int, mixed>

Cache row.

Tags
Return values
string —

get_cache_row()

Fetch cache row by document post ID.

private get_cache_row(int $post_id) : array<string|int, mixed>|null
Parameters
$post_id : int

Document post ID.

Tags
Return values
array<string|int, mixed>|null —

get_document_ids_for_attachment()

Get document IDs that reference a given attachment.

private get_document_ids_for_attachment(int $attachment_id) : array<string|int, int>
Parameters
$attachment_id : int

Attachment ID.

Tags
Return values
array<string|int, int> —

has_fast_sticky_error()

Determine if sticky error can be respected without recomputing file hash.

private has_fast_sticky_error(array<string|int, mixed>|null $row, int $post_id, int $attachment_id, string $mime_type, int $file_size, string $parser_version) : bool
Parameters
$row : array<string|int, mixed>|null

Cache row.

$post_id : int

Post ID.

$attachment_id : int

Attachment ID.

$mime_type : string

MIME type.

$file_size : int

File size.

$parser_version : string

Parser version.

Tags
Return values
bool —

has_sticky_error()

Determine if we should skip retry because error is sticky.

private has_sticky_error(array<string|int, mixed>|null $row, string $file_hash, string $parser_version) : bool
Parameters
$row : array<string|int, mixed>|null

Cache row.

$file_hash : string

File hash.

$parser_version : string

Parser version.

Tags
Return values
bool —

is_attachment_modified_since_parse()

Check if attachment post has been modified since the cache row was parsed.

private is_attachment_modified_since_parse(int $attachment_id, array<string|int, mixed> $row) : bool
Parameters
$attachment_id : int

Attachment ID.

$row : array<string|int, mixed>

Cache row.

Tags
Return values
bool —

is_cache_hit()

Determine if the cache row is reusable.

private is_cache_hit(array<string|int, mixed>|null $row, string $file_hash, string $parser_version) : bool
Parameters
$row : array<string|int, mixed>|null

Cache row.

$file_hash : string

File hash.

$parser_version : string

Parser version.

Tags
Return values
bool —

is_fast_cache_hit()

Determine if cache can be reused without recomputing file hash.

private is_fast_cache_hit(array<string|int, mixed>|null $row, int $post_id, int $attachment_id, string $mime_type, int $file_size, string $parser_version) : bool
Parameters
$row : array<string|int, mixed>|null

Cache row.

$post_id : int

Post ID.

$attachment_id : int

Attachment ID.

$mime_type : string

MIME type.

$file_size : int

File size.

$parser_version : string

Parser version.

Tags
Return values
bool —

is_fast_cache_validation_enabled()

Determine whether fast cache validation is enabled.

private is_fast_cache_validation_enabled(int $post_id, int $attachment_id) : bool
Parameters
$post_id : int

Document post ID.

$attachment_id : int

Attachment ID.

Tags
Return values
bool —

is_file_skipped_by_size()

Apply optional file size-based parse skip.

private is_file_skipped_by_size(int $file_size, int $post_id, int $attachment_id) : bool
Parameters
$file_size : int

File size in bytes.

$post_id : int

Post ID.

$attachment_id : int

Attachment ID.

Tags
Return values
bool —

is_table_available()

Check if cache table is available.

private is_table_available() : bool
Tags
Return values
bool —

log_parse_error()

Log parser failures.

private log_parse_error(int $post_id, string $message) : mixed
Parameters
$post_id : int

Document post ID.

$message : string

Error message.

Tags
Return values
mixed —

maybe_refresh_cache_metadata()

Refresh cached metadata when a cache hit still points to old attachment details.

private maybe_refresh_cache_metadata(array<string|int, mixed> $row, int $post_id, int $attachment_id, string $content, string $file_hash, string $parser_version, string $mime_type, int $file_size) : mixed
Parameters
$row : array<string|int, mixed>

Cache row.

$post_id : int

Document post ID.

$attachment_id : int

Attachment ID.

$content : string

Cached content.

$file_hash : string

File hash.

$parser_version : string

Parser version.

$mime_type : string

MIME type.

$file_size : int

File size.

Tags
Return values
mixed —

normalize_content()

Normalize content to valid UTF-8 text.

private normalize_content(string $content) : string
Parameters
$content : string

Raw content.

Tags
Return values
string —

queue_documents_for_reindex()

Queue documents for DVE reindex.

private queue_documents_for_reindex(array<string|int, int> $document_ids) : mixed
Parameters
$document_ids : array<string|int, int>

Document IDs.

Tags
Return values
mixed —

resolve_mime_type()

Resolve parse MIME type.

private resolve_mime_type(int $attachment_id, string $file_path) : string
Parameters
$attachment_id : int

Attachment ID.

$file_path : string

File path.

Tags
Return values
string —

store_cache_error()

Store parser failure row.

private store_cache_error(int $post_id, int $attachment_id, string $file_hash, string $parser_version, string $mime_type, int $file_size, string $error_message) : mixed
Parameters
$post_id : int

Document post ID.

$attachment_id : int

Attachment ID.

$file_hash : string

File hash.

$parser_version : string

Parser version.

$mime_type : string

MIME type.

$file_size : int

File size.

$error_message : string

Error message.

Tags
Return values
mixed —

store_cache_success()

Store successful parse row.

private store_cache_success(int $post_id, int $attachment_id, string $content, string $file_hash, string $parser_version, string $mime_type, int $file_size) : mixed
Parameters
$post_id : int

Document post ID.

$attachment_id : int

Attachment ID.

$content : string

Extracted content.

$file_hash : string

File hash.

$parser_version : string

Parser version.

$mime_type : string

MIME type.

$file_size : int

File size.

Tags
Return values
mixed —

upsert_row()

Insert or replace a row by post ID.

private upsert_row(array<string|int, mixed> $data) : mixed
Parameters
$data : array<string|int, mixed>

Row data.

Tags
throws
RuntimeException

When the cache write fails.

Return values
mixed —

Search results