Skip to content

Commit

Permalink
chore: Added more docblocks
Browse files Browse the repository at this point in the history
  • Loading branch information
lewislarsen committed Aug 2, 2024
1 parent 3f9de58 commit e5630c5
Show file tree
Hide file tree
Showing 37 changed files with 696 additions and 76 deletions.
10 changes: 10 additions & 0 deletions app/Livewire/Actions/Logout.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,18 @@
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Session;

/**
* Handles the user logout process.
*
* This class is responsible for logging out the user and invalidating their session.
*/
class Logout
{
/**
* Execute the logout action.
*
* Logs out the user, invalidates the session, and regenerates the CSRF token.
*/
public function __invoke(): void
{
Auth::guard('web')->logout();
Expand Down
19 changes: 18 additions & 1 deletion app/Livewire/BackupDestinations/CheckConnectionButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,29 @@
use Livewire\Component;
use Masmerise\Toaster\Toaster;

/**
* Livewire component for checking the connection to a backup destination.
*
* This component provides functionality to initiate and refresh the connection check status.
*/
class CheckConnectionButton extends Component
{
public BackupDestination $backupDestination;

/**
* Refresh the component.
*/
public function refreshSelf(): void
{
$this->dispatch('$refresh');
}

/**
* Initiate the connection check for the backup destination.
*
* This method refreshes the backup destination, marks it as checking,
* runs the check, and dispatches a notification.
*/
public function checkConnection(): void
{
$this->backupDestination->refresh();
Expand All @@ -26,11 +40,14 @@ public function checkConnection(): void

$this->backupDestination->run();

Toaster::info(__('Performing a connectivity check.'));
Toaster::info('Performing a connectivity check.');

$this->dispatch('backup-destination-connection-check-initiated-' . $this->backupDestination->getAttribute('id'));
}

/**
* Render the component.
*/
public function render(): View
{
return view('livewire.backup-destinations.check-connection-button');
Expand Down
23 changes: 15 additions & 8 deletions app/Livewire/BackupDestinations/CreateBackupDestinationForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,28 @@
use Livewire\Features\SupportRedirects\Redirector;
use Toaster;

/**
* Livewire component for creating a new backup destination.
*
* This component handles the form submission and validation for creating
* various types of backup destinations, including custom S3, S3, and local.
*/
class CreateBackupDestinationForm extends Component
{
public string $label;

public string $type = 'custom_s3';

public ?string $s3AccessKey = null;

public ?string $s3SecretKey = null;

public ?string $s3BucketName = null;

public bool $usePathStyleEndpoint = false;

public ?string $customS3Region = null;

public ?string $customS3Endpoint = null;

/**
* Handle the form submission.
*
* Validates the input, creates a new BackupDestination, and redirects to the index page.
*/
public function submit(): RedirectResponse|Redirector
{
$this->validate([
Expand Down Expand Up @@ -66,11 +70,14 @@ public function submit(): RedirectResponse|Redirector
'path_style_endpoint' => $this->usePathStyleEndpoint ?? false,
]);

Toaster::success(__('Backup destination has been added.'));
Toaster::success('Backup destination has been added.');

return Redirect::route('backup-destinations.index');
}

/**
* Render the component.
*/
public function render(): View
{
return view('livewire.backup-destinations.create-backup-destination-form');
Expand Down
18 changes: 18 additions & 0 deletions app/Livewire/BackupDestinations/DeleteBackupDestinationForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,30 @@
use Livewire\Features\SupportRedirects\Redirector;
use Masmerise\Toaster\Toaster;

/**
* Livewire component for deleting a backup destination.
*
* This component handles the deletion of a backup destination and redirects
* the user after successful deletion.
*/
class DeleteBackupDestinationForm extends Component
{
public BackupDestination $backupDestination;

/**
* Initialize the component with the given backup destination.
*/
public function mount(BackupDestination $backupDestination): void
{
$this->backupDestination = $backupDestination;
}

/**
* Delete the backup destination.
*
* This method authorizes the action, force deletes the backup destination,
* shows a success message, and redirects to the index page.
*/
public function delete(): RedirectResponse|Redirector
{
$this->authorize('forceDelete', $this->backupDestination);
Expand All @@ -32,6 +47,9 @@ public function delete(): RedirectResponse|Redirector
return Redirect::route('backup-destinations.index');
}

/**
* Render the component.
*/
public function render(): View
{
return view('livewire.backup-destinations.delete-backup-destination-form');
Expand Down
28 changes: 26 additions & 2 deletions app/Livewire/BackupDestinations/IndexItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,40 @@
use Livewire\Component;
use Masmerise\Toaster\Toaster;

/**
* Livewire component for displaying and managing a single backup destination item.
*
* This component handles the display of a backup destination, its connection status,
* and updates related to connection checks.
*/
class IndexItem extends Component
{
public BackupDestination $backupDestination;

/**
* Handle the received BackupDestinationConnectionCheck event.
*
* This method checks the reachability of the backup destination and
* displays an appropriate toast message.
*/
public function echoReceivedEvent(): void
{
if ($this->backupDestination->isReachable()) {
Toaster::success(__('The connection to the backup destination has been established.'));
Toaster::success('The connection to the backup destination has been established.');
} else {
Toaster::error(__('The connection to the backup destination could not be established. Please check the credentials.'));
Toaster::error('The connection to the backup destination could not be established. Please check the credentials.');
}

Log::debug('Received the BackupDestinationConnectionCheck event. Refreshing the component.');
$this->dispatch('$refresh');
}

/**
* Update Livewire components related to this backup destination.
*
* This method refreshes the current component and dispatches an event
* to update the CheckConnectionButton component.
*/
public function updateLivewireComponents(): void
{
$this->dispatch('$refresh');
Expand All @@ -34,11 +52,17 @@ public function updateLivewireComponents(): void
$this->dispatch('update-backup-destination-check-button-' . $this->backupDestination->getAttribute('id'));
}

/**
* Initialize the component with the given backup destination.
*/
public function mount(BackupDestination $backupDestination): void
{
$this->backupDestination = $backupDestination;
}

/**
* Render the component.
*/
public function render(): View
{
return view('livewire.backup-destinations.index-item');
Expand Down
12 changes: 12 additions & 0 deletions app/Livewire/BackupDestinations/IndexTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,22 @@
use Livewire\Component;
use Livewire\WithPagination;

/**
* Livewire component for displaying a table of backup destinations.
*
* This component handles the pagination and rendering of backup destinations
* for the authenticated user.
*/
class IndexTable extends Component
{
use WithPagination;

/**
* Render the component.
*
* Fetches paginated backup destinations for the authenticated user
* and passes them to the view.
*/
public function render(): View
{
$backupDestinations = BackupDestination::where('user_id', Auth::id())
Expand Down
29 changes: 20 additions & 9 deletions app/Livewire/BackupDestinations/UpdateBackupDestinationForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,29 @@
use Livewire\Features\SupportRedirects\Redirector;
use Toaster;

/**
* Livewire component for updating a backup destination.
*
* This component handles the form submission and validation for updating
* various types of backup destinations, including custom S3, S3, and local.
*/
class UpdateBackupDestinationForm extends Component
{
public string $label;

public string $type = 'custom_s3';

public ?string $s3AccessKey = null;

public ?string $s3SecretKey = null;

public ?string $s3BucketName = null;

public bool $usePathStyleEndpoint = false;

public ?string $customS3Region = null;

public ?string $customS3Endpoint = null;

public BackupDestination $backupDestination;

/**
* Handle the form submission for updating a backup destination.
*
* Validates the input, updates the BackupDestination, and redirects to the index page.
*/
public function submit(): RedirectResponse|Redirector
{
$this->authorize('update', $this->backupDestination);
Expand Down Expand Up @@ -69,11 +72,16 @@ public function submit(): RedirectResponse|Redirector

$this->backupDestination->save();

Toaster::success(__('Backup destination has been updated.'));
Toaster::success('Backup destination has been updated.');

return Redirect::route('backup-destinations.index');
}

/**
* Initialize the component with the given backup destination.
*
* Populates the component properties with the backup destination's attributes.
*/
public function mount(BackupDestination $backupDestination): void
{
$this->backupDestination = $backupDestination;
Expand All @@ -87,6 +95,9 @@ public function mount(BackupDestination $backupDestination): void
$this->usePathStyleEndpoint = $backupDestination->getAttribute('path_style_endpoint') ?? false;
}

/**
* Render the component.
*/
public function render(): View
{
return view('livewire.backup-destinations.update-backup-destination-form');
Expand Down
18 changes: 16 additions & 2 deletions app/Livewire/BackupTasks/Buttons/ClearLogButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,41 @@
use Livewire\Component;
use Masmerise\Toaster\Toaster;

/**
* Manages the button for clearing backup task logs.
*
* This component handles the UI and logic for removing all backup task logs
* associated with the authenticated user.
*/
class ClearLogButton extends Component
{
/**
* Clear all backup task logs for the authenticated user.
*
* Removes logs, displays a success message, and dispatches refresh events.
*/
public function clearAllLogs(): void
{
BackupTaskLog::whereHas('backupTask', function ($query): void {
$query->where('user_id', Auth::id());
})->delete();

Toaster::success(__('All your backup task logs have been removed.'));
Toaster::success('All your backup task logs have been removed.');

$this->dispatch('refreshBackupTaskHistory');
$this->dispatch('close-modal', 'clear-all-backup-task-logs');
}

/**
* Render the clear log button component.
*/
public function render(): View
{
return view('livewire.backup-tasks.buttons.clear-log-button');
}

/**
* Get the listeners array.
* Get the event listeners for the component.
*
* @return array<string, string>
*/
Expand Down
19 changes: 18 additions & 1 deletion app/Livewire/BackupTasks/Buttons/DeleteBackupTaskLogButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,45 @@
use Livewire\Component;
use Masmerise\Toaster\Toaster;

/**
* Manages the button for deleting a specific backup task log.
*
* This component handles the UI and logic for removing a single backup task log entry.
*/
class DeleteBackupTaskLogButton extends Component
{
/** @var BackupTaskLog The backup task log to be deleted */
public BackupTaskLog $backupTaskLog;

/**
* Initialize the component with a backup task log.
*/
public function mount(BackupTaskLog $backupTaskLog): void
{
$this->backupTaskLog = $backupTaskLog;
}

/**
* Delete the backup task log.
*
* Authorizes the action, deletes the log, and redirects to the index page.
*/
public function delete(): RedirectResponse|Redirector
{
$this->authorize('forceDelete', $this->backupTaskLog->getAttribute('backupTask'));

$this->backupTaskLog->forceDelete();

Toaster::success(__('Backup task log has been removed.'));
Toaster::success('Backup task log has been removed.');

$this->dispatch('refreshBackupTaskHistory');

return Redirect::route('backup-tasks.index');
}

/**
* Render the delete backup task log button component.
*/
public function render(): View
{
return view('livewire.backup-tasks.buttons.delete-backup-task-log-button');
Expand Down
Loading

0 comments on commit e5630c5

Please sign in to comment.