Skip to content

Commit 365d9e8

Browse files
authored
Merge pull request #873 from Codeinwp/feat/force-reoffload
- feat: force reoffload
2 parents 1eb28b3 + 1712feb commit 365d9e8

File tree

5 files changed

+50
-8
lines changed

5 files changed

+50
-8
lines changed

assets/src/dashboard/parts/components/Modal.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default function Modal({ icon, labels = {}, onRequestClose = () => {}, on
1212
'bg-stale-yellow': 'warning' === variant,
1313
'bg-light-blue': 'default' === variant
1414
},
15-
'p-3 rounded-full'
15+
'p-2 rounded-full flex items-center justify-center'
1616
);
1717

1818
const actionButtonClasses = classnames(
@@ -37,11 +37,12 @@ export default function Modal({ icon, labels = {}, onRequestClose = () => {}, on
3737
/>
3838

3939
<div className="flex flex-col items-center">
40-
<Icon
41-
icon={ icon }
42-
size={ 24 }
43-
className={iconClasses}
44-
/>
40+
<span className={iconClasses}>
41+
<Icon
42+
icon={ icon }
43+
size={ 24 }
44+
/>
45+
</span>
4546

4647
<h2
4748
className="mb-0"

assets/src/dashboard/parts/connected/settings/OffloadMedia.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { useDispatch, useSelect } from '@wordpress/data';
66
import { Icon } from '@wordpress/icons';
77

88
import { warning, rollback as rollbackIcon, offload, warningAlt, sync } from '../../../utils/icons';
9-
import { callSync, checkOffloadConflicts, saveSettings } from '../../../utils/api';
9+
import { callSync, clearOffloadErrors, checkOffloadConflicts, saveSettings } from '../../../utils/api';
1010
import Notice from '../../components/Notice';
1111
import RadioBoxes from '../../components/RadioBoxes';
1212
import ProgressTile from '../../components/ProgressTile';
@@ -113,7 +113,9 @@ const OffloadMedia = ({ settings, canSave, setSettings, setCanSave }) => {
113113
}, []);
114114

115115

116-
const onOffloadMedia = ( imageIds = []) => {
116+
const onOffloadMedia = async( imageIds = []) => {
117+
await clearOffloadErrors();
118+
117119
const nextSettings = { ...settings };
118120
nextSettings['show_offload_finish_notice'] = '';
119121
nextSettings['offloading_status'] = 'enabled';

assets/src/dashboard/utils/api.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,17 @@ export const callSync = ( data ) => {
592592
});
593593
};
594594

595+
export const clearOffloadErrors = async() => {
596+
try {
597+
return await apiFetch({
598+
path: optimoleDashboardApp.routes['clear_offload_errors'],
599+
method: 'GET'
600+
});
601+
} catch ( error ) {
602+
console.log( error );
603+
}
604+
};
605+
595606
export const addNotice = ( text ) => {
596607
createNotice(
597608
'info',

inc/media_offload.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2754,4 +2754,18 @@ private function get_offloaded_attachment_url( $attachment_id, $url ) {
27542754

27552755
return $url;
27562756
}
2757+
2758+
/**
2759+
* Cleanup the offload errors meta.
2760+
*/
2761+
public static function clear_offload_errors_meta() {
2762+
global $wpdb;
2763+
2764+
return $wpdb->query(
2765+
$wpdb->prepare(
2766+
"DELETE FROM {$wpdb->postmeta} WHERE meta_key = %s",
2767+
self::META_KEYS['offload_error']
2768+
)
2769+
);
2770+
}
27572771
}

inc/rest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class Optml_Rest {
7878
],
7979
'media_cloud_routes' => [
8080
'number_of_images_and_pages' => 'POST',
81+
'clear_offload_errors' => 'GET',
8182
'get_offload_conflicts' => 'GET',
8283
],
8384
'watermark_routes' => [
@@ -867,6 +868,19 @@ public function number_of_images_and_pages( WP_REST_Request $request ) {
867868
return $this->response( Optml_Media_Offload::get_image_count( $action, $refresh, $images ) );
868869
}
869870

871+
/**
872+
* Clear the offload errors from previous offload attempts.
873+
*
874+
* @param WP_REST_Request $request Rest request object.
875+
*
876+
* @return WP_REST_Response
877+
*/
878+
public function clear_offload_errors( WP_REST_Request $request ) {
879+
$delete_count = Optml_Media_Offload::clear_offload_errors_meta();
880+
881+
return $this->response( [ 'success' => $delete_count ] );
882+
}
883+
870884
/**
871885
* Get conflicts list.
872886
*

0 commit comments

Comments
 (0)