1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace FLAIRUK\GoodTillSystem\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use Illuminate\Filesystem\Filesystem; |
7
|
|
|
use Symfony\Component\Console\Input\InputOption; |
8
|
|
|
use Symfony\Component\Process\Process; |
9
|
|
|
use TCG\Voyager\Providers\VoyagerDummyServiceProvider; |
10
|
|
|
use TCG\Voyager\Traits\Seedable; |
11
|
|
|
use TCG\Voyager\VoyagerServiceProvider; |
12
|
|
|
|
13
|
|
|
class SetupCommand extends Command |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
protected $hidden = false; |
17
|
|
|
/** |
18
|
|
|
* The console command name. |
19
|
|
|
* |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $name = 'goodtill:setup'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The console command description. |
26
|
|
|
* |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $description = 'Install the Good Tiil System package'; |
30
|
|
|
|
31
|
|
|
protected function getOptions() |
32
|
|
|
{ |
33
|
|
|
return [ |
34
|
|
|
['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production', null], |
35
|
|
|
['with-dummy', null, InputOption::VALUE_NONE, 'Install with dummy data', null], |
36
|
|
|
]; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Get the composer command for the environment. |
41
|
|
|
* |
42
|
|
|
* @return string |
43
|
|
|
*/ |
44
|
|
|
protected function findComposer() |
45
|
|
|
{ |
46
|
|
|
if (file_exists(getcwd().'/composer.phar')) { |
47
|
|
|
return '"'.PHP_BINARY.'" '.getcwd().'/composer.phar'; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
return 'composer'; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function fire(Filesystem $filesystem) |
54
|
|
|
{ |
55
|
|
|
return $this->handle($filesystem); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Execute the console command. |
60
|
|
|
* |
61
|
|
|
* @param \Illuminate\Filesystem\Filesystem $filesystem |
62
|
|
|
* |
63
|
|
|
* @return void |
64
|
|
|
*/ |
65
|
|
|
public function handle(Filesystem $filesystem) |
66
|
|
|
{ |
67
|
|
|
$this->info('Publishing the Voyager assets, database, and config files'); |
68
|
|
|
|
69
|
|
|
// Publish only relevant resources on install |
70
|
|
|
// $tags = ['seeds']; |
71
|
|
|
|
72
|
|
|
$this->call('vendor:publish', ['--provider' => VoyagerServiceProvider::class, '--tag' => $tags]); |
|
|
|
|
73
|
|
|
|
74
|
|
|
// $this->info('Migrating the database tables into your application'); |
75
|
|
|
// $this->call('migrate', ['--force' => $this->option('force')]); |
76
|
|
|
|
77
|
|
|
// $this->info('Attempting to set Voyager User model as parent to App\User'); |
78
|
|
|
// if (file_exists(app_path('User.php'))) { |
79
|
|
|
// $str = file_get_contents(app_path('User.php')); |
80
|
|
|
|
81
|
|
|
// if ($str !== false) { |
82
|
|
|
// $str = str_replace('extends Authenticatable', "extends \TCG\Voyager\Models\User", $str); |
83
|
|
|
|
84
|
|
|
// file_put_contents(app_path('User.php'), $str); |
85
|
|
|
// } |
86
|
|
|
// } else { |
87
|
|
|
// $this->warn('Unable to locate "app/User.php". Did you move this file?'); |
88
|
|
|
// $this->warn('You will need to update this manually. Change "extends Authenticatable" to "extends \TCG\Voyager\Models\User" in your User model'); |
89
|
|
|
// } |
90
|
|
|
|
91
|
|
|
$this->info('Dumping the autoloaded files and reloading all new files'); |
92
|
|
|
|
93
|
|
|
$composer = $this->findComposer(); |
94
|
|
|
|
95
|
|
|
$process = new Process([$composer.' dump-autoload']); |
96
|
|
|
$process->setTimeout(null); // Setting timeout to null to prevent installation from stopping at a certain point in time |
97
|
|
|
$process->setWorkingDirectory(base_path())->run(); |
98
|
|
|
|
99
|
|
|
$this->info('Adding Environment Variables'); |
100
|
|
|
$routes_contents = $filesystem->get(base_path('.env')); |
101
|
|
|
if (false === strpos($routes_contents, "\n\nGOOD_TILL_DOAMIN=\nGOOD_TILL_USERNAME=\nGOOD_TILL_PASSWORD=")) { |
102
|
|
|
$filesystem->append( |
103
|
|
|
base_path('routes/web.php'), |
104
|
|
|
"\n\nGOOD_TILL_DOAMIN=\nGOOD_TILL_USERNAME=\nGOOD_TILL_PASSWORD=" |
105
|
|
|
); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
// $this->info('Seeding data into the database'); |
109
|
|
|
// $this->seed('VoyagerDatabaseSeeder'); |
110
|
|
|
|
111
|
|
|
// if ($this->option('with-dummy')) { |
112
|
|
|
// $this->info('Publishing dummy content'); |
113
|
|
|
// $tags = ['dummy_seeds', 'dummy_content', 'dummy_config', 'dummy_migrations']; |
114
|
|
|
// $this->call('vendor:publish', ['--provider' => VoyagerDummyServiceProvider::class, '--tag' => $tags]); |
115
|
|
|
|
116
|
|
|
// $this->info('Migrating dummy tables'); |
117
|
|
|
// $this->call('migrate'); |
118
|
|
|
|
119
|
|
|
// $this->info('Seeding dummy data'); |
120
|
|
|
// $this->seed('VoyagerDummyDatabaseSeeder'); |
121
|
|
|
// } else { |
122
|
|
|
// $this->call('vendor:publish', ['--provider' => VoyagerServiceProvider::class, '--tag' => ['config', 'voyager_avatar']]); |
123
|
|
|
// } |
124
|
|
|
|
125
|
|
|
// $this->info('Setting up the hooks'); |
126
|
|
|
// $this->call('hook:setup'); |
127
|
|
|
|
128
|
|
|
// $this->info('Adding the storage symlink to your public folder'); |
129
|
|
|
// $this->call('storage:link'); |
130
|
|
|
|
131
|
|
|
// $this->info('Successfully installed Voyager! Enjoy'); |
132
|
|
|
} |
133
|
|
|
} |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.