Skip to content

Commit 1aef0f3

Browse files
authored
Merge pull request #866 from cloudinary/fix/cache
Hotfix 3.1.1
2 parents a0ba34e + bff2d18 commit 1aef0f3

File tree

4 files changed

+55
-17
lines changed

4 files changed

+55
-17
lines changed

.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.1.0
1+
3.1.1

php/class-delivery.php

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,12 @@ public function generate_signature( $attachment_id ) {
329329
if ( ! $sql ) {
330330
$sql = Utils::get_table_sql();
331331
}
332+
$public_id = null;
333+
$relationship = Relationship::get_relationship( $attachment_id );
334+
if ( $relationship instanceof Relationship ) {
335+
$public_id = $relationship->public_id;
336+
}
332337
$sizes = $this->get_sized( $attachment_id );
333-
$public_id = $this->media->has_public_id( $attachment_id ) ? $this->media->get_public_id( $attachment_id ) : null;
334338
$settings_signature = self::get_settings_signature();
335339
$relation_signature = $this->media->get_post_meta( $attachment_id, Sync::META_KEYS['relationship'], true );
336340

@@ -480,8 +484,6 @@ public function unsync_size_relationship( $attachment_id ) {
480484
self::update_size_relations_public_id( $attachment_id, null );
481485
self::update_size_relations_state( $attachment_id, 'disable' );
482486
self::update_size_relations_transformations( $attachment_id, null );
483-
484-
do_action( 'cloudinary_flush_cache' );
485487
}
486488

487489
/**
@@ -521,12 +523,13 @@ public function get_sized( $attachment_id ) {
521523
*/
522524
public static function update_size_relations_public_id( $attachment_id, $public_id ) {
523525
$relationship = Relationship::get_relationship( $attachment_id );
524-
$relationship->public_id = $public_id;
525-
$relationship->public_hash = md5( $public_id );
526-
$relationship->signature = self::get_settings_signature();
527-
$relationship->save();
528526

529-
do_action( 'cloudinary_flush_cache' );
527+
if ( $relationship instanceof Relationship ) {
528+
$relationship->public_id = $public_id;
529+
$relationship->public_hash = md5( $public_id );
530+
$relationship->signature = self::get_settings_signature();
531+
$relationship->save();
532+
}
530533
}
531534

532535
/**
@@ -537,8 +540,11 @@ public static function update_size_relations_public_id( $attachment_id, $public_
537540
*/
538541
public static function update_size_relations_state( $attachment_id, $state ) {
539542
$relationship = Relationship::get_relationship( $attachment_id );
540-
$relationship->post_state = $state;
541-
$relationship->save();
543+
544+
if ( $relationship instanceof Relationship ) {
545+
$relationship->post_state = $state;
546+
$relationship->save();
547+
}
542548

543549
do_action( 'cloudinary_flush_cache' );
544550
}
@@ -551,7 +557,6 @@ public static function update_size_relations_state( $attachment_id, $state ) {
551557
*/
552558
public static function update_size_relations_transformations( $attachment_id, $transformations ) {
553559
Relate::update_transformations( $attachment_id, $transformations );
554-
do_action( 'cloudinary_flush_cache' );
555560
}
556561

557562
/**
@@ -700,11 +705,16 @@ public function clear_cache() {
700705
/**
701706
* Delete cached metadata.
702707
*
708+
* @param bool $hard Whether to hard flush the cache.
709+
*
703710
* @hook cloudinary_flush_cache
704711
*/
705-
public function do_clear_cache() {
712+
public function do_clear_cache( $hard = true ) {
706713
delete_post_meta_by_key( self::META_CACHE_KEY );
707-
wp_cache_flush();
714+
715+
if ( $hard ) {
716+
wp_cache_flush();
717+
}
708718
}
709719

710720
/**

php/relate/class-relationship.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313

1414
/**
1515
* Class Relationship
16+
*
17+
* @property string|null $post_state
18+
* @property string|null $public_hash
19+
* @property string|null $public_id
20+
* @property string|null $signature
21+
* @property string|null $transformations
1622
*/
1723
class Relationship {
1824

@@ -105,6 +111,7 @@ public function save() {
105111
if ( ! $this->save_on_shutdown ) {
106112
$this->save_on_shutdown = true;
107113
add_action( 'shutdown', array( $this, 'do_save' ) );
114+
add_action( 'shutdown', array( $this, 'flush_cache' ), 100 );
108115
}
109116
}
110117

@@ -115,9 +122,23 @@ public function save() {
115122
*/
116123
public function do_save() {
117124
global $wpdb;
118-
$data = $this->get_data();
125+
$data = $this->get_data();
126+
$update = false;
127+
128+
if ( ! empty( $data['id'] ) ) {
129+
$update = $wpdb->update( Utils::get_relationship_table(), $data, array( 'id' => $data['id'] ), array( '%s' ), array( '%d' ) );// phpcs:ignore WordPress.DB
130+
}
131+
132+
return $update;
133+
}
119134

120-
return $wpdb->update( Utils::get_relationship_table(), $data, array( 'id' => $data['id'] ), array( '%s' ), array( '%d' ) );// phpcs:ignore WordPress.DB
135+
/**
136+
* Flush the cache.
137+
*
138+
* @return void
139+
*/
140+
public function flush_cache() {
141+
do_action( 'cloudinary_flush_cache', false );
121142
}
122143

123144
/**

readme.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,14 @@ Your site is now setup to start using Cloudinary.
142142

143143
== Changelog ==
144144

145-
= 3.1 (22 FEBRUARY 2022) =
145+
= 3.1.1 (06 MARCH 2023) =
146+
147+
Fixes and Improvements:
148+
149+
* Fixed the *Add transformation* on the media library for newly added assets
150+
* Fixed PHP warning in error log after upgrading to PHP 8/8.X
151+
152+
= 3.1 (22 FEBRUARY 2023) =
146153

147154
Fixes and Improvements:
148155

0 commit comments

Comments
 (0)