Skip to content

Commit

Permalink
version check for upgrade scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
benkeen committed Feb 2, 2018
1 parent 213e199 commit 61c0085
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 11 deletions.
2 changes: 1 addition & 1 deletion global/code/Core.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class Core {
/**
* The release date: YYYYMMDD
*/
private static $releaseDate = "20180127";
private static $releaseDate = "20180201";

/**
* The minimum required PHP version needed to run Form Tools.
Expand Down
3 changes: 1 addition & 2 deletions global/code/Emails.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1288,8 +1288,7 @@ public static function processEmailTemplate($form_id, $submission_id, $email_id)
return array(false, "Email components not returned properly (Emails::getEmailComponents).");
}

extract(Hooks::processHookCalls("start", compact("form_id", "submission_id", "email_id", "email_components"),
array("email_components")), EXTR_OVERWRITE);
extract(Hooks::processHookCalls("start", compact("form_id", "submission_id", "email_id", "email_components"), array("email_components")), EXTR_OVERWRITE);

// if Swift Mailer is enabled, send the emails with that
$continue = true;
Expand Down
24 changes: 23 additions & 1 deletion global/code/General.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1306,5 +1306,27 @@ public static function getLoginOverrideId()
}
return $id;
}
}


/**
* Compares two versions to see if a version is earlier than a target version. Used to determine whether or not
* to trigger upgrading for modules/the Core.
*/
public static function isVersionEarlierThan($version, $target_version) {
if ($version === $target_version) {
return false;
}

list($major, $minor, $version_bugfix) = explode(".", $version);
$version_major = $major * 1000000;
$version_minor = $minor * 1000;
$version_num = $version_major + $version_minor + $version_bugfix;

list($target_major, $target_minor, $target_bugfix) = explode(".", $target_version);
$target_version_major = $target_major * 1000000;
$target_version_minor = $target_minor * 1000;
$target_version_num = $target_version_major + $target_version_minor + $target_bugfix;

return $version_num < $target_version_num;
}
}
8 changes: 1 addition & 7 deletions global/code/User.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,6 @@ public function logout($message_flag = "")

extract(Hooks::processHookCalls("main", array(), array()));

// this ensures sessions are started
// if ($g_session_type == "database") {
// $sess = new SessionManager();
// }
// @session_start();

// first, if $_SESSION["ft"]["admin"] is set, it is an administrator logging out, so just redirect them
// back to the admin pages
if (Sessions::exists("admin")) {
Expand Down Expand Up @@ -336,7 +330,7 @@ public function checkAuth($required_account_type, $auto_logout = true)
$boot_out_user = false;
$message_flag = "";

extract(Hooks::processHookCalls("end", compact("account_type"), array("boot_out_user", "message_flag")), EXTR_OVERWRITE);
extract(Hooks::processHookCalls("start", compact("account_type"), array("boot_out_user", "message_flag")), EXTR_OVERWRITE);

$account_id = $this->accountId;
$account_type = $this->accountType;
Expand Down
60 changes: 60 additions & 0 deletions tests/phpunit/General.classTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,64 @@ public function testStripChars_CustomWhitelist()
$trimmed_string = General::stripChars($string, "97531");
$this->assertEquals($trimmed_string, "13579");
}


// General::isVersionEarlierThan()

public function testIsVersionEarlierThan_TestSameVersion()
{
$this->assertEquals(General::isVersionEarlierThan("1.0.0", "1.0.0"), false);
}

public function testIsVersionEarlierThan_TestLaterVersionBugVersion()
{
$this->assertEquals(General::isVersionEarlierThan("1.0.1", "1.0.0"), false);
}

public function testIsVersionEarlierThan_TestEarlierVersionBugVersion()
{
$this->assertEquals(General::isVersionEarlierThan("1.0.0", "1.0.5"), true);
}

public function testIsVersionEarlierThan_TestLaterVersionMinorVersion()
{
$this->assertEquals(General::isVersionEarlierThan("1.4.9", "1.4.5"), false);
}

public function testIsVersionEarlierThan_TestEarlierVersionMinorVersion()
{
$this->assertEquals(General::isVersionEarlierThan("1.3.5", "1.3.9"), true);
}

public function testIsVersionEarlierThan_TestEarlierVersionMajorVersion()
{
$this->assertEquals(General::isVersionEarlierThan("2.0.0", "1.9.9"), false);
}

public function testIsVersionEarlierThan_TestLaterVersionMajorVersion()
{
$this->assertEquals(General::isVersionEarlierThan("2.0.0", "3.0.0"), true);
}

public function testIsVersionEarlierThan_TestLaterMultiCharBugVersion()
{
$this->assertEquals(General::isVersionEarlierThan("1.0.99", "1.0.0"), false);
}

public function testIsVersionEarlierThan_TestEarlierMultiCharBugVersion1()
{
$this->assertEquals(General::isVersionEarlierThan("1.0.9", "1.0.10"), true);
}

public function testIsVersionEarlierThan_TestEarlierMultiCharBugVersion2()
{
$this->assertEquals(General::isVersionEarlierThan("1.0.9", "1.0.888"), true);
}

public function testIsVersionEarlierThan_TestZeroAsSecondNumber()
{
$this->assertEquals(General::isVersionEarlierThan("40.0.4", "4.0.8"), false);
}

}

0 comments on commit 61c0085

Please sign in to comment.