-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
446828f
commit 62ad0d4
Showing
11 changed files
with
239 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
composer.phar | ||
composer.lock | ||
.DS_Store | ||
|
||
tests/_output/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
actor: Tester | ||
paths: | ||
tests: tests | ||
log: tests/_output | ||
data: tests/_data | ||
helpers: tests/_support | ||
settings: | ||
bootstrap: _bootstrap.php | ||
colors: false | ||
memory_limit: 1024M | ||
modules: | ||
config: | ||
Db: | ||
dsn: '' | ||
user: '' | ||
password: '' | ||
dump: tests/_data/dump.sql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Stevebauman\Inventory\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
|
||
class InstallCommand extends Command { | ||
|
||
/** | ||
* The console command name. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'inventory:install'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Runs the inventory migrations'; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return mixed | ||
*/ | ||
public function fire() | ||
{ | ||
$this->info('Checking Database Schema'); | ||
|
||
$this->call('inventory:check-schema'); | ||
|
||
$this->info('Running migrations'); | ||
|
||
$this->call('inventory:run-migrations'); | ||
|
||
$this->info('Inventory has been successfully installed'); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
src/Stevebauman/Inventory/Commands/RunMigrationsCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Stevebauman\Inventory\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
|
||
class RunMigrationsCommand extends Command { | ||
|
||
/** | ||
* The console command name. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'inventory:run-migrations'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Runs the inventory migrations'; | ||
|
||
public function fire() | ||
{ | ||
$this->call('migrate', array('--env' => $this->option('env'), '--vendor' => 'stevebauman/maintenance' ) ); | ||
} | ||
|
||
} |
117 changes: 117 additions & 0 deletions
117
src/Stevebauman/Inventory/Commands/SchemaCheckCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?php | ||
|
||
namespace Stevebauman\Inventory\Commands; | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Stevebauman\Maintenance\Exceptions\Commands\DatabaseTableReservedException; | ||
use Stevebauman\Maintenance\Exceptions\Commands\DependencyNotFoundException; | ||
use Illuminate\Console\Command; | ||
|
||
class SchemaCheckCommand extends Command { | ||
|
||
/** | ||
* The console command name. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'inventory:check-schema'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Checks the current database to make sure the required tables are present, and the reserved tables are not'; | ||
|
||
/* | ||
* Holds the database tables that must be present before install | ||
*/ | ||
protected $dependencies = array( | ||
'users' => 'Sentry, Sentinel or Laravel Auth', | ||
); | ||
|
||
/* | ||
* Holds the required database tables necessary to install | ||
*/ | ||
protected $reserved = array( | ||
'inventory', | ||
'inventory_stocks', | ||
'inventory_stock_movements', | ||
); | ||
|
||
/** | ||
* Executes the console command | ||
* | ||
* @throws DatabaseTableReservedException | ||
* @throws DependencyNotFoundException | ||
*/ | ||
public function fire() | ||
{ | ||
if($this->checkDependencies()) { | ||
$this->info('Schema dependencies are all good!'); | ||
} | ||
|
||
if($this->checkReserved()) { | ||
$this->info('Schema reserved tables are all good!'); | ||
} | ||
} | ||
|
||
/** | ||
* Checks the current database for dependencies | ||
* | ||
* @return bool | ||
* @throws DependencyNotFoundException | ||
*/ | ||
private function checkDependencies() | ||
{ | ||
foreach($this->dependencies as $table => $suppliedBy) { | ||
|
||
if(!$this->tableExists($table)) { | ||
|
||
if (!$this->confirmInstallDependency($suppliedBy)) { | ||
|
||
$message = sprintf('Table: %s does not exist, it is supplied by %s', $table, $suppliedBy); | ||
|
||
throw new DependencyNotFoundException($message); | ||
|
||
} | ||
|
||
} | ||
|
||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Checks the current database for reserved tables | ||
* | ||
* @return bool | ||
* @throws DatabaseTableReservedException | ||
*/ | ||
private function checkReserved() | ||
{ | ||
foreach($this->reserved as $table) { | ||
|
||
if($this->tableExists($table)) { | ||
|
||
$message = sprintf('Table: %s already exists. This table is reserved. Please remove the database table to continue', $table); | ||
|
||
throw new DatabaseTableReservedException($message); | ||
|
||
} | ||
|
||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* @param string $table | ||
* @return boolean | ||
*/ | ||
private function tableExists($table) | ||
{ | ||
return Schema::hasTable($table); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/Stevebauman/Inventory/Exceptions/Commands/DatabaseTableReservedException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
namespace Stevebauman\Inventory\Exceptions\Commands; | ||
|
||
|
||
class DatabaseTableReservedException extends \Exception {} |
6 changes: 6 additions & 0 deletions
6
src/Stevebauman/Inventory/Exceptions/Commands/DependencyNotFoundException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
namespace Stevebauman\Maintenance\Exceptions\Commands; | ||
|
||
|
||
class DependencyNotFoundException extends \Exception {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.