From 725fe54a29c3ebb0b6bd4df96985a01efab15597 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Mon, 27 Feb 2023 17:08:14 +0000 Subject: [PATCH 1/7] Use the `public_id` stored in the relationship table to determin the delivery sync --- php/class-delivery.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/php/class-delivery.php b/php/class-delivery.php index 460a09b1d..a3d25e33c 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 ); From fabc737e31db3d257be07caf4153291ab5edd987 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Mon, 27 Feb 2023 17:09:19 +0000 Subject: [PATCH 2/7] Do a late flush the cache --- php/class-delivery.php | 3 --- php/relate/class-relationship.php | 19 +++++++++++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/php/class-delivery.php b/php/class-delivery.php index a3d25e33c..1a71e8116 100644 --- a/php/class-delivery.php +++ b/php/class-delivery.php @@ -484,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' ); } /** @@ -555,7 +553,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' ); } /** diff --git a/php/relate/class-relationship.php b/php/relate/class-relationship.php index fbeb072a7..a31a823ba 100644 --- a/php/relate/class-relationship.php +++ b/php/relate/class-relationship.php @@ -105,6 +105,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 +116,23 @@ public function save() { */ public function do_save() { global $wpdb; - $data = $this->get_data(); + $data = $this->get_data(); + $update = false; - return $wpdb->update( Utils::get_relationship_table(), $data, array( 'id' => $data['id'] ), array( '%s' ), array( '%d' ) );// phpcs:ignore WordPress.DB + 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; + } + + /** + * Flush the cache. + * + * @return void + */ + public function flush_cache() { + do_action( 'cloudinary_flush_cache', false ); } /** From 957b1de917461a2e63092b4d9525b3d381c45ba1 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Mon, 27 Feb 2023 17:09:52 +0000 Subject: [PATCH 3/7] Check if object is set --- php/class-delivery.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/php/class-delivery.php b/php/class-delivery.php index 1a71e8116..65b4b395b 100644 --- a/php/class-delivery.php +++ b/php/class-delivery.php @@ -523,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(); + } } /** @@ -539,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' ); } From dc9a5527499fd9e491dd1e263685c969d29783e6 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Mon, 27 Feb 2023 17:10:27 +0000 Subject: [PATCH 4/7] Allow a soft cache flush --- php/class-delivery.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/php/class-delivery.php b/php/class-delivery.php index 65b4b395b..ab7850c95 100644 --- a/php/class-delivery.php +++ b/php/class-delivery.php @@ -705,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(); + } } /** From 870909ad76b5ad496428be4b372a7bf641e1dd63 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Mon, 27 Feb 2023 17:10:42 +0000 Subject: [PATCH 5/7] Update docbloc --- php/relate/class-relationship.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/php/relate/class-relationship.php b/php/relate/class-relationship.php index a31a823ba..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 { From 856a17fdfc5510124d38a662d7783a6279b41f02 Mon Sep 17 00:00:00 2001 From: Amit Brucker Date: Mon, 6 Mar 2023 16:40:18 +0200 Subject: [PATCH 6/7] update version --- .version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.version b/.version index ab0702a40..50e47c89c 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -3.1.0-build-6 \ No newline at end of file +3.1.1 \ No newline at end of file From bff2d1838dc6d6a394c4f17dafcb1b572fc98d7b Mon Sep 17 00:00:00 2001 From: Amit Brucker Date: Mon, 6 Mar 2023 16:55:39 +0200 Subject: [PATCH 7/7] update readme --- readme.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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: