From 64d20bdfa991cd028aaa3b10905648fac4b8a3b3 Mon Sep 17 00:00:00 2001
From: Jonas Raoni Soares da Silva <github@raoni.org>
Date: Thu, 1 Aug 2024 00:08:55 +0300
Subject: [PATCH] pkp/pkp-lib#10249 Clear invalid images and setup the
 setting_type

(cherry picked from commit f09741c62371de7721fad92321180ecd879749ab)
---
 .../upgrade/v3_4_0/I10249_FixProfileImageDataLoss.php    | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/classes/migration/upgrade/v3_4_0/I10249_FixProfileImageDataLoss.php b/classes/migration/upgrade/v3_4_0/I10249_FixProfileImageDataLoss.php
index c433a6da492..994e1d4dd8c 100644
--- a/classes/migration/upgrade/v3_4_0/I10249_FixProfileImageDataLoss.php
+++ b/classes/migration/upgrade/v3_4_0/I10249_FixProfileImageDataLoss.php
@@ -40,7 +40,11 @@ public function up(): void
                     $globPattern = "{$publicFilesPath}/profileImage-{$row->user_id}.*";
                     $candidates = glob($globPattern, GLOB_NOSORT);
                     if (empty($candidates)) {
-                        $this->_installer->log("Failed to locate a profile image for the user ID {$row->user_id} at {$globPattern}");
+                        $this->_installer->log("Failed to locate a profile image for the user ID {$row->user_id} at {$globPattern}, cleaning up the value");
+                        DB::table('user_settings')
+                            ->where('user_id', $row->user_id)
+                            ->where('setting_name', 'profileImage')
+                            ->update(['setting_value' => null]);
                         continue;
                     }
 
@@ -61,7 +65,8 @@ public function up(): void
                                 'width' => $width,
                                 'height' => $height,
                                 'dateUploaded' => date('Y-m-d H:i:s', filemtime($filePath))
-                            ])
+                            ]),
+                            'setting_type' => 'object'
                         ]);
                 }
             }, 'user_id');