Skip to content

Commit 61c0085

Browse files
committed
version check for upgrade scripts
1 parent 213e199 commit 61c0085

File tree

5 files changed

+86
-11
lines changed

5 files changed

+86
-11
lines changed

global/code/Core.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ class Core {
247247
/**
248248
* The release date: YYYYMMDD
249249
*/
250-
private static $releaseDate = "20180127";
250+
private static $releaseDate = "20180201";
251251

252252
/**
253253
* The minimum required PHP version needed to run Form Tools.

global/code/Emails.class.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,8 +1288,7 @@ public static function processEmailTemplate($form_id, $submission_id, $email_id)
12881288
return array(false, "Email components not returned properly (Emails::getEmailComponents).");
12891289
}
12901290

1291-
extract(Hooks::processHookCalls("start", compact("form_id", "submission_id", "email_id", "email_components"),
1292-
array("email_components")), EXTR_OVERWRITE);
1291+
extract(Hooks::processHookCalls("start", compact("form_id", "submission_id", "email_id", "email_components"), array("email_components")), EXTR_OVERWRITE);
12931292

12941293
// if Swift Mailer is enabled, send the emails with that
12951294
$continue = true;

global/code/General.class.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1306,5 +1306,27 @@ public static function getLoginOverrideId()
13061306
}
13071307
return $id;
13081308
}
1309-
}
13101309

1310+
1311+
/**
1312+
* Compares two versions to see if a version is earlier than a target version. Used to determine whether or not
1313+
* to trigger upgrading for modules/the Core.
1314+
*/
1315+
public static function isVersionEarlierThan($version, $target_version) {
1316+
if ($version === $target_version) {
1317+
return false;
1318+
}
1319+
1320+
list($major, $minor, $version_bugfix) = explode(".", $version);
1321+
$version_major = $major * 1000000;
1322+
$version_minor = $minor * 1000;
1323+
$version_num = $version_major + $version_minor + $version_bugfix;
1324+
1325+
list($target_major, $target_minor, $target_bugfix) = explode(".", $target_version);
1326+
$target_version_major = $target_major * 1000000;
1327+
$target_version_minor = $target_minor * 1000;
1328+
$target_version_num = $target_version_major + $target_version_minor + $target_bugfix;
1329+
1330+
return $version_num < $target_version_num;
1331+
}
1332+
}

global/code/User.class.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,6 @@ public function logout($message_flag = "")
270270

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

273-
// this ensures sessions are started
274-
// if ($g_session_type == "database") {
275-
// $sess = new SessionManager();
276-
// }
277-
// @session_start();
278-
279273
// first, if $_SESSION["ft"]["admin"] is set, it is an administrator logging out, so just redirect them
280274
// back to the admin pages
281275
if (Sessions::exists("admin")) {
@@ -336,7 +330,7 @@ public function checkAuth($required_account_type, $auto_logout = true)
336330
$boot_out_user = false;
337331
$message_flag = "";
338332

339-
extract(Hooks::processHookCalls("end", compact("account_type"), array("boot_out_user", "message_flag")), EXTR_OVERWRITE);
333+
extract(Hooks::processHookCalls("start", compact("account_type"), array("boot_out_user", "message_flag")), EXTR_OVERWRITE);
340334

341335
$account_id = $this->accountId;
342336
$account_type = $this->accountType;

tests/phpunit/General.classTest.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,64 @@ public function testStripChars_CustomWhitelist()
5555
$trimmed_string = General::stripChars($string, "97531");
5656
$this->assertEquals($trimmed_string, "13579");
5757
}
58+
59+
60+
// General::isVersionEarlierThan()
61+
62+
public function testIsVersionEarlierThan_TestSameVersion()
63+
{
64+
$this->assertEquals(General::isVersionEarlierThan("1.0.0", "1.0.0"), false);
65+
}
66+
67+
public function testIsVersionEarlierThan_TestLaterVersionBugVersion()
68+
{
69+
$this->assertEquals(General::isVersionEarlierThan("1.0.1", "1.0.0"), false);
70+
}
71+
72+
public function testIsVersionEarlierThan_TestEarlierVersionBugVersion()
73+
{
74+
$this->assertEquals(General::isVersionEarlierThan("1.0.0", "1.0.5"), true);
75+
}
76+
77+
public function testIsVersionEarlierThan_TestLaterVersionMinorVersion()
78+
{
79+
$this->assertEquals(General::isVersionEarlierThan("1.4.9", "1.4.5"), false);
80+
}
81+
82+
public function testIsVersionEarlierThan_TestEarlierVersionMinorVersion()
83+
{
84+
$this->assertEquals(General::isVersionEarlierThan("1.3.5", "1.3.9"), true);
85+
}
86+
87+
public function testIsVersionEarlierThan_TestEarlierVersionMajorVersion()
88+
{
89+
$this->assertEquals(General::isVersionEarlierThan("2.0.0", "1.9.9"), false);
90+
}
91+
92+
public function testIsVersionEarlierThan_TestLaterVersionMajorVersion()
93+
{
94+
$this->assertEquals(General::isVersionEarlierThan("2.0.0", "3.0.0"), true);
95+
}
96+
97+
public function testIsVersionEarlierThan_TestLaterMultiCharBugVersion()
98+
{
99+
$this->assertEquals(General::isVersionEarlierThan("1.0.99", "1.0.0"), false);
100+
}
101+
102+
public function testIsVersionEarlierThan_TestEarlierMultiCharBugVersion1()
103+
{
104+
$this->assertEquals(General::isVersionEarlierThan("1.0.9", "1.0.10"), true);
105+
}
106+
107+
public function testIsVersionEarlierThan_TestEarlierMultiCharBugVersion2()
108+
{
109+
$this->assertEquals(General::isVersionEarlierThan("1.0.9", "1.0.888"), true);
110+
}
111+
112+
public function testIsVersionEarlierThan_TestZeroAsSecondNumber()
113+
{
114+
$this->assertEquals(General::isVersionEarlierThan("40.0.4", "4.0.8"), false);
115+
}
116+
58117
}
118+

0 commit comments

Comments
 (0)