[Profile][User_group] Fix profile deletion violating foreign keys

This commit is contained in:
Alexei Sorokin 2020-07-24 13:09:02 +03:00 committed by Diogo Peralta Cordeiro
parent a719684c6c
commit 2d3ec87ea4
2 changed files with 20 additions and 15 deletions

View File

@ -978,6 +978,13 @@ class Profile extends Managed_DataObject
$this->_deleteAttentions(); $this->_deleteAttentions();
Avatar::deleteFromProfile($this, true); Avatar::deleteFromProfile($this, true);
$this->grantRole(Profile_role::DELETED);
$localuser = User::getKV('id', $this->id);
if ($localuser instanceof User) {
$localuser->delete();
}
// Warning: delete() will run on the batch objects, // Warning: delete() will run on the batch objects,
// not on individual objects. // not on individual objects.
$related = [ $related = [
@ -993,13 +1000,6 @@ class Profile extends Managed_DataObject
$inst->delete(); $inst->delete();
} }
$this->grantRole(Profile_role::DELETED);
$localuser = User::getKV('id', $this->id);
if ($localuser instanceof User) {
$localuser->delete();
}
return parent::delete($useWhere); return parent::delete($useWhere);
} }

View File

@ -747,13 +747,6 @@ class User_group extends Managed_DataObject
return parent::delete($useWhere); return parent::delete($useWhere);
} }
try {
$profile = $this->getProfile();
$profile->delete();
} catch (GroupNoProfileException $unp) {
common_log(LOG_INFO, "Group {$this->nickname} has no profile; continuing deletion.");
}
// Safe to delete in bulk for now // Safe to delete in bulk for now
$related = array('Group_inbox', $related = array('Group_inbox',
@ -791,10 +784,22 @@ class User_group extends Managed_DataObject
$local->delete(); $local->delete();
} }
$result = parent::delete($useWhere);
try {
$profile = $this->getProfile();
$profile->delete();
} catch (GroupNoProfileException $unp) {
common_log(
LOG_INFO,
"Group {$this->nickname} has no profile; continuing deletion."
);
}
// blow the cached ids // blow the cached ids
self::blow('user_group:notice_ids:%d', $this->id); self::blow('user_group:notice_ids:%d', $this->id);
return parent::delete($useWhere); return $result;
} }
public function update($dataObject=false) public function update($dataObject=false)