]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/User.php
Merge branch 'master' into testing
[quix0rs-gnu-social.git] / classes / User.php
index 16c256535b7ffe22efd01ecec492cbc0316f6378..2c256301c2f2d94a1cc36f4b079e9dd71b4352fc 100644 (file)
@@ -153,19 +153,12 @@ class User extends Memcached_DataObject
         return Sms_carrier::staticGet('id', $this->carrier);
     }
 
+    /**
+     * @deprecated use Subscription::start($sub, $other);
+     */
     function subscribeTo($other)
     {
-        $sub = new Subscription();
-        $sub->subscriber = $this->id;
-        $sub->subscribed = $other->id;
-
-        $sub->created = common_sql_now(); // current time
-
-        if (!$sub->insert()) {
-            return false;
-        }
-
-        return true;
+        return Subscription::start($this->getProfile(), $other);
     }
 
     function hasBlocked($other)
@@ -346,17 +339,7 @@ class User extends Memcached_DataObject
                     common_log(LOG_WARNING, sprintf("Default user %s does not exist.", $defnick),
                                __FILE__);
                 } else {
-                    $defsub = new Subscription();
-                    $defsub->subscriber = $user->id;
-                    $defsub->subscribed = $defuser->id;
-                    $defsub->created = $user->created;
-
-                    $result = $defsub->insert();
-
-                    if (!$result) {
-                        common_log_db_error($defsub, 'INSERT', __FILE__);
-                        return false;
-                    }
+                    Subscription::start($user, $defuser);
                 }
             }
 
@@ -542,8 +525,8 @@ class User extends Memcached_DataObject
             common_log(LOG_WARNING,
                 sprintf(
                     "Profile ID %d (%s) tried to block his or herself.",
-                    $profile->id,
-                    $profile->nickname
+                    $this->id,
+                    $this->nickname
                 )
             );
             return false;
@@ -565,13 +548,7 @@ class User extends Memcached_DataObject
             return false;
         }
 
-        // Cancel their subscription, if it exists
-
-        $otherUser = User::staticGet('id', $other->id);
-
-        if (!empty($otherUser)) {
-            subs_unsubscribe_to($otherUser, $this->getProfile());
-        }
+        Subscription::cancel($other, $this->getProfile());
 
         $block->query('COMMIT');
 
@@ -687,8 +664,12 @@ class User extends Memcached_DataObject
 
     function delete()
     {
-        $profile = $this->getProfile();
-        $profile->delete();
+        try {
+            $profile = $this->getProfile();
+            $profile->delete();
+        } catch (UserNoProfileException $unp) {
+            common_log(LOG_INFO, "User {$this->nickname} has no profile; continuing deletion.");
+        }
 
         $related = array('Fave',
                          'Confirm_address',
@@ -696,6 +677,7 @@ class User extends Memcached_DataObject
                          'Foreign_link',
                          'Invitation',
                          );
+
         Event::handle('UserDeleteRelated', array($this, &$related));
 
         foreach ($related as $cls) {