From 987c841b48d2c60d0453684883c64b6ce90a2f91 Mon Sep 17 00:00:00 2001 From: Daniel Preussker Date: Sat, 21 Nov 2015 11:40:24 +0000 Subject: [PATCH] Automatically mark all news as read for new users Renamed Schema for old system --- html/includes/authentication/mysql.inc.php | 11 ++++++++++- .../{com.quxlabs.notifications/001.sql => 077.sql} | 0 2 files changed, 10 insertions(+), 1 deletion(-) rename sql-schema/{com.quxlabs.notifications/001.sql => 077.sql} (100%) diff --git a/html/includes/authentication/mysql.inc.php b/html/includes/authentication/mysql.inc.php index c16e716f8..5fdf20fb8 100644 --- a/html/includes/authentication/mysql.inc.php +++ b/html/includes/authentication/mysql.inc.php @@ -104,7 +104,16 @@ function adduser($username, $password, $level, $email='', $realname='', $can_mod if (!user_exists($username)) { $hasher = new PasswordHash(8, false); $encrypted = $hasher->HashPassword($password); - return dbInsert(array('username' => $username, 'password' => $encrypted, 'level' => $level, 'email' => $email, 'realname' => $realname, 'can_modify_passwd' => $can_modify_passwd, 'descr' => $description, 'twofactor' => $twofactor), 'users'); + $userid = dbInsert(array('username' => $username, 'password' => $encrypted, 'level' => $level, 'email' => $email, 'realname' => $realname, 'can_modify_passwd' => $can_modify_passwd, 'descr' => $description, 'twofactor' => $twofactor), 'users'); + if ($userid == false) { + return false; + } + else { + foreach (dbFetchRows('select notifications.* from notifications where not exists( select 1 from notifications_attribs where notifications.notifications_id = notifications_attribs.notifications_id and notifications_attribs.user_id = ?) order by notifications.notifications_id desc',array($userid)) as $notif) { + dbInsert(array('notifications_id'=>$notif['notification_id'],'user_id'=>$userid,'key'=>'read','value'=>1),'notifications_attribs'); + } + } + return $userid; } else { return false; diff --git a/sql-schema/com.quxlabs.notifications/001.sql b/sql-schema/077.sql similarity index 100% rename from sql-schema/com.quxlabs.notifications/001.sql rename to sql-schema/077.sql