Skip to content

Commit

Permalink
Merge pull request #9846 from jonasraoni/bugfix/stable-3_4_0/9833-fix…
Browse files Browse the repository at this point in the history
…-preflight-check

#9833 Updated pre-flight script to extract the date from t…
  • Loading branch information
jonasraoni authored Apr 12, 2024
2 parents bd89cb1 + 75de993 commit 7cbab21
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
7 changes: 5 additions & 2 deletions classes/migration/upgrade/v3_4_0/PreflightCheckMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,12 @@ protected function checkUsageStatsLogs(): void
$usageStatsDir = StatisticsHelper::getUsageStatsDirPath();
// check if there are usage stats log files older than yesterday
foreach (glob($usageStatsDir . '/usageEventLogs/*') as $usageStatsLogFile) {
$lastModified = date('Ymd', filemtime($usageStatsLogFile));
if (!preg_match('/(\d{8})\.log$/', $usageStatsLogFile, $logFileDate)) {
throw new Exception("The log file \"{$usageStatsLogFile}\" doesn't follow the expected naming pattern \"usage_events_YearMonthDay.log\"");
}
$logFileDate = $logFileDate[1];
$yesterday = date('Ymd', strtotime('-1 days'));
if ($yesterday > $lastModified) {
if ($yesterday > $logFileDate) {
throw new Exception("There are unprocessed log files from more than 1 day ago in the directory {$usageStatsDir}/usageEventLogs/. This happens when the scheduled task to process usage stats logs is not being run daily. All logs in this directory older than {$yesterday} must be processed or removed before the upgrade can continue.");
}
}
Expand Down
37 changes: 37 additions & 0 deletions tools/travis/migration/v3_4_0/prepare-logs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

# @file tools/travis/migration/v3_4_0/prepare-logs.sh
#
# Copyright (c) 2024 Simon Fraser University
# Copyright (c) 2024 John Willinsky
# Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
#
# Script to adjust at maximum two logs to run the tests for the 3.4 migration.
#
# @todo: Remove once the 3.4 upgrade code gets dropped
#

set -e

# Get the list of logs
eventLogsFolder="${FILESDIR}/usageStats/usageEventLogs"
logFiles=("${eventLogsFolder}/"*)
archiveFolder="${FILESDIR}/usageStats/archive"
mkdir -p ${archiveFolder}

# Get the current and previous date in YMD format
today=$(date +"%Y%m%d")
yesterday=$(date -d "1 day ago" +"%Y%m%d")

# Rename the first two logs
if [ -e "${logFiles[0]}" ]; then
mv "${logFiles[0]}" "${eventLogsFolder}/${today}.log"
fi
if [ -e "${logFiles[1]}" ]; then
mv "${logFiles[1]}" "${eventLogsFolder}/${yesterday}.log"
fi

# Move the remaining logs to the archive folder
for file in "${logs[@]:2}"; do
mv "${file}" "${archiveFolder}/"
done

0 comments on commit 7cbab21

Please sign in to comment.