-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from deliciousbrains/get-site-command
Sites get command
- Loading branch information
Showing
5 changed files
with
256 additions
and
18 deletions.
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 |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
|
||
namespace App\Commands\Sites; | ||
|
||
use App\Commands\BaseCommand; | ||
use DeliciousBrains\SpinupWp\Resources\Site; | ||
|
||
class GetCommand extends BaseCommand | ||
{ | ||
protected $signature = 'sites:get {site_id} {--format=} {--profile=}'; | ||
|
||
protected $description = 'Get a site'; | ||
|
||
protected bool $largeOutput = true; | ||
|
||
public function action() | ||
{ | ||
$site = $this->spinupwp->sites->get($this->argument('site_id')); | ||
|
||
if ($this->displayFormat() === 'json') { | ||
return $site; | ||
} | ||
$additionalDomains = ''; | ||
|
||
if (!empty($site->additional_domains)) { | ||
$additionalDomains = implode(PHP_EOL, array_map(fn ($domain) => $domain['domain'], $site->additional_domains)); | ||
} | ||
|
||
$data = [ | ||
'ID' => $site->id, | ||
'Server ID' => $site->server_id, | ||
'Domain' => $site->domain, | ||
'Additional Domains' => $additionalDomains, | ||
'Site User' => $site->site_user, | ||
'PHP Version' => $site->php_version, | ||
'Public Folder' => $site->public_folder, | ||
'Page Cache' => $site->page_cache['enabled'] ? 'Enabled' : 'Disabled', | ||
'HTTPS' => $site->https['enabled'] ? 'Enabled' : 'Disabled', | ||
]; | ||
|
||
if ($site->database['table_prefix']) { | ||
$data['Database Table Prefix'] = $site->database['table_prefix']; | ||
} | ||
|
||
$data = $this->gitData($site, $data); | ||
|
||
$data['WP Core Update'] = $site->wp_core_update ? 'Yes' : 'No'; | ||
$data['WP Theme Updates'] = $site->wp_theme_updates; | ||
$data['WP Plugin Updates'] = $site->wp_plugin_updates; | ||
|
||
$data = $this->backupsData($site, $data); | ||
|
||
$data['Uploads Directory Protection'] = $site->nginx['uploads_directory_protected'] ? 'Enabled' : 'Disabled'; | ||
$data['XML-RPC Protection'] = $site->nginx['xmlrpc_protected'] ? 'Enabled' : 'Disabled'; | ||
$data['Multisite Rewrite Rules'] = $site->nginx['subdirectory_rewrite_in_place'] ? 'Enabled' : 'Disabled'; | ||
|
||
$data = $this->basicAuthData($site, $data); | ||
|
||
$data['Created At'] = $site->created_at; | ||
$data['Status'] = ucfirst($site->status); | ||
|
||
return $data; | ||
} | ||
|
||
public function backupsData(Site $site, array $data): array | ||
{ | ||
$scheduledBackups = (bool) $site->backups['next_run_time']; | ||
|
||
$data['Scheduled Backups'] = $scheduledBackups ? 'Enabled' : 'Disabled'; | ||
|
||
$data['File Backups'] = ($site->backups['files'] ? 'Enabled' : 'Disabled'); | ||
$data['Database Backups'] = ($site->backups['database'] ? 'Enabled' : 'Disabled'); | ||
|
||
if ($site->backups['files'] || $site->backups['database']) { | ||
$data['Backup Retention Period'] = $site->backups['retention_period'] . ' days'; | ||
} | ||
|
||
if ($scheduledBackups) { | ||
$data['Next Backup Time'] = $site->backups['next_run_time']; | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
public function gitData(Site $site, array $data): array | ||
{ | ||
$data['Git'] = 'Disabled'; | ||
|
||
if ($site->git['enabled']) { | ||
$data['Git'] = 'Enabled'; | ||
$data['Repository'] = $site->git['repo']; | ||
$data['Branch'] = $site->git['branch']; | ||
$data['Deploy Script'] = $site->git['deploy_script']; | ||
$data['Push-to-deploy'] = $site->git['push_enabled'] ? 'Enabled' : 'Disabled'; | ||
} | ||
|
||
if ($site->git['enabled'] && $site->git['push_enabled']) { | ||
$data['Deployment URL'] = $site->git['deployment_url']; | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
public function basicAuthData(Site $site, array $data): array | ||
{ | ||
$data['Basic Auth'] = 'Disabled'; | ||
|
||
if ($site->basic_auth['enabled']) { | ||
$data['Basic Auth'] = 'Enabled'; | ||
$data['Basic Auth Username'] = $site->basic_auth['username']; | ||
} | ||
|
||
return $data; | ||
} | ||
} |
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,123 @@ | ||
<?php | ||
|
||
use GuzzleHttp\Psr7\Response; | ||
|
||
$response = [ | ||
'id' => 1, | ||
'server_id' => 1, | ||
'domain' => 'hellfish.media', | ||
'additional_domains' => [ | ||
[ | ||
'domain' => 'www.hellfish.media', | ||
'redirect' => [ | ||
'enabled' => true, | ||
], | ||
'created_at' => '2019-08-24T14:15:22Z', | ||
], | ||
], | ||
'site_user' => 'hellfishmedia', | ||
'php_version' => '7.4', | ||
'public_folder' => '/', | ||
'is_wordpress' => true, | ||
'page_cache' => [ | ||
'enabled' => true, | ||
], | ||
'https' => [ | ||
'enabled' => true, | ||
'certificate_path' => '/etc/nginx/ssl/hellfish.media/certificate-bundle.crt', | ||
'private_key_path' => '/etc/nginx/ssl/hellfish.media/private-key.key', | ||
], | ||
'nginx' => [ | ||
'uploads_directory_protected' => true, | ||
'xmlrpc_protected' => true, | ||
'subdirectory_rewrite_in_place' => false, | ||
], | ||
'database' => [ | ||
'id' => 1, | ||
'user_id' => 1, | ||
'table_prefix' => 'wp_', | ||
], | ||
'backups' => [ | ||
'files' => true, | ||
'database' => true, | ||
'paths_to_exclude' => 'node_modules\\n/files/vendor', | ||
'retention_period' => 30, | ||
'next_run_time' => '2021-01-01T12:00:00.000000Z', | ||
'storage_provider' => [ | ||
'id' => 1, | ||
'region' => 'nyc3', | ||
'bucket' => 'hellfish-media', | ||
], | ||
], | ||
'wp_core_update' => true, | ||
'wp_theme_updates' => 0, | ||
'wp_plugin_updates' => 3, | ||
'git' => [ | ||
'enabled' => true, | ||
'repo' => '[email protected]:deliciousbrains/spinupwp-composer-site.git', | ||
'branch' => 'main', | ||
'deploy_script' => 'composer install --optimize-autoload --no-dev', | ||
'push_enabled' => true, | ||
'deployment_url' => 'https://api.spinupwp.app/git/jeJLdKrl63/deploy', | ||
], | ||
'basic_auth' => [ | ||
'enabled' => true, | ||
'username' => 'hellfish', | ||
], | ||
'created_at' => '2021-01-01T12:00:00.000000Z', | ||
'status' => 'deployed', | ||
|
||
]; | ||
beforeEach(function () use ($response) { | ||
setTestConfigFile(); | ||
}); | ||
|
||
afterEach(function () { | ||
deleteTestConfigFile(); | ||
}); | ||
|
||
test('sites json get command', function () use ($response) { | ||
$this->clientMock->shouldReceive('request')->with('GET', 'sites/1', [])->andReturn( | ||
new Response(200, [], json_encode(['data' => $response])) | ||
); | ||
$this->artisan('sites:get 1')->expectsOutput(json_encode($response, JSON_PRETTY_PRINT)); | ||
}); | ||
|
||
test('sites table get command', function () use ($response) { | ||
$this->clientMock->shouldReceive('request')->with('GET', 'sites/1', [])->andReturn( | ||
new Response(200, [], json_encode(['data' => $response])) | ||
); | ||
$this->artisan('sites:get 1 --format=table')->expectsTable([], [ | ||
['ID', '1'], | ||
['Server ID', '1'], | ||
['Domain', 'hellfish.media'], | ||
['Additional Domains', 'www.hellfish.media'], | ||
['Site User', 'hellfishmedia'], | ||
['PHP Version', '7.4'], | ||
['Public Folder', '/'], | ||
['Page Cache', 'Enabled'], | ||
['HTTPS', 'Enabled'], | ||
['Database Table Prefix', 'wp_'], | ||
['Git', 'Enabled'], | ||
['Repository', '[email protected]:deliciousbrains/spinupwp-composer-site.git'], | ||
['Branch', 'main'], | ||
['Deploy Script', 'composer install --optimize-autoload --no-dev'], | ||
['Push-to-deploy', 'Enabled'], | ||
['Deployment URL', 'https://api.spinupwp.app/git/jeJLdKrl63/deploy'], | ||
['WP Core Update', 'Yes'], | ||
['WP Theme Updates', '0'], | ||
['WP Plugin Updates', '3'], | ||
['Scheduled Backups', 'Enabled'], | ||
['File Backups', 'Enabled'], | ||
['Database Backups', 'Enabled'], | ||
['Backup Retention Period', '30 days'], | ||
['Next Backup Time', '2021-01-01T12:00:00.000000Z'], | ||
['Uploads Directory Protection', 'Enabled'], | ||
['XML-RPC Protection', 'Enabled'], | ||
['Multisite Rewrite Rules', 'Disabled'], | ||
['Basic Auth', 'Enabled'], | ||
['Basic Auth Username', 'hellfish'], | ||
['Created At', '2021-01-01T12:00:00.000000Z'], | ||
['Status', 'Deployed'], | ||
]); | ||
}); |
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