diff --git a/.version b/.version index a0cd9f0cc..50e47c89c 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -3.1.0 \ No newline at end of file +3.1.1 \ No newline at end of file diff --git a/php/class-delivery.php b/php/class-delivery.php index 460a09b1d..ab7850c95 100644 --- a/php/class-delivery.php +++ b/php/class-delivery.php @@ -329,8 +329,12 @@ public function generate_signature( $attachment_id ) { if ( ! $sql ) { $sql = Utils::get_table_sql(); } + $public_id = null; + $relationship = Relationship::get_relationship( $attachment_id ); + if ( $relationship instanceof Relationship ) { + $public_id = $relationship->public_id; + } $sizes = $this->get_sized( $attachment_id ); - $public_id = $this->media->has_public_id( $attachment_id ) ? $this->media->get_public_id( $attachment_id ) : null; $settings_signature = self::get_settings_signature(); $relation_signature = $this->media->get_post_meta( $attachment_id, Sync::META_KEYS['relationship'], true ); @@ -480,8 +484,6 @@ public function unsync_size_relationship( $attachment_id ) { self::update_size_relations_public_id( $attachment_id, null ); self::update_size_relations_state( $attachment_id, 'disable' ); self::update_size_relations_transformations( $attachment_id, null ); - - do_action( 'cloudinary_flush_cache' ); } /** @@ -521,12 +523,13 @@ public function get_sized( $attachment_id ) { */ public static function update_size_relations_public_id( $attachment_id, $public_id ) { $relationship = Relationship::get_relationship( $attachment_id ); - $relationship->public_id = $public_id; - $relationship->public_hash = md5( $public_id ); - $relationship->signature = self::get_settings_signature(); - $relationship->save(); - do_action( 'cloudinary_flush_cache' ); + if ( $relationship instanceof Relationship ) { + $relationship->public_id = $public_id; + $relationship->public_hash = md5( $public_id ); + $relationship->signature = self::get_settings_signature(); + $relationship->save(); + } } /** @@ -537,8 +540,11 @@ public static function update_size_relations_public_id( $attachment_id, $public_ */ public static function update_size_relations_state( $attachment_id, $state ) { $relationship = Relationship::get_relationship( $attachment_id ); - $relationship->post_state = $state; - $relationship->save(); + + if ( $relationship instanceof Relationship ) { + $relationship->post_state = $state; + $relationship->save(); + } do_action( 'cloudinary_flush_cache' ); } @@ -551,7 +557,6 @@ public static function update_size_relations_state( $attachment_id, $state ) { */ public static function update_size_relations_transformations( $attachment_id, $transformations ) { Relate::update_transformations( $attachment_id, $transformations ); - do_action( 'cloudinary_flush_cache' ); } /** @@ -700,11 +705,16 @@ public function clear_cache() { /** * Delete cached metadata. * + * @param bool $hard Whether to hard flush the cache. + * * @hook cloudinary_flush_cache */ - public function do_clear_cache() { + public function do_clear_cache( $hard = true ) { delete_post_meta_by_key( self::META_CACHE_KEY ); - wp_cache_flush(); + + if ( $hard ) { + wp_cache_flush(); + } } /** diff --git a/php/relate/class-relationship.php b/php/relate/class-relationship.php index fbeb072a7..51ba52963 100644 --- a/php/relate/class-relationship.php +++ b/php/relate/class-relationship.php @@ -13,6 +13,12 @@ /** * Class Relationship + * + * @property string|null $post_state + * @property string|null $public_hash + * @property string|null $public_id + * @property string|null $signature + * @property string|null $transformations */ class Relationship { @@ -105,6 +111,7 @@ public function save() { if ( ! $this->save_on_shutdown ) { $this->save_on_shutdown = true; add_action( 'shutdown', array( $this, 'do_save' ) ); + add_action( 'shutdown', array( $this, 'flush_cache' ), 100 ); } } @@ -115,9 +122,23 @@ public function save() { */ public function do_save() { global $wpdb; - $data = $this->get_data(); + $data = $this->get_data(); + $update = false; + + if ( ! empty( $data['id'] ) ) { + $update = $wpdb->update( Utils::get_relationship_table(), $data, array( 'id' => $data['id'] ), array( '%s' ), array( '%d' ) );// phpcs:ignore WordPress.DB + } + + return $update; + } - return $wpdb->update( Utils::get_relationship_table(), $data, array( 'id' => $data['id'] ), array( '%s' ), array( '%d' ) );// phpcs:ignore WordPress.DB + /** + * Flush the cache. + * + * @return void + */ + public function flush_cache() { + do_action( 'cloudinary_flush_cache', false ); } /** diff --git a/readme.txt b/readme.txt index 1cc03e8be..6c335b2fe 100644 --- a/readme.txt +++ b/readme.txt @@ -142,7 +142,14 @@ Your site is now setup to start using Cloudinary. == Changelog == -= 3.1 (22 FEBRUARY 2022) = += 3.1.1 (06 MARCH 2023) = + +Fixes and Improvements: + +* Fixed the *Add transformation* on the media library for newly added assets +* Fixed PHP warning in error log after upgrading to PHP 8/8.X + += 3.1 (22 FEBRUARY 2023) = Fixes and Improvements: