public $__table = 'feedsub';
public $id;
- public $uri;
+ public $uri; // varchar(191) not 255 because utf8mb4 takes more space
// PuSH subscription data
public $huburi;
return array(
'fields' => array(
'id' => array('type' => 'serial', 'not null' => true, 'description' => 'FeedSub local unique id'),
- 'uri' => array('type' => 'varchar', 'not null' => true, 'length' => 255, 'description' => 'FeedSub uri'),
+ 'uri' => array('type' => 'varchar', 'not null' => true, 'length' => 191, 'description' => 'FeedSub uri'),
'huburi' => array('type' => 'text', 'description' => 'FeedSub hub-uri'),
'secret' => array('type' => 'text', 'description' => 'FeedSub stored secret'),
'sub_state' => array('type' => 'enum("subscribe","active","unsubscribe","inactive","nohub")', 'not null' => true, 'description' => 'subscription state'),
'sub_start' => array('type' => 'datetime', 'description' => 'subscription start'),
'sub_end' => array('type' => 'datetime', 'description' => 'subscription end'),
- 'last_update' => array('type' => 'datetime', 'not null' => true, 'description' => 'when this record was last updated'),
+ 'last_update' => array('type' => 'datetime', 'description' => 'when this record was last updated'),
'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
),
public function getUri()
{
if (empty($this->uri)) {
- throw new ServerException('No URI for FeedSub entry');
+ throw new NoUriException($this);
}
return $this->uri;
}
$discover->discoverFromFeedURL($feeduri);
$huburi = $discover->getHubLink();
- if (!$huburi && !common_config('feedsub', 'fallback_hub')) {
+ if (!$huburi && !common_config('feedsub', 'fallback_hub') && !common_config('feedsub', 'nohub')) {
throw new FeedSubNoHubException();
}
// No native hub on this feed?
// Use our fallback hub, which handles polling on our behalf.
} else if (common_config('feedsub', 'nohub')) {
- // Fake it! We're just testing remote feeds w/o hubs.
- // We'll never actually get updates in this mode.
+ // For this to actually work, we'll need some polling mechanism.
+ // The FeedPoller plugin should take care of it.
return;
} else {
// TRANS: Server exception.
// No native hub on this feed?
// Use our fallback hub, which handles polling on our behalf.
} else if (common_config('feedsub', 'nohub')) {
- // Fake it! We're just testing remote feeds w/o hubs.
- // We'll never actually get updates in this mode.
+ // We need a feedpolling plugin (like FeedPoller) active so it will
+ // set the 'nohub' state to 'inactive' for us.
return;
} else {
// TRANS: Server exception.
* make sure it's inactive, unsubscribing if necessary.
*
* @return boolean true if the subscription is now inactive, false if still active.
+ * @throws NoProfileException in FeedSubSubscriberCount for missing Profile entries
* @throws Exception if something goes wrong in unsubscribe() method
*/
public function garbageCollect()
if ($this->sub_state == '' || $this->sub_state == 'inactive') {
// No active PuSH subscription, we can just leave it be.
return true;
- } else {
- // PuSH subscription is either active or in an indeterminate state.
- // Check if we're out of subscribers, and if so send an unsubscribe.
- $count = 0;
- Event::handle('FeedSubSubscriberCount', array($this, &$count));
-
- if ($count > 0) {
- common_log(LOG_INFO, __METHOD__ . ': ok, ' . $count . ' user(s) left for ' . $this->getUri());
- return false;
- } else {
- common_log(LOG_INFO, __METHOD__ . ': unsubscribing, no users left for ' . $this->getUri());
- // Unsubscribe throws various Exceptions on failure
- $this->unsubscribe();
- return true;
- }
}
+
+ // PuSH subscription is either active or in an indeterminate state.
+ // Check if we're out of subscribers, and if so send an unsubscribe.
+ $count = 0;
+ Event::handle('FeedSubSubscriberCount', array($this, &$count));
+
+ if ($count > 0) {
+ common_log(LOG_INFO, __METHOD__ . ': ok, ' . $count . ' user(s) left for ' . $this->getUri());
+ return false;
+ }
+
+ common_log(LOG_INFO, __METHOD__ . ': unsubscribing, no users left for ' . $this->getUri());
+ // Unsubscribe throws various Exceptions on failure
+ $this->unsubscribe();
+
+ return true;
}
static public function renewalCheck()
{
common_log(LOG_INFO, __METHOD__ . ": packet for \"" . $this->getUri() . "\"! $hmac $post");
- if ($this->sub_state != 'active') {
+ if (!in_array($this->sub_state, array('active', 'nohub'))) {
common_log(LOG_ERR, __METHOD__ . ": ignoring PuSH for inactive feed " . $this->getUri() . " (in state '$this->sub_state')");
return;
}
}
return false;
}
+
+ public function delete($useWhere=false)
+ {
+ try {
+ $oprofile = Ostatus_profile::getKV('feeduri', $this->getUri());
+ if ($oprofile instanceof Ostatus_profile) {
+ // Check if there's a profile. If not, handle the NoProfileException below
+ $profile = $oprofile->localProfile();
+ }
+ } catch (NoProfileException $e) {
+ // If the Ostatus_profile has no local Profile bound to it, let's clean it out at the same time
+ $oprofile->delete();
+ } catch (NoUriException $e) {
+ // FeedSub->getUri() can throw a NoUriException, let's just go ahead and delete it
+ }
+ return parent::delete($useWhere);
+ }
}