diff --git a/classes/migration/upgrade/I10249_FixProfileImageDataLoss.inc.php b/classes/migration/upgrade/I10249_FixProfileImageDataLoss.inc.php new file mode 100644 index 00000000000..ff02c37bca5 --- /dev/null +++ b/classes/migration/upgrade/I10249_FixProfileImageDataLoss.inc.php @@ -0,0 +1,70 @@ +where('setting_name', '=', 'profileImage') + ->whereRaw("COALESCE(setting_value, '') <> ''") + ->whereRaw("setting_value NOT LIKE CONCAT('%profileImage-', user_id, '.%')") + ->select('user_id') + ->chunkById(1000, function (Collection $rows) use ($publicFilesPath, $orderByModifiedDate) { + foreach ($rows as $row) { + $globPattern = "{$publicFilesPath}/profileImage-{$row->user_id}.*"; + $candidates = glob($globPattern, GLOB_NOSORT); + if (empty($candidates)) { + error_log("Failed to locate a profile image for the user ID {$row->user_id} at {$globPattern}"); + continue; + } + + if (count($candidates) > 1) { + usort($candidates, $orderByModifiedDate); + } + + $filePath = array_pop($candidates); + $fileName = basename($filePath); + [$width, $height] = getimagesize($filePath) ?: [0, 0]; + Capsule::table('user_settings') + ->where('user_id', $row->user_id) + ->where('setting_name', 'profileImage') + ->update(['setting_value' => json_encode([ + 'name' => $fileName, + 'uploadName' => $fileName, + 'width' => $width, + 'height' => $height, + 'dateUploaded' => date('Y-m-d H:i:s', filemtime($filePath)) + ])]); + } + }, 'user_id'); + } + + /** + * Reverse the migration + * @return void + */ + public function down() { + throw new PKP\install\DowngradeNotSupportedException(); + } +} diff --git a/classes/scheduledTask/ScheduledTaskDAO.inc.php b/classes/scheduledTask/ScheduledTaskDAO.inc.php index 6ea61bde46f..47413fc0e44 100644 --- a/classes/scheduledTask/ScheduledTaskDAO.inc.php +++ b/classes/scheduledTask/ScheduledTaskDAO.inc.php @@ -36,7 +36,7 @@ function getLastRunTime($className) { [$className] ); $row = $result->current(); - return $row ? strtotime($this->datetimeFromDB($row->last_run)) : null; + return $row && $row->last_run ? strtotime($this->datetimeFromDB($row->last_run)) : 0; } /**