Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Platform
Commits
85d7d305
Commit
85d7d305
authored
Oct 11, 2014
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding a platform install command
parent
310d99ab
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
149 additions
and
0 deletions
+149
-0
InstallCommand.php
Modules/Core/Console/InstallCommand.php
+122
-0
CoreServiceProvider.php
Modules/Core/Providers/CoreServiceProvider.php
+27
-0
No files found.
Modules/Core/Console/InstallCommand.php
0 → 100644
View file @
85d7d305
<?php
namespace
Modules\Core\Console
;
use
Illuminate\Console\Command
;
use
Illuminate\Support\Facades\Hash
;
use
Modules\User\Repositories\RoleRepository
;
use
Modules\User\Repositories\UserRepository
;
class
InstallCommand
extends
Command
{
/**
* The console command name.
*
* @var string
*/
protected
$name
=
'platform:install'
;
/**
* The console command description.
*
* @var string
*/
protected
$description
=
'Install the Platform CMS'
;
/**
* @var UserRepository
*/
private
$user
;
/**
* @var RoleRepository
*/
private
$role
;
/**
* Create a new command instance.
*
* @param UserRepository $user
* @param RoleRepository $role
* @return \Modules\Core\Console\InstallCommand
*/
public
function
__construct
(
$user
,
$role
)
{
parent
::
__construct
();
$this
->
user
=
$user
;
$this
->
role
=
$role
;
}
/**
* Execute the actions
*
* @return mixed
*/
public
function
fire
()
{
$this
->
info
(
'Starting the installation process...'
);
$this
->
runMigrations
();
$this
->
runSeeds
();
$this
->
createFirstUser
();
$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
()
{
$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
*/
private
function
runMigrations
()
{
$this
->
call
(
'migrate'
,
[
'--package'
=>
'cartalyst/sentinel'
]);
$this
->
info
(
'Application migrated!'
);
}
/**
* Run the seeds
*/
private
function
runSeeds
()
{
$this
->
call
(
'module:seed'
,
[
'module'
=>
'User'
]);
$this
->
info
(
'Application seeded!'
);
}
/**
* Symfony style block messages
* @param $title
* @param $message
* @param string $style
*/
protected
function
blockMessage
(
$title
,
$message
,
$style
=
'info'
)
{
$formatter
=
$this
->
getHelperSet
()
->
get
(
'formatter'
);
$errorMessages
=
[
$title
,
$message
];
$formattedBlock
=
$formatter
->
formatBlock
(
$errorMessages
,
$style
,
true
);
$this
->
line
(
$formattedBlock
);
}
}
Modules/Core/Providers/CoreServiceProvider.php
View file @
85d7d305
...
...
@@ -2,6 +2,7 @@
use
Illuminate\Routing\Router
;
use
Illuminate\Support\ServiceProvider
;
use
Modules\Core\Console\InstallCommand
;
use
Modules\User\Events\RegisterSidebarMenuItemEvent
;
class
CoreServiceProvider
extends
ServiceProvider
...
...
@@ -41,6 +42,7 @@ class CoreServiceProvider extends ServiceProvider
$this
->
app
->
booted
(
function
(
$app
)
{
$this
->
registerFilters
(
$app
[
'router'
]);
});
$this
->
registerCommands
();
}
/**
...
...
@@ -87,4 +89,29 @@ class CoreServiceProvider extends ServiceProvider
}
}
}
/**
* Register the console commands
*/
private
function
registerCommands
()
{
$this
->
registerInstallCommand
();
}
/**
* Register the installation command
*/
private
function
registerInstallCommand
()
{
$this
->
app
->
bindShared
(
'command.platform.install'
,
function
(
$app
)
{
return
new
InstallCommand
(
$app
[
'Modules\User\Repositories\UserRepository'
],
$app
[
'Modules\User\Repositories\RoleRepository'
]
);
});
$this
->
commands
(
'command.platform.install'
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment