Changeset 3417465
- Timestamp:
- 12/11/2025 02:25:56 PM (4 months ago)
- Location:
- jeero/trunk
- Files:
-
- 4 edited
-
Jeero.php (modified) (2 diffs)
-
includes/Helpers/Images.php (modified) (4 diffs)
-
includes/Inbox/Inbox.php (modified) (5 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
jeero/trunk/Jeero.php
r3355603 r3417465 6 6 * Author: Slim & Dapper 7 7 * Author URI: https://slimndap.com 8 * Version: 1.3 2.18 * Version: 1.33 9 9 * Text Domain: jeero 10 10 * … … 32 32 add_action( 'init', function() { 33 33 34 define( 'Jeero\VERSION', '1.3 2.1' );34 define( 'Jeero\VERSION', '1.33' ); 35 35 define( 'Jeero\PLUGIN_PATH', plugin_dir_path( __FILE__ ) ); 36 36 define( 'Jeero\PLUGIN_URI', plugin_dir_url( __FILE__ ) ); -
jeero/trunk/includes/Helpers/Images.php
r3056977 r3417465 16 16 */ 17 17 const 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 */ 26 const JEERO_IMG_SOURCE_URL_FIELD = 'jeero/img/source_url'; 18 27 19 28 /** … … 123 132 * 124 133 * @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. 125 135 * 126 136 * @param array $structured_image … … 129 139 */ 130 140 function 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 } 135 155 136 156 require_once( ABSPATH . 'wp-admin/includes/media.php' ); … … 167 187 // Store original URL with image. 168 188 \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 } 169 195 170 196 return $thumbnail_id; -
jeero/trunk/includes/Inbox/Inbox.php
r3296592 r3417465 22 22 23 23 const PICKUP_ITEMS_HOOK = 'jeero\inbox\pickup_items'; 24 const PROCESSING_ITEM_MARKER_PREFIX = 'jeero_inbox_processing_item_'; 24 25 25 26 // Scheduling of the next pickup is handled centrally in Jeero.php bootstrap. … … 145 146 function process_item( $item ) { 146 147 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 147 157 $action = $item[ 'action' ]; 148 158 $theater = $item[ 'theater' ]; … … 283 293 $subscription 284 294 ); 295 296 mark_process_item_ended( $item ); 285 297 286 298 return $result; … … 322 334 } 323 335 324 $items_processed[] = $item;325 326 336 $elapsed_time = microtime( true ) - $start_time; 327 337 … … 366 376 367 377 /** 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 */ 385 function 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 */ 402 function 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 */ 421 function 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 430 function 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 /** 368 439 * Schedules the next pick up. 369 440 * -
jeero/trunk/readme.txt
r3355603 r3417465 96 96 == Changelog == 97 97 98 = 1.33 = 99 * Detect and remove inbox items that blocking future pickups. 100 * Re-download images when the source URL changes. 101 98 102 = 1.32 = 99 103 * 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.