Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes #11

Merged
merged 14 commits into from
Oct 23, 2014
44 changes: 16 additions & 28 deletions src/Pingpong/Admin/AdminServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ class AdminServiceProvider extends ServiceProvider {
*/
protected $defer = false;

/**
* The providers package.
*
* @var array
*/
protected $providers = [
'Console'
];

/**
* Bootstrap the application events.
*
Expand All @@ -19,6 +28,7 @@ class AdminServiceProvider extends ServiceProvider {
public function boot()
{
$this->package('pingpong/admin');

$this->registerFiles();
}

Expand All @@ -45,42 +55,20 @@ protected function registerFiles()
*/
public function register()
{
$this->registerCommands();
$this->registerProviders();
}

/**
* Register the commands.
* Register the providers.
*
* @return void
*/
public function registerCommands()
public function registerProviders()
{
$this->app['pingpong.console.install'] = $this->app->share(function($app)
{
return new Console\AdminInstallCommand;
});

$this->app['pingpong.console.refresh'] = $this->app->share(function($app)
foreach ($this->providers as $provider)
{
return new Console\AdminRefreshCommand;
});

$this->app['pingpong.console.controller'] = $this->app->share(function($app)
{
return new Console\AdminControllerCommand;
});

$this->app['pingpong.console.migration'] = $this->app->share(function($app)
{
return new Console\AdminMigrationCommand;
});

$this->commands([
'pingpong.console.install',
'pingpong.console.refresh',
'pingpong.console.controller',
'pingpong.console.migration',
]);
$this->app->register('Pingpong\\Admin\\Providers\\' . $provider . 'ServiceProvider');
}
}

/**
Expand Down
76 changes: 0 additions & 76 deletions src/Pingpong/Admin/Console/AdminControllerCommand.php

This file was deleted.

53 changes: 53 additions & 0 deletions src/Pingpong/Admin/Console/CreateUserCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php namespace Pingpong\Admin\Console;

use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Pingpong\Admin\Entities\Role;
use Pingpong\Admin\Entities\User;

class CreateUserCommand extends Command {

/**
* The console command name.
*
* @var string
*/
protected $name = 'admin:create-user';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a new user';

/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
$name = $this->ask('Name : ');
$email = $this->ask('Email : ');
$username = $this->ask('Username : ');
$password = $this->secret('Password : ');

$user = User::firstOrcreate(compact('name', 'username', 'email', 'password'));

$this->line('Select role:');

foreach (Role::all() as $role)
{
$this->line($role->id . '. ' . $role->name);
}

$role = $this->ask("Role number : ");

$user->addRole($role);

$this->info("User [{$user->name}] created successfully.");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

class AdminInstallCommand extends Command {
class InstallCommand extends Command {

/**
* The console command name.
Expand All @@ -21,29 +21,38 @@ class AdminInstallCommand extends Command {
protected $description = 'Install the admin package.';

/**
* Create a new command instance.
* Execute the console command.
*
* @return void
* @return mixed
*/
public function __construct()
public function fire()
{
parent::__construct();
if($this->option('only-menu'))
{
$this->installMenus();

$this->info("Menus installed successfully.");
}
else
{
$this->installPackage();
}
}

/**
* Execute the console command.
*
* @return mixed
* Install the package.
*
* @return void
*/
public function fire()
protected function installPackage()
{
$this->call('admin:migration');

$this->call('migrate:publish', ['package' => 'pingpong/trusty']);

$this->call('migrate');
$this->call('db:seed', ['--class' => 'Pingpong\\Admin\\Seeders\\AdminDatabaseSeeder']);

$this->call('admin:seed');

$this->call('config:publish', ['package' => 'pingpong/admin']);

Expand All @@ -62,6 +71,7 @@ public function fire()
protected function installMenus()
{
$file = app_path('menus.php');

if( ! file_exists($file))
{
$contents = $this->laravel['files']->get(__DIR__.'/stubs/menus.txt');
Expand All @@ -70,4 +80,17 @@ protected function installMenus()
}
}


/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return array(
array('--only-menu', null, InputOption::VALUE_NONE, 'An example option.'),
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

class AdminMigrationCommand extends Command {
class MigrationCommand extends Command {

/**
* The console command name.
Expand All @@ -20,16 +20,6 @@ class AdminMigrationCommand extends Command {
*/
protected $description = 'Copy the migration file to the application.';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
Expand All @@ -38,6 +28,7 @@ public function __construct()
public function fire()
{
$destinationPath = app_path('database/migrations');

$migrationPath = __DIR__ . '/../../../migrations/';

if($this->laravel['files']->copyDirectory($migrationPath, $destinationPath))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

class AdminRefreshCommand extends Command {
class RefreshCommand extends Command {

/**
* The console command name.
Expand All @@ -20,16 +20,6 @@ class AdminRefreshCommand extends Command {
*/
protected $description = 'Refresh the migration and re-seed the database.';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
Expand All @@ -39,8 +29,7 @@ public function fire()
{
$this->call('migrate:refresh');

$this->call('db:seed', ['--class' => 'Pingpong\\Admin\\Seeders\\AdminDatabaseSeeder']);

$this->call('admin:seed');
}

}
33 changes: 33 additions & 0 deletions src/Pingpong/Admin/Console/SeedCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php namespace Pingpong\Admin\Console;

use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

class SeedCommand extends Command {

/**
* The console command name.
*
* @var string
*/
protected $name = 'admin:seed';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Run the seeders from pingpong/admin package';

/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
$this->call('db:seed', ['--class' => 'Pingpong\\Admin\\Seeders\\AdminDatabaseSeeder']);
}

}
Loading