mirror of
https://gh.wpcy.net/https://github.com/djav1985/v-wordpress-plugin-updater.git
synced 2026-05-02 11:22:19 +08:00
Agent-Logs-Url: https://github.com/djav1985/v-wordpress-plugin-updater/sessions/9f3a7e0f-e5a9-42b5-beb5-4f8edd29adf4 Co-authored-by: djav1985 <174835544+djav1985@users.noreply.github.com>
89 lines
2.6 KiB
PHP
89 lines
2.6 KiB
PHP
<?php
|
|
// phpcs:ignoreFile PSR1.Files.SideEffects.FoundWithSymbols
|
|
|
|
/**
|
|
* Project: UpdateAPI
|
|
* Author: Vontainment <services@vontainment.com>
|
|
* License: https://opensource.org/licenses/MIT MIT License
|
|
* Link: https://vontainment.com
|
|
* Version: 4.0.0
|
|
*
|
|
* File: LogModel.php
|
|
* Description: WordPress Update API
|
|
*/
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Core\DatabaseManager;
|
|
|
|
class LogModel
|
|
{
|
|
|
|
/**
|
|
* Process log entries from the database and generate grouped HTML output.
|
|
*
|
|
* @param string $type Log type: 'plugin' or 'theme'.
|
|
*
|
|
* @return string
|
|
*/
|
|
public static function getLogs(string $type): string
|
|
{
|
|
$conn = DatabaseManager::getConnection();
|
|
$rows = $conn->fetchAllAssociative(
|
|
'SELECT domain, date, status FROM logs WHERE type = ? ORDER BY date DESC',
|
|
[$type]
|
|
);
|
|
$logByDomain = [];
|
|
foreach ($rows as $row) {
|
|
if (!isset($logByDomain[$row['domain']])) {
|
|
$logByDomain[$row['domain']] = [
|
|
'date' => $row['date'],
|
|
'status' => $row['status'],
|
|
];
|
|
}
|
|
}
|
|
|
|
if (empty($logByDomain)) {
|
|
return 'No log entries found.';
|
|
}
|
|
|
|
ob_start();
|
|
echo '<div class="log-row">';
|
|
foreach ($logByDomain as $domain => $entry) {
|
|
$dateDiff = (strtotime(date('Y-m-d')) - strtotime($entry['date'])) / (60 * 60 * 24);
|
|
$classes = '';
|
|
if ($entry['status'] == 'Failed') {
|
|
$classes .= ' error';
|
|
} elseif ($entry['status'] == 'Success') {
|
|
$classes .= ' success';
|
|
}
|
|
if ($dateDiff > 30) {
|
|
$classes .= ' lost';
|
|
}
|
|
$classes = trim($classes);
|
|
echo '<div class="log-sub-box' . ($classes ? " $classes" : '') . '">';
|
|
echo '<h3>' . htmlspecialchars($domain, ENT_QUOTES, 'UTF-8') . '</h3>';
|
|
$color = $entry['status'] == 'Failed' ? 'red' : 'green';
|
|
echo '<p class="log-entry" style="color:' . $color . ';">' .
|
|
htmlspecialchars($entry['date'], ENT_QUOTES, 'UTF-8') . ' ' .
|
|
htmlspecialchars($entry['status'], ENT_QUOTES, 'UTF-8') .
|
|
'</p>';
|
|
echo '</div>';
|
|
}
|
|
echo '</div>';
|
|
$output = ob_get_contents();
|
|
ob_end_clean();
|
|
return $output;
|
|
}
|
|
|
|
/**
|
|
* Clear all known logs.
|
|
*
|
|
* @return void
|
|
*/
|
|
public static function clearAllLogs(): void
|
|
{
|
|
$conn = DatabaseManager::getConnection();
|
|
$conn->executeStatement('DELETE FROM logs');
|
|
}
|
|
}
|