-
Notifications
You must be signed in to change notification settings - Fork 0
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 #4 from hanisirfan/visitor_delete
Visitor delete
- Loading branch information
Showing
11 changed files
with
270 additions
and
8 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
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,106 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use Carbon\Carbon; | ||
use App\Models\Visitor; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\Log; | ||
|
||
class DeleteVisitorByAge extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'deleteVisitorByAge | ||
{--S|seconds= : Delete visitors with X minutes of age.} | ||
{--m|minutes= : Delete visitors with X minutes of age.} | ||
{--H|hours= : Delete visitors with X hours of age.} | ||
{--D|days= : Delete visitors with X days of age.} | ||
{--W|weeks= : Delete visitors with X weeks of age.} | ||
'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'visitorqr: Delete visitors based on age after they are added to the system.'; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return int | ||
*/ | ||
public function handle() | ||
{ | ||
if (!empty($this->option('seconds'))) { | ||
$optionSeconds = $this->option('seconds'); | ||
} else { | ||
$optionSeconds = 0; | ||
} | ||
|
||
if (!empty($this->option('minutes'))) { | ||
$optionMinutes = $this->option('minutes'); | ||
$optionMinutes = $optionMinutes * 60; | ||
} else { | ||
$optionMinutes = 0; | ||
} | ||
|
||
if (!empty($this->option('hours'))) { | ||
$optionHours = $this->option('hours'); | ||
$optionHours = ($optionHours * 60) * 60; | ||
} else { | ||
$optionHours = 0; | ||
} | ||
|
||
if (!empty($this->option('days'))) { | ||
$optionDays = $this->option('days'); | ||
$optionDays = (($optionDays * 24) * 60) * 60; | ||
} else { | ||
$optionDays = 0; | ||
} | ||
|
||
if (!empty($this->option('weeks'))) { | ||
$optionWeeks = $this->option('weeks'); | ||
$optionWeeks = ((($optionWeeks * 7) * 24) * 60) * 60; | ||
} else { | ||
$optionWeeks = 0; | ||
} | ||
|
||
$totalAgeInSeconds = $optionSeconds + $optionMinutes + $optionHours + $optionDays + $optionWeeks; | ||
|
||
$this->info('<fg=black;bg=white>Total age limit in seconds: ' . $totalAgeInSeconds); | ||
Log::channel('deleteVisitorByAgeCommand')->info('Total age limit in seconds: ' . $totalAgeInSeconds); | ||
|
||
if (Visitor::first()) { | ||
|
||
$visitors = Visitor::select('uuid', 'created_at')->get(); | ||
|
||
$now = Carbon::now(); | ||
foreach ($visitors as $visitor) { | ||
$visitorAgeInSeconds = $visitor->created_at->diffInSeconds($now); | ||
$this->info('-----------------------------------------------------------'); | ||
$this->info('Visitor UUID: ' . $visitor->uuid); | ||
$this->info('Visitor Created At: ' . $visitor->created_at); | ||
$this->info('Visitor Age In Seconds: ' . $visitorAgeInSeconds); | ||
|
||
// Deleting visitor if the age (in seconds) is more than the limit defined when running the command. | ||
if ($visitorAgeInSeconds > $totalAgeInSeconds) { | ||
|
||
Visitor::where('uuid', $visitor->uuid)->delete(); | ||
$this->info('<fg=black;bg=white>Deleted visitor with UUID: ' . $visitor->uuid); | ||
Log::channel('deleteVisitorByAgeCommand')->info('Deleted visitor with UUID: ' . $visitor->uuid); | ||
} | ||
$this->info('-----------------------------------------------------------'); | ||
} | ||
} else { | ||
$this->info('No visitors found.'); | ||
Log::channel('deleteVisitorByAgeCommand')->info('No visitors found.'); | ||
} | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
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
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,54 @@ | ||
<?php | ||
|
||
namespace App\View\Components\Visitors; | ||
|
||
use App\Models\Visitor; | ||
use DateTime; | ||
use Illuminate\View\Component; | ||
|
||
class Delete extends Component | ||
{ | ||
/** | ||
* Visitor UUID. | ||
* | ||
* @var uuid | ||
*/ | ||
public $visitorUuid; | ||
|
||
/** | ||
* Visitor Name. | ||
* | ||
* @var String | ||
*/ | ||
public $visitorName; | ||
|
||
/** | ||
* Visitor Access Date and Time. | ||
* | ||
* @var DateTime | ||
*/ | ||
public $visitorDateTime; | ||
|
||
/** | ||
* Create a new component instance. | ||
* | ||
* @param uuid $visitorUuid | ||
* @return void | ||
*/ | ||
public function __construct($visitorUuid) | ||
{ | ||
$this->visitorUuid = $visitorUuid; | ||
$this->visitorName = Visitor::select('name')->where('uuid', $visitorUuid)->first()->name; | ||
$this->visitorDateTime = Visitor::select('visit_datetime')->where('uuid', $visitorUuid)->first()->date_time; | ||
} | ||
|
||
/** | ||
* Get the view / contents that represent the component. | ||
* | ||
* @return \Illuminate\Contracts\View\View|\Closure|string | ||
*/ | ||
public function render() | ||
{ | ||
return view('components.visitors.delete'); | ||
} | ||
} |
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,34 @@ | ||
<div> | ||
<a class="btn btn-danger text-light" href="" data-bs-toggle="modal" data-bs-target="#{{ 'delete-visitor-modal-' . $visitorUuid}}"><i class="bi bi-trash"></i></a> | ||
|
||
<div class="modal text-dark fade" id="{{ 'delete-visitor-modal-' . $visitorUuid}}" tabindex="-1" aria-labelledby="{{ 'delete-visitor-modal-' . $visitorUuid . '-label'}}" aria-hidden="true"> | ||
<div class="modal-dialog"> | ||
<div class="modal-content"> | ||
<form action="{{ route('visitors.delete') }}" method="post"> | ||
@csrf | ||
<div class="modal-header"> | ||
<h5 class="modal-title" id="{{ 'delete-user-modal-' . $visitorUuid . '-label'}}">{{ __('Delete Visitor') }}</h5> | ||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> | ||
</div> | ||
<div class="modal-body"> | ||
<p>{{ __('You sure want to delete this visitors.') }}</p> | ||
|
||
<p class="fw-bold">{{ __('UUID') }}: <span class="fw-normal">{{ $visitorUuid }}</span></p> | ||
<p class="fw-bold">{{ __('Name') }}: <span class="fw-normal">{{ $visitorName }}</span></p> | ||
<p class="fw-bold">{{ __('Access Date & Time') }}: | ||
<span class="fw-normal"> | ||
<x-carbon :date="$visitorDateTime" format="d/m/Y h:i A" /> | ||
</span> | ||
</p> | ||
|
||
<input type="text" name="delete-visitor-uuid" id="delete-visitor-uuid" value="{{ $visitorUuid }}" hidden> | ||
</div> | ||
<div class="modal-footer"> | ||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{{ __('Cancel') }}</button> | ||
<button type="submit" class="btn btn-danger"><i class="bi bi-trash"></i> {{ __('Yes') }}</button> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
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