Skip to content

Commit

Permalink
Ensure we avoid running our update functionality multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
dkotter committed Jan 31, 2024
1 parent 36aac2d commit 28381c8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions includes/Classifai/Features/DescriptiveTextGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ public function maybe_rescan_image( int $attachment_id ) {
$result = $this->run( $attachment_id, 'descriptive_text' );

if ( $result && ! is_wp_error( $result ) ) {
// Ensure we don't re-run this when the attachment is updated.
remove_action( 'edit_attachment', [ $this, 'maybe_rescan_image' ] );
$this->save( $result, $attachment_id );
}
}
Expand Down
2 changes: 2 additions & 0 deletions includes/Classifai/Features/ImageTextExtraction.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ public function maybe_rescan_image( int $attachment_id ) {
$result = $this->run( $attachment_id, 'ocr' );

if ( $result && ! is_wp_error( $result ) ) {
// Ensure we don't re-run this when the attachment is updated.
remove_action( 'edit_attachment', [ $this, 'maybe_rescan_image' ] );
$this->save( $result, $attachment_id );
}
}
Expand Down
3 changes: 3 additions & 0 deletions includes/Classifai/Features/PDFTextExtraction.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ public function maybe_rescan_pdf( int $attachment_id ) {
* @param int $attachment_id The attachment ID.
*/
public function save( string $result, int $attachment_id ) {
// Ensure we don't re-run this when the attachment is updated.
remove_action( 'edit_attachment', [ $this, 'maybe_rescan_pdf' ] );

return wp_update_post(
[
'ID' => $attachment_id,
Expand Down

0 comments on commit 28381c8

Please sign in to comment.