Skip to content

Retry restore of offloaded images that previously failed rollback#1091

Merged
selul merged 8 commits into
developmentfrom
copilot/restore-offloaded-images-retry
Jul 9, 2026
Merged

Retry restore of offloaded images that previously failed rollback#1091
selul merged 8 commits into
developmentfrom
copilot/restore-offloaded-images-retry

Conversation

Copilot AI commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Failed rollbacks tag attachments with optimole_rollback_error, and the rollback selection query excludes tagged attachments. Because the clear-errors path only removed optimole_offload_error, retrying a restore silently skipped the images that had failed — potentially leaving them permanently unavailable locally. The offload flow already clears its error flags before retrying; the rollback flow did not.

Changes

  • inc/media_offload.php — Parametrized clear_offload_errors_meta() with an optional meta key (defaults to the offload-error key) and added clear_rollback_errors_meta() to delete optimole_rollback_error.
  • inc/rest.phpclear_offload_errors() clears rollback errors when the request action is rollback_images, offload errors otherwise.
  • assets/src/dashboard/utils/api.jsclearOffloadErrors() takes an action (default offload_images) forwarded as a query arg.
  • assets/src/dashboard/parts/connected/settings/OffloadMedia.jsonRollbackdMedia() awaits clearOffloadErrors('rollback_images') before syncing, mirroring the offload path.
  • inc/cli/cli_media.php — WP-CLI rollback clears rollback errors too, since it shares the rollback query.
  • tests/test-media.php — Added coverage: an offloaded attachment with optimole_rollback_error is excluded from rollback selection, then eligible again after clear_rollback_errors_meta().

Rollback flow, before → after

checkOffloadConflicts( async response => {
	if ( 0 === response.data.length ) {
		await clearOffloadErrors( 'rollback_images' ); // added: re-eligible failed items
		// ...saveSettings + callSync({ action: 'rollback_images' })
	}
});

Note: the dashboard JS change requires rebuilding assets/build/ (npm run build:dashboard); build artifacts are intentionally excluded from this diff.

Comment thread phpstan-baseline.neon Outdated
count: 1
path: inc/media_offload.php

-

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix this error @copilot

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6c9b1c5. The baseline entries were stale — both clear_offload_errors_meta() and clear_rollback_errors_meta() have @return int|bool PHPDoc, which satisfies PHPStan's missingType.return rule, so the ignore entries no longer matched. Removed both.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correction: the fix is in commit e837999.

Copilot AI changed the title [WIP] Fix restore of offloaded images to consider previously failed rollbacks Retry restore of offloaded images that previously failed rollback Jul 9, 2026
Copilot finished work on behalf of selul July 9, 2026 14:06
Copilot AI requested a review from selul July 9, 2026 14:06
Copilot finished work on behalf of selul July 9, 2026 14:10
@selul selul marked this pull request as ready for review July 9, 2026 18:44
@selul selul changed the base branch from master to development July 9, 2026 18:44
@pirate-bot

pirate-bot commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Plugin build for 5806d24 is ready 🛎️!

Copilot finished work on behalf of selul July 9, 2026 19:47
@selul selul merged commit ee0e523 into development Jul 9, 2026
10 of 12 checks passed
@selul selul deleted the copilot/restore-offloaded-images-retry branch July 9, 2026 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Restore offloaded images retry skips previously failed rollback items

3 participants