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

Self update #1097

Merged
merged 31 commits into from
Oct 16, 2016
Merged

Self update #1097

merged 31 commits into from
Oct 16, 2016

Conversation

crossan007
Copy link
Contributor

@crossan007 crossan007 commented Oct 5, 2016

Closes Bugs:
#1139
#1123
#1013

Should help with bugs like:
#1059
#875

Might Help with:
#524

Probably not quite ready for prime time, but I'd like to have it in 2.3.0

This adds capability for ChurchCRM to update itself from the latest github release.

It also adds signature verification for all source files in the project.

during Phing build, generateSignatures.php create a "signatures.json" file with a sha1 of every php and js file in the project.

at runtime, the system service will periodically call verifyApplicationIntegrity() to ensure that the files installed match the signature definition file that was generated at build.

If there are errors, then integrityCheck.json will cause the TaskService to display an alert that there are possibly corrupt files.

@crossan007 crossan007 added this to the 2.3.0 milestone Oct 5, 2016
@crossan007 crossan007 self-assigned this Oct 5, 2016
Copy link
Contributor

@DawoudIO DawoudIO left a comment

Choose a reason for hiding this comment

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

looks good, watch your install dir and your gettext

$UpgradeDir = $CRMInstallRoot."/Upgrade";
$url = $release['assets'][0]['browser_download_url'];
mkdir($UpgradeDir);
//file_put_contents($UpgradeDir."/".basename($url), file_get_contents($url));
Copy link
Contributor

Choose a reason for hiding this comment

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

why commented out

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

for($i = 0; $i < $zip->numFiles; $i++)
{
$archivedFileName = $zip->getNameIndex($i);
$targetFilename = str_replace("churchcrm/","/",$archivedFileName);
Copy link
Contributor

Choose a reason for hiding this comment

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

what are you trying to do here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we don't want to maintain the "churchcrm" folder inside of the zip archive when we extract it.

}

if($integrityCheckData->status == "failure") {
array_push($tasks, $this->addTask("Application Integrity Check Failed", "/integrityCheck.json", true));
Copy link
Contributor

Choose a reason for hiding this comment

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

where are you sending the user

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right now I'm showing them an ugly json file with details about why the integrity check failed.

This is the UI i still have to build

require 'Include/Functions.php';

// Set the page title and include HTML header
$sPageTitle = "Upgrade ChurchCRM";
Copy link
Contributor

Choose a reason for hiding this comment

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

gettext

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed


<div class="login-box">
<div class="login-logo">
Upgrade <b>Church</b>CRM</a>
Copy link
Contributor

Choose a reason for hiding this comment

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

gettext

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

</div>
<div class="login-box-body" style="display:none" id="finalPhase">
<p class="login-box-msg"><?= gettext('Step 4: Login') ?></p>
<a href="Login.php?Logoff=True" class="btn btn-primary">Login to Upgraded System</a>
Copy link
Contributor

Choose a reason for hiding this comment

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

gettext

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

console.log(data);
var downloadButton = "<button class=\"btn btn-primary\" id=\"downloadbutton\" role=\"button\" onclick=\"javascript:downloadbutton('"+data.filename+"')\"><i class='fa fa-download'></i> "+data.filename+"</button>";
$("#backupstatus").css("color","green");
$("#backupstatus").html("Backup Complete, Ready for Download.");
Copy link
Contributor

Choose a reason for hiding this comment

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

gettext

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

$("#applyUpdate").click(function(){
$.ajax({
type : 'POST',
url : window.CRM.root +'/api/systemupgrade/doUpgrade', // the url where we want to POST
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure rest API has case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed


$app->group('/systemupgrade', function () {

$this->get('/downloadLatestRelease', function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

all lower case or -

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

echo json_encode($upgradeFile);
});

$this->post('/doUpgrade', function ($request, $response, $args) {
Copy link
Contributor

Choose a reason for hiding this comment

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

same

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@DawoudIO
Copy link
Contributor

DawoudIO commented Oct 8, 2016

how do you test this ;)

@crossan007
Copy link
Contributor Author

That's a very good question.

I think there's a small glitch in the getLatestRelese() function that causes the app to "upgrade" if the latest version hosted on GitHub is less than the current build (i.e. our dev environments will always ask us to upgrade to whatever the last published version was).

Using this bug, you can upgrade your dev environment (2.3.0) to the latest release (2.2.3).

You should be able to just follow the prompts.

After it's complete, you should have a completely broken system, since downgrading the app is not supported :-)


//Set the page title
$sPageTitle = gettext('Integrity Check Results');
if (!$_SESSION['bFinance'])
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't get this check

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whooopss.. That's what i get for copying / pasting a page. I should get rid of the header too...

exit;
}
require 'Include/Header.php';
$CRMInstallRoot = __DIR__;
Copy link
Contributor

Choose a reason for hiding this comment

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

no need for the var

?>

<div class="box box-body">
<p><?= gettext("Previous Integrity Check Result:") ?>
Copy link
Contributor

Choose a reason for hiding this comment

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

use the callout warning css to get read or green

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in a commit coming soon to a Repo near you

$diff = $previous->diff($now); // calculate the difference.
if (!$sLastIntegrityCheckTimeStamp || $diff->h >= $sIntegrityCheckInterval) // if there was no previous backup, or if the interval suggests we do a backup now.
{
$CRMInstallRoot = dirname(__DIR__);
Copy link
Contributor

Choose a reason for hiding this comment

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

temp var not used else where

(1043, 'sQBDTSettings', @JSONV , 'json', @JSONV , 'QuickBooks Deposit Ticket Settings', 'ChurchInfoReport', 'Step7', NULL),
(1044, 'sEnableIntegrityCheck', '1', 'boolean', '1', 'Enable Integrity Check', 'General', "Step5", NULL),
(1045, 'sIntegrityCheckInterval', '1', 'Text', '1', 'Interval in Hours for Integrity Check', 'General', "Step5", NULL),
(1046, 'sLastIntegrityCheckTimeStamp', '', 'Text', '', 'Last Integrity Check Timestamp', 'General', "Step5", NULL);
Copy link
Contributor

Choose a reason for hiding this comment

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

why not timestamp type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't have a "timestamp" type available as a type in this context.

These are not SQL column types, but rather types enumerated in lines 185-221 of SystemSettings.php

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we can track this separately, as there are a few other places where we may want to use a TimeStamp

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tracking this in #1140

(1043, 'sQBDTSettings', @JSONV , 'json', @JSONV , 'QuickBooks Deposit Ticket Settings', 'ChurchInfoReport', 'Step7', NULL);
(1043, 'sQBDTSettings', @JSONV , 'json', @JSONV , 'QuickBooks Deposit Ticket Settings', 'ChurchInfoReport', 'Step7', NULL),
(1044, 'sEnableIntegrityCheck', '1', 'boolean', '1', 'Enable Integrity Check', 'General', "Step5", NULL),
(1045, 'sIntegrityCheckInterval', '1', 'Text', '1', 'Interval in Hours for Integrity Check', 'General', "Step5", NULL),
Copy link
Contributor

Choose a reason for hiding this comment

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

1hr is too fast... 1 day or 1 week... i lean to 1 week... maybe a drop down of options

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for MVP, let's stick with "hours" as the unit. We can make it like 24, 48, or 168

@DawoudIO
Copy link
Contributor

Clicking "Fetch Update Files" needs a spinner or something... i was not sure what was going on...
Same for "Apply Update Files"

<li><? gettext("Full Path:")?> <span id="updateFullPath"> </span></li>
<li><? gettext("SHA1:")?> <span id="updateSHA1"> </span></li>
</ul>
<input type="button" class="btn btn-warning" id="applyUpdate" <?= 'value="' . gettext("Apply Update Files") . '"' ?>>
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be called.... upgrade system

<li><? gettext("Full Path:")?> <span id="updateFullPath"> </span></li>
<li><? gettext("SHA1:")?> <span id="updateSHA1"> </span></li>
</ul>
<input type="button" class="btn btn-warning" id="applyUpdate" <?= 'value="' . gettext("Apply Update Files") . '"' ?>>
Copy link
Contributor

Choose a reason for hiding this comment

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

why is "value" in php echo tag

$this->post('/doupgrade', function ($request, $response, $args) {
$input = (object)$request->getParsedBody();
$upgradeResult = $this->SystemService->doUpgrade($input->fullPath,$input->sha1);
echo json_encode($upgradeResult);
Copy link
Contributor

Choose a reason for hiding this comment

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

where should we delete the zip file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it happens in SystemService doUpgrade()

@DawoudIO
Copy link
Contributor

address the issues above and we should be able to merge this soon

@DawoudIO DawoudIO self-assigned this Oct 15, 2016
@crossan007 crossan007 merged commit 84969cd into develop Oct 16, 2016
@crossan007 crossan007 deleted the self-update branch October 16, 2016 03:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants