webberzone.dev Recent

Import_Processor class Pro only

Import_Processor

Import Processor class.

Namespace: WebberZone\Knowledge_Base\Pro\GitHub
Since: 3.1.0
Source: includes/github/class-import-processor.php line 23

Methods

__construct()

Constructor.

Since: 3.1.0
Line: 50

public function __construct( API $api );
TypeNameDescription
API$apiGitHub API instance.

process_file()

Process a single markdown file from a GitHub repo.

Since: 3.1.0
Line: 81

public function process_file( string $repo_owner, string $repo_name, string $file_path, int $product_id, string $ref = ..., array $mapping = ..., ?array $post_map = ... ): array;
TypeNameDescription
string$repo_ownerGitHub repository owner.
string$repo_nameGitHub repository name.
string$file_pathPath to the .md file within the repo.
int$product_idFallback product term ID.
string$refOptional branch, tag, or SHA to fetch from.
array$mappingFull repository mapping array.
array$post_mapOptional precomputed file_path => [post_id, sha] map (avoids a per-file meta query).

Returns: array — string, post_id: int, title: string, slug: string, error?: string, warning?: string}

handle_renamed_file()

Handle a renamed file — update path meta and re-process.

Since: 3.1.0
Line: 350

public function handle_renamed_file( string $old_path, string $new_path, string $repo_owner, string $repo_name, array $mapping = ..., ?array $post_map = ... ): array;
TypeNameDescription
string$old_pathPrevious file path within the repo.
string$new_pathNew file path within the repo.
string$repo_ownerRepository owner.
string$repo_nameRepository name.
array$mappingFull repository mapping array.
array|null$post_mapOptional precomputed file_path => [post_id, sha] map.

Returns: array — string, post_id: int, title: string, slug: string, error?: string}

get_file_list()

Get the list of markdown files for a repository mapping.

Since: 3.1.0
Line: 394

public function get_file_list( string $repo_owner, string $repo_name, array $mapping, string $ref = ... ): array|\WP_Error;
TypeNameDescription
string$repo_ownerRepository owner.
string$repo_nameRepository name.
array$mappingRepository mapping array.
string$refBranch, tag, or SHA.

Returns: array|\WP_Error — Array of [files, sha_map] on success, WP_Error on failure.

get_pre_skip_info()

Check if a file’s tree SHA matches the stored SHA for an existing post.

Returns existing post data if unchanged, null if the file should be processed.

Since: 3.1.0
Line: 411

public function get_pre_skip_info( string $repo_owner, string $repo_name, string $file_path, string $tree_sha ): ?array;
TypeNameDescription
string$repo_ownerRepository owner.
string$repo_nameRepository name.
string$file_pathPath to the .md file.
string$tree_shaSHA from the Git tree.

Returns: ?array — Existing post info array or null if should process.

build_post_map()

Build a map of file_path → post data for all imported posts in a repo.

Uses a single JOIN query instead of N get_post_meta() calls. Public so batch callers (e.g. the webhook executor) can build the map once and pass it into process_file()/handle_*_file() to avoid a per-file meta query.

Since: 3.1.0
Line: 505

public function build_post_map( string $repo_owner, string $repo_name ): array;
TypeNameDescription
string$repo_ownerRepository owner.
string$repo_nameRepository name.

Returns: array — array{post_id: int, sha: string}>

handle_deleted_file()

Handle a deleted file — set its article to draft or permanently delete.

Since: 3.1.0
Line: 552

public function handle_deleted_file( string $repo_owner, string $repo_name, string $file_path, array $mapping = ..., ?array $post_map = ... ): array;
TypeNameDescription
string$repo_ownerRepository owner.
string$repo_nameRepository name.
string$file_pathPath to the .md file that was removed.
array$mappingFull repository mapping array.
array|null$post_mapOptional precomputed file_path => [post_id, sha] map.

Returns: array — string, post_id: int, title: string, slug: string}

import_repository()

Import all Markdown files from a mapped repository folder.

Since: 3.1.0
Line: 599

public function import_repository( string $repo_owner, string $repo_name, array $mapping, string $ref = ... ): array;
TypeNameDescription
string$repo_ownerRepository owner.
string$repo_nameRepository name.
array$mappingFull repository mapping array (must include folder_path, product_id).
string$refBranch, tag, or SHA to import from.

Returns: array — int, created: int, updated: int, errors: array, results: array}

assign_taxonomies() static

Assign product, section, and tag taxonomies to a post.

Since: 3.1.0
Line: 797

static public function assign_taxonomies( int $post_id, array $fm, int $product_id ): void;
TypeNameDescription
int$post_idThe post ID.
array$fmParsed frontmatter.
int$product_idFallback product term ID.

Returns: void

sideload_images()

Sideload images from GitHub raw URLs into the Media Library.

Since: 3.1.0
Line: 941

public function sideload_images( string $html, string $repo_owner, string $repo_name, string $ref, string $file_path ): string;
TypeNameDescription
string$htmlPost content HTML.
string$repo_ownerRepository owner.
string$repo_nameRepository name.
string$refBranch, tag, or SHA.
string$file_pathImporting file’s repo-relative path (for resolving relative src).

Returns: string — HTML with image src attributes replaced with sideloaded URLs.