Cybo Advanced Field EngineCyboweb Technologies · Documentation · v1.0.2

cafe_validate_field_group_import()

Purpose

Checks a CAFE export file and reports what cafe_import_field_groups() would do, without writing anything (a dry run). The Check file step in CAFE → Tools → Import uses it.

Syntax

cafe_validate_field_group_import( array|string $data, string $mode = 'upsert' ): Cybo\AdvancedFieldEngine\Tools\ImportResult

Parameters

Parameter Type Default Description
$data string|array - The JSON text of an export file, or the decoded document.
$mode string 'upsert' 'create', 'update' or 'upsert', as for the import.

Return value

An Cybo\AdvancedFieldEngine\Tools\ImportResult describing the planned changes (created, updated, skipped with reasons), warnings and errors. to_array()['dry_run'] is true.

Example

$preview = cafe_validate_field_group_import( $json, 'update' );

foreach ( $preview->errors() as $error ) {
	printf( "%s: %s\n", $error['path'], $error['message'] );
}

printf(
	"%d fields would be updated.\n",
	$preview->to_array()['summary']['updated']['fields']
);

Notes

  • Uses exactly the same rules as the import, so a clean preview means the import will succeed. The one exception is a conflict that only appears while writing fields one by one, such as two fields swapping names. Then the import is rolled back as a whole.
  • Nothing is written, no hooks run, and no caches change.