Skip to content

Allow WP-CLI wp optimole media rollback_images command to execute when offload_media is set to rollback state #1161

Description

@pirate-bot

Status (2026-10-11)

Fixed in PR #1173 (bugfix/1161 → development, approved by pirate-bot at 0e438a7d).

  • Fix: wp optimole media rollback_images now runs while a rollback started from the dashboard is in progress, so it can finish a rollback that WP-Cron cannot. It is still refused when Image Storage is off and no rollback was started. The offload limit no longer stops a rollback.
  • Added for safety: the command and the background transfer never move images at the same time (a database lock). If a background step is moving images at that moment, the command stops with "Another image transfer is running. Wait for it to finish, then run this command again."
  • Tests: the real command, run with Image Storage off and a rollback in progress; the lock, held from a second database connection. They fail on development.
  • Live check: on a local site that is not connected to Optimole, the command is no longer refused, and it is refused while a second process holds the lock.
  • Not proven: a full rollback with the command on a connected site with offloaded images.

Impact: 75 · Confidence: 95 · Complexity: 30

Description

  1. Problem: When a site administrator initiates an image transfer/rollback from the plugin dashboard ('Transfer back from Optimole'), Optimole sets the plugin storage mode to rollback, which stores the offload_media setting option as disabled. If the administrator or host then attempts to run the command-line rollback tool (wp optimole media rollback_images), the WP-CLI command throws an error: Error: You need to have the offload_media option enabled in order to use this command and aborts.
  2. Desired behavior: WP-CLI's wp optimole media rollback_images command should check whether a rollback is currently active or in progress (or allow execution if offload_media is disabled due to an ongoing rollback state), rather than strictly requiring offload_media to be enabled.
  3. Acceptance Criteria:
  • Running wp optimole media rollback_images succeeds when an image rollback operation has been initiated from the dashboard (where offload_media is disabled or set to rollback mode).
  • The CLI command only rejects execution if no offloaded images exist or if offload media was never configured/active.

Customer Context

The customer needed to roll back 11,000+ offloaded images. The background WP-Cron process stalled due to server cron restrictions. When support instructed the customer and host to run wp optimole media rollback_images via SSH/terminal, the WP-CLI command failed because selecting 'Transfer back from Optimole' in the plugin dashboard had set offload_media to disabled.

Root Cause Analysis

The customer needed to restore offloaded media back to the local WordPress Media Library. The plugin's UI dashboard action 'Transfer back from Optimole' sets the plugin's offload storage mode to rollback, which sets the offload_media option value to disabled. When background WP-Cron stalled and support instructed the host to run wp optimole media rollback_images via WP-CLI, the CLI command failed because it enforces a strict check requiring offload_media to be enabled before initiating or resuming a rollback. The root cause is a workflow/validation contradiction in the plugin code: initiating a rollback in UI turns off offload_media, but the CLI command requires offload_media to be enabled.

Alternative Suggestions

Relax or adjust the option check in Optml_Media_Offload / WP-CLI rollback command handler so that wp optimole media rollback_images checks whether offloaded images exist or whether storage mode is in rollback state, rather than strictly asserting offload_media == enabled.

Reasoning

The customer experienced a failure running the CLI rollback command wp optimole media rollback_images because selecting 'Transfer back from Optimole' in the WordPress admin dashboard saved the storage mode as rollback, which updated offload_media option to disabled. Consequently, when attempting to run wp optimole media rollback_images via CLI as recommended for reliable or large background operations, WP-CLI halts with Error: You need to have the offload_media option enabled in order to use this command. The CLI rollback command should automatically permit execution when offload_media is in a rollback state or automatically bypass this option check during a rollback operation.


Source: HelpScout #3456031569
Generated by feature-request-triage workflow (ID: feature-request-triage_6ab502db326f90.60727165)

Activity

  1. self-assigned this
    on Oct 9, 2026
  2. milicavs commented on Oct 11, 2026

    @milicavs

    🧪 QA steps and test sandbox

    When Transfer back from Optimole is started in the dashboard but the background transfer stalls (for example on a host where WP-Cron doesn't run), the WP-CLI command wp optimole media rollback_images can't finish it: it refuses to run with "You need to have the offload_media option enabled in order to use this command".

    Requires: your own Optimole account (API key) with Image Storage, and a terminal on the sandbox for WP-CLI (SSH, from the sandbox's page in SandyWP).

    Step Build Bot check
    Reproduce the bug Optimole 4.2.16 (released) ✅ Reproduced: with a rollback in progress, the command stopped with the offload_media error
    Verify the fix PR #1173 build 0e438a7 ✅ Fixed: the same command ran and printed "All images have been uploaded to your media library"; it is still refused when no rollback was started

    On the sandbox:

    • https://qa-optimole-wp-1161.s1-sandywp.com runs the release. Sign in to SandyWP and use the sandbox's Auto Login.
    • WP-Cron is turned off, like the customer's host, so a transfer started from the dashboard never moves on its own.
    • The Media Library already has three 1600px images to offload.
    • Tools → QA Logs shows debug.log, which the public site can't read.
    • If it has stopped after a day without use, the next qa-playground run brings it back.
    • The bot had no Optimole account: it set the "rollback in progress" state directly and had no offloaded images to move.

    Reproduce on Optimole 4.2.16:

    1. Optimole → connect with your API key.
    2. Optimole → Settings → Image Storage: turn on offloading.
    3. In the terminal, run wp optimole media move_to_optimole (the dashboard's offload can't run without WP-Cron).
    4. Back in Image Storage, click Transfer back from Optimole. The progress stays at 0%.
    5. In the terminal, run wp optimole media rollback_images.
    • Bug: Error: You need to have the offload_media option enabled in order to use this command, and the images stay on Optimole.

    Verify the fix on the same sandbox:

    1. Download the PR build above, then go to Plugins → Add New Plugin → Upload Plugin and click Replace current with uploaded.
    2. Repeat the steps above from step 2.
    • Fixed: the command shows a progress bar and ends with "All images have been uploaded to your media library". Each image's File URL in Media → Library is back on /wp-content/uploads/…. Plugins still shows 4.2.16, since the build has no version bump.
    Edge cases
    • Image Storage off and no transfer started: rollback_images is still refused with the offload_media error.
    • move_to_optimole while a transfer back is in progress: still refused.
    • Account at its offload limit: rollback_images still runs (only offloading stops at the limit).
    • Run the command twice at once in two terminals: the second stops with "Another image transfer is running. Wait for it to finish, then run this command again.", and no image gets a -1 copy in uploads.

    Fix: #1173 (open)

  3. pirate-bot commented on Oct 11, 2026

    @pirate-bot
    CollaboratorAuthor

    QA agent — 🟢 Passing checks · WP-CLI completes dashboard-started rollbacks without duplicate restores in the tested scenarios.

    With a seeded Optimole account and mocked cloud responses, the candidate resumed dashboard-started rollback and restored all 11,001 lightweight image fixtures. The base build rejected the same stalled-rollback state. Quota checks and competing command/background transfers behaved as expected, with no duplicate files. All six outcomes and the PR’s 17 added tests passed; live-account and distributed-database coverage remain follow-ups.

    Worth a human look

    1. Repeat rollback with a real Optimole Image Storage account and the customer’s full-resolution 11,000+ media library.
    2. Exercise transfer locking on real HyperDB/LudicrousDB and multi-primary database deployments.
    3. Try bulk transfers on a database driver without advisory-lock support; the PR’s simulated fallback test passed here.
    4. Check simultaneous single-image moves and bulk rollback; the code review notes that the unchanged single-image path does not take this new lock.
    Checks (6 passed)
    • ✅ Starting Transfer back from Optimole in Image Storage with WP-Cron disabled persists offload_media=disabled and an active rollback, with the transfer still at 0%.
    • ✅ wp optimole media rollback_images shows progress and finishes with All images have been uploaded to your media library after dashboard-started rollback, including at the offload limit and in the reported 11,000+ image scenario.
    • ✅ After the command completes, every selected image is restored to wp-content/uploads and its Media Library File URL is local, with no offloaded metadata remaining.
    • ✅ An active image-moving lock refuses the command with Another image transfer is running. Wait for it to finish, then run this command again.; a merely scheduled or ended worker does not prevent rollback.
    • ✅ Competing command and background rollback attempts restore each image once, with no -1 copies in wp-content/uploads; skipped background steps move and schedule nothing while the moving lock is held.
    • ✅ With Image Storage off and no rollback active the command refuses with the offload_media error; move_to_optimole remains refused during rollback and stops at the account offload limit.

    Full report, evidence and session trail

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions