Skip to main content

GravityKit\GravityMigrate\Background\BackgroundController

Decides, for each migration request, whether to hand it to the Foundation scheduler or leave

it on the synchronous path, and answers the status/cancel routes the UI polls once a job is running.

Import and Export register their own routes; this class registers on the same Foundation AJAX route filters at a later priority and decorates the routes it cares about. When the scheduler is unavailable every request falls through to the synchronous path.

Since: %ver%

Source: src/Background/BackgroundController.php:32

Details

  • Kind: class
  • Namespace: GravityKit\GravityMigrate\Background

Methods

MethodDescription
get_instance()Returns class instance.
__construct()Constructor.
import_routes()Adds the import-side background routes to whatever gk_importer routes already exist.
export_routes()Adds the export-side background routes to whatever gk_exporter routes already exist.
active_import_job_id()The id of the background import job a page or repeat request should reattach to,
active_export_job_id()The id of a background export still running, or 0.
active_external_import()The background platform migration this user may watch, or null when none is running.
background_export_is_active()Whether a background export still legitimately owns {@see Options::EXPORT_RECORD}.

Method Reference

get_instance()

public static function get_instance(): BackgroundController

Returns class instance.

Returns

  • BackgroundController

Since: %ver%

Source: src/Background/BackgroundController.php:202

__construct()

public function __construct( $gateway=null, ?Util $util=null )

Constructor.

Both parameters stay untyped so a duck-typed stand-in can be injected: \SchedulerGateway is final, and Util's constructor bootstraps WP_Filesystem.

Parameters

NameTypeDefaultDescription
$gatewaymixednullA \SchedulerGateway, or a stand-in exposing its public methods.
$utilUtil | nullnullDefaults to Util::get_instance().

Since: %ver%

Source: src/Background/BackgroundController.php:221

import_routes()

public function import_routes( array $routes ): array

Adds the import-side background routes to whatever gk_importer routes already exist.

Parameters

NameTypeDefaultDescription
$routesarrayRoutes already registered by \GravityKit\GravityMigrate\Import::ajax_routes().

Returns

  • array

Since: %ver%

Source: src/Background/BackgroundController.php:235

export_routes()

public function export_routes( array $routes ): array

Adds the export-side background routes to whatever gk_exporter routes already exist.

Parameters

NameTypeDefaultDescription
$routesarrayRoutes already registered by \GravityKit\GravityMigrate\Export::ajax_routes().

Returns

  • array

Since: %ver%

Source: src/Background/BackgroundController.php:303

active_import_job_id()

public function active_import_job_id(): int

The id of the background import job a page or repeat request should reattach to,

or 0 when none is active.

"Active" means the job's scheduler instance is pending, running, or paused. A terminal instance — or a stale BG_IMPORT_STATE option left behind by one — reports 0, so a finished migration never hijacks a fresh page load.

Returns

  • int

Since: %ver%

Source: src/Background/BackgroundController.php:366

active_export_job_id()

public function active_export_job_id(): int

The id of a background export still running, or 0.

The export twin of \self::active_import_job_id(): a page load consults it so a reload during a long export reattaches to the run rather than rendering an idle Export button beside a migration that is still going.

Returns

  • int

Since: %ver%

Source: src/Background/BackgroundController.php:381

active_external_import()

public function active_external_import(): ?array

The background platform migration this user may watch, or null when none is running.

Import and export are each found through the state option they write, so a page that was not open when the run started can still ask about them by id. An external batch writes no such option -- everything it needs lives in its own job data -- so its id lives only in the page that started it, and a reload throws it away.

The scheduler's own list of live instances stands in for the missing option, filtered by \self::current_user_owns_job() -- the same predicate the status and cancel routes gate on. Answering with anything broader would name a run those routes then refuse to report on, and would put a Cancel button for somebody else's migration on this page.

Returns

  • array{jobId: — int, provider: string, formIds: array, formCount: int}|null

Since: %ver%

Source: src/Background/BackgroundController.php:402

background_export_is_active()

public function background_export_is_active(): bool

Whether a background export still legitimately owns {@see Options::EXPORT_RECORD}.

The export-side twin of \GravityKit\GravityMigrate\Import::background_import_is_active(), with the same two-tier answer: the scheduler itself when the gateway can reach it (paused counts as active -- a paused export's record is still live), and a staleness window on the state option's own heartbeat when it cannot. An orphaned state option past the window is deleted so it cannot refuse every later export.

Returns

  • bool

Since: %ver%

Source: src/Background/BackgroundController.php:529