Added clicks counter to redirects.
This commit is contained in:
parent
d96209a059
commit
55ff555f46
2 changed files with 18 additions and 2 deletions
12
database/2023_01_31_001812_add_clicks_counter.php
Normal file
12
database/2023_01_31_001812_add_clicks_counter.php
Normal 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;
|
||||
');
|
||||
}
|
||||
}
|
|
@ -47,7 +47,7 @@ final class RedirectorRoutes {
|
|||
}
|
||||
|
||||
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(2, $id, DbType::STRING);
|
||||
$getInfo->execute();
|
||||
|
@ -56,7 +56,11 @@ final class RedirectorRoutes {
|
|||
if(!$info->next())
|
||||
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) {
|
||||
|
|
Loading…
Reference in a new issue