]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
add a method to update key fields in User
authorEvan Prodromou <evan@controlezvous.ca>
Sun, 22 Jun 2008 14:56:44 +0000 (10:56 -0400)
committerEvan Prodromou <evan@controlezvous.ca>
Sun, 22 Jun 2008 14:56:44 +0000 (10:56 -0400)
darcs-hash:20080622145644-34904-92549d9bb68251214c4dc370f6e2a56f516ceecb.gz

classes/User.php

index d750c7847296091f6e93e2cf626041bdf77587e7..e8281a72318a3222f6efaf1e35ee09dc1faaf3d8 100644 (file)
@@ -61,4 +61,23 @@ class User extends DB_DataObject
                $sub->subscribed = $other->id;
                return $sub->find();
        }
+
+       # 'update' won't write key columns, so we have to do it ourselves.
+       
+       function updateKeys(&$orig) {
+               $parts = array();
+               foreach (array('nickname', 'email') as $k) {
+                       if ($this->$k != $orig->$k) {
+                               $parts[] = $k . '="' . $this->$k . '"';
+                       }
+               }
+               if (count($parts) == 0) {
+                       # No changes
+                       return;
+               }
+               $toupdate = implode(', ', $parts);
+               $qry = 'UPDATE ' . $this->tableName() . ' SET ' . $toupdate . 
+                 ' WHERE id = ' . $this->id;
+               return $this->query($qry);
+       }
 }