fix bug : deleted entities crash site when in usser flag_lists 2
This commit is contained in:
parent
7ab8742528
commit
9ad0aa199f
@ -130,7 +130,8 @@ function materio_duplicatemails(){
|
|||||||
|
|
||||||
function materio_missingflags(){
|
function materio_missingflags(){
|
||||||
$flags = db_query('SELECT fcid,fid,entity_type,entity_id,uid FROM {flag_lists_content}');
|
$flags = db_query('SELECT fcid,fid,entity_type,entity_id,uid FROM {flag_lists_content}');
|
||||||
|
|
||||||
|
$missingentities = 0;
|
||||||
foreach ($flags as $key => $value) {
|
foreach ($flags as $key => $value) {
|
||||||
// $entity = entity_load($value->entity_type, array($value->entity_id));
|
// $entity = entity_load($value->entity_type, array($value->entity_id));
|
||||||
$query = new EntityFieldQuery();
|
$query = new EntityFieldQuery();
|
||||||
@ -139,25 +140,28 @@ function materio_missingflags(){
|
|||||||
->propertyCondition('nid', $value->entity_id);
|
->propertyCondition('nid', $value->entity_id);
|
||||||
$entity = $query->execute();
|
$entity = $query->execute();
|
||||||
|
|
||||||
if(!isset($entity['node'])){
|
if(!isset($entity[$value->entity_type])){
|
||||||
$missingentities[$value->fid] = $value;
|
// $missingentities[$value->fid] = $value;
|
||||||
|
$missingentities++;
|
||||||
|
db_delete('flag_lists_content')
|
||||||
|
->condition('fcid', $value->fcid)
|
||||||
|
->execute();
|
||||||
|
watchdog('flag_lists', t('Deleted entry @fcid from flat_lists_content', array('@fcid' => $value->fcid)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bail out early if there are no duplicates.
|
// Bail out early if there are no duplicates.
|
||||||
if (!$missingentities) {
|
if (!$missingentities) {
|
||||||
return t('No missing entities in flags.');
|
return t('No missing entities in flags.');
|
||||||
}else{
|
|
||||||
dsm($missingentities);
|
|
||||||
}
|
}
|
||||||
|
// else{
|
||||||
|
// dsm($missingentities);
|
||||||
|
// }
|
||||||
|
|
||||||
// delete flags with missing entities
|
// delete flags with missing entities
|
||||||
foreach ($missingentities as $fid => $value) {
|
// foreach ($missingentities as $fid => $value) {
|
||||||
db_delete('flag_lists_content')
|
//
|
||||||
->condition('fcid', $value->fcid)
|
// }
|
||||||
->execute();
|
|
||||||
watchdog('flag_lists', t('Deleted entry @fcid from flat_lists_content', array('@fcid' => $value->fcid)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Turn the data we've got into markup.
|
// Turn the data we've got into markup.
|
||||||
$output = t('@count missing entities in flag lists have been cleaned', array('@count'=> count($missingentities)));
|
$output = t('@count missing entities in flag lists have been cleaned', array('@count'=> count($missingentities)));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user