diff --git a/Job/EntriesCount.php b/Job/EntriesCount.php new file mode 100644 index 0000000..d2653c1 --- /dev/null +++ b/Job/EntriesCount.php @@ -0,0 +1,56 @@ +app->db(); + + return $db->fetchAllColumn( + $db->limit( + 'SELECT user_id + FROM xf_user + WHERE user_id > ? + ORDER BY user_id', + $batch + ), + $start + ); + } + + private function countPublishedEntriesByUserId($userId): int + { + $db = Laravel::db(); + + if( $userId instanceof User ) + $userId = $userId->user_id; + + return $db->fetchOne( + "SELECT COUNT(*) FROM entries WHERE state = 'published' AND user_id = ?", $userId + ); + } + + protected function rebuildById($id): void + { + $count = $this->countPublishedEntriesByUserId($id); + + $this->app->db()->update( + 'xf_user', + ['rhpz_entry_count' => $count], + 'user_id = ?', + $id + ); + } + + protected function getStatusType(): Phrase + { + return \XF::phrase('entries'); + } +} \ No newline at end of file diff --git a/Service/Discord/BotService.php b/Service/Discord/BotService.php index b0f6a9e..d50e241 100644 --- a/Service/Discord/BotService.php +++ b/Service/Discord/BotService.php @@ -6,17 +6,17 @@ use XF\Service\AbstractService; class BotService extends AbstractService { - protected string $dbPath; + protected ?string $dbPath; protected ?\PDO $pdo = null; protected function setup() { - $this->dbPath = \XF::config('discord_db_path'); + $this->dbPath = \XF::config('discord_db_path') ?? null; } - protected function getDb(): \PDO + protected function getDb(): ?\PDO { - if (!$this->pdo) { + if (!$this->pdo && $this->dbPath) { $this->pdo = new \PDO("sqlite:" . $this->dbPath); $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); $this->pdo->exec('PRAGMA journal_mode=WAL;'); @@ -29,6 +29,8 @@ class BotService extends AbstractService { try { $db = $this->getDb(); + if( !$db ) + return false; $stmt = $db->prepare("INSERT INTO actions (action, data) VALUES (:action, :data)"); return $stmt->execute([ diff --git a/_data/help_pages.xml b/_data/help_pages.xml index 31828b1..bdd1e2c 100644 --- a/_data/help_pages.xml +++ b/_data/help_pages.xml @@ -1,2 +1,8 @@ - + + + + + + + diff --git a/_data/navigation.xml b/_data/navigation.xml index 7d2bc0f..ddcd6e8 100644 --- a/_data/navigation.xml +++ b/_data/navigation.xml @@ -1,22 +1,23 @@ - + - + - - + + + diff --git a/_data/phrases.xml b/_data/phrases.xml index 9febf13..9d3c5f9 100644 --- a/_data/phrases.xml +++ b/_data/phrases.xml @@ -7,6 +7,17 @@ + + + + + + + + + + + @@ -17,13 +28,14 @@ - + + diff --git a/_data/templates.xml b/_data/templates.xml index 607890b..bfd1451 100644 --- a/_data/templates.xml +++ b/_data/templates.xml @@ -536,6 +536,92 @@ ]]> + + + + +