Closes #922: Add bulk-restore WP-CLI command#1087
Conversation
Up to standards ✅🟢 Issues
|
| Category | Results |
|---|---|
| UnusedCode | 1 medium |
🟢 Metrics 32 complexity · 0 duplication
Metric Results Complexity 32 Duplication 0
🟢 Coverage 52.44% diff coverage
Metric Results Coverage variation Report missing for 9b42eaa1 Diff coverage ✅ 52.44% diff coverage (50.00%) Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (9b42eaa) Report Missing Report Missing Report Missing Head commit (260ac4a) 18639 284 1.52% Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#1087) 164 86 52.44% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%1 Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Adds `wp imagify restore [<contexts>...]` WP-CLI subcommand. Restores all
optimized images synchronously (no ActionScheduler), calling
imagify_get_optimization_process()->restore() per eligible image and reporting
per-context counts (restored / errors / total) via WP_CLI messages.
- RestoreCommand: library/custom-folders contexts (default: all), CONTEXT_MAP,
WP_CLI::success/warning/error based on outcome
- Bulk::run_restore(): synchronous loop, returns {success, message, restored,
errors, total}; ActionScheduler hook removed
- BulkInterface: add get_optimized_media_ids(): array
- WP, CustomFolders: real DB query filtering to IDs with backup on disk
- Noop, NGG: explicit get_optimized_media_ids() returning []
- AbstractBulk: default method removed (each class must implement explicitly)
- RestoreCommandTest: 8 unit tests with WP_CLI capture fixture
- Tests/Unit/bootstrap.php: remove references to deleted filesystem stubs
- docs/api/wp-cli.md: full command reference for wp imagify restore
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
78fa0f9 to
e5fcd29
Compare
…ized_media_ids() Return type must match BulkInterface::get_optimized_media_ids(): array. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…unused \$options Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Note
This pull request was generated by the AI delivery pipeline (Claude Sonnet 4.6). Review carefully before merging.
Description
Fixes #922
Adds
wp imagify restore [<contexts>...]WP-CLI subcommand. When a large number of images need to be restored (e.g. before switching compression level), the media library bulk-restore UI is impractical for operators. This command restores optimized media synchronously, printing per-context counts (restored / errors / total) and a final success or warning message.Type of change
Detailed scenario
What was tested
Automated unit tests in
Tests/Unit/classes/CLI/RestoreCommandTest.phpcover:libraryandcustom-folderscontexts and emitsWP_CLI::success().libraryargument maps to internalwpcontext.custom-foldersis passed through as-is.WP_CLI::warning()emitted, no success.WP_CLI::error()emitted with the bad value, command aborts.WP_CLI::warning()emitted instead of success.get_name()returnsimagify restore.get_synopsis()has one optional repeatingcontextspositional arg.32 unit tests, 81 assertions — all pass, 0 errors.
How to test
wp imagify restore— restores both contexts, prints counts, emits success.wp imagify restore library— restores WordPress media library only.wp imagify restore custom-folders— restores custom-folders only.WP_CLI::warning()instead of success.wp imagify restore invalid— should print an error withinvalidin the message.Affected Features & Quality Assurance Scope
wp imagifyroot command)Imagify\Bulk\Bulk::run_restore()— rewritten to synchronous)Imagify\Bulk\WPandImagify\Bulk\CustomFolders— newget_optimized_media_ids()implementationImagify\Bulk\NoopandNGG— explicitget_optimized_media_ids(): arrayreturning[]Imagify\Bulk\BulkInterface—get_optimized_media_ids(): arrayadded to interfaceimagify_restore_mediahook removed fromBulk::init()Technical description
Documentation
docs/api/wp-cli.mdupdated with full command reference forwp imagify restore, including arguments, examples, behaviour, andget_optimized_media_ids()context implementations.New dependencies
None.
Risks
Restore is a local filesystem operation (swap optimized file with backup). No API quota cost. No new async jobs or external calls introduced.
Mandatory Checklist
Code validation
Code style
Unticked items justification
Type of change: only "New feature" applies — this is a net-new WP-CLI subcommand with no existing behaviour changed or fixed.
Additional Checks