Reference Omeka Classic plugin

Classes and Jobs

The plugin's classes are in src/, under the ResourceVersioning\ namespace, loaded by the plugin's autoloader. Other plugins and scripts can use them once Omeka has loaded its plugins.

Classes

ResourceVersioning\VersionStore

The history table.

Method Description
get(int $versionId): ?array One version, with snapshot decoded and record_exists
latest(string $type, int $id): ?array A record's newest version
predecessor(array $version): ?array The version before a version
versionBefore(string $type, int $id, string $cutoff): ?array The newest version made before $cutoff (UTC, Y-m-d H:i:s), or the record's baseline
listForRecord(string $type, int $id, int $limit = 50, int $offset = 0): array A record's versions, newest first, without snapshots
listAll(array $filters = []), countAll(array $filters = []) Every version; filters record_type, record_id, user_id, operation, batch_key, is_batch, date_from, date_to (UTC), limit, offset
listBatchGroups(array $filters = []) Bulk operations: one row per batch key, with counts and times
affectedRecords(array $criteria): array The records with a version matching the criteria
recreations(string $type, int $id): array The records recreated from a deleted record's versions
insert(string $type, int $id, array $snapshot, string $hash, string $operation, array $meta = []): array Store a version; meta: user, is_batch, restored_from
pruneRecord(string $type, int $id, int $max): int Keep a record's newest $max versions
pruneByAge(int $days, int $batchSize = 1000): int Delete one batch of versions older than $days
batchKey(): string The batch key of this request or process

Record types are item, collection and file; operations are the constants OPERATION_CREATE, OPERATION_UPDATE, OPERATION_DELETE, OPERATION_RESTORE and OPERATION_BASELINE.

ResourceVersioning\Snapshotter

Method Description
build(string $type, int $id, bool $forDelete = false): ?array A record's snapshot, read from the database, or null when it does not exist
hash(array $snapshot): string The hash that tells states apart
title(array $snapshot): string The record's title in a snapshot
typeOf($record): ?string item, collection, file or null for a record object

ResourceVersioning\RestoreService

Method Description
prepare(array $version, bool $recreating = false): array What applying a version will do: snapshot (with dropped references removed), texts (by element id) and warnings
restore(int $versionId, bool $allowRecreate = false, array $context = []): array Restore a version, or recreate its deleted record when allowed. Returns success, message, warnings, record_id, version_id, and unchanged or recreated
rollbackPlan(array $criteria): array The dry run: cutoff and targets, each with record_type, record_id, record_exists, action (restore, recreate, skip), skip_reason and target
rollback(array $criteria, array $context = [], ?callable $progress = null): array Run a plan; returns the counts total, restored, recreated, unchanged, skipped, failed and up to 100 errors

Criteria: batch_key, or date_from (UTC) with optionally date_to; and optionally user_id, record_type, recreate_deleted. Permission checks are the caller's: the admin pages use ResourceVersioning\Access.

ResourceVersioning\Diff\SnapshotDiff and TextDiff

SnapshotDiff::compare(array $old, array $new, ?callable $labels = null): array returns has_changes, fields, elements and summary. SnapshotDiff::toText(array $snapshot) gives the canonical JSON that TextDiff::diff() and TextDiff::toHtml() compare line by line.

Jobs

Both are Omeka jobs, started with sendLongRunning(), and record their progress in resource_version_runs.

ResourceVersioning\Job\BatchRollback

Option run_id: a resource_version_runs row of type rollback, whose criteria it runs with RestoreService::rollback(), as the user who started it. To start one from code:

$runId = ResourceVersioning\RunStore::create('rollback', ['batch_key' => $key], current_user());
Zend_Registry::get('bootstrap')->getResource('jobs')
    ->sendLongRunning('ResourceVersioning\Job\BatchRollback', ['run_id' => $runId]);

ResourceVersioning\Job\Prune

Option run_id (a row of type prune). Deletes the versions older than the retention period, 1,000 at a time, and does nothing when no period is set.

Audit Trail

When the Audit Trail plugin is installed, the plugin reports to it through the audit_trail_log hook (nothing happens without it):

Action Resource type When
item.restore, collection.restore, file.restore item, collection, file A version was restored (data: version_id, version_num, new_version_id, warnings, and rollback_run for a rollback's restores)
item.recreate, collection.recreate item, collection A deleted record was recreated (the new record's id; data: deleted_id, version_id)
version_rollback.run version_rollback A batch rollback finished (the run's id; data: criteria, counts, errors)
version_prune.run version_prune A prune finished (data: deleted, days)

The saves themselves are logged by Audit Trail as usual.

Settings

The Omeka options resource_versioning_enabled, resource_versioning_record_types (a JSON list), resource_versioning_capture_batch, resource_versioning_max_versions, resource_versioning_retention_days and resource_versioning_restore_owner, read through ResourceVersioning\Settings.

Log in for Support