Added clicks counter to redirects.

This commit is contained in:
flash 2023-01-31 00:24:21 +00:00
parent d96209a059
commit 55ff555f46
2 changed files with 18 additions and 2 deletions

View file

@ -0,0 +1,12 @@
<?php
use Index\Data\IDbConnection;
use Index\Data\Migration\IDbMigration;
final class AddClicksCounter_20230131_001812 implements IDbMigration {
public function migrate(IDbConnection $conn): void {
$conn->execute('
ALTER TABLE awk_redirects
ADD COLUMN redir_clicks BIGINT UNSIGNED NOT NULL DEFAULT 0 AFTER redir_url;
');
}
}

View file

@ -47,7 +47,7 @@ final class RedirectorRoutes {
} }
public function redirectDatabase($response, $request, $id) { public function redirectDatabase($response, $request, $id) {
$getInfo = $this->dbConn->prepare('SELECT redir_url FROM awk_redirects WHERE redir_id = ? OR redir_vanity = ?'); $getInfo = $this->dbConn->prepare('SELECT redir_id, redir_url FROM awk_redirects WHERE redir_id = ? OR redir_vanity = ?');
$getInfo->addParameter(1, $id, DbType::INTEGER); $getInfo->addParameter(1, $id, DbType::INTEGER);
$getInfo->addParameter(2, $id, DbType::STRING); $getInfo->addParameter(2, $id, DbType::STRING);
$getInfo->execute(); $getInfo->execute();
@ -56,7 +56,11 @@ final class RedirectorRoutes {
if(!$info->next()) if(!$info->next())
return 404; return 404;
$this->redirect($response, $request, $info->getString(0)); $incClicks = $this->dbConn->prepare('UPDATE awk_redirects SET redir_clicks = redir_clicks + 1 WHERE redir_id = ?');
$incClicks->addParameter(1, $info->getInteger(0), DbType::INTEGER);
$incClicks->execute();
$this->redirect($response, $request, $info->getString(1));
} }
private function redirectSimple($response, $request, string $format, string $argument) { private function redirectSimple($response, $request, string $format, string $argument) {