[image_view_counter] use a proper DB version counter

This commit is contained in:
Shish 2024-06-21 19:18:21 +01:00 committed by Shish
parent 7150af6b9e
commit d7f0f17fea
2 changed files with 18 additions and 2 deletions

View file

@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace Shimmie2;
abstract class ImageViewCounterConfig
{
public const VERSION = 'ext_image_view_counter';
}

View file

@ -6,6 +6,8 @@ namespace Shimmie2;
use function MicroHTML\{TD,TH,TR};
require_once "config.php";
class ImageViewCounter extends Extension
{
/** @var ImageViewCounterTheme */
@ -78,14 +80,18 @@ class ImageViewCounter extends Extension
{
global $database, $config;
if ($config->get_bool("image_viewcounter_installed") == false) { //todo
if ($config->get_bool("image_viewcounter_installed")) {
$this->set_version(ImageViewCounterConfig::VERSION, 1);
$config->delete("image_viewcounter_installed");
}
if ($this->get_version(ImageViewCounterConfig::VERSION) < 1) {
$database->create_table("image_views", "
id SCORE_AIPK,
image_id INTEGER NOT NULL,
user_id INTEGER NOT NULL,
timestamp INTEGER NOT NULL,
ipaddress SCORE_INET NOT NULL");
$config->set_bool("image_viewcounter_installed", true);
$this->set_version(ImageViewCounterConfig::VERSION, 1);
}
}