Try-catch on profile deletion unsubscribe actions

This commit is contained in:
Mikael Nordfeldth 2016-01-03 22:21:03 +01:00
parent 3bddf01350
commit f467b89f40

View File

@ -941,41 +941,48 @@ class Profile extends Managed_DataObject
function _deleteSubscriptions() function _deleteSubscriptions()
{ {
$sub = new Subscription(); $sub = new Subscription();
$sub->subscriber = $this->id; $sub->subscriber = $this->getID();
$sub->find(); $sub->find();
while ($sub->fetch()) { while ($sub->fetch()) {
$other = Profile::getKV('id', $sub->subscribed); try {
if (empty($other)) { $other = $sub->getSubscribed();
continue; if (!$other->sameAs($this)) {
}
if ($other->id == $this->id) {
continue;
}
Subscription::cancel($this, $other); Subscription::cancel($this, $other);
} }
} catch (NoResultException $e) {
$subd = new Subscription(); // Profile not found
$subd->subscribed = $this->id; common_log(LOG_INFO, 'Subscribed profile id=='.$sub->subscribed.' not found when deleting profile id=='.$this->getID().', ignoring...');
$subd->find(); } catch (ServerException $e) {
// Subscription cancel failed
while ($subd->fetch()) { common_log(LOG_INFO, 'Subscribed profile id=='.$other->getID().' could not be reached for unsubscription notice when deleting profile id=='.$this->getID().', ignoring...')
$other = Profile::getKV('id', $subd->subscriber);
if (empty($other)) {
continue;
} }
if ($other->id == $this->id) {
continue;
} }
$sub = new Subscription();
$sub->subscribed = $this->getID();
$sub->find();
while ($sub->fetch()) {
try {
$other = $sub->getSubscriber();
common_log(LOG_INFO, 'Subscriber profile id=='.$sub->subscribed.' not found when deleting profile id=='.$this->getID().', ignoring...');
if (!$other->sameAs($this)) {
Subscription::cancel($other, $this); Subscription::cancel($other, $this);
} }
} catch (NoResultException $e) {
// Profile not found
common_log(LOG_INFO, 'Subscribed profile id=='.$sub->subscribed.' not found when deleting profile id=='.$this->getID().', ignoring...');
} catch (ServerException $e) {
// Subscription cancel failed
common_log(LOG_INFO, 'Subscriber profile id=='.$other->getID().' could not be reached for unsubscription notice when deleting profile id=='.$this->getID().', ignoring...')
}
}
// Finally delete self-subscription
$self = new Subscription(); $self = new Subscription();
$self->subscriber = $this->getID();
$self->subscriber = $this->id; $self->subscribed = $this->getID();
$self->subscribed = $this->id;
$self->delete(); $self->delete();
} }