configure-delete-window (#66)
Let users configure the amount of time that a tick can be deleted Reviewed-on: https://gitea.subcultureofone.org/greg/tkr/pulls/66 Co-authored-by: Greg Sarjeant <greg@subcultureofone.org> Co-committed-by: Greg Sarjeant <greg@subcultureofone.org>
This commit is contained in:
parent
86abf587f6
commit
801bbebf4f
@ -0,0 +1,2 @@
|
||||
ALTER TABLE settings
|
||||
ADD COLUMN tick_delete_hours INTEGER NULL;
|
@ -42,6 +42,12 @@ if (!$prerequisites->validateApplication()) {
|
||||
// Get the working database connection from prerequisites
|
||||
$db = $prerequisites->getDatabase();
|
||||
|
||||
// Apply any pending database migrations
|
||||
if (!$prerequisites->applyMigrations($db)){
|
||||
$prerequisites->generateWebSummary();
|
||||
exit;
|
||||
}
|
||||
|
||||
// Check if setup is complete (user exists and URL is configured)
|
||||
if (!(preg_match('/tkr-setup$/', $path))) {
|
||||
try {
|
||||
|
@ -91,6 +91,7 @@ class AdminController extends Controller {
|
||||
$itemsPerPage = (int) ($postData['items_per_page'] ?? 25);
|
||||
$strictAccessibility = isset($postData['strict_accessibility']);
|
||||
$logLevel = (int) ($postData['log_level'] ?? 0);
|
||||
$tickDeleteHours = (int) ($postData['tick_delete_hours'] ?? 1);
|
||||
|
||||
// Password
|
||||
$password = $postData['password'] ?? '';
|
||||
@ -152,6 +153,7 @@ class AdminController extends Controller {
|
||||
$app['settings']->itemsPerPage = $itemsPerPage;
|
||||
$app['settings']->strictAccessibility = $strictAccessibility;
|
||||
$app['settings']->logLevel = $logLevel;
|
||||
$app['settings']->tickDeleteHours = $tickDeleteHours;
|
||||
|
||||
// Save site settings and reload config from database
|
||||
$app['settings'] = $app['settings']->save();
|
||||
|
@ -442,7 +442,7 @@ class Prerequisites {
|
||||
}
|
||||
}
|
||||
|
||||
private function applyMigrations($db) {
|
||||
public function applyMigrations($db) {
|
||||
try {
|
||||
$migrator = new Migrator($db);
|
||||
$migrator->migrate();
|
||||
|
@ -12,8 +12,7 @@ class SettingsModel {
|
||||
public ?int $cssId = null;
|
||||
public bool $strictAccessibility = true;
|
||||
public ?int $logLevel = null;
|
||||
// not currently configurable
|
||||
public int $tickDeleteHours = 1;
|
||||
public ?int $tickDeleteHours = null;
|
||||
|
||||
public function __construct(private PDO $db) {}
|
||||
|
||||
@ -28,7 +27,8 @@ class SettingsModel {
|
||||
items_per_page,
|
||||
css_id,
|
||||
strict_accessibility,
|
||||
log_level
|
||||
log_level,
|
||||
tick_delete_hours
|
||||
FROM settings WHERE id=1");
|
||||
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
@ -41,7 +41,8 @@ class SettingsModel {
|
||||
$c->itemsPerPage = (int) $row['items_per_page'];
|
||||
$c->cssId = (int) $row['css_id'];
|
||||
$c->strictAccessibility = (bool) $row['strict_accessibility'];
|
||||
$c->logLevel = $row['log_level'];
|
||||
$c->logLevel = (int) ($row['log_level'] ?? 2);
|
||||
$c->tickDeleteHours = (int) ($row['tick_delete_hours'] ?? 1);
|
||||
}
|
||||
|
||||
return $c;
|
||||
@ -51,6 +52,7 @@ class SettingsModel {
|
||||
$settingsCount = (int) $this->db->query("SELECT COUNT(*) FROM settings")->fetchColumn();
|
||||
|
||||
if ($settingsCount === 0){
|
||||
Log::debug('Initializing settings');
|
||||
$stmt = $this->db->prepare("INSERT INTO settings (
|
||||
id,
|
||||
site_title,
|
||||
@ -60,10 +62,12 @@ class SettingsModel {
|
||||
items_per_page,
|
||||
css_id,
|
||||
strict_accessibility,
|
||||
log_level
|
||||
log_level,
|
||||
tick_delete_hours
|
||||
)
|
||||
VALUES (1, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
VALUES (1, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||
} else {
|
||||
Log::debug('Updating settings');
|
||||
$stmt = $this->db->prepare("UPDATE settings SET
|
||||
site_title=?,
|
||||
site_description=?,
|
||||
@ -72,10 +76,21 @@ class SettingsModel {
|
||||
items_per_page=?,
|
||||
css_id=?,
|
||||
strict_accessibility=?,
|
||||
log_level=?
|
||||
log_level=?,
|
||||
tick_delete_hours=?
|
||||
WHERE id=1");
|
||||
}
|
||||
|
||||
Log::debug("Site title: " . $this->siteTitle);
|
||||
Log::debug("Site description: " . $this->siteDescription);
|
||||
Log::debug("Base URL: " . $this->baseUrl);
|
||||
Log::debug("Base path: " . $this->basePath);
|
||||
Log::debug("Items per page: " . $this->itemsPerPage);
|
||||
Log::debug("CSS ID: " . $this->cssId);
|
||||
Log::debug("Strict accessibility: " . $this->strictAccessibility);
|
||||
Log::debug("Log level: " . $this->logLevel);
|
||||
Log::debug("Tick delete window: " . $this->tickDeleteHours);
|
||||
|
||||
$stmt->execute([$this->siteTitle,
|
||||
$this->siteDescription,
|
||||
$this->baseUrl,
|
||||
@ -83,7 +98,8 @@ class SettingsModel {
|
||||
$this->itemsPerPage,
|
||||
$this->cssId,
|
||||
$this->strictAccessibility,
|
||||
$this->logLevel
|
||||
$this->logLevel,
|
||||
$this->tickDeleteHours
|
||||
]);
|
||||
|
||||
return $this->get();
|
||||
|
@ -61,13 +61,18 @@
|
||||
name="items_per_page"
|
||||
value="<?= $settings->itemsPerPage ?>" min="1" max="50"
|
||||
required>
|
||||
<label for="tick_delete_hours">Tick delete window (hours)</label>
|
||||
<input type="number"
|
||||
id="tick_delete_hours"
|
||||
name="tick_delete_hours"
|
||||
value="<?= ($settings->tickDeleteHours ?? 1) ?>" min="1">
|
||||
<label for="strict_accessibility">Strict accessibility</label>
|
||||
<input type="checkbox"
|
||||
id="strict_accessibility"
|
||||
name="strict_accessibility"
|
||||
value="1"
|
||||
<?php if ($settings->strictAccessibility): ?> checked <?php endif; ?>>
|
||||
<label for="strict_accessibility">Log Level</label>
|
||||
<label for="log_level">Log Level</label>
|
||||
<select id="log_level" name="log_level">
|
||||
<option value="1" <?= ($settings->logLevel ?? 2) == 1 ? 'selected' : '' ?>>DEBUG</option>
|
||||
<option value="2" <?= ($settings->logLevel ?? 2) == 2 ? 'selected' : '' ?>>INFO</option>
|
||||
|
@ -22,6 +22,7 @@ class AdminControllerTest extends TestCase
|
||||
$this->settings->baseUrl = 'https://example.com';
|
||||
$this->settings->basePath = '/tkr';
|
||||
$this->settings->itemsPerPage = 10;
|
||||
$this->settings->tickDeleteHours = 2;
|
||||
|
||||
$this->user = new UserModel($this->mockPdo);
|
||||
$this->user->username = 'testuser';
|
||||
@ -119,7 +120,8 @@ class AdminControllerTest extends TestCase
|
||||
'items_per_page' => 15,
|
||||
'css_id' => null,
|
||||
'strict_accessibility' => true,
|
||||
'log_level' => 2
|
||||
'log_level' => 2,
|
||||
'tick_delete_hours' => 3
|
||||
],
|
||||
[
|
||||
'username' => 'newuser',
|
||||
@ -153,7 +155,8 @@ class AdminControllerTest extends TestCase
|
||||
'base_path' => '/updated',
|
||||
'items_per_page' => 15,
|
||||
'strict_accessibility' => 'on',
|
||||
'log_level' => 2
|
||||
'log_level' => 2,
|
||||
'tick_delete_hours' => 3
|
||||
];
|
||||
|
||||
$result = $controller->saveSettings($postData, false);
|
||||
@ -177,7 +180,8 @@ class AdminControllerTest extends TestCase
|
||||
'items_per_page' => 10,
|
||||
'css_id' => null,
|
||||
'strict_accessibility' => true,
|
||||
'log_level' => 2
|
||||
'log_level' => 2,
|
||||
'tick_delete_hours' => 3
|
||||
],
|
||||
[
|
||||
'username' => 'testuser',
|
||||
|
Loading…
x
Reference in New Issue
Block a user