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

This commit is contained in:
Alexei Sorokin 2020-07-24 13:09:02 +03:00
parent 62f4dfdc7a
commit 33e9b57b78
2 changed files with 20 additions and 15 deletions

View File

@ -978,6 +978,13 @@ class Profile extends Managed_DataObject
$this->_deleteAttentions();
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,
// not on individual objects.
$related = [
@ -993,13 +1000,6 @@ class Profile extends Managed_DataObject
$inst->delete();
}
$this->grantRole(Profile_role::DELETED);
$localuser = User::getKV('id', $this->id);
if ($localuser instanceof User) {
$localuser->delete();
}
return parent::delete($useWhere);
}

View File

@ -747,13 +747,6 @@ class User_group extends Managed_DataObject
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
$related = array('Group_inbox',
@ -791,10 +784,22 @@ class User_group extends Managed_DataObject
$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
self::blow('user_group:notice_ids:%d', $this->id);
return parent::delete($useWhere);
return $result;
}
public function update($dataObject=false)