Skip to content

Commit 499998f

Browse files
committed
build: always use the Mago version from composer.json
1 parent 39143ac commit 499998f

File tree

5 files changed

+126
-62
lines changed

5 files changed

+126
-62
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,8 @@ jobs:
4444
#- name: Lint with PHPCS
4545
# run: phpmyfaq/src/libs/bin/phpcs --standard=PSR12 ./phpmyfaq/src/phpMyFAQ
4646

47-
- name: Setup Mago
47+
- name: Setup Mago CLI
4848
uses: nhedger/setup-mago@v1
49-
with:
50-
version: latest
5149

5250
- name: Run Mago
5351
run: |

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"twig/twig": "^3.10"
5656
},
5757
"require-dev": {
58-
"carthage-software/mago": "^1.0.0-beta.28",
58+
"carthage-software/mago": "^1.0.0-beta.31",
5959
"doctrine/instantiator": "2.*",
6060
"mikey179/vfsstream": "^1.6",
6161
"phpdocumentor/reflection-docblock": "5.*",

composer.lock

Lines changed: 11 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpmyfaq/src/phpMyFAQ/Administration/AdminLog.php

Lines changed: 12 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
namespace phpMyFAQ\Administration;
2121

2222
use phpMyFAQ\Configuration;
23-
use phpMyFAQ\Database;
2423
use phpMyFAQ\Entity\AdminLog as AdminLogEntity;
2524
use phpMyFAQ\User;
2625
use Symfony\Component\HttpFoundation\Request;
@@ -32,22 +31,24 @@
3231
*/
3332
readonly class AdminLog
3433
{
34+
/** @var AdminLogRepository */
35+
private AdminLogRepository $repository;
36+
3537
/**
3638
* Constructor.
3739
*/
3840
public function __construct(
3941
private Configuration $configuration,
4042
) {
43+
$this->repository = new AdminLogRepository($this->configuration);
4144
}
4245

4346
/**
4447
* Returns the number of entries.
4548
*/
4649
public function getNumberOfEntries(): int
4750
{
48-
$query = sprintf('SELECT id FROM %sfaqadminlog', Database::getTablePrefix());
49-
50-
return $this->configuration->getDb()->numRows($this->configuration->getDb()->query($query));
51+
return $this->repository->getNumberOfEntries();
5152
}
5253

5354
/**
@@ -56,27 +57,7 @@ public function getNumberOfEntries(): int
5657
*/
5758
public function getAll(): array
5859
{
59-
$data = [];
60-
61-
$query = sprintf(
62-
'SELECT id, time, usr AS user, text, ip FROM %sfaqadminlog ORDER BY id DESC',
63-
Database::getTablePrefix(),
64-
);
65-
66-
$result = $this->configuration->getDb()->query($query);
67-
68-
while ($row = $this->configuration->getDb()->fetchObject($result)) {
69-
$adminLog = new AdminLogEntity();
70-
$adminLog
71-
->setId($row->id)
72-
->setTime($row->time)
73-
->setUserId($row->user)
74-
->setText($row->text)
75-
->setIp($row->ip);
76-
$data[$row->id] = $adminLog;
77-
}
78-
79-
return $data;
60+
return $this->repository->getAll();
8061
}
8162

8263
/**
@@ -87,35 +68,20 @@ public function getAll(): array
8768
*/
8869
public function log(User $user, string $logText = ''): bool
8970
{
90-
if ($this->configuration->get('main.enableAdminLog')) {
91-
$request = Request::createFromGlobals();
92-
$query = sprintf(
93-
"INSERT INTO %sfaqadminlog (id, time, usr, text, ip) VALUES (%d, %d, %d, '%s', '%s')",
94-
Database::getTablePrefix(),
95-
$this->configuration->getDb()->nextId(Database::getTablePrefix() . 'faqadminlog', 'id'),
96-
$request->server->get('REQUEST_TIME'),
97-
$user->getUserId(),
98-
$this->configuration->getDb()->escape(nl2br($logText)),
99-
$this->configuration->getDb()->escape($request->getClientIp()),
100-
);
101-
102-
return (bool) $this->configuration->getDb()->query($query);
71+
if (!$this->configuration->get('main.enableAdminLog')) {
72+
return false; // early return, avoids else
10373
}
10474

105-
return false;
75+
$request = Request::createFromGlobals();
76+
return $this->repository->add($user, $logText, $request);
10677
}
10778

10879
/**
10980
* Deletes logging data older than 30 days.
11081
*/
11182
public function delete(): bool
11283
{
113-
$query = sprintf(
114-
'DELETE FROM %sfaqadminlog WHERE time < %d',
115-
Database::getTablePrefix(),
116-
Request::createFromGlobals()->server->get('REQUEST_TIME') - (30 * 86400),
117-
);
118-
119-
return (bool) $this->configuration->getDb()->query($query);
84+
$timestamp = (int) Request::createFromGlobals()->server->get('REQUEST_TIME') - (30 * 86400);
85+
return $this->repository->deleteOlderThan($timestamp);
12086
}
12187
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
/**
4+
* AdminLog Repository.
5+
*
6+
* This Source Code Form is subject to the terms of the Mozilla Public License,
7+
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
8+
* obtain one at https://mozilla.org/MPL/2.0/.
9+
*
10+
* @package phpMyFAQ
11+
* @author Thorsten Rinne <[email protected]>
12+
* @copyright 2025 phpMyFAQ Team
13+
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
14+
* @link https://www.phpmyfaq.de
15+
* @since 2025-10-16
16+
*/
17+
18+
declare(strict_types=1);
19+
20+
namespace phpMyFAQ\Administration;
21+
22+
use phpMyFAQ\Configuration;
23+
use phpMyFAQ\Database;
24+
use phpMyFAQ\Entity\AdminLog as AdminLogEntity;
25+
use phpMyFAQ\User;
26+
use Symfony\Component\HttpFoundation\Request;
27+
28+
readonly class AdminLogRepository
29+
{
30+
public function __construct(
31+
private Configuration $configuration,
32+
) {
33+
}
34+
35+
public function getNumberOfEntries(): int
36+
{
37+
$query = sprintf('SELECT id FROM %sfaqadminlog', Database::getTablePrefix());
38+
39+
return $this->configuration->getDb()->numRows($this->configuration->getDb()->query($query));
40+
}
41+
42+
/**
43+
* @return array<int, AdminLogEntity>
44+
*/
45+
public function getAll(): array
46+
{
47+
$data = [];
48+
49+
$query = sprintf(
50+
'SELECT id, time, usr AS user, text, ip FROM %sfaqadminlog ORDER BY id DESC',
51+
Database::getTablePrefix(),
52+
);
53+
54+
$result = $this->configuration->getDb()->query($query);
55+
56+
while ($row = $this->configuration->getDb()->fetchObject($result)) {
57+
$adminLog = new AdminLogEntity();
58+
$adminLog
59+
->setId($row->id)
60+
->setTime($row->time)
61+
->setUserId($row->user)
62+
->setText($row->text)
63+
->setIp($row->ip);
64+
$data[$row->id] = $adminLog;
65+
}
66+
67+
return $data;
68+
}
69+
70+
public function add(User $user, string $logText, Request $request): bool
71+
{
72+
$table = Database::getTablePrefix() . 'faqadminlog';
73+
$id = $this->configuration->getDb()->nextId($table, 'id');
74+
$time = (int) $request->server->get('REQUEST_TIME');
75+
$userId = $user->getUserId();
76+
$text = $this->configuration->getDb()->escape(nl2br($logText));
77+
$ip = $this->configuration->getDb()->escape((string) $request->getClientIp());
78+
79+
$query = strtr("INSERT INTO table: (id, time, usr, text, ip) VALUES (id:, time:, userId:, 'text:', 'ip:')", [
80+
'table:' => $table,
81+
'id:' => (string) $id,
82+
'time:' => (string) $time,
83+
'userId:' => (string) $userId,
84+
'text:' => $text,
85+
'ip:' => $ip,
86+
]);
87+
88+
return (bool) $this->configuration->getDb()->query($query);
89+
}
90+
91+
public function deleteOlderThan(int $timestamp): bool
92+
{
93+
$table = Database::getTablePrefix() . 'faqadminlog';
94+
$query = strtr('DELETE FROM table: WHERE time < ts:', [
95+
'table:' => $table,
96+
'ts:' => (string) $timestamp,
97+
]);
98+
99+
return (bool) $this->configuration->getDb()->query($query);
100+
}
101+
}

0 commit comments

Comments
 (0)