-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3bd9d4a
commit 59ed941
Showing
20 changed files
with
693 additions
and
0 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,100 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Mail\User\QuietModeExpiredMail; | ||
use App\Models\User; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Support\Carbon; | ||
use Illuminate\Support\Facades\Mail; | ||
use Symfony\Component\Console\Command\Command as CommandAlias; | ||
|
||
/** | ||
* Class ResetQuietModeStatus | ||
* | ||
* This command resets the quiet mode for users whose quiet mode has expired. | ||
* It processes users in chunks to efficiently handle large datasets. | ||
*/ | ||
class ResetQuietModeStatus extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'vanguard:reset-quiet-mode'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Resets the quiet mode for users whose quiet mode has expired.'; | ||
|
||
/** | ||
* The count of users whose quiet mode was reset. | ||
*/ | ||
protected int $resetCount = 0; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* This method initiates the process of resetting expired quiet modes, | ||
* provides informational output, and returns the command's exit status. | ||
*/ | ||
public function handle(): int | ||
{ | ||
$this->components->info('Starting to reset expired quiet modes...'); | ||
|
||
$this->resetExpiredQuietModes(); | ||
|
||
$this->components->info("Quiet mode reset for {$this->resetCount} users."); | ||
|
||
return CommandAlias::SUCCESS; | ||
} | ||
|
||
/** | ||
* Reset quiet mode for users whose quiet mode has expired. | ||
* | ||
* This method queries the database for users with expired quiet mode | ||
* and processes them in chunks to efficiently handle large datasets. | ||
*/ | ||
protected function resetExpiredQuietModes(): void | ||
{ | ||
User::query() | ||
->whereDate('quiet_until', '<=', Carbon::today()) | ||
->whereNotNull('quiet_until') | ||
->chunkById(100, function ($users): void { | ||
foreach ($users as $user) { | ||
$this->resetUserQuietMode($user); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Reset quiet mode for a single user and increment the reset count. | ||
* | ||
* This method clears the quiet mode for the given user, increments the reset count, | ||
* and logs an informational message about the action. It handles both User models | ||
* and generic Eloquent models for flexibility. | ||
* | ||
* @param User|Model $user The user whose quiet mode is being reset | ||
*/ | ||
protected function resetUserQuietMode(User|Model $user): void | ||
{ | ||
if ($user instanceof User) { | ||
$user->clearQuietMode(); | ||
|
||
Mail::to($user)->queue(new QuietModeExpiredMail($user)); | ||
|
||
$this->resetCount++; | ||
|
||
$this->info("Quiet mode reset for user: {$user->getAttribute('email')}"); | ||
} else { | ||
$this->warn('Unexpected model type encountered. Expected User, got ' . $user::class); | ||
} | ||
} | ||
} |
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,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Livewire\Profile; | ||
|
||
use Illuminate\View\View; | ||
use Livewire\Component; | ||
|
||
/** | ||
* Class QuietModePage | ||
* | ||
* This Livewire component represents the Quiet Mode page in the user's profile section. | ||
* It is responsible for rendering the Quiet Mode page view with the appropriate layout. | ||
* The Quiet Mode feature allows users to temporarily disable notifications and updates. | ||
*/ | ||
class QuietModePage extends Component | ||
{ | ||
/** | ||
* Render the Quiet Mode page component. | ||
* | ||
* This method returns the view for the Quiet Mode page, using the 'account-app' layout. | ||
* The view contains controls for managing the user's Quiet Mode settings. | ||
* | ||
* @return View The rendered view for the Quiet Mode page | ||
*/ | ||
public function render(): View | ||
{ | ||
return view('livewire.profile.quiet-mode-page') | ||
->layout('components.layouts.account-app'); | ||
} | ||
} |
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,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Mail\User; | ||
|
||
use App\Models\User; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Mail\Mailable; | ||
use Illuminate\Mail\Mailables\Content; | ||
use Illuminate\Mail\Mailables\Envelope; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
/** | ||
* Class QuietModeExpiredMail | ||
* | ||
* This mailable is responsible for sending an email notification to users | ||
* when their Quiet Mode period has expired and been automatically deactivated. | ||
*/ | ||
class QuietModeExpiredMail extends Mailable implements ShouldQueue | ||
{ | ||
use Queueable; | ||
use SerializesModels; | ||
|
||
public function __construct(public readonly User $user) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Get the message envelope. | ||
* | ||
* This method defines the subject line and any additional headers for the email. | ||
*/ | ||
public function envelope(): Envelope | ||
{ | ||
return new Envelope( | ||
subject: __('Welcome back! Your Quiet Mode period has ended'), | ||
); | ||
} | ||
|
||
/** | ||
* Get the message content definition. | ||
* | ||
* This method specifies the view to be used for the email content | ||
* and any data that should be passed to that view. | ||
*/ | ||
public function content(): Content | ||
{ | ||
return new Content( | ||
markdown: 'mail.user.quiet-mode-expired-mail', | ||
with: [ | ||
'first_name' => $this->user->getAttribute('first_name'), | ||
], | ||
); | ||
} | ||
} |
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
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
15 changes: 15 additions & 0 deletions
15
database/migrations/2024_08_21_175702_add_quiet_until_column_to_users_table.php
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,15 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
public function up(): void | ||
{ | ||
Schema::table('users', function (Blueprint $table) { | ||
$table->dateTime('quiet_until')->nullable()->after('remember_token'); | ||
}); | ||
} | ||
}; |
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
Oops, something went wrong.