Documentation
Documentation
Graphic_Data_Transfer_Importer
in package
Class Graphic_Data_Transfer_Importer.
Tags
Table of Contents
Constants
- BACKUP_OPTION_PREFIX : mixed = 'graphic_data_transfer_backup_'
- Prefix of the options backing up the posts an import updates, followed by the batch ID and the post ID.
- BATCHES_OPTION : mixed = 'graphic_data_transfer_batches'
- Option holding the record of each import, keyed by batch ID.
- HISTORY_SIZE : mixed = 20
- Number of imports kept in the import history.
- JOB_LIFETIME : mixed = \DAY_IN_SECONDS
- Jobs older than this many seconds are deleted.
- JOB_OPTION_PREFIX : mixed = 'graphic_data_transfer_job_'
- Prefix of the option holding each import job's state.
- JOBS_OPTION : mixed = 'graphic_data_transfer_jobs'
- Option listing open jobs (token => creation time), for clean-up.
- TIME_BUDGET : mixed = 10
- Seconds of media work to do per request.
- WORK_FOLDER : mixed = 'graphic-data-transfer'
- Folder inside uploads that holds packages while they are imported.
Properties
- $checked_files : array<string, string>
- Media files taken out of the package to be checked, by zip path.
- $content : array<string|int, mixed>
- Decoded content.json.
- $data_names : array<int, array<string, string>>
- New names of the data files of updated Figures, by source Figure ID and name in the package.
- $id_map : array<int, int>
- Source post ID => new post ID, filled while importing.
- $job : array<string|int, mixed>
- Job state.
- $manifest : array<string|int, mixed>
- Decoded manifest.json.
- $matched : array<int, int>|null
- Package post that matches each post on this site.
- $media_by_url : array<string, array{0: array, 1: string}>|null
- Package media by source URL.
- $posts : array<int, array<string|int, mixed>>
- Package posts keyed by source ID.
- $reference_info : array<int, array{title: string, slug: string}>|null
- Source target ID => title and slug, from the package's references.
- $report : array<string|int, mixed>
- Report of the import being run.
- $required_refs : array<int, array<string|int, mixed>>
- Required references of each package post, keyed by source ID, built with $targets. See get_link_targets().
- $targets : array<string, array<string|int, mixed>>|null
- Links to content outside the package, built on first use. See get_link_targets().
- $term_map : array<int, int>
- Source term ID => term ID on this site.
- $url_map : array<string, string>|null
- Source URL => new URL, built on first use.
- $zip : ZipArchive|null
- Open package.
Methods
- append_chunk() : true|WP_Error
- Append an uploaded chunk to the package.
- cancel() : void
- Abandon the job and delete the uploaded package.
- check() : array<string|int, mixed>|WP_Error
- Validate the uploaded package and work out what importing it will do.
- check_links() : array{next: int, total: int, failed: array[]}
- Check whether some of the package's web addresses can be reached. Only reads the job, so it can run while the plan is being reviewed.
- create_job() : string|WP_Error
- Start a new import job for the current user.
- find_file_to_check() : array{0: string, 1: int, 2: int}
- Find the file behind an address, in the package or on this site, for the validator.
- get_batches() : array<string|int, array<string|int, mixed>>
- Import history, most recent first.
- get_token() : string
- Job token.
- is_uploaded() : bool
- Whether every chunk has arrived.
- load() : Graphic_Data_Transfer_Importer|WP_Error
- Load an existing job belonging to the current user.
- read_linked_field() : string|null
- Read a field of a linked post, for the validator.
- run_step() : array<string|int, mixed>|WP_Error
- Run the next step of the import.
- undo() : array<string|int, mixed>|WP_Error
- Remove everything an import created and restore what it updated and the About post. An import cannot be undone while a later one that updated the same content has not been.
- add_link_target() : void
- Add a link target, or record another use of an existing one.
- backup_about() : void
- Back up the About post before it is overwritten.
- backup_post() : void
- Back up a post before it is updated.
- complete_batch() : void
- Mark the current batch as finished and save its report.
- convert_bulk_import() : true|WP_Error
- If the upload is a bulk import (a zip of TSV files), replace it with the package it converts into. Bulk imports are for administrators.
- create_post() : int
- Create a post (or overwrite the About post) with its core fields.
- delete_backups() : void
- Delete the backups of the posts an import updated.
- delete_folder() : void
- Delete a folder and the files in it.
- delete_job() : void
- Delete a job's state and folder.
- delete_stale_jobs() : void
- Delete jobs that were abandoned.
- describe_invalid() : array<string|int, mixed>
- Describe a post with errors, for the report.
- describe_plan() : array<string|int, mixed>
- Summarise the plan for the dry-run screen.
- describe_unlinked() : array<string|int, mixed>
- Describe a reference left empty, for the report.
- extract_to() : void
- Copy a file out of the package.
- fail() : void
- Stop the import step. run_step() catches this, undoes the import and reports the message.
- find_about() : int
- The existing About post, if there is one.
- find_existing_media() : int|string
- Find an attachment (or uploads file) on this site identical to a package media file, so it is not uploaded twice.
- find_existing_term() : int
- The Instance Type on this site that a package term matches: the one a bulk import's row names, otherwise the one with the same slug.
- find_post_by_slug() : int
- Find a post of a type by slug.
- find_post_by_source() : int
- Find the post on this site that a source post ID refers to: the original itself when this is the source site, or an earlier import (preferring one with the given slug over a later copy of it).
- finish() : void
- Delete the job and its uploaded package.
- finish_post() : void
- Write a post's meta and fix every reference, URL and status.
- get_backup_keys() : array<string|int, string>
- Meta that an update can change, and so undo restores.
- get_batch() : array<string|int, mixed>
- The current batch record.
- get_checksum() : string
- Checksum of a file in the package.
- get_chosen_link() : int
- The post on this site chosen (or, before that, suggested) for a link.
- get_link_options() : array<string, array<string|int, array<string|int, mixed>>>
- The posts on this site that links can point at, by type. Scenes, Modals and Figures carry their Instance (and Scene) so the choices can be narrowed; Modals also carry their tabs.
- get_link_targets() : array<string, array<string|int, mixed>>
- Every link from a package post to content outside the package, each of which the user points at a post on this site (or leaves empty).
- get_link_token() : string
- Name for a post on this site when comparing links: "s:<source ID>" if a package post matches it, as for links inside the package, otherwise its ID.
- get_lock() : string
- Name of the other user who is editing a post, if there is one.
- get_meta_to_check() : array<string|int, mixed>
- A package post's fields with its links as validation compares them (see get_link_token()).
- get_named_post() : int
- The post that a bulk import's row matches (see Graphic_Data_Transfer_Tsv::match_row()).
- get_option_label() : string
- A post's title for a link choice, noting when it is not shown on the site.
- get_package_path() : string
- Path of the uploaded package.
- get_package_warnings() : array<string|int, string>
- Warnings about the package itself.
- get_plain_media_path() : string
- Uploads-relative path of a plain (non-library) media file, with each part of the path made safe.
- get_progress() : array<string|int, mixed>
- Progress for the browser.
- get_reference_info() : array{title: string, slug: string}
- Title and slug of a source post that the package links to, as recorded by the exporter.
- get_source_key() : string
- Value stored in SOURCE_META_KEY for an item from this package.
- get_source_site() : string
- Source site URL recorded in the package.
- get_svg_error() : string
- Run an SVG through the plugin's SVG validator.
- get_tab_targets() : array<string|int, array<string|int, mixed>>
- Figures whose Modal is outside the package: once the Modal is chosen, the user picks which of its tabs the Figure goes in.
- get_unique_meta_value() : string
- Make a meta value unique among posts of a type by adding -2, -3, .
- get_unknown_fields() : string
- Package fields that this version does not import, as text for a warning (for example "Figure: figure_new, figure_other; Scene: x"), or '' if there are none.
- get_url_map() : array<string, string>
- Source URL => new URL. strtr() replaces the longest match first, so media URLs win over the site URL they start with.
- get_work_dir() : string
- This job's folder.
- get_work_root() : string
- Folder that holds all import jobs, protected from direct access.
- import_content() : void
- Import terms, posts, data files and references.
- import_data_files() : array<int, array<string, string>>
- Copy figure data files into each new figure's data folder.
- import_media() : array{id: int, reused: bool, warning: string}
- Import one media file and record its new URLs.
- import_media_step() : void
- Import media files until the time budget runs out.
- import_terms() : void
- Reuse or create the package's Instance Type terms.
- is_icon_claimed() : bool
- Whether another Modal of the same Scene has an icon.
- is_id() : bool
- Whether a value is a positive whole number (a post or term ID).
- is_package_post() : bool
- Whether a source post ID is a package post of the given type.
- is_same_site() : bool
- Whether the package was exported from this site.
- make_plan() : array<string|int, mixed>
- Decide what will happen to each item.
- media_result() : array<string|int, mixed>
- Build a media result.
- name_updated_data_files() : void
- Name the data files of updated Figures. Files that are already in the Figure's folder keep their name; otherwise all the Figure's new files get a name ending that is free, because its revisions may still use the earlier files.
- open() : true|WP_Error
- Open and validate the package.
- prepare_figure_update() : array<string|int, mixed>
- Adjust a Figure's fields for an update: leave out a chart that has not changed, keep data files the package does not have, and use the names the data files were given.
- record_batch_file() : void
- Remember a plain file written to uploads, so undo can remove it.
- resolve_post() : int
- Resolve a reference to a source post: the imported copy of a package post, otherwise the post the user chose for it.
- restore_post() : bool
- Put an updated post back as it was before an import.
- rewrite_figure_id() : mixed
- Point a figure's own references (its data folder and the figureId in its saved rendering) at the new figure ID.
- rewrite_urls() : mixed
- Replace source-site URLs (media, figure data and internal links) with their equivalents on this site.
- save_job() : void
- Save the job state.
- set_actions() : void
- Apply the user's choices of what to update, then check every post with all the choices made.
- set_choices() : true|WP_Error
- Validate and save the user's link and tab choices. A choice that is not given takes the suggestion.
- sideload() : int|WP_Error
- Add a package file to the Media Library.
- start_batch() : string
- Record the start of an import.
- suggest_link() : int
- Suggest a post on this site for a link: the same post (when this is the source site), an earlier import of it, or a post of the same type with the same slug.
- update_batch() : void
- Update the current batch record.
- update_post() : void
- Update a post's core fields with those the package holds. Its author, date and WordPress status stay as they are. Saves the revision, so the post's meta must have been written.
- update_term() : void
- Update an Instance Type, after backing it up.
-
validate()
: array{errors: string[], warnings: string[], urls: array
} - Check a package post as its edit screen would check it.
- walk_block_references() : array<string|int, mixed>
- Call a function for every Graphic Data reference in a block tree and replace the attribute with its return value.
- write_meta() : void
- Save a post's meta. When overwriting (the About post), fields the package does not include are removed so the result matches the source.
Constants
BACKUP_OPTION_PREFIX
Prefix of the options backing up the posts an import updates, followed by the batch ID and the post ID.
public
mixed
BACKUP_OPTION_PREFIX
= 'graphic_data_transfer_backup_'
BATCHES_OPTION
Option holding the record of each import, keyed by batch ID.
public
mixed
BATCHES_OPTION
= 'graphic_data_transfer_batches'
HISTORY_SIZE
Number of imports kept in the import history.
public
mixed
HISTORY_SIZE
= 20
JOB_LIFETIME
Jobs older than this many seconds are deleted.
public
mixed
JOB_LIFETIME
= \DAY_IN_SECONDS
JOB_OPTION_PREFIX
Prefix of the option holding each import job's state.
public
mixed
JOB_OPTION_PREFIX
= 'graphic_data_transfer_job_'
JOBS_OPTION
Option listing open jobs (token => creation time), for clean-up.
public
mixed
JOBS_OPTION
= 'graphic_data_transfer_jobs'
TIME_BUDGET
Seconds of media work to do per request.
public
mixed
TIME_BUDGET
= 10
WORK_FOLDER
Folder inside uploads that holds packages while they are imported.
public
mixed
WORK_FOLDER
= 'graphic-data-transfer'
Properties
$checked_files
Media files taken out of the package to be checked, by zip path.
private
array<string, string>
$checked_files
= array()
$content
Decoded content.json.
private
array<string|int, mixed>
$content
$data_names
New names of the data files of updated Figures, by source Figure ID and name in the package.
private
array<int, array<string, string>>
$data_names
= array()
$id_map
Source post ID => new post ID, filled while importing.
private
array<int, int>
$id_map
= array()
$job
Job state.
private
array<string|int, mixed>
$job
$manifest
Decoded manifest.json.
private
array<string|int, mixed>
$manifest
$matched
Package post that matches each post on this site.
private
array<int, int>|null
$matched
= \null
$media_by_url
Package media by source URL.
private
array<string, array{0: array, 1: string}>|null
$media_by_url
= \null
$posts
Package posts keyed by source ID.
private
array<int, array<string|int, mixed>>
$posts
= array()
$reference_info
Source target ID => title and slug, from the package's references.
private
array<int, array{title: string, slug: string}>|null
$reference_info
= \null
$report
Report of the import being run.
private
array<string|int, mixed>
$report
= array()
$required_refs
Required references of each package post, keyed by source ID, built with $targets. See get_link_targets().
private
array<int, array<string|int, mixed>>
$required_refs
= array()
$targets
Links to content outside the package, built on first use. See get_link_targets().
private
array<string, array<string|int, mixed>>|null
$targets
= \null
$term_map
Source term ID => term ID on this site.
private
array<int, int>
$term_map
= array()
$url_map
Source URL => new URL, built on first use.
private
array<string, string>|null
$url_map
= \null
$zip
Open package.
private
ZipArchive|null
$zip
Methods
append_chunk()
Append an uploaded chunk to the package.
public
append_chunk(string $chunk_path, int $offset) : true|WP_Error
Parameters
- $chunk_path : string
-
Uploaded temporary file.
- $offset : int
-
Byte offset of the chunk in the package.
Return values
true|WP_Errorcancel()
Abandon the job and delete the uploaded package.
public
cancel() : void
check()
Validate the uploaded package and work out what importing it will do.
public
check() : array<string|int, mixed>|WP_Error
Return values
array<string|int, mixed>|WP_Error —Dry-run report.
check_links()
Check whether some of the package's web addresses can be reached. Only reads the job, so it can run while the plan is being reviewed.
public
check_links(int $offset) : array{next: int, total: int, failed: array[]}
Parameters
- $offset : int
-
First address to check.
Return values
array{next: int, total: int, failed: array[]} —Where to continue, and the unreachable addresses with the fields that hold them.
create_job()
Start a new import job for the current user.
public
static create_job(int $size[, bool $figure_only = false ]) : string|WP_Error
Parameters
- $size : int
-
Total size of the package in bytes.
- $figure_only : bool = false
-
Only accept a package holding a single Figure (imports by Editors).
Return values
string|WP_Error —Job token.
find_file_to_check()
Find the file behind an address, in the package or on this site, for the validator.
public
find_file_to_check(string $url) : array{0: string, 1: int, 2: int}
Parameters
- $url : string
-
Address.
Return values
array{0: string, 1: int, 2: int} —Path ('' if there is none), and the width and height of a resized image (or 0).
get_batches()
Import history, most recent first.
public
static get_batches() : array<string|int, array<string|int, mixed>>
Return values
array<string|int, array<string|int, mixed>>get_token()
Job token.
public
get_token() : string
Return values
stringis_uploaded()
Whether every chunk has arrived.
public
is_uploaded() : bool
Return values
boolload()
Load an existing job belonging to the current user.
public
static load(string $token) : Graphic_Data_Transfer_Importer|WP_Error
Parameters
- $token : string
-
Job token.
Return values
Graphic_Data_Transfer_Importer|WP_Errorread_linked_field()
Read a field of a linked post, for the validator.
public
read_linked_field(string $link, string $type, string $key) : string|null
Parameters
- $link : string
-
Link, from get_link_token().
- $type : string
-
Post type linked to.
- $key : string
-
Meta key.
Return values
string|null —Null if the linked post is not known.
run_step()
Run the next step of the import.
public
run_step([array<string|int, mixed>|null $choices = null ]) : array<string|int, mixed>|WP_Error
Parameters
- $choices : array<string|int, mixed>|null = null
-
Used by the first step only: 'links' (target key => post ID on this site, 0 to leave empty), 'tabs' (source Figure ID => Modal tab number), and 'update' and 'terms' (source IDs of the posts and Instance Types that update their match). Missing links and tabs take the dry run's suggestion.
Return values
array<string|int, mixed>|WP_Error —Progress: done (bool), progress, total, and the report when done.
undo()
Remove everything an import created and restore what it updated and the About post. An import cannot be undone while a later one that updated the same content has not been.
public
static undo(string $batch_id[, string $message = '' ]) : array<string|int, mixed>|WP_Error
Parameters
- $batch_id : string
-
Batch ID.
- $message : string = ''
-
Optional note saved with the batch.
Return values
array<string|int, mixed>|WP_Error —Counts of removed items.
add_link_target()
Add a link target, or record another use of an existing one.
private
add_link_target(string $key, string $type, int $source_id, array<string|int, mixed> $entry, string $field, bool $required, string $parent) : void
Parameters
- $key : string
-
Target key.
- $type : string
-
Target post type.
- $source_id : int
-
Source target ID (0 for an unset parent).
- $entry : array<string|int, mixed>
-
Package post holding the link.
- $field : string
-
Meta key or block attribute.
- $required : bool
-
Whether the link is a required parent.
- $parent : string
-
Key of the parent target, or ''.
backup_about()
Back up the About post before it is overwritten.
private
backup_about(int $about_id) : void
Parameters
- $about_id : int
-
About post ID.
backup_post()
Back up a post before it is updated.
private
backup_post(int $post_id) : void
Parameters
- $post_id : int
-
Post ID.
complete_batch()
Mark the current batch as finished and save its report.
private
complete_batch() : void
convert_bulk_import()
If the upload is a bulk import (a zip of TSV files), replace it with the package it converts into. Bulk imports are for administrators.
private
convert_bulk_import() : true|WP_Error
Return values
true|WP_Error —The error's data lists every problem found in the spreadsheets ('errors').
create_post()
Create a post (or overwrite the About post) with its core fields.
private
create_post(array<string|int, mixed> $entry, array<string|int, mixed> $plan) : int
Meta and references are written by finish_post(), and so is all of an update, so that one revision holds it.
Parameters
- $entry : array<string|int, mixed>
-
Package post.
- $plan : array<string|int, mixed>
-
Planned action.
Tags
Return values
int —New post ID.
delete_backups()
Delete the backups of the posts an import updated.
private
static delete_backups(string $batch_id, array<string|int, mixed> $batch) : void
Parameters
- $batch_id : string
-
Batch ID.
- $batch : array<string|int, mixed>
-
Batch record.
delete_folder()
Delete a folder and the files in it.
private
static delete_folder(string $dir) : void
Parameters
- $dir : string
-
Folder path.
delete_job()
Delete a job's state and folder.
private
static delete_job(string $token) : void
Parameters
- $token : string
-
Job token.
delete_stale_jobs()
Delete jobs that were abandoned.
private
static delete_stale_jobs() : void
describe_invalid()
Describe a post with errors, for the report.
private
describe_invalid(array<string|int, mixed> $entry, int $post_id, array<string|int, mixed> $plan) : array<string|int, mixed>
Parameters
- $entry : array<string|int, mixed>
-
Package post.
- $post_id : int
-
Post ID on this site.
- $plan : array<string|int, mixed>
-
Planned action.
Return values
array<string|int, mixed>describe_plan()
Summarise the plan for the dry-run screen.
private
describe_plan(array<string|int, mixed> $plan) : array<string|int, mixed>
Parameters
- $plan : array<string|int, mixed>
-
Plan from make_plan().
Return values
array<string|int, mixed>describe_unlinked()
Describe a reference left empty, for the report.
private
describe_unlinked(array<string|int, mixed> $entry, int $post_id, string $field, string $target_type, int $target_id) : array<string|int, mixed>
Parameters
- $entry : array<string|int, mixed>
-
Package post holding the reference.
- $post_id : int
-
New post ID.
- $field : string
-
Field or block attribute.
- $target_type : string
-
Target post type.
- $target_id : int
-
Source target ID.
Return values
array<string|int, mixed>extract_to()
Copy a file out of the package.
private
extract_to(string $file, string $destination) : void
The destination is always chosen by the importer, never taken from the zip, so entries cannot be written outside their folder.
Parameters
- $file : string
-
Path inside the zip.
- $destination : string
-
Absolute destination path.
Tags
fail()
Stop the import step. run_step() catches this, undoes the import and reports the message.
private
static fail(string $message) : void
Parameters
- $message : string
-
Plain-text message (shown with textContent).
Tags
find_about()
The existing About post, if there is one.
private
find_about() : int
Return values
int —Post ID, or 0.
find_existing_media()
Find an attachment (or uploads file) on this site identical to a package media file, so it is not uploaded twice.
private
find_existing_media(array<string|int, mixed> $media) : int|string
Parameters
- $media : array<string|int, mixed>
-
Package media entry.
Return values
int|string —Attachment ID, uploads-relative path for a plain file, or 0.
find_existing_term()
The Instance Type on this site that a package term matches: the one a bulk import's row names, otherwise the one with the same slug.
private
find_existing_term(array<string|int, mixed> $term) : int
Parameters
- $term : array<string|int, mixed>
-
Package term.
Return values
int —Term ID, or 0.
find_post_by_slug()
Find a post of a type by slug.
private
find_post_by_slug(string $post_type, string $slug) : int
Parameters
- $post_type : string
-
Post type.
- $slug : string
-
Slug.
Return values
int —Post ID, or 0.
find_post_by_source()
Find the post on this site that a source post ID refers to: the original itself when this is the source site, or an earlier import (preferring one with the given slug over a later copy of it).
private
find_post_by_source(string $post_type, int $source_id[, string $slug = '' ]) : int
Parameters
- $post_type : string
-
Post type.
- $source_id : int
-
Source post ID.
- $slug : string = ''
-
Source slug.
Return values
int —Post ID, or 0.
finish()
Delete the job and its uploaded package.
private
finish() : void
finish_post()
Write a post's meta and fix every reference, URL and status.
private
finish_post(int $source_id, array<string|int, mixed> $entry, array<string|int, mixed> $plan, array<string|int, mixed> $data_paths) : void
Parameters
- $source_id : int
-
Source post ID.
- $entry : array<string|int, mixed>
-
Package post.
- $plan : array<string|int, mixed>
-
Planned action.
- $data_paths : array<string|int, mixed>
-
Meta key => new data file path, for figures.
get_backup_keys()
Meta that an update can change, and so undo restores.
private
static get_backup_keys(string $type) : array<string|int, string>
Parameters
- $type : string
-
Post type.
Return values
array<string|int, string>get_batch()
The current batch record.
private
get_batch() : array<string|int, mixed>
Return values
array<string|int, mixed>get_checksum()
Checksum of a file in the package.
private
get_checksum(string $file) : string
Parameters
- $file : string
-
Path inside the zip.
Return values
stringget_chosen_link()
The post on this site chosen (or, before that, suggested) for a link.
private
get_chosen_link(string $key) : int
Parameters
- $key : string
-
Target key.
Return values
int —Post ID, or 0.
get_link_options()
The posts on this site that links can point at, by type. Scenes, Modals and Figures carry their Instance (and Scene) so the choices can be narrowed; Modals also carry their tabs.
private
get_link_options(array<string|int, string> $types) : array<string, array<string|int, array<string|int, mixed>>>
Parameters
- $types : array<string|int, string>
-
Post types that are linked to.
Return values
array<string, array<string|int, array<string|int, mixed>>>get_link_targets()
Every link from a package post to content outside the package, each of which the user points at a post on this site (or leaves empty).
private
get_link_targets() : array<string, array<string|int, mixed>>
A target is keyed "
Required parents form a chain (Instance, then Scene, then Modal), and
each target records the target above it as parent so the choices on
offer can be narrowed to what belongs to the chosen parent.
Also fills $required_refs: for each post with required parents, one
entry per parent whose key is the target key, '' when the parent is
in the package, or 'none' when it is missing and cannot be chosen.
Return values
array<string, array<string|int, mixed>> —Target key => key, type, source_id, title, required, parent, used_by and suggested (post ID or 0).
get_link_token()
Name for a post on this site when comparing links: "s:<source ID>" if a package post matches it, as for links inside the package, otherwise its ID.
private
get_link_token(int $post_id) : string
Parameters
- $post_id : int
-
Post ID, or 0.
Return values
stringget_lock()
Name of the other user who is editing a post, if there is one.
private
get_lock(int $post_id) : string
Parameters
- $post_id : int
-
Post ID.
Return values
stringget_meta_to_check()
A package post's fields with its links as validation compares them (see get_link_token()).
private
get_meta_to_check(int $source_id) : array<string|int, mixed>
Parameters
- $source_id : int
-
Source post ID.
Return values
array<string|int, mixed>get_named_post()
The post that a bulk import's row matches (see Graphic_Data_Transfer_Tsv::match_row()).
private
get_named_post(array<string|int, mixed> $entry) : int
Parameters
- $entry : array<string|int, mixed>
-
Package post.
Return values
int —Post ID, or 0.
get_option_label()
A post's title for a link choice, noting when it is not shown on the site.
private
get_option_label(WP_Post $post) : string
Parameters
- $post : WP_Post
-
Post.
Return values
stringget_package_path()
Path of the uploaded package.
private
get_package_path() : string
Return values
stringget_package_warnings()
Warnings about the package itself.
private
get_package_warnings() : array<string|int, string>
Return values
array<string|int, string>get_plain_media_path()
Uploads-relative path of a plain (non-library) media file, with each part of the path made safe.
private
get_plain_media_path(string $file) : string
Parameters
- $file : string
-
Path inside the zip (media/files/...).
Return values
string —Relative path, or '' if it is not a plain media file.
get_progress()
Progress for the browser.
private
get_progress(bool $done) : array<string|int, mixed>
Parameters
- $done : bool
-
Whether the import has finished.
Return values
array<string|int, mixed>get_reference_info()
Title and slug of a source post that the package links to, as recorded by the exporter.
private
get_reference_info(int $source_id) : array{title: string, slug: string}
Parameters
- $source_id : int
-
Source post ID.
Return values
array{title: string, slug: string}get_source_key()
Value stored in SOURCE_META_KEY for an item from this package.
private
get_source_key(int|string $source_id) : string
Parameters
- $source_id : int|string
-
Source post, attachment or term ID.
Return values
stringget_source_site()
Source site URL recorded in the package.
private
get_source_site() : string
Return values
stringget_svg_error()
Run an SVG through the plugin's SVG validator.
private
get_svg_error(string $path) : string
Parameters
- $path : string
-
File path.
Return values
string —Error message, or '' if the file is not an SVG or is valid.
get_tab_targets()
Figures whose Modal is outside the package: once the Modal is chosen, the user picks which of its tabs the Figure goes in.
private
get_tab_targets() : array<string|int, array<string|int, mixed>>
Return values
array<string|int, array<string|int, mixed>> —Figure source ID, title, its tab on the source site and the key of its Modal's target.
get_unique_meta_value()
Make a meta value unique among posts of a type by adding -2, -3, .
private
get_unique_meta_value(string $type, string $key, string $value, int $post_id) : string
..
Parameters
- $type : string
-
Post type.
- $key : string
-
Meta key.
- $value : string
-
Wanted value.
- $post_id : int
-
Post being saved.
Return values
stringget_unknown_fields()
Package fields that this version does not import, as text for a warning (for example "Figure: figure_new, figure_other; Scene: x"), or '' if there are none.
private
get_unknown_fields() : string
Return values
stringget_url_map()
Source URL => new URL. strtr() replaces the longest match first, so media URLs win over the site URL they start with.
private
get_url_map() : array<string, string>
Return values
array<string, string>get_work_dir()
This job's folder.
private
get_work_dir() : string
Return values
stringget_work_root()
Folder that holds all import jobs, protected from direct access.
private
static get_work_root() : string
Return values
string —Path with trailing slash.
import_content()
Import terms, posts, data files and references.
private
import_content() : void
Tags
import_data_files()
Copy figure data files into each new figure's data folder.
private
import_data_files() : array<int, array<string, string>>
Return values
array<int, array<string, string>> —Source figure ID => meta key => new absolute path.
import_media()
Import one media file and record its new URLs.
private
import_media(array<string|int, mixed> $media) : array{id: int, reused: bool, warning: string}
Parameters
- $media : array<string|int, mixed>
-
Package media entry.
Return values
array{id: int, reused: bool, warning: string} —Result.
import_media_step()
Import media files until the time budget runs out.
private
import_media_step() : void
import_terms()
Reuse or create the package's Instance Type terms.
private
import_terms() : void
Tags
is_icon_claimed()
Whether another Modal of the same Scene has an icon.
private
is_icon_claimed(int $source_id, string $icon, string $scene) : bool
Parameters
- $source_id : int
-
Modal being checked.
- $icon : string
-
Icon ID.
- $scene : string
-
Scene, from get_link_token().
Return values
boolis_id()
Whether a value is a positive whole number (a post or term ID).
private
static is_id(mixed $value) : bool
Parameters
- $value : mixed
-
Value.
Return values
boolis_package_post()
Whether a source post ID is a package post of the given type.
private
is_package_post(int $source_id, string $type) : bool
Parameters
- $source_id : int
-
Source post ID.
- $type : string
-
Post type.
Return values
boolis_same_site()
Whether the package was exported from this site.
private
is_same_site() : bool
Return values
boolmake_plan()
Decide what will happen to each item.
private
make_plan() : array<string|int, mixed>
Return values
array<string|int, mixed>media_result()
Build a media result.
private
media_result(int $id, bool $reused, string $warning) : array<string|int, mixed>
Parameters
- $id : int
-
Attachment ID (0 for plain files or failures).
- $reused : bool
-
Whether an existing file was used.
- $warning : string
-
Problem, if any.
Return values
array<string|int, mixed>name_updated_data_files()
Name the data files of updated Figures. Files that are already in the Figure's folder keep their name; otherwise all the Figure's new files get a name ending that is free, because its revisions may still use the earlier files.
private
name_updated_data_files() : void
open()
Open and validate the package.
private
open() : true|WP_Error
Return values
true|WP_Errorprepare_figure_update()
Adjust a Figure's fields for an update: leave out a chart that has not changed, keep data files the package does not have, and use the names the data files were given.
private
prepare_figure_update(array<string|int, mixed> $meta, array<string|int, mixed> $entry, int $source_id, int $post_id, array<string|int, mixed> $data_paths) : array<string|int, mixed>
Parameters
- $meta : array<string|int, mixed>
-
Fields.
- $entry : array<string|int, mixed>
-
Package post.
- $source_id : int
-
Source Figure ID.
- $post_id : int
-
Figure being updated.
- $data_paths : array<string|int, mixed>
-
Meta key => new data file path.
Return values
array<string|int, mixed>record_batch_file()
Remember a plain file written to uploads, so undo can remove it.
private
record_batch_file(string $path) : void
Parameters
- $path : string
-
Absolute path.
resolve_post()
Resolve a reference to a source post: the imported copy of a package post, otherwise the post the user chose for it.
private
resolve_post(int $source_id, string $target_type) : int
Parameters
- $source_id : int
-
Source post ID.
- $target_type : string
-
Post type the reference points at.
Return values
int —Post ID on this site, or 0 to leave the reference empty.
restore_post()
Put an updated post back as it was before an import.
private
static restore_post(string $batch_id, int $post_id) : bool
Parameters
- $batch_id : string
-
Batch ID.
- $post_id : int
-
Post ID.
Return values
bool —Whether it was restored.
rewrite_figure_id()
Point a figure's own references (its data folder and the figureId in its saved rendering) at the new figure ID.
private
rewrite_figure_id(mixed $value, int $old_id, int $new_id) : mixed
Parameters
- $value : mixed
-
Meta value or array of meta values.
- $old_id : int
-
Source figure ID.
- $new_id : int
-
New figure ID.
rewrite_urls()
Replace source-site URLs (media, figure data and internal links) with their equivalents on this site.
private
rewrite_urls(mixed $value) : mixed
Parameters
- $value : mixed
-
String or array.
save_job()
Save the job state.
private
save_job() : void
set_actions()
Apply the user's choices of what to update, then check every post with all the choices made.
private
set_actions(array<string|int, mixed> $choices) : void
A new post with errors is held, and an update with errors, or without a required parent, is not made.
Parameters
- $choices : array<string|int, mixed>
-
'update' and 'terms'; see run_step().
set_choices()
Validate and save the user's link and tab choices. A choice that is not given takes the suggestion.
private
set_choices(array<string|int, mixed> $choices) : true|WP_Error
Parameters
- $choices : array<string|int, mixed>
-
'links' and 'tabs'; see run_step().
Return values
true|WP_Errorsideload()
Add a package file to the Media Library.
private
sideload(array<string|int, mixed> $media) : int|WP_Error
Parameters
- $media : array<string|int, mixed>
-
Package media entry.
Return values
int|WP_Error —Attachment ID.
start_batch()
Record the start of an import.
private
start_batch() : string
Return values
string —Batch ID.
suggest_link()
Suggest a post on this site for a link: the same post (when this is the source site), an earlier import of it, or a post of the same type with the same slug.
private
suggest_link(string $type, int $source_id, string $slug) : int
Parameters
- $type : string
-
Target post type.
- $source_id : int
-
Source target ID.
- $slug : string
-
Source target slug.
Return values
int —Post ID, or 0.
update_batch()
Update the current batch record.
private
update_batch(array<string|int, mixed> $changes) : void
Parameters
- $changes : array<string|int, mixed>
-
Fields to set.
update_post()
Update a post's core fields with those the package holds. Its author, date and WordPress status stay as they are. Saves the revision, so the post's meta must have been written.
private
update_post(int $post_id, array<string|int, mixed> $entry, string $content, string $excerpt) : void
Parameters
- $post_id : int
-
Post ID.
- $entry : array<string|int, mixed>
-
Package post.
- $content : string
-
Content for this site.
- $excerpt : string
-
Excerpt for this site.
Tags
update_term()
Update an Instance Type, after backing it up.
private
update_term(int $term_id, array<string|int, mixed> $term) : void
Parameters
- $term_id : int
-
Term ID.
- $term : array<string|int, mixed>
-
Package term.
validate()
Check a package post as its edit screen would check it.
private
validate(int $source_id, bool $update) : array{errors: string[], warnings: string[], urls: array}
Parameters
- $source_id : int
-
Source post ID.
- $update : bool
-
Whether it updates the post it matches, whose fields then stand in for those it does not hold.
Return values
array{errors: string[], warnings: string[], urls: arraywalk_block_references()
Call a function for every Graphic Data reference in a block tree and replace the attribute with its return value.
private
walk_block_references(array<string|int, mixed> $blocks, callable $callback) : array<string|int, mixed>
Parameters
- $blocks : array<string|int, mixed>
-
Parsed blocks.
- $callback : callable
-
Receives block name, attribute, value and target post type; returns the new value.
Return values
array<string|int, mixed> —Blocks.
write_meta()
Save a post's meta. When overwriting (the About post), fields the package does not include are removed so the result matches the source.
private
write_meta(int $post_id, string $type, array<string|int, mixed> $meta, bool $overwrite) : void
Parameters
- $post_id : int
-
Post ID.
- $type : string
-
Post type.
- $meta : array<string|int, mixed>
-
Meta key => value.
- $overwrite : bool
-
Whether an existing post is being replaced.