Skip to content

Commit

Permalink
Better order
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmlozano committed Nov 26, 2021
1 parent 5a5fba5 commit 5976e83
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 62 deletions.
111 changes: 61 additions & 50 deletions app/Commands/Sites/GetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,79 +26,90 @@ public function action()
$additionalDomains = implode(PHP_EOL, array_map(fn ($domain) => $domain['domain'], $site->additional_domains));
}

return array_merge(
[
'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,
'Uploads Directory Protected' => $site->nginx['uploads_directory_protected'] ? 'Enabled' : 'Disabled',
'XML-RPC Protection' => $site->nginx['xmlrpc_protected'] ? 'Enabled' : 'Disabled',
'Multisite Rewrite Rules' => $site->nginx['subdirectory_rewrite_in_place'] ? 'Enabled' : 'Disabled',
'Page Cache' => $site->page_cache['enabled'] ? 'Enabled' : 'Disabled',
'HTTPS' => $site->https['enabled'] ? 'Enabled' : 'Disabled',
'Database Table Prefix' => $site->database['table_prefix'] ?: 'No Database',
'WP Core Update' => $site->wp_core_update ? 'Yes' : 'No',
'WP Theme Updates' => $site->wp_theme_updates,
'WP Plugin Updates' => $site->wp_plugin_updates,
'Created At' => $site->created_at,
'Status' => ucfirst($site->status),
],
$this->basicAuthData($site),
$this->gitData($site),
$this->backupsData($site),
);
$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
public function backupsData(Site $site, array $data): array
{
$backups = ['Scheduled Backupś' => 'Disabled'];
$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']) {
$backups['Scheduled Backups'] = 'Disabled';
if ($site->backups['next_run_time']) {
$backups['Scheduled Backups'] = 'Enabled';
$backups['Next Run Time'] = $site->backups['next_run_time'];
}
$backups['File Backups'] = ($site->backups['files'] ? 'Enabled' : 'Disabled');
$backups['Database Backups'] = ($site->backups['database'] ? 'Enabled' : 'Disabled');
$backups['Retention Period'] = $site->backups['retention_period'];
$data['Backup Retention Period'] = $site->backups['retention_period'] . ' days';
}

if ($scheduledBackups) {
$data['Next Backup Time'] = $site->backups['next_run_time'];
}

return $backups;
return $data;
}

public function gitData(Site $site): array
public function gitData(Site $site, array $data): array
{
$git = ['Git' => 'Disabled'];
$data['Git'] = 'Disabled';

if ($site->git['enabled']) {
$git['Git'] = 'Enabled';
$git['Repository'] = $site->git['repo'];
$git['Branch'] = $site->git['branch'];
$git['Deploy Script'] = $site->git['deploy_script'];
$git['Push-to-deploy'] = $site->git['push_enabled'] ? 'Enabled' : 'Disabled';
$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']) {
$git['Deployment URL'] = $site->git['deployment_url'];
$data['Deployment URL'] = $site->git['deployment_url'];
}

return $git;
return $data;
}

public function basicAuthData(Site $site): array
public function basicAuthData(Site $site, array $data): array
{
$basicAuth = ['Basic Auth' => 'Disabled'];
$data['Basic Auth'] = 'Disabled';

if ($site->basic_auth['enabled']) {
$basicAuth['Basic Auth'] = 'Enabled';
$basicAuth['Basic Auth Username'] = $site->basic_auth['username'];
$data['Basic Auth'] = 'Enabled';
$data['Basic Auth Username'] = $site->basic_auth['username'];
}

return $basicAuth;
return $data;
}
}
24 changes: 12 additions & 12 deletions tests/Feature/Commands/SitesGetCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,29 +95,29 @@
['Site User', 'hellfishmedia'],
['PHP Version', '7.4'],
['Public Folder', '/'],
['Uploads Directory Protected', 'Enabled'],
['XML-RPC Protection', 'Enabled'],
['Multisite Rewrite Rules', 'Disabled'],
['Page Cache', 'Enabled'],
['HTTPS', 'Enabled'],
['Database Table Prefix', 'wp_'],
['WP Core Update', 'Yes'],
['WP Theme Updates', '0'],
['WP Plugin Updates', '3'],
['Created At', '2021-01-01T12:00:00.000000Z'],
['Status', 'Deployed'],
['Basic Auth', 'Enabled'],
['Basic Auth Username', 'hellfish'],
['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'],
['Next Run Time', '2021-01-01T12:00:00.000000Z'],
['File Backups', 'Enabled'],
['Database Backups', 'Enabled'],
['Retention Period', '30'],
['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'],
]);
});

0 comments on commit 5976e83

Please sign in to comment.