forked from GNUsocial/gnu-social
A better way to safely delete Foreign_links
This commit is contained in:
parent
6aac7cc6cd
commit
e3c4b0c85d
@ -113,4 +113,21 @@ class Foreign_link extends Memcached_DataObject
|
|||||||
return User::staticGet($this->user_id);
|
return User::staticGet($this->user_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make sure we only ever delete one record at a time
|
||||||
|
function safeDelete()
|
||||||
|
{
|
||||||
|
if (!empty($this->user_id)
|
||||||
|
&& !empty($this->foreign_id)
|
||||||
|
&& !empty($this->service))
|
||||||
|
{
|
||||||
|
return $this->delete();
|
||||||
|
} else {
|
||||||
|
common_debug(LOG_WARNING,
|
||||||
|
'Foreign_link::safeDelete() tried to delete a '
|
||||||
|
. 'Foreign_link without a fully specified compound key: '
|
||||||
|
. var_export($this, true));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -273,16 +273,7 @@ function remove_twitter_link($flink)
|
|||||||
common_log(LOG_INFO, 'Removing Twitter bridge Foreign link for ' .
|
common_log(LOG_INFO, 'Removing Twitter bridge Foreign link for ' .
|
||||||
"user $user->nickname (user id: $user->id).");
|
"user $user->nickname (user id: $user->id).");
|
||||||
|
|
||||||
$result = false;
|
$result = $flink->safeDelete();
|
||||||
|
|
||||||
// Be extra careful to make sure we have a good flink
|
|
||||||
// before deleting
|
|
||||||
if (!empty($flink->user_id)
|
|
||||||
&& !empty($flink->foreign_id)
|
|
||||||
&& !empty($flink->service))
|
|
||||||
{
|
|
||||||
$result = $flink->delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($result)) {
|
if (empty($result)) {
|
||||||
common_log(LOG_ERR, 'Could not remove Twitter bridge ' .
|
common_log(LOG_ERR, 'Could not remove Twitter bridge ' .
|
||||||
|
@ -278,7 +278,7 @@ class TwitterauthorizationAction extends Action
|
|||||||
$result = $flink->find(true);
|
$result = $flink->find(true);
|
||||||
|
|
||||||
if (!empty($result)) {
|
if (!empty($result)) {
|
||||||
$flink->delete();
|
$flink->safeDelete();
|
||||||
}
|
}
|
||||||
|
|
||||||
$flink->user_id = $user_id;
|
$flink->user_id = $user_id;
|
||||||
|
@ -250,16 +250,7 @@ class TwittersettingsAction extends ConnectSettingsAction
|
|||||||
$user = common_current_user();
|
$user = common_current_user();
|
||||||
$flink = Foreign_link::getByUserID($user->id, TWITTER_SERVICE);
|
$flink = Foreign_link::getByUserID($user->id, TWITTER_SERVICE);
|
||||||
|
|
||||||
$result = false;
|
$result = $flink->safeDelete();
|
||||||
|
|
||||||
// Be extra careful to make sure we have a good flink
|
|
||||||
// before deleting
|
|
||||||
if (!empty($flink->user_id)
|
|
||||||
&& !empty($flink->foreign_id)
|
|
||||||
&& !empty($flink->service))
|
|
||||||
{
|
|
||||||
$result = $flink->delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($result)) {
|
if (empty($result)) {
|
||||||
common_log_db_error($flink, 'DELETE', __FILE__);
|
common_log_db_error($flink, 'DELETE', __FILE__);
|
||||||
|
Loading…
Reference in New Issue
Block a user