Pārlūkot izejas kodu

Add Models\PM\UpdateUsername

Visman 4 gadi atpakaļ
vecāks
revīzija
3f340482ac
2 mainītis faili ar 51 papildinājumiem un 0 dzēšanām
  1. 50 0
      app/Models/PM/UpdateUsername.php
  2. 1 0
      app/Models/User/Save.php

+ 50 - 0
app/Models/PM/UpdateUsername.php

@@ -0,0 +1,50 @@
+<?php
+/**
+ * This file is part of the ForkBB <https://github.com/forkbb>.
+ *
+ * @copyright (c) Visman <mio.visman@yandex.ru, https://github.com/MioVisman>
+ * @license   The MIT License (MIT)
+ */
+
+declare(strict_types=1);
+
+namespace ForkBB\Models\PM;
+
+use ForkBB\Models\Method;
+use ForkBB\Models\User\Model as User;
+use RuntimeException;
+
+class UpdateUsername extends Method
+{
+    /**
+     * Обновляет имя пользователя в таблицах PM
+     */
+    public function updateUsername(User $user): void
+    {
+        if ($user->isGuest) {
+            throw new RuntimeException('User expected, not guest');
+        }
+
+        $vars = [
+            ':id'   => $user->id,
+            ':name' => $user->username,
+        ];
+        $query = 'UPDATE ::pm_posts
+            SET poster=?s:name
+            WHERE poster_id=?i:id';
+
+        $this->c->DB->exec($query, $vars);
+
+        $query = 'UPDATE ::pm_topics
+            SET poster=?s:name
+            WHERE poster_id=?i:id';
+
+        $this->c->DB->exec($query, $vars);
+
+        $query = 'UPDATE ::pm_topics
+            SET target=?s:name
+            WHERE target_id=?i:id';
+
+        $this->c->DB->exec($query, $vars);
+    }
+}

+ 1 - 0
app/Models/User/Save.php

@@ -156,6 +156,7 @@ class Save extends Action
         $this->c->topics->updateUsername($user);
         $this->c->forums->updateUsername($user);
         $this->c->Online->updateUsername($user);
+        $this->c->pms->updateUsername($user);
 
         // ???? и т.д.
     }