Skip to content

Commit 517af08

Browse files
authored
Merge pull request #677 from 10up/fix/623
Ensure we don't run updates more than once
2 parents 36aac2d + e6073d5 commit 517af08

File tree

5 files changed

+9
-4
lines changed

5 files changed

+9
-4
lines changed

includes/Classifai/Features/DescriptiveTextGenerator.php

+2
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ public function maybe_rescan_image( int $attachment_id ) {
263263
$result = $this->run( $attachment_id, 'descriptive_text' );
264264

265265
if ( $result && ! is_wp_error( $result ) ) {
266+
// Ensure we don't re-run this when the attachment is updated.
267+
remove_action( 'edit_attachment', [ $this, 'maybe_rescan_image' ] );
266268
$this->save( $result, $attachment_id );
267269
}
268270
}

includes/Classifai/Features/ImageCropping.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,8 @@ public function attachment_data_meta_box_content() {
295295
* @param int $attachment_id Attachment ID.
296296
*/
297297
public function maybe_crop_image( int $attachment_id ) {
298-
$metadata = wp_get_attachment_metadata( $attachment_id );
299-
300298
if ( clean_input( 'rescan-smart-crop' ) ) {
301-
$result = $this->run( $attachment_id, 'crop', $metadata );
299+
$result = $this->run( $attachment_id, 'crop' );
302300

303301
if ( ! empty( $result ) && ! is_wp_error( $result ) ) {
304302
$meta = $this->save( $result, $attachment_id );

includes/Classifai/Features/ImageTextExtraction.php

+2
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ public function maybe_rescan_image( int $attachment_id ) {
301301
$result = $this->run( $attachment_id, 'ocr' );
302302

303303
if ( $result && ! is_wp_error( $result ) ) {
304+
// Ensure we don't re-run this when the attachment is updated.
305+
remove_action( 'edit_attachment', [ $this, 'maybe_rescan_image' ] );
304306
$this->save( $result, $attachment_id );
305307
}
306308
}

includes/Classifai/Features/PDFTextExtraction.php

+3
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ public function maybe_rescan_pdf( int $attachment_id ) {
211211
* @param int $attachment_id The attachment ID.
212212
*/
213213
public function save( string $result, int $attachment_id ) {
214+
// Ensure we don't re-run this when the attachment is updated.
215+
remove_action( 'edit_attachment', [ $this, 'maybe_rescan_pdf' ] );
216+
214217
return wp_update_post(
215218
[
216219
'ID' => $attachment_id,

includes/Classifai/Providers/Azure/ComputerVision.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ public function rest_endpoint_callback( $attachment_id, string $route_to_call =
723723

724724
$metadata = wp_get_attachment_metadata( $attachment_id );
725725

726-
if ( ! $metadata ) {
726+
if ( ! $metadata || ! is_array( $metadata ) ) {
727727
return new WP_Error( 'invalid', esc_html__( 'No valid metadata found.', 'classifai' ) );
728728
}
729729

0 commit comments

Comments
 (0)