Plugin Directory

Changeset 3417465


Ignore:
Timestamp:
12/11/2025 02:25:56 PM (4 months ago)
Author:
slimndap
Message:

1.33

Location:
jeero/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • jeero/trunk/Jeero.php

    r3355603 r3417465  
    66 * Author:          Slim & Dapper
    77 * Author URI:      https://slimndap.com
    8  * Version:         1.32.1
     8 * Version:         1.33
    99 * Text Domain:     jeero
    1010 *
     
    3232add_action( 'init', function() {
    3333
    34     define( 'Jeero\VERSION', '1.32.1' );
     34    define( 'Jeero\VERSION', '1.33' );
    3535    define( 'Jeero\PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
    3636    define( 'Jeero\PLUGIN_URI', plugin_dir_url( __FILE__ ) );
  • jeero/trunk/includes/Helpers/Images.php

    r3056977 r3417465  
    1616 */
    1717const JEERO_IMG_REF_FIELD = 'jeero/img/url';
     18
     19/**
     20 * Stores the last downloaded URL for an image ref.
     21 *
     22 * @since 1.33
     23 *
     24 * @var string
     25 */
     26const JEERO_IMG_SOURCE_URL_FIELD = 'jeero/img/source_url';
    1827
    1928/**
     
    123132 *
    124133 * @since   1.26
     134 * @since   1.33    Re-downloads when the URL changes for the same ref, stores source URL meta, and replaces outdated attachments.
    125135 *
    126136 * @param   array           $structured_image
     
    129139 */
    130140function add_structured_image_to_library( $structured_image, $post_id ) {
    131    
    132     if ( $thumbnail_id = get_existing_thumbnail_for_structured_image( $structured_image ) ) {
    133         return $thumbnail_id;
    134     }       
     141
     142    $existing_thumbnail_id = get_existing_thumbnail_for_structured_image( $structured_image );
     143
     144    if ( $existing_thumbnail_id ) {
     145        $stored_url = \get_post_meta( $existing_thumbnail_id, JEERO_IMG_SOURCE_URL_FIELD, true );
     146
     147        if ( ! empty( $structured_image['url'] ) && $stored_url === $structured_image['url'] ) {
     148            // Ensure future checks have the URL stored, even for legacy attachments.
     149            if ( empty( $stored_url ) ) {
     150                \update_post_meta( $existing_thumbnail_id, JEERO_IMG_SOURCE_URL_FIELD, $structured_image['url'] );
     151            }
     152            return $existing_thumbnail_id;
     153        }
     154    }
    135155
    136156    require_once( ABSPATH . 'wp-admin/includes/media.php' );
     
    167187    // Store original URL with image.
    168188    \update_post_meta( $thumbnail_id, JEERO_IMG_REF_FIELD, $structured_image[ 'ref' ] );
     189    \update_post_meta( $thumbnail_id, JEERO_IMG_SOURCE_URL_FIELD, $structured_image[ 'url' ] );
     190
     191    if ( $existing_thumbnail_id && $thumbnail_id !== $existing_thumbnail_id ) {
     192        // Remove outdated attachment so the new download becomes the canonical image for this ref.
     193        \wp_delete_attachment( $existing_thumbnail_id, true );
     194    }
    169195   
    170196    return $thumbnail_id;
  • jeero/trunk/includes/Inbox/Inbox.php

    r3296592 r3417465  
    2222
    2323const PICKUP_ITEMS_HOOK = 'jeero\inbox\pickup_items';
     24const PROCESSING_ITEM_MARKER_PREFIX = 'jeero_inbox_processing_item_';
    2425
    2526// Scheduling of the next pickup is handled centrally in Jeero.php bootstrap.
     
    145146function process_item( $item ) {
    146147   
     148    $is_item_blocking = is_item_blocking( $item );
     149    if ( $is_item_blocking ) {
     150        Logs\Log( sprintf( 'Skipping inbox item %s because a previous attempt is still marked as running.', $item['ID'] ?? 'unknown' ) );
     151        mark_process_item_ended( $item );
     152        return true;
     153    }
     154
     155    mark_process_item_start( $item );
     156
    147157    $action = $item[ 'action' ];
    148158    $theater = $item[ 'theater' ];
     
    283293        $subscription
    284294    );
     295
     296    mark_process_item_ended( $item );
    285297   
    286298    return $result;
     
    322334        }
    323335       
    324         $items_processed[] = $item;
    325        
    326336        $elapsed_time = microtime( true ) - $start_time;
    327337       
     
    366376
    367377/**
     378 * Marks an inbox item before processing attempt starts.
     379 *
     380 * Persist a marker in permanent storage (option/transient/DB key) before processing
     381 * begins so we can detect stuck items when processing is interrupted.
     382 *
     383 * @param array $item The inbox payload that is about to be processed.
     384 */
     385function mark_process_item_start( $item ) {
     386    $key = get_processing_marker_key( $item );
     387    if ( $key === '' ) {
     388        return;
     389    }
     390
     391    \set_transient( $key, true, 0 );
     392}
     393
     394/**
     395 * Clears the processing attempt marker after processing successfully ended.
     396 *
     397 * When processing completes without fatal issues, this helper removes the marker
     398 * so the inbox item is not treated as blocking in future runs.
     399 *
     400 * @param array $item The inbox payload that finished processing.
     401 */
     402function mark_process_item_ended( $item ) {
     403    $key = get_processing_marker_key( $item );
     404    if ( $key === '' ) {
     405        return;
     406    }
     407
     408    \delete_transient( $key );
     409}
     410
     411/**
     412 * Checks if an inbox item triggered a blocking error during its previous processing attempt.
     413 *
     414 * This should return true when the marker set by {@link mark_process_item_start()}
     415 * is still present because processing failed before {@link mark_process_item_ended()}
     416 * could run.
     417 *
     418 * @param array $item The inbox payload to inspect.
     419 * @return bool True when the item is considered blocking, false otherwise.
     420 */
     421function is_item_blocking( $item ) {
     422    $key = get_processing_marker_key( $item );
     423    if ( $key === '' ) {
     424        return false;
     425    }
     426
     427    return \false !== \get_transient( $key );
     428}
     429
     430function get_processing_marker_key( $item ) {
     431    if ( empty( $item[ 'ID' ] ) ) {
     432        return '';
     433    }
     434
     435    return PROCESSING_ITEM_MARKER_PREFIX . \md5( (string) $item[ 'ID' ] );
     436}
     437
     438/**
    368439 * Schedules the next pick up.
    369440 *
  • jeero/trunk/readme.txt

    r3355603 r3417465  
    9696== Changelog ==
    9797
     98= 1.33 =
     99* Detect and remove inbox items that blocking future pickups.
     100* Re-download images when the source URL changes.
     101
    98102= 1.32 =
    99103* Added a new 'jeero/loaded' action to allow other plugins or themes to hook into the initialization process of Jeero.
Note: See TracChangeset for help on using the changeset viewer.