From 441a2c811b9804314f6cffaded67b90122a56130 Mon Sep 17 00:00:00 2001
From: Michael Lee <lee.5151@osu.edu>
Date: Tue, 20 Aug 2024 13:18:45 -0400
Subject: [PATCH] update opic cache hook to also flush image style when
 refreshing images

---
 .../custom/imagecache_render/imagecache_render.module       | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/web/modules/custom/imagecache_render/imagecache_render.module b/web/modules/custom/imagecache_render/imagecache_render.module
index b428b6daf2..a835d36227 100644
--- a/web/modules/custom/imagecache_render/imagecache_render.module
+++ b/web/modules/custom/imagecache_render/imagecache_render.module
@@ -62,11 +62,15 @@ function imagecache_render_imagecache_external_needs_refresh_alter(&$needs_refre
     date_default_timezone_set('America/New_York');
     $current_hour = (int) date('G');
     if ($current_hour >= 3 && $current_hour < 5) {
-        if (filemtime($filepath) < \Drupal::time()->getRequestTime() - 60 * 60 * 24 - (30 * 60)) {
+        $image_style_name = 'people_profile_image';
+        $image_style = \Drupal::entityTypeManager()->getStorage('image_style')->load($image_style_name);
+        if ($image_style && filemtime($filepath) < \Drupal::time()->getRequestTime() - 60 * 60 * 24 - (30 * 60)) {
             \Drupal::logger('imagecache_external')->notice('@filepath older than 24 hours, refreshing', [
                 '@filepath' => $filepath,
             ]);
             $needs_refresh = TRUE;
+            $image_uri = str_replace('public://', '', $filepath);
+            $image_style->flush($image_uri);
         }
     }
 }
-- 
GitLab