From 3902bcd18de8ce0ab3bc03de4f1c794238c4f5c3 Mon Sep 17 00:00:00 2001 From: Shahal Tharique Date: Sun, 14 Jun 2020 23:51:52 +0530 Subject: [PATCH] Added support for db prefix in command line installer --- app/Console/Commands/Install.php | 8 ++++++-- app/Utilities/Installer.php | 10 ++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/Console/Commands/Install.php b/app/Console/Commands/Install.php index 8e759f50b..46207a9a0 100644 --- a/app/Console/Commands/Install.php +++ b/app/Console/Commands/Install.php @@ -15,6 +15,7 @@ class Install extends Command const OPT_DB_NAME = 'db-name'; const OPT_DB_USERNAME = 'db-username'; const OPT_DB_PASSWORD = 'db-password'; + const OPT_DB_PREFIX = 'db-prefix'; const OPT_COMPANY_NAME = 'company-name'; const OPT_COMPANY_EMAIL = 'company-email'; const OPT_ADMIN_EMAIL = 'admin-email'; @@ -33,6 +34,7 @@ class Install extends Command {--db-name= : Name of the database} {--db-username=root : Username to use to access the database} {--db-password= : Password to use to access the database} + {--db-prefix= : Table name prefix} {--company-name=My Company : Name of the company} {--company-email=my@company.com : Email of the company} {--admin-email= : Admin user email} @@ -102,10 +104,11 @@ class Install extends Command 'OPT_DB_NAME', 'OPT_DB_USERNAME', 'OPT_DB_PASSWORD', + 'OPT_DB_PREFIX', 'OPT_COMPANY_NAME', 'OPT_COMPANY_EMAIL', 'OPT_ADMIN_EMAIL', - 'OPT_ADMIN_PASSWORD', + 'OPT_ADMIN_PASSWORD' ]; foreach ($contants as $const) { @@ -177,10 +180,11 @@ class Install extends Command $this->db_name = $this->option(self::OPT_DB_NAME); $this->db_username = $this->option(self::OPT_DB_USERNAME); $this->db_password = $this->option(self::OPT_DB_PASSWORD); + $this->db_prefix = $this->option(self::OPT_DB_PREFIX); $this->line('Connecting to database ' . $this->db_name . '@' . $this->db_host . ':' . $this->db_port); - if (!Installer::createDbTables($this->db_host, $this->db_port, $this->db_name, $this->db_username, $this->db_password)) { + if (!Installer::createDbTables($this->db_host, $this->db_port, $this->db_name, $this->db_username, $this->db_password, $this->db_prefix)) { $this->error('Error: Could not connect to the database! Please, make sure the details are correct.'); return false; diff --git a/app/Utilities/Installer.php b/app/Utilities/Installer.php index cd44b82c6..d0d8ef7fd 100644 --- a/app/Utilities/Installer.php +++ b/app/Utilities/Installer.php @@ -141,14 +141,14 @@ class Installer ]); } - public static function createDbTables($host, $port, $database, $username, $password) + public static function createDbTables($host, $port, $database, $username, $password, $prefix = null) { if (!static::isDbValid($host, $port, $database, $username, $password)) { return false; } // Set database details - static::saveDbVariables($host, $port, $database, $username, $password); + static::saveDbVariables($host, $port, $database, $username, $password, $prefix); // Try to increase the maximum execution time set_time_limit(300); // 5 minutes @@ -199,9 +199,11 @@ class Installer return true; } - public static function saveDbVariables($host, $port, $database, $username, $password) + public static function saveDbVariables($host, $port, $database, $username, $password, $prefix = null) { - $prefix = strtolower(Str::random(3) . '_'); + if (is_null($prefix)){ + $prefix = strtolower(Str::random(3) . '_'); + } // Update .env file static::updateEnv([