Skip to content

Commit

Permalink
Fixes matomo-org#6468 Error in system check when always_populate_raw_…
Browse files Browse the repository at this point in the history
…post_data is not -1 on PHP 5.6+
  • Loading branch information
mattab committed Nov 27, 2014
1 parent 315b6fe commit 04ee32f
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 48 deletions.
65 changes: 41 additions & 24 deletions plugins/Installation/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -635,30 +635,7 @@ private function setupSystemCheckView($view)
{
$view->infos = self::getSystemInformation();

$view->helpMessages = array(
'zlib' => 'Installation_SystemCheckZlibHelp',
'gzopen' => 'Installation_SystemCheckZlibHelp',
'SPL' => 'Installation_SystemCheckSplHelp',
'iconv' => 'Installation_SystemCheckIconvHelp',
'mbstring' => 'Installation_SystemCheckMbstringHelp',
'Reflection' => 'Required extension that is built in PHP, see http://www.php.net/manual/en/book.reflection.php',
'json' => 'Installation_SystemCheckWarnJsonHelp',
'libxml' => 'Installation_SystemCheckWarnLibXmlHelp',
'dom' => 'Installation_SystemCheckWarnDomHelp',
'SimpleXML' => 'Installation_SystemCheckWarnSimpleXMLHelp',
'set_time_limit' => 'Installation_SystemCheckTimeLimitHelp',
'mail' => 'Installation_SystemCheckMailHelp',
'parse_ini_file' => 'Installation_SystemCheckParseIniFileHelp',
'glob' => 'Installation_SystemCheckGlobHelp',
'debug_backtrace' => 'Installation_SystemCheckDebugBacktraceHelp',
'create_function' => 'Installation_SystemCheckCreateFunctionHelp',
'eval' => 'Installation_SystemCheckEvalHelp',
'gzcompress' => 'Installation_SystemCheckGzcompressHelp',
'gzuncompress' => 'Installation_SystemCheckGzuncompressHelp',
'pack' => 'Installation_SystemCheckPackHelp',
'php5-json' => 'Installation_SystemCheckJsonHelp',
'session.auto_start' => 'Installation_SystemCheckSessionAutostart',
);
$view->helpMessages = $this->getSystemCheckHelpMessages();

$view->problemWithSomeDirectories = (false !== array_search(false, $view->infos['directories']));
}
Expand Down Expand Up @@ -746,4 +723,44 @@ protected function updateComponents()
return $result;
});
}

/**
* @return array
*/
private function getSystemCheckHelpMessages()
{
$helpMessages = array(
// Extensions
'zlib' => 'Installation_SystemCheckZlibHelp',
'gzopen' => 'Installation_SystemCheckZlibHelp',
'SPL' => 'Installation_SystemCheckSplHelp',
'iconv' => 'Installation_SystemCheckIconvHelp',
'mbstring' => 'Installation_SystemCheckMbstringHelp',
'Reflection' => 'Required extension that is built in PHP, see http://www.php.net/manual/en/book.reflection.php',
'json' => 'Installation_SystemCheckWarnJsonHelp',
'libxml' => 'Installation_SystemCheckWarnLibXmlHelp',
'dom' => 'Installation_SystemCheckWarnDomHelp',
'SimpleXML' => 'Installation_SystemCheckWarnSimpleXMLHelp',

// Functions
'set_time_limit' => 'Installation_SystemCheckTimeLimitHelp',
'mail' => 'Installation_SystemCheckMailHelp',
'parse_ini_file' => 'Installation_SystemCheckParseIniFileHelp',
'glob' => 'Installation_SystemCheckGlobHelp',
'debug_backtrace' => 'Installation_SystemCheckDebugBacktraceHelp',
'create_function' => 'Installation_SystemCheckCreateFunctionHelp',
'eval' => 'Installation_SystemCheckEvalHelp',
'gzcompress' => 'Installation_SystemCheckGzcompressHelp',
'gzuncompress' => 'Installation_SystemCheckGzuncompressHelp',
'pack' => 'Installation_SystemCheckPackHelp',
'php5-json' => 'Installation_SystemCheckJsonHelp',
);

// Add standard message for required PHP.ini settings
$requiredSettings = SystemCheck::getRequiredPhpSettings();
foreach($requiredSettings as $requiredSetting) {
$helpMessages[$requiredSetting] = Piwik::translate('Installation_SystemCheckPhpSetting', $requiredSetting);
}
return $helpMessages;
}
}
66 changes: 48 additions & 18 deletions plugins/Installation/SystemCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,11 @@ public static function getSystemInformation()
$infos['desired_extensions'] = self::getRecommendedExtensions();
$infos['missing_desired_extensions'] = self::getRecommendedExtensionsMissing();

$infos['desired_functions'] = self::getRecommendedFunctions();
$infos['missing_desired_functions'] = self::getRecommendedFunctionsMissing();

//TODO create recommended settings
$desired_settings = array(
'session.auto_start',
);
$infos['desired_functions'] = array_merge(self::getRecommendedFunctions(), $desired_settings);
$infos['needed_settings'] = self::getRequiredPhpSettings();
$infos['missing_settings'] = self::getMissingPhpSettings();

$infos['openurl'] = Http::getTransportMethod();
$infos['gd_ok'] = SettingsServer::isGdExtensionEnabled();
Expand Down Expand Up @@ -159,7 +157,6 @@ protected static function getDirectoriesShouldBeWritable()
if (!DbHelper::isInstalled()) {
// at install, need /config to be writable (so we can create config.ini.php)
$directoriesToCheck[] = '/config/';
return $directoriesToCheck;
}
return $directoriesToCheck;
}
Expand All @@ -169,7 +166,7 @@ protected static function getDirectoriesShouldBeWritable()
*/
protected static function getRequiredFunctions()
{
return $needed_functions = array(
return array(
'debug_backtrace',
'create_function',
'eval',
Expand Down Expand Up @@ -372,9 +369,9 @@ protected static function isPhpExtensionLoaded($needed_extension)
protected static function getRequiredExtensionsMissing()
{
$missingExtensions = array();
foreach (self::getRequiredExtensions() as $needed_extension) {
if (!self::isPhpExtensionLoaded($needed_extension)) {
$missingExtensions[] = $needed_extension;
foreach (self::getRequiredExtensions() as $requiredExtension) {
if (!self::isPhpExtensionLoaded($requiredExtension)) {
$missingExtensions[] = $requiredExtension;
}
}

Expand All @@ -400,14 +397,7 @@ protected static function getRecommendedExtensionsMissing()
*/
protected static function getRecommendedFunctionsMissing()
{
$recommendedFunctionsMissing = self::getFunctionsMissing(self::getRecommendedFunctions());

$sessionAutoStarted = (int)ini_get('session.auto_start');
if ($sessionAutoStarted) {
$recommendedFunctionsMissing[] = 'session.auto_start';
}

return $recommendedFunctionsMissing;
return self::getFunctionsMissing(self::getRecommendedFunctions());
}

/**
Expand Down Expand Up @@ -437,5 +427,45 @@ protected static function getMinimumRecommendedMemoryLimit()
return Config::getInstance()->General['minimum_memory_limit'];
}

private static function isPhpVersionAtLeast56()
{
return version_compare( PHP_VERSION, '5.6', '>=');
}

/**
* @return array
*/
public static function getRequiredPhpSettings()
{
$requiredPhpSettings = array(
// setting = required value
// Note: value must be an integer only
'session.auto_start=0',
);

if (self::isPhpVersionAtLeast56()) {
// always_populate_raw_post_data must be -1
$requiredPhpSettings[] = 'always_populate_raw_post_data=-1';
}
return $requiredPhpSettings;
}

/**
* @return array
*/
protected static function getMissingPhpSettings()
{
$missingPhpSettings = array();
foreach(self::getRequiredPhpSettings() as $requiredSetting) {
list($requiredSettingName, $requiredSettingValue) = explode('=', $requiredSetting);

$currentValue = ini_get($requiredSettingName);
$currentValue = (int)$currentValue;

if($currentValue != $requiredSettingValue) {
$missingPhpSettings[] = $requiredSetting;
}
}
return $missingPhpSettings;
}
}
3 changes: 2 additions & 1 deletion plugins/Installation/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"SystemCheckPhp": "PHP version",
"SystemCheckPhpPdoAndMysqli": "More information on: %1$sPHP PDO%2$s and %3$sMYSQLI%4$s.",
"SystemCheckSplHelp": "You need to configure and rebuild PHP with the Standard PHP Library (SPL) enabled (by default).",
"SystemCheckSettings": "Required PHP configuration (php.ini)",
"SystemCheckSummaryNoProblems": "Huzzah! There are no problems with your Piwik setup. Give yourself a pat on the back.",
"SystemCheckSummaryThereWereErrors": "Uh-oh! Piwik has detected some %1$scritical issues%2$s with your Piwik setup. %3$sThese issues should be fixed immediately.%4$s",
"SystemCheckSummaryThereWereWarnings": "There are some issues with your system. Piwik will run, but you might experience some minor problems.",
Expand All @@ -112,7 +113,7 @@
"SystemCheckZlibHelp": "You need to configure and rebuild PHP with \"zlib\" support enabled, --with-zlib.",
"SystemCheckCronArchiveProcess": "Archive Cron",
"SystemCheckCronArchiveProcessCLI": "Managing processes via CLI",
"SystemCheckSessionAutostart": "To prevent some issues please set the following in your php.ini file: session.auto_start=0",
"SystemCheckPhpSetting": "To prevent some critical issue, you must set the following in your php.ini file: %s",
"NotSupported": "not supported",
"Tables": "Creating the Tables",
"TablesCreatedSuccess": "Tables created with success!",
Expand Down
30 changes: 25 additions & 5 deletions plugins/Installation/templates/_systemCheckSection.twig
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,13 @@
{% for needed_extension in infos.needed_extensions %}
{% if needed_extension in infos.missing_extensions %}
{{ error }}
{% set hasError %}1{% endset %}
<br/>{{ 'Installation_RestartWebServer'|translate }}
{% else %}
{{ ok }}
{% endif %}
{{ needed_extension }}
<br/>
{% endfor %}
<br/>{% if hasError is defined %}{{ 'Installation_RestartWebServer'|translate }}{% endif %}
</td>
</tr>
{% if infos.missing_extensions|length > 0 %}
Expand All @@ -84,16 +83,37 @@
{% if needed_function in infos.missing_functions %}
{{ error }}
<span class='err'>{{ needed_function }}</span>
{% set hasError %}1{% endset %}
<p>
<em>{{ helpMessages[needed_function]|translate }}</em>
<em>
{{ helpMessages[needed_function]|translate }}
<br/>{{ 'Installation_RestartWebServer'|translate }}
</em>
</p>
{% else %}
{{ ok }} {{ needed_function }}
<br/>
{% endif %}
{% endfor %}
<br/>{% if hasError is defined %}{{ 'Installation_RestartWebServer'|translate }}{% endif %}
</td>
</tr>
<tr>
<td class="label">{{ 'Installation_SystemCheckSettings'|translate }}</td>
<td>
{% for needed_setting in infos.needed_settings %}
{% if needed_setting in infos.missing_settings %}
{{ error }}
<span class='err'>{{ needed_setting }}</span>
<p>
<em>
{{ helpMessages[needed_setting]|translate }}
<br/>{{ 'Installation_RestartWebServer'|translate }}
</em>
</p>
{% else %}
{{ ok }} {{ needed_setting }}
<br/>
{% endif %}
{% endfor %}
</td>
</tr>
<tr>
Expand Down

0 comments on commit 04ee32f

Please sign in to comment.