Laravel 10 + Cachet Core

This commit is contained in:
James Brooks
2024-01-19 20:03:17 +00:00
parent 8b565ab7f0
commit cf674850dd
1271 changed files with 8105 additions and 123368 deletions
-76
View File
@@ -1,76 +0,0 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Contracts\Events\Dispatcher;
/**
* This is the app reset command.
*
* @author James Brooks <james@alt-three.com>
*/
class AppResetCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:reset';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Resets and installs the application';
/**
* The events instance.
*
* @var \Illuminate\Contracts\Events\Dispatcher
*/
protected $events;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct(Dispatcher $events)
{
$this->events = $events;
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->events->fire('command.resetting', $this);
$this->events->fire('command.generatekey', $this);
$this->events->fire('command.cacheconfig', $this);
$this->events->fire('command.cacheroutes', $this);
$this->events->fire('command.publishvendors', $this);
$this->events->fire('command.resetmigrations', $this);
$this->events->fire('command.runmigrations', $this);
$this->events->fire('command.runseeding', $this);
$this->events->fire('command.updatecache', $this);
$this->events->fire('command.extrastuff', $this);
$this->events->fire('command.reset', $this);
}
}
-73
View File
@@ -1,73 +0,0 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Contracts\Events\Dispatcher;
/**
* This is the app update command.
*
* @author James Brooks <james@alt-three.com>
*/
class AppUpdateCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:update';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Updates the application';
/**
* The events instance.
*
* @var \Illuminate\Contracts\Events\Dispatcher
*/
protected $events;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct(Dispatcher $events)
{
$this->events = $events;
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->events->fire('command.updating', $this);
$this->events->fire('command.cacheconfig', $this);
$this->events->fire('command.cacheroutes', $this);
$this->events->fire('command.publishvendors', $this);
$this->events->fire('command.runmigrations', $this);
$this->events->fire('command.updatecache', $this);
$this->events->fire('command.extrastuff', $this);
$this->events->fire('command.updated', $this);
}
}
-47
View File
@@ -1,47 +0,0 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Console\Commands;
use CachetHQ\Cachet\Bus\Jobs\System\SendBeaconJob;
use Illuminate\Console\Command;
/**
* This is the beacon command class.
*
* @author James Brooks <james@alt-three.com>
*/
class BeaconCommand extends Command
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'cachet:beacon';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Communicate with the Cachet Beacon server';
/**
* Execute the console command.
*
* @return void
*/
public function handle()
{
dispatch(new SendBeaconJob());
}
}
@@ -1,101 +0,0 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Console\Commands;
use CachetHQ\Cachet\Models\MetricPoint;
use Illuminate\Console\Command;
use Illuminate\Console\ConfirmableTrait;
use Symfony\Component\Console\Input\InputOption;
/**
* This is the demo seeder of metric points command.
*
* @author James Brooks <james@alt-three.com>
*/
class DemoMetricPointSeederCommand extends Command
{
use ConfirmableTrait;
/**
* The console command name.
*
* @var string
*/
protected $name = 'cachet:metrics';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Seeds the demo Cachet metrics with points';
/**
* Execute the console command.
*
* @return void
*/
public function handle()
{
if (!$this->confirmToProceed()) {
return;
}
$this->seedMetricPoints();
$this->info('Demo metric seeded with demo data successfully!');
}
/**
* Seed the metric points table.
*
* @return void
*/
protected function seedMetricPoints()
{
MetricPoint::truncate();
$points = [];
// Generate 24 hours of metric points
for ($i = 0; $i <= 23; $i++) {
for ($j = 0; $j <= 59; $j++) {
$this->info("{$i}:{$j}");
$pointTime = date("Y-m-d {$i}:{$j}:00");
$points[] = [
'metric_id' => 1,
'value' => random_int(1, 10),
'created_at' => $pointTime,
'updated_at' => $pointTime,
];
}
}
foreach (array_chunk($points, 100) as $chunk) {
MetricPoint::insert($chunk);
}
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return [
['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'],
];
}
}
-468
View File
@@ -1,468 +0,0 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Console\Commands;
use CachetHQ\Cachet\Models\Action;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\ComponentGroup;
use CachetHQ\Cachet\Models\Incident;
use CachetHQ\Cachet\Models\IncidentTemplate;
use CachetHQ\Cachet\Models\IncidentUpdate;
use CachetHQ\Cachet\Models\Metric;
use CachetHQ\Cachet\Models\MetricPoint;
use CachetHQ\Cachet\Models\Schedule;
use CachetHQ\Cachet\Models\Subscriber;
use CachetHQ\Cachet\Models\User;
use CachetHQ\Cachet\Settings\Repository;
use Carbon\Carbon;
use DateInterval;
use DateTime;
use Illuminate\Console\Command;
use Illuminate\Console\ConfirmableTrait;
use Symfony\Component\Console\Input\InputOption;
/**
* This is the demo seeder command.
*
* @author James Brooks <james@alt-three.com>
*/
class DemoSeederCommand extends Command
{
use ConfirmableTrait;
/**
* The console command name.
*
* @var string
*/
protected $name = 'cachet:seed';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Seeds Cachet with demo data';
/**
* The settings repository.
*
* @var \CachetHQ\Cachet\Settings\Repository
*/
protected $settings;
/**
* Create a new demo seeder command instance.
*
* @param \CachetHQ\Cachet\Settings\Repository $settings
*
* @return void
*/
public function __construct(Repository $settings)
{
parent::__construct();
$this->settings = $settings;
}
/**
* Execute the console command.
*
* @return void
*/
public function handle()
{
if (!$this->confirmToProceed()) {
return;
}
$this->seedUsers();
$this->seedActions();
$this->seedComponentGroups();
$this->seedComponents();
$this->seedIncidents();
$this->seedIncidentTemplates();
$this->seedMetricPoints();
$this->seedMetrics();
$this->seedSchedules();
$this->seedSettings();
$this->seedSubscribers();
$this->info('Database seeded with demo data successfully!');
}
/**
* Seed the actions table.
*
* @return void
*/
protected function seedActions()
{
Action::truncate();
}
/**
* Seed the component groups table.
*
* @return void
*/
protected function seedComponentGroups()
{
$defaultGroups = [
[
'name' => 'Websites',
'order' => 1,
'collapsed' => 0,
'visible' => ComponentGroup::VISIBLE_AUTHENTICATED,
], [
'name' => 'Services',
'order' => 2,
'collapsed' => 1,
'visible' => ComponentGroup::VISIBLE_GUEST,
],
];
ComponentGroup::truncate();
foreach ($defaultGroups as $group) {
ComponentGroup::create($group);
}
}
/**
* Seed the components table.
*
* @return void
*/
protected function seedComponents()
{
$defaultComponents = [
[
'name' => 'API',
'description' => 'Used by third-parties to connect to us',
'status' => 1,
'order' => 0,
'group_id' => 0,
'link' => '',
], [
'name' => 'Documentation',
'description' => 'Kindly powered by Readme.io',
'status' => 1,
'order' => 0,
'group_id' => 1,
'link' => 'https://docs.cachethq.io',
], [
'name' => 'Website',
'description' => '',
'status' => 1,
'order' => 0,
'group_id' => 1,
'link' => 'https://cachethq.io',
], [
'name' => 'Laravel Artisan Cheatsheet',
'description' => 'A searchable, bookmarkable cheatsheet for Laravel\'s Artisan commands.',
'status' => 1,
'order' => 0,
'group_id' => 2,
'link' => 'https://artisan.page',
], [
'name' => 'Checkmango',
'description' => 'The Full-Stack A/B Testing Platform',
'status' => 1,
'order' => 1,
'group_id' => 2,
'link' => 'https://checkmango.com',
], [
'name' => 'GitHub',
'description' => '',
'status' => 1,
'order' => 0,
'group_id' => 0,
'link' => 'https://github.com/cachethq/cachet',
],
];
Component::truncate();
foreach ($defaultComponents as $component) {
Component::create($component);
}
}
/**
* Seed the incidents table.
*
* @return void
*/
protected function seedIncidents()
{
$incidentMessage = <<<'EINCIDENT'
# Of course it does!
What kind of web application doesn't these days?
## Headers are fun aren't they
It's _exactly_ why we need Markdown. For **emphasis** and such.
EINCIDENT;
$defaultIncidents = [
[
'name' => 'Our monkeys aren\'t performing',
'message' => 'We\'re investigating an issue with our monkeys not performing as they should be.',
'status' => Incident::INVESTIGATING,
'component_id' => 0,
'visible' => 1,
'stickied' => false,
'user_id' => 1,
'occurred_at' => Carbon::now(),
],
[
'name' => 'This is an unresolved incident',
'message' => 'Unresolved incidents are left without a **Fixed** update.',
'status' => Incident::INVESTIGATING,
'component_id' => 0,
'visible' => 1,
'stickied' => false,
'user_id' => 1,
'occurred_at' => Carbon::now(),
],
];
Incident::truncate();
IncidentUpdate::truncate();
foreach ($defaultIncidents as $defaultIncident) {
$incident = Incident::create($defaultIncident);
$this->seedIncidentUpdates($incident);
}
}
/**
* Seed the incident templates table.
*
* @return void
*/
protected function seedIncidentTemplates()
{
IncidentTemplate::truncate();
}
/**
* Seed the incident updates table for a given incident.
*
* @return void
*/
protected function seedIncidentUpdates($incident)
{
$defaultUpdates = [
1 => [
[
'status' => Incident::FIXED,
'message' => 'The monkeys are back and rested!',
'user_id' => 1,
], [
'status' => Incident::WATCHED,
'message' => 'Our monkeys need a break from performing. They\'ll be back after a good rest.',
'user_id' => 1,
], [
'status' => Incident::IDENTIFIED,
'message' => 'We have identified the issue with our lovely performing monkeys.',
'user_id' => 1,
],
],
2 => [
[
'status' => Incident::WATCHED,
'message' => 'We\'re actively watching this issue, so it remains unresolved.',
'user_id' => 1,
],
],
];
$updates = $defaultUpdates[$incident->id];
foreach ($updates as $updateId => $update) {
$update['incident_id'] = $incident->id;
IncidentUpdate::create($update);
}
}
/**
* Seed the metric points table.
*
* @return void
*/
protected function seedMetricPoints()
{
MetricPoint::truncate();
// Generate 11 hours of metric points
for ($i = 0; $i < 11; $i++) {
$metricTime = (new DateTime())->sub(new DateInterval('PT'.$i.'H'));
MetricPoint::create([
'metric_id' => 1,
'value' => random_int(1, 10),
'created_at' => $metricTime,
'updated_at' => $metricTime,
]);
}
}
/**
* Seed the metrics table.
*
* @return void
*/
protected function seedMetrics()
{
$defaultMetrics = [
[
'name' => 'Cups of coffee',
'suffix' => 'Cups',
'description' => 'How many cups of coffee we\'ve drank.',
'default_value' => 0,
'calc_type' => 1,
'display_chart' => 1,
],
];
Metric::truncate();
foreach ($defaultMetrics as $metric) {
Metric::create($metric);
}
}
/**
* Seed the schedules table.
*
* @return void
*/
protected function seedSchedules()
{
$defaultSchedules = [
[
'name' => 'Demo resets every half hour!',
'message' => 'You can schedule downtime for _your_ service!',
'status' => Schedule::UPCOMING,
'scheduled_at' => (new DateTime())->add(new DateInterval('PT2H')),
],
];
Schedule::truncate();
foreach ($defaultSchedules as $schedule) {
Schedule::create($schedule);
}
}
/**
* Seed the settings table.
*
* @return void
*/
protected function seedSettings()
{
$defaultSettings = [
[
'key' => 'app_name',
'value' => 'Cachet Demo',
], [
'key' => 'app_domain',
'value' => 'https://demo.cachethq.io',
], [
'key' => 'show_support',
'value' => '1',
], [
'key' => 'app_locale',
'value' => 'en',
], [
'key' => 'app_timezone',
'value' => 'Europe/London',
], [
'key' => 'app_incident_days',
'value' => '7',
], [
'key' => 'app_refresh_rate',
'value' => '0',
], [
'key' => 'display_graphs',
'value' => '1',
], [
'key' => 'app_about',
'value' => 'This is the demo instance of [Cachet](https://cachethq.io?ref=demo). The open-source status page system, for everyone. 3.x is coming soon! [Read the announcement](https://github.com/cachethq/cachet/discussions/4342).',
], [
'key' => 'enable_subscribers',
'value' => '0',
], [
'key' => 'header',
'value' => '<script src="https://cdn.usefathom.com/script.js" data-site="NQKCLYJJ" defer></script>',
],
];
$this->settings->clear();
foreach ($defaultSettings as $setting) {
$this->settings->set($setting['key'], $setting['value']);
}
}
/**
* Seed the subscribers.
*
* @return void
*/
protected function seedSubscribers()
{
Subscriber::truncate();
}
/**
* Seed the users table.
*
* @return void
*/
protected function seedUsers()
{
$users = [
[
'username' => 'test',
'password' => 'test123',
'email' => 'test@example.com',
'level' => User::LEVEL_ADMIN,
'api_key' => '9yMHsdioQosnyVK4iCVR',
],
];
User::truncate();
foreach ($users as $user) {
User::create($user);
}
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return [
['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'],
];
}
}
-448
View File
@@ -1,448 +0,0 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Console\Commands;
use CachetHQ\Cachet\Models\User;
use Dotenv\Dotenv;
use Dotenv\Exception\InvalidPathException;
use Illuminate\Console\Command;
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Contracts\Events\Dispatcher;
/**
* This is the install command class.
*
* @author James Brooks <james@alt-three.com>
*/
class InstallCommand extends Command
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'cachet:install';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Install Cachet';
/**
* The events instance.
*
* @var \Illuminate\Contracts\Events\Dispatcher
*/
protected $events;
/**
* Create a new command instance.
*
* @param Dispatcher $events
*/
public function __construct(Dispatcher $events)
{
$this->events = $events;
parent::__construct();
}
/**
* Execute the console command.
*
* @return void
*/
public function handle()
{
if ($this->confirm('Do you want to configure Cachet before installing?')) {
$this->configureEnvironmentFile();
$this->configureKey();
$this->configureDatabase();
$this->configureDrivers();
$this->configureMail();
$this->configureCachet();
$this->configureUser();
}
$this->line('Installing Cachet...');
$this->events->fire('command.installing', $this);
$this->events->fire('command.generatekey', $this);
$this->events->fire('command.cacheconfig', $this);
$this->events->fire('command.cacheroutes', $this);
$this->events->fire('command.publishvendors', $this);
$this->events->fire('command.runmigrations', $this);
$this->events->fire('command.runseeding', $this);
$this->events->fire('command.updatecache', $this);
$this->events->fire('command.linkstorage', $this);
$this->events->fire('command.extrastuff', $this);
$this->events->fire('command.installed', $this);
$this->info('Cachet is installed ⚡');
}
/**
* Copy the environment file.
*
* @return void
*/
protected function configureEnvironmentFile()
{
$dir = app()->environmentPath();
$file = app()->environmentFile();
$path = "{$dir}/{$file}";
if (file_exists($path)) {
$this->line('Environment file already exists. Moving on.');
return;
}
copy("$path.example", $path);
}
/**
* Generate the app key.
*
* @return void
*/
protected function configureKey()
{
$this->call('key:generate');
}
/**
* Configure the database.
*
* @param array $default
*
* @return void
*/
protected function configureDatabase(array $default = [])
{
$config = array_merge([
'DB_DRIVER' => null,
'DB_HOST' => null,
'DB_DATABASE' => null,
'DB_USERNAME' => null,
'DB_PASSWORD' => null,
'DB_PORT' => null,
'DB_PREFIX' => null,
], $default);
$config['DB_DRIVER'] = $this->choice('Which database driver do you want to use?', [
'mysql' => 'MySQL',
'pgsql' => 'PostgreSQL',
'sqlite' => 'SQLite',
], $config['DB_DRIVER']);
if ($config['DB_DRIVER'] === 'sqlite') {
$config['DB_DATABASE'] = $this->ask('Please provide the full path to your SQLite file.', $config['DB_DATABASE']);
} else {
$config['DB_HOST'] = $this->ask("What is the host of your {$config['DB_DRIVER']} database?", $config['DB_HOST']);
if ($config['DB_HOST'] === 'localhost' && $config['DB_DRIVER'] === 'mysql') {
$this->warn("Using 'localhost' will result in the usage of a local unix socket. Use 127.0.0.1 if you want to connect over TCP");
}
$config['DB_DATABASE'] = $this->ask('What is the name of the database that Cachet should use?', $config['DB_DATABASE']);
$config['DB_USERNAME'] = $this->ask('What username should we connect with?', $config['DB_USERNAME']);
$config['DB_PASSWORD'] = $this->secret('What password should we connect with?', $config['DB_PASSWORD']);
$config['DB_PORT'] = $config['DB_DRIVER'] === 'mysql' ? 3306 : 5432;
if ($this->confirm('Is your database listening on a non-standard port number?')) {
$config['DB_PORT'] = $this->anticipate('What port number is your database using?', [3306, 5432], $config['DB_PORT']);
}
}
if ($this->confirm('Do you want to use a prefix on the table names?')) {
$config['DB_PREFIX'] = $this->ask('Please enter the prefix now...', $config['DB_PREFIX']);
}
// Format the settings ready to display them in the table.
$this->formatConfigsTable($config);
if (!$this->confirm('Are these settings correct?')) {
return $this->configureDatabase($config);
}
foreach ($config as $setting => $value) {
$this->writeEnv($setting, $value);
}
}
/**
* Configure other drivers.
*
* @param array $default
*
* @return void
*/
protected function configureDrivers(array $default = [])
{
$config = array_merge([
'CACHE_DRIVER' => null,
'SESSION_DRIVER' => null,
'QUEUE_DRIVER' => null,
], $default);
// Format the settings ready to display them in the table.
$this->formatConfigsTable($config);
$config['CACHE_DRIVER'] = $this->choice('Which cache driver do you want to use?', [
'apc' => 'APC(u)',
'array' => 'Array',
'database' => 'Database',
'file' => 'File',
'memcached' => 'Memcached',
'redis' => 'Redis',
], $config['CACHE_DRIVER']);
// We need to configure Redis.
if ($config['CACHE_DRIVER'] === 'redis') {
$this->configureRedis();
}
$config['SESSION_DRIVER'] = $this->choice('Which session driver do you want to use?', [
'apc' => 'APC(u)',
'array' => 'Array',
'database' => 'Database',
'file' => 'File',
'memcached' => 'Memcached',
'redis' => 'Redis',
], $config['SESSION_DRIVER']);
// We need to configure Redis.
if ($config['SESSION_DRIVER'] === 'redis') {
$this->configureRedis();
}
$config['QUEUE_DRIVER'] = $this->choice('Which queue driver do you want to use?', [
'null' => 'None',
'sync' => 'Synchronous',
'database' => 'Database',
'beanstalkd' => 'Beanstalk',
'sqs' => 'Amazon SQS',
'redis' => 'Redis',
], $config['QUEUE_DRIVER']);
// We need to configure Redis, but only if the cache driver wasn't redis.
if ($config['QUEUE_DRIVER'] === 'redis' && ($config['SESSION_DRIVER'] !== 'redis' || $config['CACHE_DRIVER'] !== 'redis')) {
$this->configureRedis();
}
// Format the settings ready to display them in the table.
$this->formatConfigsTable($config);
if (!$this->confirm('Are these settings correct?')) {
return $this->configureDrivers($config);
}
foreach ($config as $setting => $value) {
$this->writeEnv($setting, $value);
}
}
/**
* Configure mail.
*
* @param array $config
*
* @return void
*/
protected function configureMail(array $config = [])
{
$config = array_merge([
'MAIL_DRIVER' => null,
'MAIL_HOST' => null,
'MAIL_PORT' => null,
'MAIL_USERNAME' => null,
'MAIL_PASSWORD' => null,
'MAIL_ADDRESS' => null,
'MAIL_NAME' => null,
'MAIL_ENCRYPTION' => null,
], $config);
// Don't continue with these settings if we're not interested in notifications.
if (!$this->confirm('Do you want Cachet to send mail notifications?')) {
return;
}
$config['MAIL_DRIVER'] = $this->choice('What driver do you want to use to send notifications?', [
'smtp' => 'SMTP',
'mail' => 'Mail',
'sendmail' => 'Sendmail',
'mailgun' => 'Mailgun',
'mandrill' => 'Mandrill',
'ses' => 'Amazon SES',
'sparkpost' => 'SparkPost',
'log' => 'Log (Testing)',
]);
if (!$config['MAIL_DRIVER'] === 'log') {
if ($config['MAIL_DRIVER'] === 'smtp') {
$config['MAIL_HOST'] = $this->ask('Please supply your mail server host');
}
$config['MAIL_ADDRESS'] = $this->ask('What email address should we send notifications from?');
$config['MAIL_USERNAME'] = $this->ask('What username should we connect as?');
$config['MAIL_PASSWORD'] = $this->secret('What password should we connect with?');
}
// Format the settings ready to display them in the table.
$this->formatConfigsTable($config);
if (!$this->confirm('Are these settings correct?')) {
return $this->configureMail($config);
}
foreach ($config as $setting => $value) {
$this->writeEnv($setting, $value);
}
}
/**
* Configure Cachet.
*
* @param array $config
*
* @return void
*/
protected function configureCachet(array $config = [])
{
$config = [];
if ($this->confirm('Do you wish to use Cachet Beacon?')) {
$config['CACHET_BEACON'] = 'true';
}
if ($this->confirm('Do you wish to use Emoji? This requires a GitHub oAuth Token!')) {
$config['GITHUB_TOKEN'] = $this->ask('Please enter your GitHub oAuth Token');
$config['CACHET_EMOJI'] = 'true';
}
foreach ($config as $setting => $value) {
$this->writeEnv($setting, $value);
}
}
/**
* Configure the first user.
*
* @return void
*/
protected function configureUser()
{
if (!$this->confirm('Do you want to create an admin user?')) {
return;
}
// We need to refresh the config to get access to the newly connected database.
$this->getFreshConfiguration();
// Now we need to install the application.
// $this->call('cachet:install');
$user = [
'username' => $this->ask('Please enter your username'),
'email' => $this->ask('Please enter your email'),
'password' => $this->secret('Please enter your password'),
'level' => User::LEVEL_ADMIN,
];
User::create($user);
}
/**
* Configure the redis connection.
*
* @return void
*/
protected function configureRedis()
{
$config = [
'REDIS_HOST' => null,
'REDIS_DATABASE' => null,
'REDIS_PORT' => null,
];
$config['REDIS_HOST'] = $this->ask('What is the host of your redis server?');
$config['REDIS_DATABASE'] = $this->ask('What is the name of the database that Cachet should use?');
$config['REDIS_PORT'] = $this->ask('What port should Cachet use?', 6379);
foreach ($config as $setting => $value) {
$this->writeEnv($setting, $value);
}
}
/**
* Format the configs into a pretty table that we can easily read.
*
* @param array $config
*
* @return void
*/
protected function formatConfigsTable(array $config)
{
$configRows = [];
foreach ($config as $setting => $value) {
$configRows[] = compact('setting', 'value');
}
$this->table(['Setting', 'Value'], $configRows);
}
/**
* Boot a fresh copy of the application configuration.
*
* @return void
*/
protected function getFreshConfiguration()
{
$app = require $this->laravel->bootstrapPath().'/app.php';
$app->make(Kernel::class)->bootstrap();
}
/**
* Writes to the .env file with given parameters.
*
* @param string $key
* @param mixed $value
*
* @return void
*/
protected function writeEnv($key, $value)
{
$dir = app()->environmentPath();
$file = app()->environmentFile();
$path = "{$dir}/{$file}";
try {
(new Dotenv($dir, $file))->load();
$envKey = strtoupper($key);
$envValue = env($envKey) ?: 'null';
$envFileContents = file_get_contents($path);
$envFileContents = str_replace("{$envKey}={$envValue}", "{$envKey}={$value}", $envFileContents, $count);
if ($count < 1 && $envValue === 'null') {
$envFileContents = str_replace("{$envKey}=", "{$envKey}={$value}", $envFileContents);
}
file_put_contents($path, $envFileContents);
} catch (InvalidPathException $e) {
throw $e;
}
}
}
-46
View File
@@ -1,46 +0,0 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Console\Commands;
use Illuminate\Console\Command;
/**
* This is the version command class.
*
* @author James Brooks <james@alt-three.com>
*/
class VersionCommand extends Command
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'cachet:version';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Display the version of Cachet';
/**
* Execute the console command.
*
* @return void
*/
public function handle()
{
$this->info('Cachet '.CACHET_VERSION.' is installed ⚡');
}
}
+11 -43
View File
@@ -1,59 +1,27 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Console;
namespace CachetHQ\Cachet\Console;
use CachetHQ\Cachet\Console\Commands\AppResetCommand;
use CachetHQ\Cachet\Console\Commands\AppUpdateCommand;
use CachetHQ\Cachet\Console\Commands\BeaconCommand;
use CachetHQ\Cachet\Console\Commands\DemoMetricPointSeederCommand;
use CachetHQ\Cachet\Console\Commands\DemoSeederCommand;
use CachetHQ\Cachet\Console\Commands\InstallCommand;
use CachetHQ\Cachet\Console\Commands\VersionCommand;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
/**
* This is the console kernel class.
*
* @author Graham Campbell <graham@alt-three.com>
* @author Joseph Cohen <joe@alt-three.com>
* @author James Brooks <james@alt-three.com>
*/
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
* Define the application's command schedule.
*/
protected $commands = [
AppResetCommand::class,
AppUpdateCommand::class,
BeaconCommand::class,
DemoMetricPointSeederCommand::class,
DemoSeederCommand::class,
InstallCommand::class,
VersionCommand::class,
];
protected function schedule(Schedule $schedule): void
{
// $schedule->command('inspire')->hourly();
}
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
*
* @return void
* Register the commands for the application.
*/
protected function schedule(Schedule $schedule)
protected function commands(): void
{
$schedule->command('cachet:beacon')->twiceDaily(0, 12);
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}