Skip to main content

GravityKit\GravityMigrate\Background\ExternalImportJobDriver

Imports a batch of forms from one external platform, one form at a time, across Foundation

scheduler task executions.

The batch's shape -- form list, provider, impersonated user -- travels as Foundation job data. Its per-form results do NOT, and must not: job data reaches the database through Action Scheduler's extended_args, a varchar(8000), and past 8,000 characters $wpdb->update() refuses the value, runs no query and logs nothing. A map of 145 outcomes crosses that at roughly the fiftieth form, so the checkpoint vanished in silence, taking the resume index with it, and every retry began again at the first form: one 145-form migration created 322 Gravity Forms while the job reported none. Job data therefore carries a count, and the results live in this batch's own option (\self::progress_option_name()), which has no such ceiling.

Since: %ver%

Source: src/Background/ExternalImportJobDriver.php:33

Details

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

Properties

PropertyTypeDescription
$gateway_overrideobject | nullTest seam: overrides the scheduler gateway run() resolves against.
$resolver_overridecallable | nullTest seam: overrides the importer resolver run() uses instead of resolving it from the

Methods

MethodDescription
set_gateway_for_testing()Sets the scheduler gateway a test wants run() to use.
set_resolver_for_testing()Sets the importer resolver a test wants run() to use instead of the real registry.
run()Runs one cooperative slice of a background external-import batch.
progress_option_name()Where this batch's per-form results live.
default_resolver()The default provider-slug-to-importer resolver: the registered importer for the slug, or

Method Reference

set_gateway_for_testing()

public static function set_gateway_for_testing( $gateway ): void

Sets the scheduler gateway a test wants run() to use.

Parameters

NameTypeDefaultDescription
$gatewayobject | nullScripted gateway double, or null to clear the override.

Returns

  • void

Since: %ver%

Source: src/Background/ExternalImportJobDriver.php:63

set_resolver_for_testing()

public static function set_resolver_for_testing( ?callable $resolver ): void

Sets the importer resolver a test wants run() to use instead of the real registry.

Parameters

NameTypeDefaultDescription
$resolvercallable | nullScripted resolver, or null to clear the override. Takes a provider slug and returns an ImporterInterface|null.

Returns

  • void

Since: %ver%

Source: src/Background/ExternalImportJobDriver.php:77

run()

public static function run( array $args=[], $job_data=null )

Runs one cooperative slice of a background external-import batch.

Impersonates the user who scheduled the job, resolves the batch's importer once, then imports remaining forms one at a time -- recording a result for each and continuing past a single form's failure -- until the list is exhausted or the scheduler's time budget for this task execution runs out.

Parameters

NameTypeDefaultDescription
$argsarray[]Task args. index is the position to resume from.
$job_dataarray | nullnullShared job data: provider, form_ids, user_id, results.

Returns

  • mixed — The gateway's checkpoint/completion result.

Throws

  • Exception — When the job data is missing what the batch needs to run, or the batch's importer cannot be resolved.

Since: %ver%

Source: src/Background/ExternalImportJobDriver.php:99

progress_option_name()

public static function progress_option_name( int $job_id ): string

Where this batch's per-form results live.

Not in the job's own data. Foundation persists job data through Action Scheduler, which stores the whole blob in extended_args, a varchar(8000). Past 8,000 characters wpdb::process_fields() refuses the value and returns false without running a query and without logging anything, so the checkpoint loses both the results and the resume index in silence. The retry restarts at the first form and imports the batch again: a 145-form migration produced 322 Gravity Forms this way, while the job reported none.

One option per batch, because batches take no lock and several run at once. A single shared row would mean the last writer erased the only copy of the other's results.

Parameters

NameTypeDefaultDescription
$job_idintThe batch's job instance id.

Returns

  • string

Since: %ver%

Source: src/Background/ExternalImportJobDriver.php:259

default_resolver()

public static function default_resolver( string $provider ): ?ImporterInterface

The default provider-slug-to-importer resolver: the registered importer for the slug, or

null when the slug is unregistered.

Parameters

NameTypeDefaultDescription
$providerstringProvider slug.

Returns

  • ImporterInterface | null

Since: %ver%

Source: src/Background/ExternalImportJobDriver.php:418