Recent

Import_ProcessorclassPro only

Import_Processor

Import Processor class.

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

Methods

__construct()

Constructor.

Since: 3.1.0
Line: 62

public function __construct( API $api );
Type Name Description
API $api GitHub API instance.

process_file()

Process a single markdown file from a GitHub repo.

Since: 3.1.0
Line: 93

public function process_file( string $repo_owner, string $repo_name, string $file_path, int $product_id, string $ref = ..., array $mapping = ..., ?array $post_map = ... ): array;
Type Name Description
string $repo_owner GitHub repository owner.
string $repo_name GitHub repository name.
string $file_path Path to the .md file within the repo.
int $product_id Fallback product term ID.
string $ref Optional branch, tag, or SHA to fetch from.
array $mapping Full repository mapping array.
array $post_map Optional 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, note?: string}

handle_renamed_file()

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

Since: 3.1.0
Line: 394

public function handle_renamed_file( string $old_path, string $new_path, string $repo_owner, string $repo_name, array $mapping = ..., ?array $post_map = ... ): array;
Type Name Description
string $old_path Previous file path within the repo.
string $new_path New file path within the repo.
string $repo_owner Repository owner.
string $repo_name Repository name.
array $mapping Full repository mapping array.
array|null $post_map Optional 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: 438

public function get_file_list( string $repo_owner, string $repo_name, array $mapping, string $ref = ... ): array|\WP_Error;
Type Name Description
string $repo_owner Repository owner.
string $repo_name Repository name.
array $mapping Repository mapping array.
string $ref Branch, 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: 455

public function get_pre_skip_info( string $repo_owner, string $repo_name, string $file_path, string $tree_sha ): ?array;
Type Name Description
string $repo_owner Repository owner.
string $repo_name Repository name.
string $file_path Path to the .md file.
string $tree_sha SHA 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: 549

public function build_post_map( string $repo_owner, string $repo_name ): array;
Type Name Description
string $repo_owner Repository owner.
string $repo_name Repository 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: 596

public function handle_deleted_file( string $repo_owner, string $repo_name, string $file_path, array $mapping = ..., ?array $post_map = ... ): array;
Type Name Description
string $repo_owner Repository owner.
string $repo_name Repository name.
string $file_path Path to the .md file that was removed.
array $mapping Full repository mapping array.
array|null $post_map Optional 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: 643

public function import_repository( string $repo_owner, string $repo_name, array $mapping, string $ref = ... ): array;
Type Name Description
string $repo_owner Repository owner.
string $repo_name Repository name.
array $mapping Full repository mapping array (must include folder_path, product_id).
string $ref Branch, 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: 842

static public function assign_taxonomies( int $post_id, array $fm, int $product_id ): void;
Type Name Description
int $post_id The post ID.
array $fm Parsed frontmatter.
int $product_id Mapping product term ID. When non-zero, takes precedence over frontmatter products.

Returns: void

sideload_images()

Sideload images from GitHub raw URLs into the Media Library.

Since: 3.1.0
Line: 987

public function sideload_images( string $html, string $repo_owner, string $repo_name, string $ref, string $file_path ): string;
Type Name Description
string $html Post content HTML.
string $repo_owner Repository owner.
string $repo_name Repository name.
string $ref Branch, tag, or SHA.
string $file_path Importing file’s repo-relative path (for resolving relative src).

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

dedup_key_to_url() static

Convert a dedup key back to a fetchable source URL.

Inverse of get_image_dedup_key(): github-raw:owner/repo/path keys become raw.githubusercontent.com URLs with a HEAD ref (the ref was stripped when the key was built, and get_image_dedup_key() normalises HEAD back to the same identity on re-import). Any other key is already a URL and is returned as-is.

Since: 3.1.0
Line: 1348

static public function dedup_key_to_url( string $dedup_key ): string;
Type Name Description
string $dedup_key Dedup key stored in _wzkb_github_media_source.

Returns: string — Source URL.