Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add upgrade logging #4533

Merged
merged 7 commits into from
Nov 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 51 additions & 29 deletions src/ChurchCRM/Service/SystemService.php
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
use PDO;
use ChurchCRM\Utils\InputUtils;
use ChurchCRM\Utils\LoggerUtils;
use ChurchCRM\Utils\ExecutionTime;

require SystemURLs::getDocumentRoot() . '/vendor/ifsnop/mysqldump-php/src/Ifsnop/Mysqldump/Mysqldump.php';

@@ -443,22 +444,30 @@ public static function runTimerJobs()

public function downloadLatestRelease()
{
$release = $this->getLatestRelease();
$UpgradeDir = SystemURLs::getDocumentRoot() . '/Upgrade';
foreach ($release['assets'] as $asset) {
if ($asset['name'] == "ChurchCRM-" . $release['name'] . ".zip") {
$url = $asset['browser_download_url'];
}
$logger = LoggerUtils::getAppLogger();
$logger->debug("Querying for latest release");
$release = $this->getLatestRelease();
$logger->debug("Query result: " . print_r($release,true));
$UpgradeDir = SystemURLs::getDocumentRoot() . '/Upgrade';
foreach ($release['assets'] as $asset) {
if ($asset['name'] == "ChurchCRM-" . $release['name'] . ".zip") {
$url = $asset['browser_download_url'];
}
mkdir($UpgradeDir);
file_put_contents($UpgradeDir . '/' . basename($url), file_get_contents($url));
$returnFile = [];
$returnFile['fileName'] = basename($url);
$returnFile['releaseNotes'] = $release['body'];
$returnFile['fullPath'] = $UpgradeDir . '/' . basename($url);
$returnFile['sha1'] = sha1_file($UpgradeDir . '/' . basename($url));

return $returnFile;
}
$logger->debug("Creating upgrade directory: " . $UpgradeDir);
mkdir($UpgradeDir);
$logger->info("Downloading release from: " . $url . " to: ". $UpgradeDir . '/' . basename($url));
$executionTime = new ExecutionTime();
file_put_contents($UpgradeDir . '/' . basename($url), file_get_contents($url));
$logger->info("Finished downloading file. Execution time: " .$executionTime->getMiliseconds()." ms");
$returnFile = [];
$returnFile['fileName'] = basename($url);
$returnFile['releaseNotes'] = $release['body'];
$returnFile['fullPath'] = $UpgradeDir . '/' . basename($url);
$returnFile['sha1'] = sha1_file($UpgradeDir . '/' . basename($url));
$logger->info("SHA1 hash for ". $returnFile['fullPath'] .": " . $returnFile['sha1']);
$logger->info("Release notes: " . $returnFile['releaseNotes'] );
return $returnFile;
}

public function moveDir($src, $dest)
@@ -478,21 +487,34 @@ public function moveDir($src, $dest)

public function doUpgrade($zipFilename, $sha1)
{
ini_set('max_execution_time', 60);
Copy link
Contributor Author

@crossan007 crossan007 Nov 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a system task for this that warns if it's below 120 seconds, so this line could prevent an otherwise successful upgrade.

if ($sha1 == sha1_file($zipFilename)) {
$zip = new \ZipArchive();
if ($zip->open($zipFilename) == true) {
$zip->extractTo(SystemURLs::getDocumentRoot() . '/Upgrade');
$zip->close();
$this->moveDir(SystemURLs::getDocumentRoot() . '/Upgrade/churchcrm', SystemURLs::getDocumentRoot());
}
unlink($zipFilename);
SystemConfig::setValue('sLastIntegrityCheckTimeStamp', null);

return 'success';
} else {
return 'hash validation failure';
$logger = LoggerUtils::getAppLogger();
$logger->info("Beginnging upgrade process");
$logger->info("PHP max_execution_time is now: " . ini_get("max_execution_time"));
$logger->info("Beginning hash validation on " . $zipFilename);
if ($sha1 == sha1_file($zipFilename)) {
$logger->info("Hash validation succeeded on " . $zipFilename . " Got: " . sha1_file($zipFilename));
$zip = new \ZipArchive();
if ($zip->open($zipFilename) == true) {
$logger->info("Extracting " . $zipFilename." to: " . SystemURLs::getDocumentRoot() . '/Upgrade');
$executionTime = new ExecutionTime();
$zip->extractTo(SystemURLs::getDocumentRoot() . '/Upgrade');
$zip->close();
$logger->info("Extraction completed. Took:" . $executionTime->getMiliseconds());
$logger->info("Moving extracted zip into place");
$executionTime = new ExecutionTime();
$this->moveDir(SystemURLs::getDocumentRoot() . '/Upgrade/churchcrm', SystemURLs::getDocumentRoot());
$logger->info("Move completed. Took:" . $executionTime->getMiliseconds());
}
$logger->info("Deleting zip archive: ".$zipFilename);
unlink($zipFilename);
SystemConfig::setValue('sLastIntegrityCheckTimeStamp', null);
$logger->debug("Set sLastIntegrityCheckTimeStamp to null");
$logger->info("Upgrade process complete");
return 'success';
} else {
$logger->err("Hash validation failed on " . $zipFilename.". Expected: ".$sha1. ". Got: ".sha1_file($zipFilename));
return 'hash validation failure';
}
}

// Returns a file size limit in bytes based on the PHP upload_max_filesize
6 changes: 3 additions & 3 deletions src/UpgradeCRM.php
Original file line number Diff line number Diff line change
@@ -97,7 +97,7 @@
<i class="fa fa-cloud-download bg-blue"></i>
<div class="timeline-item" >
<h3 class="timeline-header"><?= gettext('Step 2: Fetch Update Package on Server') ?> <span id="status2"></span></h3>
<div class="timeline-body" id="fetchPhase" style="display: none">
<div class="timeline-body" id="fetchPhase" <?= $_GET['expertmode'] ? '':'style="display: none"' ?>>
<p><?= gettext('Fetch the latest files from the ChurchCRM GitHub release page')?></p>
<input type="button" class="btn btn-primary" id="fetchUpdate" <?= 'value="'.gettext('Fetch Update Files').'"' ?> >
</div>
@@ -107,7 +107,7 @@
<i class="fa fa-cogs bg-blue"></i>
<div class="timeline-item" >
<h3 class="timeline-header"><?= gettext('Step 3: Apply Update Package on Server') ?> <span id="status3"></span></h3>
<div class="timeline-body" id="updatePhase" style="display: none">
<div class="timeline-body" id="updatePhase" <?= $_GET['expertmode'] ? '':'style="display: none"' ?>>
<p><?= gettext('Extract the upgrade archive, and apply the new files')?></p>
<h4><?= gettext('Release Notes') ?></h4>
<pre id="releaseNotes"></pre>
@@ -125,7 +125,7 @@
<i class="fa fa-sign-in bg-blue"></i>
<div class="timeline-item" >
<h3 class="timeline-header"><?= gettext('Step 4: Login') ?></h3>
<div class="timeline-body" id="finalPhase" style="display: none">
<div class="timeline-body" id="finalPhase" <?= $_GET['expertmode'] ? '':'style="display: none"' ?>>
<a href="Logoff.php" class="btn btn-primary"><?= gettext('Login to Upgraded System') ?> </a>
</div>
</div>