[Jaws-commits] r13388 - trunk/jaws/html/include/Jaws

afz at jaws-project.com afz at jaws-project.com
Sat Aug 11 21:39:32 UTC 2012


Author: afz
Date: 2012-08-11 21:39:32 +0000 (Sat, 11 Aug 2012)
New Revision: 13388

Modified:
   trunk/jaws/html/include/Jaws/User.php
Log:
renamed avatar if username renamed

Modified: trunk/jaws/html/include/Jaws/User.php
===================================================================
--- trunk/jaws/html/include/Jaws/User.php	2012-08-11 21:39:27 UTC (rev 13387)
+++ trunk/jaws/html/include/Jaws/User.php	2012-08-11 21:39:32 UTC (rev 13388)
@@ -724,6 +724,12 @@
             }
         }
 
+        // get user information, we need it for rename avatar
+        $user = Jaws_User::GetUser((int)$id, true, true);
+        if (Jaws_Error::IsError($user) || empty($user)) {
+            return false;
+        }
+
         $params = array();
         $params['id']                = $id;
         $params['username']          = $username;
@@ -741,6 +747,15 @@
             $params['expiry_date'] = $GLOBALS['app']->UserTime2UTC($expiry_date);
         }
 
+        // set new avatar name if username changed
+        if (($username !== $user['username']) && !empty($user['avatar'])) {
+            $avtr_path = JAWS_DATA. 'avatar' . DIRECTORY_SEPARATOR;
+            $fileinfo = pathinfo($user['avatar']);
+            if (isset($fileinfo['extension']) && !empty($fileinfo['extension'])) {
+                $params['avatar'] = $username. '.'. $fileinfo['extension'];
+            }
+        }
+
         $sql = '
             UPDATE [[users]] SET
                 [username] = {username},
@@ -761,6 +776,9 @@
         if (!is_null($logon_hours)) {
             $sql .= ', [logon_hours] = {logon_hours} ';
         }
+        if (isset($params['avatar'])) {
+            $sql .= ', [avatar] = {avatar} ';
+        }
         if (!is_null($status)) {
             $sql .= ', [status] = {status} ';
         }
@@ -771,6 +789,13 @@
             return $result;
         }
 
+        // rename avatar name
+        if (isset($params['avatar'])) {
+            Jaws_Utils::Delete($avtr_path. $params['avatar']);
+            @rename($avtr_path. $user['avatar'],
+                    $avtr_path. $params['avatar']);
+        }
+
         if (isset($GLOBALS['app']->Session) && $GLOBALS['app']->Session->GetAttribute('user') == $id) {
             $GLOBALS['app']->Session->SetAttribute('nickname', $nickname);
             $GLOBALS['app']->Session->SetAttribute('email',    $email);



More information about the Jaws-commits mailing list