Fix for broken profile flag admin UI: delete stray flag entries when users are deleted so broken entries don't litter the lookups.
* added ProfileDeleteRelated event to match UserDeleteRelated, to allow plugins to add extra related tables on profile deletion * UserFlagPlugin: deleting flags when target profile is deleted * UserFlagPlugin: deleting flags when flagging user is deleted * UserFlagPlugin: fix for autoloader -- class names are case-insensitive. We may get lowercase class names coming in at times, such as when creating DB objects programatically from a table name. Note that any already-existing bogus entries need to be removed from the database: select * from user_flag_profile where (select id from profile where id=profile_id) is null; select * from user_flag_profile where (select id from user where id=user_id) is null;
This commit is contained in:
parent
fe18100281
commit
b93244395f
@ -504,6 +504,7 @@ class Profile extends Memcached_DataObject
|
|||||||
'Reply',
|
'Reply',
|
||||||
'Group_member',
|
'Group_member',
|
||||||
);
|
);
|
||||||
|
Event::handle('ProfileDeleteRelated', array($this, &$related));
|
||||||
|
|
||||||
foreach ($related as $cls) {
|
foreach ($related as $cls) {
|
||||||
$inst = new $cls();
|
$inst = new $cls();
|
||||||
|
@ -102,20 +102,20 @@ class UserFlagPlugin extends Plugin
|
|||||||
|
|
||||||
function onAutoload($cls)
|
function onAutoload($cls)
|
||||||
{
|
{
|
||||||
switch ($cls)
|
switch (strtolower($cls))
|
||||||
{
|
{
|
||||||
case 'FlagprofileAction':
|
case 'flagprofileaction':
|
||||||
case 'AdminprofileflagAction':
|
case 'adminprofileflagaction':
|
||||||
case 'ClearflagAction':
|
case 'clearflagaction':
|
||||||
include_once INSTALLDIR.'/plugins/UserFlag/' .
|
include_once INSTALLDIR.'/plugins/UserFlag/' .
|
||||||
strtolower(mb_substr($cls, 0, -6)) . '.php';
|
strtolower(mb_substr($cls, 0, -6)) . '.php';
|
||||||
return false;
|
return false;
|
||||||
case 'FlagProfileForm':
|
case 'flagprofileform':
|
||||||
case 'ClearFlagForm':
|
case 'clearflagform':
|
||||||
include_once INSTALLDIR.'/plugins/UserFlag/' . strtolower($cls . '.php');
|
include_once INSTALLDIR.'/plugins/UserFlag/' . strtolower($cls . '.php');
|
||||||
return false;
|
return false;
|
||||||
case 'User_flag_profile':
|
case 'user_flag_profile':
|
||||||
include_once INSTALLDIR.'/plugins/UserFlag/'.$cls.'.php';
|
include_once INSTALLDIR.'/plugins/UserFlag/'.ucfirst(strtolower($cls)).'.php';
|
||||||
return false;
|
return false;
|
||||||
default:
|
default:
|
||||||
return true;
|
return true;
|
||||||
@ -258,4 +258,39 @@ class UserFlagPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure that flag entries for a profile are deleted
|
||||||
|
* along with the profile when deleting users.
|
||||||
|
* This prevents breakage of the admin profile flag UI.
|
||||||
|
*
|
||||||
|
* @param Profile $profile
|
||||||
|
* @param array &$related list of related tables; entries
|
||||||
|
* with matching profile_id will be deleted.
|
||||||
|
*
|
||||||
|
* @return boolean hook result
|
||||||
|
*/
|
||||||
|
|
||||||
|
function onProfileDeleteRelated($profile, &$related)
|
||||||
|
{
|
||||||
|
$related[] = 'user_flag_profile';
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure that flag entries created by a user are deleted
|
||||||
|
* when that user gets deleted.
|
||||||
|
*
|
||||||
|
* @param User $user
|
||||||
|
* @param array &$related list of related tables; entries
|
||||||
|
* with matching user_id will be deleted.
|
||||||
|
*
|
||||||
|
* @return boolean hook result
|
||||||
|
*/
|
||||||
|
|
||||||
|
function onUserDeleteRelated($user, &$related)
|
||||||
|
{
|
||||||
|
$related[] = 'user_flag_profile';
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user