2016-03-05 00:18:10 +00:00
|
|
|
<?php
|
2016-02-29 15:59:36 +00:00
|
|
|
|
2016-03-05 00:18:10 +00:00
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use App\Models\Timezone;
|
|
|
|
|
use Artisan;
|
2016-02-29 15:59:36 +00:00
|
|
|
use Config;
|
2016-03-05 00:18:10 +00:00
|
|
|
use DB;
|
2016-02-29 15:59:36 +00:00
|
|
|
use Input;
|
|
|
|
|
use Redirect;
|
2016-03-05 00:18:10 +00:00
|
|
|
use Response;
|
|
|
|
|
use View;
|
2016-02-29 15:59:36 +00:00
|
|
|
|
|
|
|
|
class InstallerController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
2016-03-05 00:18:10 +00:00
|
|
|
if (file_exists(base_path('installed'))) {
|
|
|
|
|
abort(403, 'Unauthorized action.');
|
|
|
|
|
}
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function showInstaller()
|
|
|
|
|
{
|
|
|
|
|
$data['paths'] = [
|
|
|
|
|
storage_path('app'),
|
|
|
|
|
storage_path('framework'),
|
|
|
|
|
storage_path('logs'),
|
|
|
|
|
public_path('user_content'),
|
2016-03-05 00:18:10 +00:00
|
|
|
base_path('.env'),
|
2016-02-29 15:59:36 +00:00
|
|
|
];
|
|
|
|
|
$data['requirements'] = [
|
|
|
|
|
'openssl',
|
|
|
|
|
'pdo',
|
|
|
|
|
'mbstring',
|
|
|
|
|
'fileinfo',
|
2016-03-05 00:18:10 +00:00
|
|
|
'tokenizer',
|
2016-02-29 15:59:36 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return View::make('Installer.Installer', $data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function postInstaller()
|
|
|
|
|
{
|
2016-03-02 23:37:33 +00:00
|
|
|
set_time_limit(300);
|
2016-02-29 15:59:36 +00:00
|
|
|
|
|
|
|
|
$database['type'] = 'mysql';
|
|
|
|
|
$database['host'] = Input::get('database_host');
|
|
|
|
|
$database['name'] = Input::get('database_name');
|
|
|
|
|
$database['username'] = Input::get('database_username');
|
|
|
|
|
$database['password'] = Input::get('database_password');
|
|
|
|
|
|
|
|
|
|
$mail['driver'] = Input::get('mail_driver');
|
|
|
|
|
$mail['port'] = Input::get('mail_port');
|
|
|
|
|
$mail['username'] = Input::get('mail_username');
|
|
|
|
|
$mail['password'] = Input::get('mail_password');
|
|
|
|
|
$mail['encryption'] = Input::get('mail_encryption');
|
|
|
|
|
$mail['from_address'] = Input::get('mail_from_address');
|
|
|
|
|
$mail['from_name'] = Input::get('mail_from_name');
|
|
|
|
|
$mail['host'] = Input::get('mail_host');
|
|
|
|
|
|
|
|
|
|
$app_url = Input::get('app_url');
|
|
|
|
|
$app_key = str_random(16);
|
2016-03-02 23:37:33 +00:00
|
|
|
$version = file_get_contents(base_path('VERSION'));
|
2016-02-29 15:59:36 +00:00
|
|
|
|
|
|
|
|
if (Input::get('test') === 'db') {
|
|
|
|
|
$is_db_valid = self::testDatabase($database);
|
|
|
|
|
|
|
|
|
|
if ($is_db_valid === 'yes') {
|
|
|
|
|
return Response::json([
|
2016-03-05 00:18:10 +00:00
|
|
|
'status' => 'success',
|
2016-02-29 15:59:36 +00:00
|
|
|
'message' => 'Success, Your connection works!',
|
2016-03-05 00:18:10 +00:00
|
|
|
'test' => 1,
|
2016-02-29 15:59:36 +00:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Response::json([
|
2016-03-05 00:18:10 +00:00
|
|
|
'status' => 'error',
|
2016-02-29 15:59:36 +00:00
|
|
|
'message' => 'Unable to connect! Please check your settings',
|
2016-03-05 00:18:10 +00:00
|
|
|
'test' => 1,
|
2016-02-29 15:59:36 +00:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-05 00:18:10 +00:00
|
|
|
$config = "APP_ENV=production\n".
|
|
|
|
|
"APP_DEBUG=false\n".
|
|
|
|
|
"APP_URL={$app_url}\n".
|
|
|
|
|
"APP_KEY={$app_key}\n\n".
|
|
|
|
|
"DB_TYPE=mysql\n".
|
|
|
|
|
"DB_HOST={$database['host']}\n".
|
|
|
|
|
"DB_DATABASE={$database['name']}\n".
|
|
|
|
|
"DB_USERNAME={$database['username']}\n".
|
|
|
|
|
"DB_PASSWORD={$database['password']}\n\n".
|
|
|
|
|
"MAIL_DRIVER={$mail['driver']}\n".
|
|
|
|
|
"MAIL_PORT={$mail['port']}\n".
|
|
|
|
|
"MAIL_ENCRYPTION={$mail['encryption']}\n".
|
|
|
|
|
"MAIL_HOST={$mail['host']}\n".
|
|
|
|
|
"MAIL_USERNAME={$mail['username']}\n".
|
|
|
|
|
"MAIL_FROM_NAME={$mail['from_name']}\n".
|
|
|
|
|
"MAIL_FROM_ADDRESS={$mail['from_address']}\n".
|
2016-02-29 15:59:36 +00:00
|
|
|
"MAIL_PASSWORD={$mail['password']}\n\n";
|
|
|
|
|
|
2016-03-05 00:18:10 +00:00
|
|
|
$fp = fopen(base_path().'/.env', 'w');
|
2016-02-29 15:59:36 +00:00
|
|
|
fwrite($fp, $config);
|
|
|
|
|
fclose($fp);
|
|
|
|
|
|
2016-03-02 23:37:33 +00:00
|
|
|
Config::set('database.default', $database['type']);
|
2016-03-05 00:18:10 +00:00
|
|
|
Config::set('database.connections.mysql.host', $database['host']);
|
|
|
|
|
Config::set('database.connections.mysql.database', $database['name']);
|
|
|
|
|
Config::set('database.connections.mysql.username', $database['username']);
|
|
|
|
|
Config::set('database.connections.mysql.password', $database['password']);
|
2016-03-02 23:37:33 +00:00
|
|
|
|
|
|
|
|
DB::reconnect();
|
|
|
|
|
|
2016-03-05 00:18:10 +00:00
|
|
|
Artisan::call('migrate', ['--force' => true]);
|
2016-02-29 15:59:36 +00:00
|
|
|
if (Timezone::count() == 0) {
|
2016-03-05 00:18:10 +00:00
|
|
|
Artisan::call('db:seed', ['--force' => true]);
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
2016-03-05 00:18:10 +00:00
|
|
|
Artisan::call('optimize', ['--force' => true]);
|
2016-02-29 15:59:36 +00:00
|
|
|
|
2016-03-05 00:18:10 +00:00
|
|
|
$fp = fopen(base_path().'/installed', 'w');
|
2016-03-02 23:37:33 +00:00
|
|
|
fwrite($fp, $version);
|
2016-02-29 23:50:41 +00:00
|
|
|
fclose($fp);
|
|
|
|
|
|
2016-03-05 00:18:10 +00:00
|
|
|
return Redirect::route('showSignup', ['first_run' => 'yup']);
|
2016-02-29 15:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function testDatabase($database)
|
|
|
|
|
{
|
|
|
|
|
Config::set('database.default', $database['type']);
|
2016-03-05 00:18:10 +00:00
|
|
|
Config::set('database.connections.mysql.host', $database['host']);
|
|
|
|
|
Config::set('database.connections.mysql.database', $database['name']);
|
|
|
|
|
Config::set('database.connections.mysql.username', $database['username']);
|
|
|
|
|
Config::set('database.connections.mysql.password', $database['password']);
|
2016-02-29 15:59:36 +00:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
DB::reconnect();
|
|
|
|
|
$success = DB::connection()->getDatabaseName() ? 'yes' : 'no';
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
return $e->getMessage();
|
|
|
|
|
}
|
2016-03-05 00:18:10 +00:00
|
|
|
|
2016-02-29 15:59:36 +00:00
|
|
|
return $success;
|
|
|
|
|
}
|
2016-03-05 00:18:10 +00:00
|
|
|
}
|