";
- die();
- }
-
- // Write the config file
- global $usingEnv;
- if ($usingEnv) {
- $this->statusMessage("Setting up 'mysite/_config.php' for use with environment variables...");
- $this->writeToFile("mysite/_config.php", "statusMessage("Setting up 'mysite/_config.php'...");
- // Create databaseConfig
- $lines = array(
- $lines[] = " 'type' => '$type'"
- );
- foreach ($dbConfig as $key => $value) {
- $lines[] = " '{$key}' => '$value'";
- }
- $databaseConfigContent = implode(",\n", $lines);
- $this->writeToFile("mysite/_config.php", <<statusMessage("Setting up 'mysite/_config/theme.yml'");
- $this->writeToFile("mysite/_config/theme.yml", <<writeConfigPHP($config);
+ $this->writeConfigYaml($config);
+ $this->writeConfigEnv($config);
+ // Write other stuff
if (!$this->checkModuleExists('cms')) {
$this->writeToFile("mysite/code/RootURLController.php", <<hasRewritingCapability()) {
if ($isApache) {
- $this->statusMessage("Setting up '.htaccess' file...");
$this->createHtaccess();
} elseif ($isIIS) {
- $this->statusMessage("Setting up 'web.config' file...");
$this->createWebConfig();
}
}
@@ -282,18 +199,187 @@ HTML;
return $this->errors;
}
+ /**
+ * Write all .env files
+ *
+ * @param $config
+ */
+ protected function writeConfigEnv($config)
+ {
+ if (!$config['usingEnv']) {
+ return;
+ }
+
+ $path = $this->getBaseDir() . '.env';
+ $vars = [];
+
+ // Retain existing vars
+ // Note: vars with # or " in them are discarded
+ if (file_exists($path)) {
+ $env = new Dotenv($this->getBaseDir());
+ foreach ($env->load() as $line) {
+ if (preg_match('/^(?\w+)\s*=\s*("?)(?[^"#]*)("?)$/', $line, $matches)) {
+ $vars[$matches['key']] = $matches['value'];
+ }
+ }
+ }
+
+ // Set base URL
+ if (!isset($vars['SS_BASE_URL']) && isset($_SERVER['HTTP_HOST'])) {
+ $vars['SS_BASE_URL'] = 'http://' . $_SERVER['HTTP_HOST'] . BASE_URL;
+ }
+
+ // Set DB env
+ if (empty($config['db']['database'])) {
+ $vars['SS_DATABASE_CHOOSE_NAME'] = true;
+ } else {
+ $vars['SS_DATABASE_NAME'] = $config['db']['database'];
+ }
+ $vars['SS_DATABASE_CLASS'] = $config['db']['type'];
+ if (isset($config['db']['server'])) {
+ $vars['SS_DATABASE_SERVER'] = $config['db']['server'];
+ }
+ if (isset($config['db']['username'])) {
+ $vars['SS_DATABASE_USERNAME'] = $config['db']['username'];
+ }
+ if (isset($config['db']['password'])) {
+ $vars['SS_DATABASE_PASSWORD'] = $config['db']['password'];
+ }
+ if (isset($config['db']['path'])) {
+ $vars['SS_DATABASE_PATH'] = $config['db']['path'];
+ // sqlite compat
+ $vars['SS_SQLITE_DATABASE_PATH'] = $config['db']['path'];
+ }
+ if (isset($config['db']['key'])) {
+ $vars['SS_DATABASE_KEY'] = $config['db']['key'];
+ // sqlite compat
+ $vars['SS_SQLITE_DATABASE_KEY'] = $config['db']['key'];
+ }
+
+ // Write all env vars
+ $lines = [
+ '# Generated by SilverStripe Installer'
+ ];
+ ksort($vars);
+ foreach ($vars as $key => $value) {
+ $lines[] = $key.'="'.addcslashes($value, '"').'"';
+ }
+
+ $this->writeToFile('.env', implode("\n", $lines));
+
+ // Re-load env vars for installer access
+ $path = $this->getBaseDir();
+ (new Dotenv($path))->load();
+ }
+
+ /**
+ * Write all *.php files
+ *
+ * @param array $config
+ */
+ protected function writeConfigPHP($config)
+ {
+ if ($config['usingEnv']) {
+ $this->writeToFile("mysite/_config.php", " $value) {
+ $lines[] = sprintf(
+ " '%s' => '%s'",
+ addslashes($key),
+ addslashes($value)
+ );
+ }
+ $databaseConfigContent = implode(",\n", $lines);
+ $this->writeToFile("mysite/_config.php", <<ymlString($config['locale']);
+
+ // Set either specified, or no theme
+ if ($config['theme'] && $config['theme'] !== 'tutorial') {
+ $theme = $this->ymlString($config['theme']);
+ $themeYML = <<writeToFile("mysite/_config/theme.yml", <<getBaseDir();
$this->statusMessage("Setting up $base$filename");
if ((@$fh = fopen($base . $filename, 'wb')) && fwrite($fh, $content) && fclose($fh)) {
+ // Set permissions to writable
+ @chmod($base . $filename, 0775);
return true;
}
$this->error("Couldn't write to file $base$filename");
return false;
}
+ /**
+ * Ensure root .htaccess is setup
+ */
public function createHtaccess()
{
$start = "### SILVERSTRIPE START ###\n";
@@ -473,18 +559,6 @@ TEXT;
HTML;
}
- public function var_export_array_nokeys($array)
- {
- $retval = "array(\n";
- foreach ($array as $item) {
- $retval .= "\t'";
- $retval .= trim($item);
- $retval .= "',\n";
- }
- $retval .= ")";
- return $retval;
- }
-
/**
* Show an installation status message.
* The output differs depending on whether this is CLI or web based
@@ -496,4 +570,29 @@ HTML;
echo "
$msg
\n";
flush();
}
+
+ /**
+ * @param $config
+ */
+ protected function sendInstallStats($config)
+ {
+ // Try to determine the database version from the helper
+ $dbType = $config['db']['type'];
+ $helper = $this->getDatabaseConfigurationHelper($dbType);
+ if ($helper) {
+ $databaseVersion = $dbType . ': ' . $helper->getDatabaseVersion($config['db']);
+ } else {
+ $databaseVersion = $dbType;
+ }
+
+ $args = http_build_query(array_filter([
+ 'SilverStripe' => $config['version'],
+ 'PHP' => phpversion(),
+ 'Database' => $databaseVersion,
+ 'WebServer' => $this->findWebserver(),
+ 'ID' => empty($_SESSION['StatsID']) ? null : $_SESSION['StatsID']
+ ]));
+ $url = "http://ss2stat.silverstripe.com/Installation/add?{$args}";
+ @$_SESSION['StatsID'] = file_get_contents($url);
+ }
}
diff --git a/src/Dev/Install/client/js/install.js b/src/Dev/Install/client/js/install.js
index 2bd164d0e..40047180c 100644
--- a/src/Dev/Install/client/js/install.js
+++ b/src/Dev/Install/client/js/install.js
@@ -1,59 +1,49 @@
$(document).ready(function () {
- /**
- * Toggle field readonly modes, if check configuration comes from
- * environment variables (values populated on reload).
- */
- $('#use_environment').click(function (e) {
- if (!$(this).is(':checked')) {
- $('.configured-by-env').removeAttr('disabled');
- } else {
- $('.configured-by-env').attr('disabled', 'disabled');
- }
- });
+ /**
+ * Hide all existing database warnings, and show only current one
+ */
+ $('#database_selection > li > label, #database_selection > li > input:radio').click(function () {
+ $('.dbfields').hide();
+ // only show fields if there's no db error
+ if (!$('.databaseError', $(this).parent()).length) {
+ $('.dbfields', $(this).parent()).show();
+ }
+ $('.databaseError').hide();
+ $('.databaseError', $(this).parent()).show();
+ });
- /**
- * Hide all existing database warnings, and show only current one
- */
- $('#database_selection li label, #database_selection input:radio').click(function (e) {
- $('.dbfields').hide();
- // only show fields if there's no db error
- if (!$('.databaseError', $(this).parent()).length) {
- $('.dbfields', $(this).parent()).show();
- }
- $('.databaseError').hide();
- $('.databaseError', $(this).parent()).show();
- });
+ // Handle install button
+ $('#install_button').click(function (e) {
+ // Confirm on re-install
+ if (
+ $(this).hasClass('mustconfirm')
+ && !confirm('Are you sure you wish to replace the existing installation config?')
+ ) {
+ e.preventDefault();
+ return false;
+ }
- // Select first
- $('#database_selection li input:checked').siblings('label').click();
+ // Process
+ $('#saving_top').hide();
+ $(this).val('Installing SilverStripe...');
+ return true;
+ });
- /**
- * Install button
- */
- $('#reinstall_confirmation').click(function () {
- $('#install_button').attr('disabled', !$(this).is(':checked'));
- });
+ /**
+ * Show all the requirements
+ */
+ $('h5.requirement a').click(function () {
+ if ($(this).text() === 'Hide All Requirements') {
+ // hide the shown requirements
+ $(this).parents('h5').next('table.testResults').find('.good').hide();
+ $(this).text('Show All Requirements');
+ } else {
+ // show the requirements.
+ $(this).parents('h5').next('table.testResults').find('.good').show();
+ $(this).text('Hide All Requirements');
+ }
- $('#install_button').click(function () {
- $('#saving_top').hide();
- $(this).val('Installing SilverStripe...');
- });
-
- /**
- * Show all the requirements
- */
- $('h5.requirement a').click(function () {
- if ($(this).text() == 'Hide All Requirements') {
- // hide the shown requirements
- $(this).parents('h5').next('table.testResults').find('.good').hide();
- $(this).text('Show All Requirements');
- } else {
- // show the requirements.
- $(this).parents('h5').next('table.testResults').find('.good').show();
- $(this).text('Hide All Requirements');
- }
-
- return false;
- });
+ return false;
+ });
});
diff --git a/src/Dev/Install/config-form.html b/src/Dev/Install/config-form.html
index a9685e3a3..6d2851210 100644
--- a/src/Dev/Install/config-form.html
+++ b/src/Dev/Install/config-form.html
@@ -7,8 +7,8 @@
SilverStripe CMS / Framework Installation
-
-
+
+
@@ -41,7 +41,7 @@
Note: SilverStripe is already installed here.
- If you wish to reinstall SilverStripe, please delete the mysite/_config.php file first.
+ If you choose to reinstall SilverStripe, your current settings will be replaced
hasWarnings()): ?>
@@ -94,33 +94,24 @@
$details) {
- $checked = ($databaseConfig['type'] == $class || $type == $class) ? ' checked="checked"' : '';
+ foreach ($databaseClasses as $class => $details) {
+ $checked = ($databaseConfig['type'] == $class) ? ' checked="checked"' : '';
$disabled = $help = '';
- if($usingEnv) {
- // All are disabled by default when environment is used
- $disabled = 'disabled="disabled"';
- // If SS_DATABASE_CLASS is specified, check the database in the list
- if(getenv('SS_DATABASE_CLASS') == $class) {
- $checked = ' checked="checked"';
- }
- } else {
- $disabled = !$details['supported'] || !$details['hasModule'] ? 'notavailable="true"' : '';
- if ($disabled) {
- if (!$details['supported'] && !$details['hasModule']) {
- $help = 'PHP does not have the required extension, and SilverStripe does not have the correct module installed';
- $helpText = '
'.$details['missingExtensionText'].'
';
- $helpText .= '
'.$details['missingModuleText'].'
';
- } else if ($details['supported'] && !$details['hasModule']) {
- $help = 'PHP has the required extension, but SilverStripe is missing the module';
- $helpText = '
'.$details['missingModuleText'].'
';
- } else if (!$details['supported'] && $details['hasModule']) {
- $help = 'SilverStripe has the module installed, but PHP is missing the required extension';
- $helpText = '
'.$details['missingExtensionText'].'
';
- }
- $help .= "
$helpText
";
- }
- }
+ $disabled = !$details['supported'] || !$details['hasModule'] ? 'notavailable="true"' : '';
+ if ($disabled) {
+ if (!$details['supported'] && !$details['hasModule']) {
+ $help = 'PHP does not have the required extension, and SilverStripe does not have the correct module installed';
+ $helpText = '
'.$details['missingExtensionText'].'
';
+ $helpText .= '
'.$details['missingModuleText'].'
';
+ } else if ($details['supported'] && !$details['hasModule']) {
+ $help = 'PHP has the required extension, but SilverStripe is missing the module';
+ $helpText = '
'.$details['missingModuleText'].'
';
+ } else if (!$details['supported'] && $details['hasModule']) {
+ $help = 'SilverStripe has the module installed, but PHP is missing the required extension';
+ $helpText = '