Initial Commit
This commit is contained in:
62
admin/controller.php
Normal file
62
admin/controller.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
namespace Pterodactyl\Http\Controllers\Admin\Extensions\activitypurges;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
use Illuminate\View\Factory as ViewFactory;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Pterodactyl\Http\Controllers\Controller;
|
||||
use Pterodactyl\BlueprintFramework\Libraries\ExtensionLibrary\Admin\BlueprintAdminLibrary as BlueprintExtensionLibrary;
|
||||
|
||||
class activitypurgesExtensionController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private ViewFactory $view,
|
||||
private BlueprintExtensionLibrary $blueprint,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Handle both GET and POST requests.
|
||||
*/
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$message = null;
|
||||
|
||||
if ($request->isMethod('post')) {
|
||||
// Validate the input timestamp.
|
||||
$validated = $request->validate([
|
||||
'timestamp' => 'required|date'
|
||||
]);
|
||||
|
||||
// Convert the HTML datetime-local value to MySQL datetime format.
|
||||
$rawTimestamp = $validated['timestamp'];
|
||||
$mysqlTimestamp = date('Y-m-d H:i:s', strtotime($rawTimestamp));
|
||||
|
||||
try {
|
||||
// Purge records older than the provided timestamp.
|
||||
$deleted = DB::table('activity_logs')
|
||||
->where('timestamp', '<', $mysqlTimestamp)
|
||||
->delete();
|
||||
|
||||
$message = "{$deleted} log(s) have been purged successfully.";
|
||||
} catch (\Exception $e) {
|
||||
\Log::error('Purge error: ' . $e->getMessage());
|
||||
$message = "An error occurred while purging logs.";
|
||||
}
|
||||
}
|
||||
|
||||
return $this->view->make('admin.extensions.activitypurges.index', [
|
||||
'root' => "/admin/extensions/activitypurges",
|
||||
'blueprint' => $this->blueprint,
|
||||
'message' => $message,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle POST requests by delegating to index().
|
||||
*/
|
||||
public function post(Request $request): View
|
||||
{
|
||||
return $this->index($request);
|
||||
}
|
||||
}
|
||||
30
admin/view.blade.php
Normal file
30
admin/view.blade.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<!--
|
||||
Content on this page will be displayed on your extension's admin page.
|
||||
-->
|
||||
<div class="box box-info">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">Information</h3>
|
||||
</div>
|
||||
<div class="box-body">
|
||||
<!-- Display success message if available -->
|
||||
@if(isset($message) && $message)
|
||||
<div class="alert alert-success">
|
||||
{{ $message }}
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<p>
|
||||
An Extension Used To <code>Clear/Purge</code> old Activity Logs, in order to clear database storage used.
|
||||
</p>
|
||||
|
||||
<!-- The form posts to the same page -->
|
||||
<form method="POST" action="{{ $root }}">
|
||||
@csrf
|
||||
<div class="form-group">
|
||||
<label for="timestamp">Purge logs older than:</label>
|
||||
<input type="datetime-local" name="timestamp" id="timestamp" class="form-control" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-danger">Purge Logs</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user