simplified install command
This commit is contained in:
parent
8c2e12a3fa
commit
2cb3f117a5
@ -30,7 +30,7 @@ Akaunting uses [Laravel](http://laravel.com), the best existing PHP framework, a
|
||||
* Finally, launch the [web installer](https://akaunting.com/docs/installation) or run the following command:
|
||||
|
||||
```bash
|
||||
php artisan install --db-host="localhost" --db-name="my_db" --db-username="my_admin" --db-password="my_pass" --company-name="My Company" --company-email="my@company.com" --admin-email="my@company.com" --admin-password="123456"
|
||||
php artisan install --db-name="akaunting" --db-username="root" --db-password="pass" --admin-email="admin@company.com" --admin-password="123456"
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
@ -22,33 +22,19 @@ class Install extends Command
|
||||
const OPT_LOCALE = 'locale';
|
||||
const OPT_NO_INTERACTION = 'no-interaction';
|
||||
|
||||
public $dbHost;
|
||||
public $dbPort;
|
||||
public $dbName;
|
||||
public $dbUsername;
|
||||
public $dbPassword;
|
||||
|
||||
public $companyName;
|
||||
public $companyEmail;
|
||||
|
||||
public $adminEmail;
|
||||
public $adminPassword;
|
||||
|
||||
public $locale;
|
||||
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'install
|
||||
{--db-host= : Database host}
|
||||
{--db-host=localhost : Database host}
|
||||
{--db-port=3306 : Port of the database host}
|
||||
{--db-name= : Name of the database}
|
||||
{--db-username= : Username to use to access the database}
|
||||
{--db-password= : Password to use to access the database}
|
||||
{--company-name= : Name of the company managed buy the app}
|
||||
{--company-email= : email used to contact the company}
|
||||
{--company-name=My Company : Name of the company}
|
||||
{--company-email=my@company.com : Email of the company}
|
||||
{--admin-email= : Admin user email}
|
||||
{--admin-password= : Admin user password}
|
||||
{--locale=en-GB : Language used in the app}
|
||||
@ -61,14 +47,6 @@ class Install extends Command
|
||||
*/
|
||||
protected $description = 'Allows to install Akaunting directly through CLI';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
@ -76,11 +54,10 @@ class Install extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$missingOptions = $this->checkOptions();
|
||||
if (!empty($missingOptions) && $this->option(self::OPT_NO_INTERACTION)) {
|
||||
if (($missing_options = $this->getMissingOptions()) && $this->option(self::OPT_NO_INTERACTION)) {
|
||||
$this->line('❌ Some options are missing and --no-interaction is present. Please run the following command for more informations :');
|
||||
$this->line('❌ php artisan help install');
|
||||
$this->line('❌ Missing options are : ' . join(', ', $missingOptions));
|
||||
$this->line('❌ php artisan help install');
|
||||
$this->line('❌ Missing options are : ' . implode(', ', $missing_options));
|
||||
|
||||
return self::CMD_ERROR;
|
||||
}
|
||||
@ -99,10 +76,10 @@ class Install extends Command
|
||||
}
|
||||
|
||||
$this->line('Creating company');
|
||||
Installer::createCompany($this->companyName, $this->companyEmail, $this->locale);
|
||||
Installer::createCompany($this->company_name, $this->company_email, $this->locale);
|
||||
|
||||
$this->line('Creating admin');
|
||||
Installer::createUser($this->adminEmail, $this->adminPassword, $this->locale);
|
||||
Installer::createUser($this->admin_email, $this->admin_password, $this->locale);
|
||||
|
||||
$this->line('Applying the final touches');
|
||||
Installer::finalTouches();
|
||||
@ -113,61 +90,41 @@ class Install extends Command
|
||||
/**
|
||||
* Check that all options are presents. otherwise returns an array of the missing options
|
||||
*/
|
||||
private function checkOptions()
|
||||
private function getMissingOptions()
|
||||
{
|
||||
$missingOptions = array();
|
||||
$missing_options = [];
|
||||
|
||||
$this->locale = $this->option(self::OPT_LOCALE);
|
||||
if (empty($this->locale)) {
|
||||
$missingOptions[] = self::OPT_LOCALE;
|
||||
$contants = [
|
||||
'OPT_LOCALE',
|
||||
'OPT_DB_PORT',
|
||||
'OPT_DB_HOST',
|
||||
'OPT_DB_NAME',
|
||||
'OPT_DB_USERNAME',
|
||||
'OPT_DB_PASSWORD',
|
||||
'OPT_COMPANY_NAME',
|
||||
'OPT_COMPANY_EMAIL',
|
||||
'OPT_ADMIN_EMAIL',
|
||||
'OPT_ADMIN_PASSWORD',
|
||||
];
|
||||
|
||||
foreach ($contants as $const) {
|
||||
$option = constant("self::$const");
|
||||
|
||||
$property = str_replace('-', '_', $option);
|
||||
|
||||
$this->$property = $this->option($option);
|
||||
|
||||
if (empty($this->$property)) {
|
||||
// Allow empty password
|
||||
if ($property == 'db_password') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$missing_options[] = $option;
|
||||
}
|
||||
}
|
||||
|
||||
$this->dbHost = $this->option(self::OPT_DB_HOST);
|
||||
if (empty($this->dbHost)) {
|
||||
$missingOptions[] = self::OPT_DB_HOST;
|
||||
}
|
||||
|
||||
$this->dbPort = $this->option(self::OPT_DB_PORT);
|
||||
if (empty($this->dbPort)) {
|
||||
$missingOptions[] = self::OPT_DB_PORT;
|
||||
}
|
||||
|
||||
$this->dbName = $this->option(self::OPT_DB_NAME);
|
||||
if (empty($this->dbName)) {
|
||||
$missingOptions[] = self::OPT_DB_NAME;
|
||||
}
|
||||
|
||||
$this->dbUsername = $this->option(self::OPT_DB_USERNAME);
|
||||
if (empty($this->dbUsername)) {
|
||||
$missingOptions[] = self::OPT_DB_USERNAME;
|
||||
}
|
||||
|
||||
$this->dbPassword = $this->option(self::OPT_DB_PASSWORD);
|
||||
if (empty($this->dbPassword)) {
|
||||
$missingOptions[] = self::OPT_DB_PASSWORD;
|
||||
}
|
||||
|
||||
$this->companyName = $this->option(self::OPT_COMPANY_NAME);
|
||||
if (empty($this->companyName)) {
|
||||
$missingOptions[] = self::OPT_COMPANY_NAME;
|
||||
}
|
||||
|
||||
$this->companyEmail = $this->option(self::OPT_COMPANY_EMAIL);
|
||||
if (empty($this->companyEmail)) {
|
||||
$missingOptions[] = self::OPT_COMPANY_EMAIL;
|
||||
}
|
||||
|
||||
$this->adminEmail = $this->option(self::OPT_ADMIN_EMAIL);
|
||||
if (empty($this->adminEmail)) {
|
||||
$missingOptions[] = self::OPT_ADMIN_EMAIL;
|
||||
}
|
||||
|
||||
$this->adminPassword = $this->option(self::OPT_ADMIN_PASSWORD);
|
||||
if (empty($this->adminPassword)) {
|
||||
$missingOptions[] = self::OPT_ADMIN_PASSWORD;
|
||||
}
|
||||
|
||||
return $missingOptions;
|
||||
return $missing_options;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -175,54 +132,54 @@ class Install extends Command
|
||||
*/
|
||||
private function prompt()
|
||||
{
|
||||
if (empty($this->dbHost)) {
|
||||
$this->dbHost = $this->ask('What is the database host?', 'localhost');
|
||||
if (empty($this->db_host)) {
|
||||
$this->db_host = $this->ask('What is the database host?', 'localhost');
|
||||
}
|
||||
|
||||
if (empty($this->dbPort)) {
|
||||
$this->dbPort = $this->ask('What is the database port?', '3606');
|
||||
if (empty($this->db_port)) {
|
||||
$this->db_port = $this->ask('What is the database port?', '3306');
|
||||
}
|
||||
|
||||
if (empty($this->dbName)) {
|
||||
$this->dbName = $this->ask('What is the database name?');
|
||||
if (empty($this->db_name)) {
|
||||
$this->db_name = $this->ask('What is the database name?');
|
||||
}
|
||||
|
||||
if (empty($this->dbUsername)) {
|
||||
$this->dbUsername = $this->ask('What is the database username?');
|
||||
if (empty($this->db_username)) {
|
||||
$this->db_username = $this->ask('What is the database username?');
|
||||
}
|
||||
|
||||
if (empty($this->dbPassword)) {
|
||||
$this->dbPassword = $this->secret('What is the database password?');
|
||||
if (empty($this->db_password)) {
|
||||
$this->db_password = $this->secret('What is the database password?', '');
|
||||
}
|
||||
|
||||
if (empty($this->companyName)) {
|
||||
$this->companyName = $this->ask('What is the company name?');
|
||||
if (empty($this->company_name)) {
|
||||
$this->company_name = $this->ask('What is the company name?', 'My Company');
|
||||
}
|
||||
|
||||
if (empty($this->companyEmail)) {
|
||||
$this->companyEmail = $this->ask('What is the company contact email?');
|
||||
if (empty($this->company_email)) {
|
||||
$this->company_email = $this->ask('What is the company contact email?', 'my@company.com');
|
||||
}
|
||||
|
||||
if (empty($this->adminEmail)) {
|
||||
$this->adminEmail = $this->ask('What is the admin email?', $this->companyEmail);
|
||||
if (empty($this->admin_email)) {
|
||||
$this->admin_email = $this->ask('What is the admin email?', $this->company_email);
|
||||
}
|
||||
|
||||
if (empty($this->adminPassword)) {
|
||||
$this->adminPassword = $this->secret('What is the admin password?');
|
||||
if (empty($this->admin_password)) {
|
||||
$this->admin_password = $this->secret('What is the admin password?');
|
||||
}
|
||||
}
|
||||
|
||||
private function createDatabaseTables()
|
||||
{
|
||||
$this->dbHost = $this->option(self::OPT_DB_HOST);
|
||||
$this->dbPort = $this->option(self::OPT_DB_PORT);
|
||||
$this->dbName = $this->option(self::OPT_DB_NAME);
|
||||
$this->dbUsername = $this->option(self::OPT_DB_USERNAME);
|
||||
$this->dbPassword = $this->option(self::OPT_DB_PASSWORD);
|
||||
$this->db_host = $this->option(self::OPT_DB_HOST);
|
||||
$this->db_port = $this->option(self::OPT_DB_PORT);
|
||||
$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->line('Connecting to database ' . $this->dbName . '@' . $this->dbHost . ':' . $this->dbPort);
|
||||
$this->line('Connecting to database ' . $this->db_name . '@' . $this->db_host . ':' . $this->db_port);
|
||||
|
||||
if (!Installer::createDbTables($this->dbHost, $this->dbPort, $this->dbName, $this->dbUsername, $this->dbPassword)) {
|
||||
if (!Installer::createDbTables($this->db_host, $this->db_port, $this->db_name, $this->db_username, $this->db_password)) {
|
||||
$this->error('Error: Could not connect to the database! Please, make sure the details are correct.');
|
||||
|
||||
return false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user