| @@ 11-115 (lines=105) @@ | ||
| 8 | use Setting; |
|
| 9 | use Schema; |
|
| 10 | ||
| 11 | class ConfigCommand extends Command { |
|
| 12 | ||
| 13 | /** |
|
| 14 | * The console command name. |
|
| 15 | * |
|
| 16 | * @var string |
|
| 17 | */ |
|
| 18 | protected $name = 'jlourenco:config'; |
|
| 19 | ||
| 20 | /** |
|
| 21 | * The console command description. |
|
| 22 | * |
|
| 23 | * @var string |
|
| 24 | */ |
|
| 25 | protected $description = 'Command to setup all the configurations for the jlourenco packages'; |
|
| 26 | ||
| 27 | /** |
|
| 28 | * Create a new command instance. |
|
| 29 | */ |
|
| 30 | public function __construct() |
|
| 31 | { |
|
| 32 | parent::__construct(); |
|
| 33 | } |
|
| 34 | ||
| 35 | /** |
|
| 36 | * Execute the console command. |
|
| 37 | * |
|
| 38 | * @return mixed |
|
| 39 | */ |
|
| 40 | public function fire() |
|
| 41 | { |
|
| 42 | if (!$this->confirm('Running this command will reset all jlourenco config files. Are you sure? ')) |
|
| 43 | { |
|
| 44 | $this->info('Command was aborted by the user.'); |
|
| 45 | return; |
|
| 46 | } |
|
| 47 | ||
| 48 | $this->compileConfigFiles(); |
|
| 49 | // $this->checkSentinelConfigFiles(); |
|
| 50 | ||
| 51 | $this->info('Command ran successfully'); |
|
| 52 | } |
|
| 53 | ||
| 54 | private function compileConfigFiles() |
|
| 55 | { |
|
| 56 | $path = base_path('/config'); |
|
| 57 | $mainFile = $path . '/jlourenco.php'; |
|
| 58 | $fileExists = file_exists($mainFile); |
|
| 59 | ||
| 60 | $files = array_filter(scandir($path), function ($var) { |
|
| 61 | return (!(stripos($var, 'jlourenco.') === false) && $var != 'jlourenco.php'); |
|
| 62 | }); |
|
| 63 | ||
| 64 | if ($fileExists) |
|
| 65 | unlink($mainFile); |
|
| 66 | ||
| 67 | touch($mainFile); |
|
| 68 | ||
| 69 | $content = "<?php\n"; |
|
| 70 | $content .= "return [\n\n"; |
|
| 71 | ||
| 72 | foreach ($files as $file) |
|
| 73 | { |
|
| 74 | $in = fopen($path . '/' . $file, "r"); |
|
| 75 | ||
| 76 | while ($line = fgets($in)) |
|
| 77 | { |
|
| 78 | if ((stripos($line, '<?php') === false) && (stripos($line, '];') === false) && (stripos($line, 'return [') === false)) |
|
| 79 | $content .= $line; |
|
| 80 | } |
|
| 81 | ||
| 82 | fclose($in); |
|
| 83 | ||
| 84 | unlink($path . '/' . $file); |
|
| 85 | } |
|
| 86 | ||
| 87 | $content .= "];\n"; |
|
| 88 | ||
| 89 | $bytesWritten = File::append($mainFile, $content); |
|
| 90 | ||
| 91 | if ($bytesWritten === false) |
|
| 92 | $this->info('Couldn\'t write to config file.'); |
|
| 93 | ||
| 94 | $this->info('Config files compiled'); |
|
| 95 | } |
|
| 96 | ||
| 97 | private function checkSentinelConfigFiles() |
|
| 98 | { |
|
| 99 | Setting::set('cartalyst.sentinel.users.model', 'jlourenco\base\Models\BaseUser'); |
|
| 100 | Setting::set('cartalyst.sentinel.roles.model', 'jlourenco\base\Models\Group'); |
|
| 101 | ||
| 102 | /* |
|
| 103 | $l = new FileLoader( |
|
| 104 | new \Illuminate\Filesystem\Filesystem(), |
|
| 105 | base_path().'/config/cartalyst.sentinel.php' |
|
| 106 | ); |
|
| 107 | ||
| 108 | $conf = ['' => '']; |
|
| 109 | $conf2 = ['cartalyst.sentinel.roles.model' => 'jlourenco\base\Models\Group']; |
|
| 110 | ||
| 111 | $l->save($conf, '', 'cartalyst.sentinel'); |
|
| 112 | */ |
|
| 113 | } |
|
| 114 | ||
| 115 | } |
|
| 116 | ||
| @@ 11-116 (lines=106) @@ | ||
| 8 | use Setting; |
|
| 9 | use Schema; |
|
| 10 | ||
| 11 | class SetupCommand extends Command {
|
|
| 12 | ||
| 13 | /** |
|
| 14 | * The console command name. |
|
| 15 | * |
|
| 16 | * @var string |
|
| 17 | */ |
|
| 18 | protected $name = 'jlourenco:setup'; |
|
| 19 | ||
| 20 | /** |
|
| 21 | * The console command description. |
|
| 22 | * |
|
| 23 | * @var string |
|
| 24 | */ |
|
| 25 | protected $description = 'Command to setup all the requirements for the jlourenco packages'; |
|
| 26 | ||
| 27 | /** |
|
| 28 | * Create a new command instance. |
|
| 29 | */ |
|
| 30 | public function __construct() |
|
| 31 | {
|
|
| 32 | parent::__construct(); |
|
| 33 | } |
|
| 34 | ||
| 35 | /** |
|
| 36 | * Execute the console command. |
|
| 37 | * |
|
| 38 | * @return mixed |
|
| 39 | */ |
|
| 40 | public function fire() |
|
| 41 | {
|
|
| 42 | if (!$this->confirm('Running this command will reset all jlourenco config files. Are you sure? '))
|
|
| 43 | {
|
|
| 44 | $this->info('Command was aborted by the user.');
|
|
| 45 | return; |
|
| 46 | } |
|
| 47 | ||
| 48 | $this->compileConfigFiles(); |
|
| 49 | // $this->checkSentinelConfigFiles(); |
|
| 50 | Schema::dropIfExists('users');
|
|
| 51 | ||
| 52 | $this->info('Command ran successfully');
|
|
| 53 | } |
|
| 54 | ||
| 55 | private function compileConfigFiles() |
|
| 56 | {
|
|
| 57 | $path = base_path('/config');
|
|
| 58 | $mainFile = $path . '/jlourenco.php'; |
|
| 59 | $fileExists = file_exists($mainFile); |
|
| 60 | ||
| 61 | $files = array_filter(scandir($path), function ($var) {
|
|
| 62 | return (!(stripos($var, 'jlourenco.') === false) && $var != 'jlourenco.php'); |
|
| 63 | }); |
|
| 64 | ||
| 65 | if ($fileExists) |
|
| 66 | unlink($mainFile); |
|
| 67 | ||
| 68 | touch($mainFile); |
|
| 69 | ||
| 70 | $content = "<?php\n"; |
|
| 71 | $content .= "return [\n\n"; |
|
| 72 | ||
| 73 | foreach ($files as $file) |
|
| 74 | {
|
|
| 75 | $in = fopen($path . '/' . $file, "r"); |
|
| 76 | ||
| 77 | while ($line = fgets($in)) |
|
| 78 | {
|
|
| 79 | if ((stripos($line, '<?php') === false) && (stripos($line, '];') === false) && (stripos($line, 'return [') === false)) |
|
| 80 | $content .= $line; |
|
| 81 | } |
|
| 82 | ||
| 83 | fclose($in); |
|
| 84 | ||
| 85 | unlink($path . '/' . $file); |
|
| 86 | } |
|
| 87 | ||
| 88 | $content .= "];\n"; |
|
| 89 | ||
| 90 | $bytesWritten = File::append($mainFile, $content); |
|
| 91 | ||
| 92 | if ($bytesWritten === false) |
|
| 93 | $this->info('Couldn\'t write to config file.');
|
|
| 94 | ||
| 95 | $this->info('Config files compiled');
|
|
| 96 | } |
|
| 97 | ||
| 98 | private function checkSentinelConfigFiles() |
|
| 99 | {
|
|
| 100 | Setting::set('cartalyst.sentinel.users.model', 'jlourenco\base\Models\BaseUser');
|
|
| 101 | Setting::set('cartalyst.sentinel.roles.model', 'jlourenco\base\Models\Group');
|
|
| 102 | ||
| 103 | /* |
|
| 104 | $l = new FileLoader( |
|
| 105 | new \Illuminate\Filesystem\Filesystem(), |
|
| 106 | base_path().'/config/cartalyst.sentinel.php' |
|
| 107 | ); |
|
| 108 | ||
| 109 | $conf = ['' => '']; |
|
| 110 | $conf2 = ['cartalyst.sentinel.roles.model' => 'jlourenco\base\Models\Group']; |
|
| 111 | ||
| 112 | $l->save($conf, '', 'cartalyst.sentinel'); |
|
| 113 | */ |
|
| 114 | } |
|
| 115 | ||
| 116 | } |
|
| 117 | ||