|
|
@ -24,6 +24,45 @@ class Setup |
|
|
|
private $_http_protocol; |
|
|
|
private $_http_protocol; |
|
|
|
private $_domain; |
|
|
|
private $_domain; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private $_l = [ |
|
|
|
|
|
|
|
'ru' => [ |
|
|
|
|
|
|
|
'Connection failed. Try again' => 'Ошибка соединения. Попробуйте снова', |
|
|
|
|
|
|
|
'MySQL setup complete' => 'Настройка MySQL завершена', |
|
|
|
|
|
|
|
'Installation complete' => 'Установка завершена', |
|
|
|
|
|
|
|
'Please set subdomains aliases in you domain DNS:' => 'Настройте DNS домена для поддоменов:', |
|
|
|
|
|
|
|
'Select initialization type' => 'Укажите тип установки', |
|
|
|
|
|
|
|
'[d] - Development' => '[d] - Для разработки', |
|
|
|
|
|
|
|
'[p] - Production' => '[p] - Для работы', |
|
|
|
|
|
|
|
'Select installer language' => 'Укажите язык установщика', |
|
|
|
|
|
|
|
'Language [en]: ' => 'Язык [en]', |
|
|
|
|
|
|
|
'Type [p]: ' => 'Тип [p]', |
|
|
|
|
|
|
|
'MySQL settings' => 'Параметры соединения с MySQL', |
|
|
|
|
|
|
|
'Host [localhost]: ' => 'Хост [localhost]: ', |
|
|
|
|
|
|
|
'Database name: ' => 'Название базы: ', |
|
|
|
|
|
|
|
'Database name must be set' => 'Название базы не должно быть пустым', |
|
|
|
|
|
|
|
'User: ' => 'Пользователь: ', |
|
|
|
|
|
|
|
'User must be set' => 'Имя пользователя не должно быть пустым', |
|
|
|
|
|
|
|
'Password: ' => 'Пароль', |
|
|
|
|
|
|
|
'Set your HTTP protocol (http/https)' => 'Укажите HTTP протокол (http/https)', |
|
|
|
|
|
|
|
'HTTP Protocol [http]: ' => 'HTTP протокол [http]: ', |
|
|
|
|
|
|
|
'Website domain name' => 'Домен сайта', |
|
|
|
|
|
|
|
'Example: site.com, domain.ru' => 'Например: site.com, domain.ru', |
|
|
|
|
|
|
|
'Domain name: ' => 'Домен: ', |
|
|
|
|
|
|
|
'Domain must be set' => 'Назание домена не должно быть пустым', |
|
|
|
|
|
|
|
'Create admin account' => 'Создание аккаунта администратора', |
|
|
|
|
|
|
|
'Username: ' => 'Имя пользователя: ', |
|
|
|
|
|
|
|
'Username must be set' => 'Имя пользователя не должно быть пустым', |
|
|
|
|
|
|
|
'E-mail must be set' => 'E-mail адрес не должен быть пустым', |
|
|
|
|
|
|
|
'E-mail must be correct' => 'Ошибка e-mail адреса', |
|
|
|
|
|
|
|
'Password must be set' => 'Пароль не может быть пустым', |
|
|
|
|
|
|
|
'Repeat password: ' => 'Повторите пароль: ', |
|
|
|
|
|
|
|
'Passwords must be equal' => 'Пароли должны совпадать', |
|
|
|
|
|
|
|
'Admin account complete' => 'Аккаунт администратора создан', |
|
|
|
|
|
|
|
'Prepare MySQL tables' => 'Подготовка MySQL таблиц', |
|
|
|
|
|
|
|
'Complete' => 'Готово', |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
public function run() |
|
|
|
public function run() |
|
|
|
{ |
|
|
|
{ |
|
|
|
// select language |
|
|
|
// select language |
|
|
@ -42,10 +81,10 @@ class Setup |
|
|
|
|
|
|
|
|
|
|
|
// config db |
|
|
|
// config db |
|
|
|
while (!$this->setupMySQL()) { |
|
|
|
while (!$this->setupMySQL()) { |
|
|
|
echo Console::log('Connection failed. Try again', 'red') . PHP_EOL; |
|
|
|
echo Console::log($this->l('Connection failed. Try again'), 'red') . PHP_EOL; |
|
|
|
} |
|
|
|
} |
|
|
|
$this->setConfigMySQL(); |
|
|
|
$this->setConfigMySQL(); |
|
|
|
echo Console::log('MySQL setup complete', 'green') . PHP_EOL; |
|
|
|
echo Console::log($this->l('MySQL setup complete'), 'green') . PHP_EOL; |
|
|
|
|
|
|
|
|
|
|
|
// apply migrations |
|
|
|
// apply migrations |
|
|
|
$this->runMigrations(); |
|
|
|
$this->runMigrations(); |
|
|
@ -57,9 +96,9 @@ class Setup |
|
|
|
$this->setConfigDomains(); |
|
|
|
$this->setConfigDomains(); |
|
|
|
|
|
|
|
|
|
|
|
echo '---------------------' . PHP_EOL; |
|
|
|
echo '---------------------' . PHP_EOL; |
|
|
|
echo Console::log('Installation complete', 'yellow') . PHP_EOL; |
|
|
|
echo Console::log($this->l('Installation complete'), 'yellow') . PHP_EOL; |
|
|
|
echo PHP_EOL; |
|
|
|
echo PHP_EOL; |
|
|
|
echo Console::log('Please set subdomains aliases in you domain DNS:', 'normal') . PHP_EOL; |
|
|
|
echo Console::log($this->l('Please set subdomains aliases in you domain DNS:'), 'normal') . PHP_EOL; |
|
|
|
echo Console::log('admin.' . $this->_domain, 'normal') . PHP_EOL; |
|
|
|
echo Console::log('admin.' . $this->_domain, 'normal') . PHP_EOL; |
|
|
|
echo Console::log('static.' . $this->_domain, 'normal') . PHP_EOL; |
|
|
|
echo Console::log('static.' . $this->_domain, 'normal') . PHP_EOL; |
|
|
|
echo '---------------------' . PHP_EOL; |
|
|
|
echo '---------------------' . PHP_EOL; |
|
|
@ -68,36 +107,36 @@ class Setup |
|
|
|
private function selectType() |
|
|
|
private function selectType() |
|
|
|
{ |
|
|
|
{ |
|
|
|
echo '---------------------' . PHP_EOL; |
|
|
|
echo '---------------------' . PHP_EOL; |
|
|
|
echo Console::log('Select initialization type', 'white') . PHP_EOL; |
|
|
|
echo Console::log($this->l('Select initialization type'), 'white') . PHP_EOL; |
|
|
|
echo Console::log('[d] - Development', 'normal') . PHP_EOL; |
|
|
|
echo Console::log($this->l('[d] - Development'), 'normal') . PHP_EOL; |
|
|
|
echo Console::log('[p] - Production', 'normal') . PHP_EOL; |
|
|
|
echo Console::log($this->l('[p] - Production'), 'normal') . PHP_EOL; |
|
|
|
echo '---------------------' . PHP_EOL; |
|
|
|
echo '---------------------' . PHP_EOL; |
|
|
|
$this->_type = readline('Type [p]: ') ?: 'p'; |
|
|
|
$this->_type = readline($this->l('Type [p]: ')) ?: 'p'; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private function selectLanguage() |
|
|
|
private function selectLanguage() |
|
|
|
{ |
|
|
|
{ |
|
|
|
echo '---------------------' . PHP_EOL; |
|
|
|
echo '---------------------' . PHP_EOL; |
|
|
|
echo Console::log('Select installer language', 'white') . PHP_EOL; |
|
|
|
echo Console::log($this->l('Select installer language'), 'white') . PHP_EOL; |
|
|
|
echo Console::log('[ru] - Русский', 'normal') . PHP_EOL; |
|
|
|
echo Console::log('[ru] - Русский', 'normal') . PHP_EOL; |
|
|
|
echo Console::log('[en] - English', 'normal') . PHP_EOL; |
|
|
|
echo Console::log('[en] - English', 'normal') . PHP_EOL; |
|
|
|
echo '---------------------' . PHP_EOL; |
|
|
|
echo '---------------------' . PHP_EOL; |
|
|
|
$this->_language = readline('Language [en]: ') ?: 'en'; |
|
|
|
$this->_language = readline($this->l('Language [en]: ')) ?: 'en'; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private function setupMySQL(): bool |
|
|
|
private function setupMySQL(): bool |
|
|
|
{ |
|
|
|
{ |
|
|
|
echo '---------------------' . PHP_EOL; |
|
|
|
echo '---------------------' . PHP_EOL; |
|
|
|
echo Console::log('MySQL settings', 'white') . PHP_EOL; |
|
|
|
echo Console::log($this->l('MySQL settings'), 'white') . PHP_EOL; |
|
|
|
echo '---------------------' . PHP_EOL; |
|
|
|
echo '---------------------' . PHP_EOL; |
|
|
|
$this->_db_host = readline('Host [localhost]: ') ?: 'localhost'; |
|
|
|
$this->_db_host = readline($this->l('Host [localhost]: ')) ?: 'localhost'; |
|
|
|
while (!$this->_db_name = readline('Database name: ')) { |
|
|
|
while (!$this->_db_name = readline($this->l('Database name: '))) { |
|
|
|
echo Console::log('Database name must be set', 'red') . PHP_EOL; |
|
|
|
echo Console::log($this->l('Database name must be set'), 'red') . PHP_EOL; |
|
|
|
}; |
|
|
|
}; |
|
|
|
while (!$this->_db_user = readline('User: ')) { |
|
|
|
while (!$this->_db_user = readline($this->l('User: '))) { |
|
|
|
echo Console::log('User must be set', 'red') . PHP_EOL; |
|
|
|
echo Console::log($this->l('User must be set'), 'red') . PHP_EOL; |
|
|
|
}; |
|
|
|
}; |
|
|
|
$this->_db_pass = readline('Password: '); |
|
|
|
$this->_db_pass = readline($this->l('Password: ')); |
|
|
|
|
|
|
|
|
|
|
|
return $this->checkDatabaseConnection(); |
|
|
|
return $this->checkDatabaseConnection(); |
|
|
|
} |
|
|
|
} |
|
|
@ -127,16 +166,16 @@ class Setup |
|
|
|
private function setConfigDomains() |
|
|
|
private function setConfigDomains() |
|
|
|
{ |
|
|
|
{ |
|
|
|
echo '---------------------' . PHP_EOL; |
|
|
|
echo '---------------------' . PHP_EOL; |
|
|
|
echo Console::log('Set your HTTP protocol (http/https)', 'white') . PHP_EOL; |
|
|
|
echo Console::log($this->l('Set your HTTP protocol (http/https)'), 'white') . PHP_EOL; |
|
|
|
echo '---------------------' . PHP_EOL; |
|
|
|
echo '---------------------' . PHP_EOL; |
|
|
|
$this->_http_protocol = readline('HTTP Protocol [http]: ') ?: 'http'; |
|
|
|
$this->_http_protocol = readline($this->l('HTTP Protocol [http]: ')) ?: 'http'; |
|
|
|
|
|
|
|
|
|
|
|
echo '---------------------' . PHP_EOL; |
|
|
|
echo '---------------------' . PHP_EOL; |
|
|
|
echo Console::log('Website domain name', 'white') . PHP_EOL; |
|
|
|
echo Console::log($this->l('Website domain name'), 'white') . PHP_EOL; |
|
|
|
echo Console::log('Example: site.com, domain.ru', 'normal') . PHP_EOL; |
|
|
|
echo Console::log($this->l('Example: site.com, domain.ru'), 'normal') . PHP_EOL; |
|
|
|
echo '---------------------' . PHP_EOL; |
|
|
|
echo '---------------------' . PHP_EOL; |
|
|
|
while (!$this->_domain = readline('Domain name: ')) { |
|
|
|
while (!$this->_domain = readline($this->l('Domain name: '))) { |
|
|
|
echo Console::log('Domain must be set', 'red') . PHP_EOL; |
|
|
|
echo Console::log($this->l('Domain must be set'), 'red') . PHP_EOL; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
$file = __DIR__ . '/common/config/params-local.php'; |
|
|
|
$file = __DIR__ . '/common/config/params-local.php'; |
|
|
@ -160,32 +199,32 @@ class Setup |
|
|
|
private function addAdmin(): void |
|
|
|
private function addAdmin(): void |
|
|
|
{ |
|
|
|
{ |
|
|
|
echo '---------------------' . PHP_EOL; |
|
|
|
echo '---------------------' . PHP_EOL; |
|
|
|
echo Console::log('Create admin account', 'white') . PHP_EOL; |
|
|
|
echo Console::log($this->l('Create admin account'), 'white') . PHP_EOL; |
|
|
|
echo '---------------------' . PHP_EOL; |
|
|
|
echo '---------------------' . PHP_EOL; |
|
|
|
while (!$this->_username = readline('Username: ')) { |
|
|
|
while (!$this->_username = readline($this->l('Username: '))) { |
|
|
|
echo Console::log('Username must be set', 'red') . PHP_EOL; |
|
|
|
echo Console::log($this->l('Username must be set'), 'red') . PHP_EOL; |
|
|
|
}; |
|
|
|
}; |
|
|
|
while (!$this->_email || ($this->_email && $this->checkEmail($this->_email))) { |
|
|
|
while (!$this->_email || ($this->_email && $this->checkEmail($this->_email))) { |
|
|
|
$this->_email = readline('E-mail: '); |
|
|
|
$this->_email = readline('E-mail: '); |
|
|
|
if (!$this->_email) { |
|
|
|
if (!$this->_email) { |
|
|
|
echo Console::log('E-mail must be set', 'red') . PHP_EOL; |
|
|
|
echo Console::log($this->l('E-mail must be set'), 'red') . PHP_EOL; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!$this->checkEmail($this->_email)) { |
|
|
|
if (!$this->checkEmail($this->_email)) { |
|
|
|
echo Console::log('E-mail must be correct', 'red') . PHP_EOL; |
|
|
|
echo Console::log($this->l('E-mail must be correct'), 'red') . PHP_EOL; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
$password = null; |
|
|
|
$password = null; |
|
|
|
while (!$this->_password || $this->_password != $password) { |
|
|
|
while (!$this->_password || $this->_password != $password) { |
|
|
|
while (!$this->_password = readline('Password: ')) { |
|
|
|
while (!$this->_password = readline($this->l('Password: '))) { |
|
|
|
echo Console::log('Password must be set', 'red') . PHP_EOL; |
|
|
|
echo Console::log($this->l('Password must be set'), 'red') . PHP_EOL; |
|
|
|
}; |
|
|
|
}; |
|
|
|
$password = readline('Repeat password: '); |
|
|
|
$password = readline($this->l('Repeat password: ')); |
|
|
|
if ($this->_password != $password) { |
|
|
|
if ($this->_password != $password) { |
|
|
|
echo Console::log('Passwords must be equal', 'red') . PHP_EOL; |
|
|
|
echo Console::log($this->l('Passwords must be equal'), 'red') . PHP_EOL; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
shell_exec('php yii user/add-admin "' . $this->_username . '" "' . $this->_email . '" "' . $this->_password . '"'); |
|
|
|
shell_exec('php ' . __DIR__ . '/yii user/add-admin "' . $this->_username . '" "' . $this->_email . '" "' . $this->_password . '"'); |
|
|
|
echo Console::log('Admin account complete', 'green') . PHP_EOL; |
|
|
|
echo Console::log($this->l('Admin account complete'), 'green') . PHP_EOL; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private function checkEmail($email): bool |
|
|
|
private function checkEmail($email): bool |
|
|
@ -197,10 +236,15 @@ class Setup |
|
|
|
private function runMigrations(): void |
|
|
|
private function runMigrations(): void |
|
|
|
{ |
|
|
|
{ |
|
|
|
echo '---------------------' . PHP_EOL; |
|
|
|
echo '---------------------' . PHP_EOL; |
|
|
|
echo Console::log('Prepare MySQL tables', 'white') . PHP_EOL; |
|
|
|
echo Console::log($this->l('Prepare MySQL tables'), 'white') . PHP_EOL; |
|
|
|
echo '---------------------' . PHP_EOL; |
|
|
|
echo '---------------------' . PHP_EOL; |
|
|
|
shell_exec('php yii migrate --interactive=0'); |
|
|
|
shell_exec('php ' . __DIR__ . '/yii migrate --interactive=0'); |
|
|
|
echo Console::log('Complete', 'green') . PHP_EOL; |
|
|
|
echo Console::log($this->l('Complete'), 'green') . PHP_EOL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private function l($str): string |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return isset($this->_l[$this->_language]) && isset($this->_l[$this->_language][$str]) ? $this->_l[$this->_language][$str] : $str; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|