Skip to content

Commit

Permalink
Run PHP version checks before booting the app
Browse files Browse the repository at this point in the history
  • Loading branch information
mbabker committed Aug 16, 2015
1 parent 368d336 commit 3381065
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 17 deletions.
21 changes: 8 additions & 13 deletions app/bundles/InstallBundle/Configurator/Step/CheckStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ public function checkRequirements()
{
$messages = array();

if (version_compare(PHP_VERSION, '5.3.7', '<')) {
$messages[] = 'mautic.install.minimum.php.version';
}

if (version_compare(PHP_VERSION, '5.3.16', '==')) {
$messages[] = 'mautic.install.buggy.php.version';
}
Expand All @@ -111,19 +107,18 @@ public function checkRequirements()
$messages[] = 'mautic.install.logs.unwritable';
}

if (version_compare(PHP_VERSION, '5.3.7', '>=')) {
$timezones = array();
foreach (\DateTimeZone::listAbbreviations() as $abbreviations) {
foreach ($abbreviations as $abbreviation) {
$timezones[$abbreviation['timezone_id']] = true;
}
}
$timezones = array();

if (!isset($timezones[date_default_timezone_get()])) {
$messages[] = 'mautic.install.timezone.not.supported';
foreach (\DateTimeZone::listAbbreviations() as $abbreviations) {
foreach ($abbreviations as $abbreviation) {
$timezones[$abbreviation['timezone_id']] = true;
}
}

if (!isset($timezones[date_default_timezone_get()])) {
$messages[] = 'mautic.install.timezone.not.supported';
}

if (get_magic_quotes_gpc()) {
$messages[] = 'mautic.install.magic_quotes_enabled';
}
Expand Down
3 changes: 0 additions & 3 deletions app/bundles/InstallBundle/Views/Install/check.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
<ul class="list-group">
<?php foreach ($majors as $message) : ?>
<?php switch ($message) :
case 'mautic.install.minimum.php.version': ?>
<li class="list-group-item"> <?php echo $view['translator']->trans($message, array('%minimum%' => '5.3.7', '%installed' => PHP_VERSION)); ?></li>
<?php break;
case 'mautic.install.cache.unwritable': ?>
<li class="list-group-item"><?php echo $view['translator']->trans('mautic.install.directory.unwritable', array('%path%' => $appRoot . '/cache')); ?></li>
<?php break;
Expand Down
20 changes: 19 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/

// Define Mautic's supported PHP versions
define('MAUTIC_MINIMUM_PHP', '5.3.7');
define('MAUTIC_MAXIMUM_PHP', '5.6.999');

// Are we running the minimum version?
if (version_compare(PHP_VERSION, MAUTIC_MINIMUM_PHP, '<')) {
echo 'Your server does not meet the minimum PHP requirements. Mautic requires PHP version '.MAUTIC_MINIMUM_PHP.' while your server has '.PHP_VERSION.'. Please contact your host to update your PHP installation.';

exit;
}

// Are we running a version newer than what Mautic supports?
if (version_compare(PHP_VERSION, MAUTIC_MAXIMUM_PHP, '>')) {
echo 'Mautic does not support PHP version '.PHP_VERSION.' at this time. To use Mautic, you will need to downgrade to an earlier version.';

exit;
}

// Fix for hosts that do not have date.timezone set, it will be reset based on users settings
date_default_timezone_set ('UTC');

Expand Down Expand Up @@ -50,4 +68,4 @@
$message = 'The site is currently offline due to encountering an error. If the problem persists, please contact the system administrator.';
$submessage = 'System administrators, check server logs for errors.';
include __DIR__ . '/offline.php';
}
}
18 changes: 18 additions & 0 deletions index_dev.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/

// Define Mautic's supported PHP versions
define('MAUTIC_MINIMUM_PHP', '5.3.7');
define('MAUTIC_MAXIMUM_PHP', '5.6.999');

// Are we running the minimum version?
if (version_compare(PHP_VERSION, MAUTIC_MINIMUM_PHP, '<')) {
echo 'Your server does not meet the minimum PHP requirements. Mautic requires PHP version '.MAUTIC_MINIMUM_PHP.' while your server has '.PHP_VERSION.'. Please contact your host to update your PHP installation.';

exit;
}

// Are we running a version newer than what Mautic supports?
if (version_compare(PHP_VERSION, MAUTIC_MAXIMUM_PHP, '>')) {
echo 'Mautic does not support PHP version '.PHP_VERSION.' at this time. To use Mautic, you will need to downgrade to an earlier version.';

exit;
}

// Fix for hosts that do not have date.timezone set, it will be reset based on users settings
date_default_timezone_set ('UTC');

Expand Down

0 comments on commit 3381065

Please sign in to comment.