diff --git a/plugins/OStatus/OStatusPlugin.php b/plugins/OStatus/OStatusPlugin.php index c0f9dadc4a..8444c3d73d 100644 --- a/plugins/OStatus/OStatusPlugin.php +++ b/plugins/OStatus/OStatusPlugin.php @@ -251,14 +251,14 @@ class OStatusPlugin extends Plugin */ function onEndUnsubscribe($user, $other) { - $feed = Feedinfo::staticGet('profile_id', $other->id); + $profile = Ostatus_profile::staticGet('profile_id', $other->id); if ($feed) { $sub = new Subscription(); $sub->subscribed = $other->id; $sub->limit(1); if (!$sub->find(true)) { common_log(LOG_INFO, "Unsubscribing from now-unused feed $feed->feeduri on hub $feed->huburi"); - $feed->unsubscribe(); + $profile->unsubscribe(); } } return true; @@ -269,7 +269,7 @@ class OStatusPlugin extends Plugin */ function onCheckSchema() { $schema = Schema::get(); - $schema->ensureTable('feedinfo', Feedinfo::schemaDef()); + $schema->ensureTable('ostatus_profile', Ostatus_profile::schemaDef()); $schema->ensureTable('hubsub', HubSub::schemaDef()); return true; } diff --git a/plugins/OStatus/actions/feedsubsettings.php b/plugins/OStatus/actions/feedsubsettings.php index 6f592bf5b0..af8bf4d25e 100644 --- a/plugins/OStatus/actions/feedsubsettings.php +++ b/plugins/OStatus/actions/feedsubsettings.php @@ -182,9 +182,9 @@ class FeedSubSettingsAction extends ConnectSettingsAction } $this->munger = $discover->feedMunger(); - $this->feedinfo = $this->munger->feedInfo(); + $this->profile = $this->munger->ostatusProfile(); - if ($this->feedinfo->huburi == '' && !common_config('feedsub', 'nohub')) { + if ($this->profile->huburi == '' && !common_config('feedsub', 'nohub')) { $this->showForm(_m('Feed is not PuSH-enabled; cannot subscribe.')); return false; } @@ -196,13 +196,13 @@ class FeedSubSettingsAction extends ConnectSettingsAction { if ($this->validateFeed()) { $this->preview = true; - $this->feedinfo = Feedinfo::ensureProfile($this->munger); + $this->profile = Ostatus_profile::ensureProfile($this->munger); // If not already in use, subscribe to updates via the hub - if ($this->feedinfo->sub_start) { - common_log(LOG_INFO, __METHOD__ . ": double the fun! new sub for {$this->feedinfo->feeduri} last subbed {$this->feedinfo->sub_start}"); + if ($this->profile->sub_start) { + common_log(LOG_INFO, __METHOD__ . ": double the fun! new sub for {$this->profile->feeduri} last subbed {$this->profile->sub_start}"); } else { - $ok = $this->feedinfo->subscribe(); + $ok = $this->profile->subscribe(); common_log(LOG_INFO, __METHOD__ . ": sub was $ok"); if (!$ok) { $this->showForm(_m('Feed subscription failed! Bad response from hub.')); @@ -212,15 +212,15 @@ class FeedSubSettingsAction extends ConnectSettingsAction // And subscribe the current user to the local profile $user = common_current_user(); - $profile = $this->feedinfo->getProfile(); + $profile = $this->profile->getLocalProfile(); if (!$profile) { throw new ServerException("Feed profile was not saved properly."); } - if ($this->feedinfo->isGroup()) { + if ($this->profile->isGroup()) { if ($user->isMember($profile)) { $this->showForm(_m('Already a member!')); - } elseif (Group_member::join($this->feedinfo->group_id, $user->id)) { + } elseif (Group_member::join($this->profile->group_id, $user->id)) { $this->showForm(_m('Joined remote group!')); } else { $this->showForm(_m('Remote group join failed!')); @@ -247,7 +247,7 @@ class FeedSubSettingsAction extends ConnectSettingsAction function previewFeed() { - $feedinfo = $this->munger->feedinfo(); + $profile = $this->munger->ostatusProfile(); $notice = $this->munger->notice(0, true); // preview if ($notice) { diff --git a/plugins/OStatus/actions/ostatussub.php b/plugins/OStatus/actions/ostatussub.php index ffc4ae8dfe..9774286fdd 100644 --- a/plugins/OStatus/actions/ostatussub.php +++ b/plugins/OStatus/actions/ostatussub.php @@ -164,9 +164,9 @@ class OStatusSubAction extends Action } $this->munger = $discover->feedMunger(); - $this->feedinfo = $this->munger->feedInfo(); + $this->profile = $this->munger->ostatusProfile(); - if ($this->feedinfo->huburi == '') { + if ($this->profile->huburi == '') { $this->showForm(_m('Feed is not PuSH-enabled; cannot subscribe.')); return false; } @@ -178,13 +178,13 @@ class OStatusSubAction extends Action { if ($this->validateFeed()) { $this->preview = true; - $this->feedinfo = Feedinfo::ensureProfile($this->munger); + $this->profile = Ostatus_profile::ensureProfile($this->munger); // If not already in use, subscribe to updates via the hub - if ($this->feedinfo->sub_start) { - common_log(LOG_INFO, __METHOD__ . ": double the fun! new sub for {$this->feedinfo->feeduri} last subbed {$this->feedinfo->sub_start}"); + if ($this->profile->sub_start) { + common_log(LOG_INFO, __METHOD__ . ": double the fun! new sub for {$this->profile->feeduri} last subbed {$this->profile->sub_start}"); } else { - $ok = $this->feedinfo->subscribe(); + $ok = $this->profile->subscribe(); common_log(LOG_INFO, __METHOD__ . ": sub was $ok"); if (!$ok) { $this->showForm(_m('Feed subscription failed! Bad response from hub.')); @@ -194,7 +194,7 @@ class OStatusSubAction extends Action // And subscribe the current user to the local profile $user = common_current_user(); - $profile = $this->feedinfo->getProfile(); + $profile = $this->profile->getProfile(); if ($user->isSubscribed($profile)) { $this->showForm(_m('Already subscribed!')); @@ -209,7 +209,7 @@ class OStatusSubAction extends Action function previewFeed() { - $feedinfo = $this->munger->feedinfo(); + $profile = $this->munger->ostatusProfile(); $notice = $this->munger->notice(0, true); // preview if ($notice) { diff --git a/plugins/OStatus/actions/pushcallback.php b/plugins/OStatus/actions/pushcallback.php index 471d079ab9..a446593ff9 100644 --- a/plugins/OStatus/actions/pushcallback.php +++ b/plugins/OStatus/actions/pushcallback.php @@ -48,9 +48,9 @@ class PushCallbackAction extends Action throw new ServerException('Empty or invalid feed id', 400); } - $feedinfo = Feedinfo::staticGet('id', $feedid); - if (!$feedinfo) { - throw new ServerException('Unknown feed id ' . $feedid, 400); + $profile = Ostatus_profile::staticGet('id', $feedid); + if (!$profile) { + throw new ServerException('Unknown OStatus/PuSH feed id ' . $feedid, 400); } $hmac = ''; @@ -59,7 +59,7 @@ class PushCallbackAction extends Action } $post = file_get_contents('php://input'); - $feedinfo->postUpdates($post, $hmac); + $profile->postUpdates($post, $hmac); } /** @@ -78,8 +78,8 @@ class PushCallbackAction extends Action throw new ServerException("Bogus hub callback: bad mode", 404); } - $feedinfo = Feedinfo::staticGet('feeduri', $topic); - if (!$feedinfo) { + $profile = Ostatus_profile::staticGet('feeduri', $topic); + if (!$profile) { common_log(LOG_WARNING, __METHOD__ . ": bogus hub callback for unknown feed $topic"); throw new ServerException("Bogus hub callback: unknown feed", 404); } @@ -93,16 +93,16 @@ class PushCallbackAction extends Action // OK! if ($mode == 'subscribe') { common_log(LOG_INFO, __METHOD__ . ': sub confirmed'); - $feedinfo->sub_start = common_sql_date(time()); + $profile->sub_start = common_sql_date(time()); if ($lease_seconds > 0) { - $feedinfo->sub_end = common_sql_date(time() + $lease_seconds); + $profile->sub_end = common_sql_date(time() + $lease_seconds); } else { - $feedinfo->sub_end = null; + $profile->sub_end = null; } - $feedinfo->update(); + $profile->update(); } else { common_log(LOG_INFO, __METHOD__ . ": unsub confirmed; deleting sub record for $topic"); - $feedinfo->delete(); + $profile->delete(); } print $challenge; diff --git a/plugins/OStatus/classes/Feedinfo.php b/plugins/OStatus/classes/Ostatus_profile.php similarity index 92% rename from plugins/OStatus/classes/Feedinfo.php rename to plugins/OStatus/classes/Ostatus_profile.php index 5b8a9039a6..748ecce18f 100644 --- a/plugins/OStatus/classes/Feedinfo.php +++ b/plugins/OStatus/classes/Ostatus_profile.php @@ -25,17 +25,17 @@ /* PuSH subscription flow: - $feedinfo->subscribe() + $profile->subscribe() generate random verification token save to verify_token sends a sub request to the hub... - feedsub/callback + main/push/callback hub sends confirmation back to us via GET We verify the request, then echo back the challenge. On our end, we save the time we subscribed and the lease expiration - feedsub/callback + main/push/callback hub sends us updates via POST */ @@ -51,23 +51,27 @@ class FeedDBException extends FeedSubException } } -class Feedinfo extends Memcached_DataObject +class Ostatus_profile extends Memcached_DataObject { - public $__table = 'feedinfo'; + public $__table = 'ostatus_profile'; public $id; public $profile_id; + public $group_id; public $feeduri; public $homeuri; - public $huburi; // PuSH subscription data + public $huburi; public $secret; public $verify_token; + public $sub_state; // subscribe, active, unsubscribe public $sub_start; public $sub_end; + public $salmonuri; + public $created; public $lastupdate; @@ -96,6 +100,7 @@ class Feedinfo extends Memcached_DataObject 'huburi' => DB_DATAOBJECT_STR, 'secret' => DB_DATAOBJECT_STR, 'verify_token' => DB_DATAOBJECT_STR, + 'sub_state' => DB_DATAOBJECT_STR, 'sub_start' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME, 'sub_end' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME, 'salmonuri' => DB_DATAOBJECT_STR, @@ -126,6 +131,8 @@ class Feedinfo extends Memcached_DataObject 32, true), new ColumnDef('secret', 'varchar', 64, true), + new ColumnDef('sub_state', "enum('subscribe','active','unsubscribe')", + null, true), new ColumnDef('sub_start', 'datetime', null, true), new ColumnDef('sub_end', 'datetime', @@ -175,7 +182,7 @@ class Feedinfo extends Memcached_DataObject * Fetch the StatusNet-side profile for this feed * @return Profile */ - public function getProfile() + public function getLocalProfile() { return Profile::staticGet('id', $this->profile_id); } @@ -183,23 +190,23 @@ class Feedinfo extends Memcached_DataObject /** * @param FeedMunger $munger * @param boolean $isGroup is this a group record? - * @return Feedinfo + * @return Ostatus_profile */ public static function ensureProfile($munger) { - $feedinfo = $munger->feedinfo(); + $entity = $munger->ostatusProfile(); - $current = self::staticGet('feeduri', $feedinfo->feeduri); + $current = self::staticGet('feeduri', $entity->feeduri); if ($current) { // @fixme we should probably update info as necessary return $current; } - $feedinfo->query('BEGIN'); + $entity->query('BEGIN'); // Awful hack! Awful hack! - $feedinfo->verify = common_good_rand(16); - $feedinfo->secret = common_good_rand(32); + $entity->verify = common_good_rand(16); + $entity->secret = common_good_rand(32); try { $profile = $munger->profile(); @@ -223,8 +230,8 @@ class Feedinfo extends Memcached_DataObject $profile->setOriginal($filename); } - $feedinfo->profile_id = $profile->id; - if ($feedinfo->isGroup()) { + $entity->profile_id = $profile->id; + if ($entity->isGroup()) { $group = new User_group(); $group->nickname = $profile->nickname . '@remote'; // @fixme $group->fullname = $profile->fullname; @@ -237,21 +244,21 @@ class Feedinfo extends Memcached_DataObject $group->setOriginal($filename); } - $feedinfo->group_id = $group->id; + $entity->group_id = $group->id; } - $result = $feedinfo->insert(); + $result = $entity->insert(); if (empty($result)) { - throw new FeedDBException($feedinfo); + throw new FeedDBException($entity); } - $feedinfo->query('COMMIT'); + $entity->query('COMMIT'); } catch (FeedDBException $e) { common_log_db_error($e->obj, 'INSERT', __FILE__); - $feedinfo->query('ROLLBACK'); + $entity->query('ROLLBACK'); return false; } - return $feedinfo; + return $entity; } /** diff --git a/plugins/OStatus/lib/feedmunger.php b/plugins/OStatus/lib/feedmunger.php index 927a2fe7a7..c895b6ce24 100644 --- a/plugins/OStatus/lib/feedmunger.php +++ b/plugins/OStatus/lib/feedmunger.php @@ -83,17 +83,17 @@ class FeedMunger $this->url = $url; } - function feedinfo() + function ostatusProfile() { - $feedinfo = new Feedinfo(); - $feedinfo->feeduri = $this->url; - $feedinfo->homeuri = $this->feed->link; - $feedinfo->huburi = $this->getHubLink(); + $profile = new Ostatus_profile(); + $profile->feeduri = $this->url; + $profile->homeuri = $this->feed->link; + $profile->huburi = $this->getHubLink(); $salmon = $this->getSalmonLink(); if ($salmon) { - $feedinfo->salmonuri = $salmon; + $profile->salmonuri = $salmon; } - return $feedinfo; + return $profile; } function getAtomLink($item, $attribs=array()) @@ -258,9 +258,7 @@ class FeedMunger { // hack hack hack // should get profile for this entry's author... - $feed = new Feedinfo(); - $feed->feeduri = $self; - $feed = Feedinfo::staticGet('feeduri', $this->getSelfLink()); + $remote = Ostatus_profile::staticGet('feeduri', $this->getSelfLink()); if ($feed) { return $feed->profile_id; } else {