Commit ec7b8142 authored by Nicolas Widart's avatar Nicolas Widart

Squashed 'Modules/Core/' changes from b63dd42..e8e79e4

e8e79e4 Make sentinel migrations/seeds optional

git-subtree-dir: Modules/Core
git-subtree-split: e8e79e4002d7b0bc292eae14b75bd23dfcb27977
parent f00433ca
...@@ -22,29 +22,29 @@ class InstallCommand extends Command ...@@ -22,29 +22,29 @@ class InstallCommand extends Command
*/ */
protected $description = 'Install the Platform CMS'; protected $description = 'Install the Platform CMS';
/** /**
* @var UserRepository * @var UserRepository
*/ */
private $user; private $user;
/** /**
* @var Filesystem * @var Filesystem
*/ */
private $finder; private $finder;
/** /**
* Create a new command instance. * Create a new command instance.
* *
* @param UserRepository $user * @param UserRepository $user
* @param Filesystem $finder * @param Filesystem $finder
* @return \Modules\Core\Console\InstallCommand * @return \Modules\Core\Console\InstallCommand
*/ */
public function __construct($user, Filesystem $finder) public function __construct($user, Filesystem $finder)
{ {
parent::__construct(); parent::__construct();
$this->user = $user; $this->user = $user;
$this->finder = $finder; $this->finder = $finder;
} }
/** /**
* Execute the actions * Execute the actions
...@@ -53,145 +53,171 @@ class InstallCommand extends Command ...@@ -53,145 +53,171 @@ class InstallCommand extends Command
*/ */
public function fire() public function fire()
{ {
$this->info('Starting the installation process...'); $this->info('Starting the installation process...');
$this->configureDatabase(); $this->configureDatabase();
$this->runMigrations(); if ($this->confirm('Do you wish to init sentinel and create its first user? [yes|no]')) {
$this->runUserCommands();
}
$this->runSeeds(); $this->runMigrations();
$this->createFirstUser();
$this->publishAssets(); $this->publishAssets();
$this->blockMessage('Success!', 'Platform ready! You can now login with your username and password at /backend'); $this->blockMessage(
'Success!',
'Platform ready! You can now login with your username and password at /backend'
);
} }
/** /**
* Create the first user that'll have admin access *
*/ */
private function createFirstUser() private function runUserCommands()
{ {
$this->line('Creating an Admin user account...'); $this->runSentinelMigrations();
$this->runUserSeeds();
$firstname = $this->ask('Enter your first name'); $this->createFirstUser();
$lastname = $this->ask('Enter your last name');
$email = $this->ask('Enter your email address'); $this->info('User commands done.');
$password = $this->secret('Enter a password');
$userInfo = [
'first_name' => $firstname,
'last_name' => $lastname,
'email' => $email,
'password' => Hash::make($password),
];
$this->user->createWithRoles($userInfo, ['admin']);
$this->info('Admin account created!');
} }
/**
* Create the first user that'll have admin access
*/
private function createFirstUser()
{
$this->line('Creating an Admin user account...');
$firstname = $this->ask('Enter your first name');
$lastname = $this->ask('Enter your last name');
$email = $this->ask('Enter your email address');
$password = $this->secret('Enter a password');
$userInfo = [
'first_name' => $firstname,
'last_name' => $lastname,
'email' => $email,
'password' => Hash::make($password),
];
$this->user->createWithRoles($userInfo, ['admin']);
$this->info('Admin account created!');
}
/** /**
* Run the migrations * Run migrations specific to Sentinel
*/ */
private function runMigrations() private function runSentinelMigrations()
{ {
$this->call('migrate', ['--package' => 'cartalyst/sentinel']); $this->call('migrate', ['--package' => 'cartalyst/sentinel']);
$this->call('module:migrate', ['module' => 'Setting']);
$this->info('Application migrated!');
} }
/** /**
* Run the seeds * Run the migrations
*/ */
private function runSeeds() private function runMigrations()
{
$this->call('module:migrate', ['module' => 'Setting']);
$this->info('Application migrated!');
}
private function runUserSeeds()
{ {
$this->call('module:seed', ['module' => 'User']); $this->call('module:seed', ['module' => 'User']);
$this->info('Application seeded!');
} }
/** /**
* Symfony style block messages * Run the seeds
* @param $title
* @param $message
* @param string $style
*/ */
protected function blockMessage($title, $message, $style = 'info') private function runSeeds()
{ {
$formatter = $this->getHelperSet()->get('formatter'); $this->info('Application seeded!');
$errorMessages = [$title, $message]; }
$formattedBlock = $formatter->formatBlock($errorMessages, $style, true);
$this->line($formattedBlock);
}
/** /**
* Publish the CMS assets * Symfony style block messages
* @param $title
* @param $message
* @param string $style
*/ */
private function publishAssets() protected function blockMessage($title, $message, $style = 'info')
{ {
$this->call('module:publish', ['module' => 'Core']); $formatter = $this->getHelperSet()->get('formatter');
} $errorMessages = [$title, $message];
$formattedBlock = $formatter->formatBlock($errorMessages, $style, true);
$this->line($formattedBlock);
}
/** /**
* Configuring the database information * Publish the CMS assets
*/ */
private function configureDatabase() private function publishAssets()
{ {
// Ask for credentials $this->call('module:publish', ['module' => 'Core']);
$databaseName = $this->ask('Enter your database name'); }
$databaseUsername = $this->ask('Enter your database username');
$databasePassword = $this->secret('Enter your database password');
$this->setLaravelConfiguration($databaseName, $databaseUsername, $databasePassword); /**
$this->configureEnvironmentFile($databaseName, $databaseUsername, $databasePassword); * Configuring the database information
} */
private function configureDatabase()
{
// Ask for credentials
$databaseName = $this->ask('Enter your database name');
$databaseUsername = $this->ask('Enter your database username');
$databasePassword = $this->secret('Enter your database password');
/** $this->setLaravelConfiguration($databaseName, $databaseUsername, $databasePassword);
* Writing the environment file $this->configureEnvironmentFile($databaseName, $databaseUsername, $databasePassword);
* @param $databaseName }
* @param $databaseUsername
* @param $databasePassword /**
* Writing the environment file
* @param $databaseName
* @param $databaseUsername
* @param $databasePassword
*/ */
private function configureEnvironmentFile($databaseName, $databaseUsername, $databasePassword) private function configureEnvironmentFile($databaseName, $databaseUsername, $databasePassword)
{ {
Dotenv::makeMutable(); Dotenv::makeMutable();
$environmentFile = $this->finder->get('.env.example'); $environmentFile = $this->finder->get('.env.example');
$search = [ $search = [
"DB_USERNAME=homestead", "DB_USERNAME=homestead",
"DB_PASSWORD=homestead" "DB_PASSWORD=homestead"
]; ];
$replace = [ $replace = [
"DB_USERNAME=$databaseUsername", "DB_USERNAME=$databaseUsername",
"DB_PASSWORD=$databasePassword" . PHP_EOL "DB_PASSWORD=$databasePassword" . PHP_EOL
]; ];
$newEnvironmentFile = str_replace($search, $replace, $environmentFile); $newEnvironmentFile = str_replace($search, $replace, $environmentFile);
$newEnvironmentFile .= "DB_NAME=$databaseName"; $newEnvironmentFile .= "DB_NAME=$databaseName";
// Write the new environment file // Write the new environment file
$this->finder->put('.env', $newEnvironmentFile); $this->finder->put('.env', $newEnvironmentFile);
// Delete the old environment file // Delete the old environment file
$this->finder->delete('env.example'); $this->finder->delete('env.example');
$this->info('Environment file written'); $this->info('Environment file written');
Dotenv::makeImmutable(); Dotenv::makeImmutable();
} }
/** /**
* Set DB credentials to laravel config * Set DB credentials to laravel config
* @param $databaseName * @param $databaseName
* @param $databaseUsername * @param $databaseUsername
* @param $databasePassword * @param $databasePassword
*/ */
private function setLaravelConfiguration($databaseName, $databaseUsername, $databasePassword) private function setLaravelConfiguration($databaseName, $databaseUsername, $databasePassword)
{ {
$this->laravel['config']['database.connections.mysql.database'] = $databaseName; $this->laravel['config']['database.connections.mysql.database'] = $databaseName;
$this->laravel['config']['database.connections.mysql.username'] = $databaseUsername; $this->laravel['config']['database.connections.mysql.username'] = $databaseUsername;
$this->laravel['config']['database.connections.mysql.password'] = $databasePassword; $this->laravel['config']['database.connections.mysql.password'] = $databasePassword;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment