mirror of
https://github.com/OPSnet/Gazelle.git
synced 2026-01-16 18:04:34 -05:00
relay email changes to pg
This commit is contained in:
@@ -143,10 +143,15 @@ class Pg {
|
||||
public function insert(string $query, ...$args): int {
|
||||
$begin = microtime(true);
|
||||
$st = $this->prepare($query);
|
||||
if ($st->execute([...$args])) {
|
||||
$id = (int)$this->pdo->lastInsertId();
|
||||
$this->stats->register($query, $id, $begin, [...$args]);
|
||||
return $id;
|
||||
try {
|
||||
if ($st->execute([...$args])) {
|
||||
$id = (int)$this->pdo->lastInsertId();
|
||||
$this->stats->register($query, $id, $begin, [...$args]);
|
||||
return $id;
|
||||
}
|
||||
} catch (\PDOException $e) {
|
||||
throw new \PDOException($e->getMessage()
|
||||
. " $query " . json_encode($args, JSON_UNESCAPED_SLASHES));
|
||||
}
|
||||
$this->stats->error($query);
|
||||
return 0;
|
||||
|
||||
@@ -224,6 +224,12 @@ class History extends \Gazelle\BaseUser {
|
||||
", $this->user->id, $newEmail, $ipaddr, $useragent
|
||||
);
|
||||
$affected = self::$db->affected_rows();
|
||||
$this->pg()->insert("
|
||||
insert into history_email
|
||||
(id_user, email, useragent, ip)
|
||||
values (?, ?, ?, ?::inet)
|
||||
", $this->id, $newEmail, $useragent, $ipaddr
|
||||
);
|
||||
if ($notify) {
|
||||
$irc::sendMessage(
|
||||
$this->user->username(),
|
||||
|
||||
@@ -158,7 +158,13 @@ class UserCreator extends Base {
|
||||
INSERT INTO users_history_emails
|
||||
(UserID, Email, IP, useragent, created)
|
||||
VALUES (?, ?, ?, ?, now() - INTERVAL ? SECOND)
|
||||
', $this->id, $e, $ipaddr, $useragent, $past--
|
||||
', $this->id, $e, $ipaddr, $useragent, $past
|
||||
);
|
||||
$this->pg()->insert("
|
||||
insert into history_email
|
||||
(id_user, email, useragent, ip, created)
|
||||
values (?, ?, ?, ?::inet, now() - '1 second'::interval * ?)
|
||||
", $this->id, $e, $useragent, $ipaddr, $past--
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
34
misc/pg-migrations/20250719000000_history_user_email.php
Normal file
34
misc/pg-migrations/20250719000000_history_user_email.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
use Phinx\Util\Literal;
|
||||
|
||||
final class HistoryUserEmail extends AbstractMigration {
|
||||
public function up(): void {
|
||||
$this->table('history_email', ['id' => false, 'primary_key' => 'id_history_email'])
|
||||
->addColumn('id_history_email', 'integer', ['identity' => true])
|
||||
->addColumn('id_user', 'integer')
|
||||
->addColumn('ip', 'inet')
|
||||
->addColumn('created', 'timestamp', ['timezone' => true, 'default' => 'CURRENT_TIMESTAMP'])
|
||||
->addColumn('email', Literal::from('citext'))
|
||||
->addColumn('useragent', 'text')
|
||||
->save();
|
||||
$this->query(
|
||||
<<<END_SQL
|
||||
insert into history_email
|
||||
(id_user, email, ip, created, useragent)
|
||||
select "UserID", "Email", "IP"::inet, created, useragent
|
||||
from relay.users_history_emails
|
||||
END_SQL
|
||||
);
|
||||
$this->query("
|
||||
create index he_u_idx on history_email (id_user)
|
||||
");
|
||||
}
|
||||
|
||||
public function down(): void {
|
||||
$this->table('history_email')->drop()->save();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user