Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(installer): allow empty database table prefix during installation
fixes #12904
  • Loading branch information
jeabakker committed Nov 25, 2019
1 parent 110c144 commit 622b47c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
4 changes: 2 additions & 2 deletions engine/classes/Elgg/Cli/InstallCommand.php
Expand Up @@ -47,11 +47,11 @@ protected function execute(InputInterface $input, OutputInterface $output) {
* Database parameters
*/
'dbhost' => $this->ask('Enter database host [localhost]: ', 'localhost'),
'dbport' => $this->ask('Enter database port: '),
'dbport' => $this->ask('Enter database port [3306]: ', '3306'),
'dbuser' => $this->ask('Enter database username: '),
'dbpassword' => $this->ask('Enter database password: ', null, true),
'dbname' => $this->ask('Enter database name: '),
'dbprefix' => $this->ask('Enter database prefix [elgg_]: ', 'elgg_'),
'dbprefix' => $this->ask('Enter database prefix (for example: elgg_): ', '', false, false),
/**
* Site settings
*/
Expand Down
4 changes: 2 additions & 2 deletions engine/classes/ElggInstaller.php
Expand Up @@ -418,7 +418,7 @@ protected function runDatabase($submissionVars) {
'dbprefix' => [
'type' => 'text',
'value' => 'elgg_',
'required' => true,
'required' => false,
],
'dataroot' => [
'type' => 'text',
Expand Down Expand Up @@ -1199,7 +1199,7 @@ protected function validateDatabaseVars($submissionVars, $formVars) {
// non-Latin letters) or an underscore (_). Subsequent characters in an
// identifier or key word can be letters, underscores, digits (0-9), or dollar signs ($).
// Refs #4994
if (!preg_match("/^[a-zA-Z_][\w]*$/", $submissionVars['dbprefix'])) {
if (!empty($submissionVars['dbprefix']) && !preg_match("/^[a-zA-Z_][\w]*$/", $submissionVars['dbprefix'])) {
$app->_services->systemMessages->addErrorMessage(elgg_echo('install:error:database_prefix'));

return false;
Expand Down
35 changes: 34 additions & 1 deletion engine/tests/phpunit/unit/ElggInstallerTest.php
Expand Up @@ -278,7 +278,7 @@ public function testDatabase() {
'dbprefix' => [
'type' => 'text',
'value' => 'elgg_',
'required' => true,
'required' => false,
],
'dataroot' => [
'type' => 'text',
Expand Down Expand Up @@ -356,6 +356,39 @@ public function testDatabaseAction() {

elgg_delete_directory($dataroot);
}

public function testDatabaseActionWithEmptyPrefix() {

$dataroot = dirname(Paths::elgg()) . '/_installer_testing_dataroot/';
elgg_delete_directory($dataroot);

mkdir($dataroot);

$request = $this->prepareHttpRequest('install.php?step=database', 'POST', [
'dbprefix' => '',
'dbname' => getenv('ELGG_DB_NAME') ? : '',
'dbuser' => getenv('ELGG_DB_USER') ? : '',
'dbpassword' => getenv('ELGG_DB_PASS') ? : '',
'dbhost' => getenv('ELGG_DB_HOST') ? : 'localhost',
'dbport' => getenv('ELGG_DB_PORT') ? : 3306,
'dbencoding' => getenv('ELGG_DB_ENCODING') ? : 'utf8mb4',
'dataroot' => $dataroot,
'wwwroot' => getenv('ELGG_WWWROOT') ? : 'http://localhost/',
'timezone' => 'UTC',
]);

$this->getApp()->_services->setValue('request', $request);

$mock = $this->mock;
/* @var $mock ElggInstaller */

$response = $mock->run();

$this->assertInstanceOf(\Elgg\Http\RedirectResponse::class, $response);
$this->assertEquals(elgg_normalize_url('install.php?step=settings'), $response->getForwardURL());

elgg_delete_directory($dataroot);
}

public function testSettings() {

Expand Down

0 comments on commit 622b47c

Please sign in to comment.