fix bug : deleted entities crash site when in usser flag_lists
This commit is contained in:
@@ -18,6 +18,10 @@ function materio_admin_permission() {
|
||||
'title' => t('access duplicate mails list'),
|
||||
'description' => t('access duplicate mails list.'),
|
||||
),
|
||||
'access missing flags list' => array(
|
||||
'title' => t('access missing flags list'),
|
||||
'description' => t('access missing flags list.'),
|
||||
),
|
||||
'materio admin fix term reference field' => array(
|
||||
'title' => t('Materio admin fix term reference field'),
|
||||
'description' => t('Materio admin fix term reference field.'),
|
||||
@@ -55,6 +59,15 @@ function materio_admin_menu() {
|
||||
}
|
||||
}
|
||||
|
||||
if(module_exists('flag') && module_exists('flag_lists')){
|
||||
$items['admin/people/missingflags'] = array(
|
||||
'title' => "Missing Flags",
|
||||
'page callback' => 'materio_missingflags',
|
||||
'access callback' => 'user_access',
|
||||
'access arguments' => array('access missing flags list'),
|
||||
'type' => MENU_LOCAL_TASK
|
||||
);
|
||||
}
|
||||
|
||||
// fix term ref field lost with taxonomy
|
||||
$items['admin/config/content/materio'] = array(
|
||||
@@ -114,6 +127,43 @@ function materio_duplicatemails(){
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
function materio_missingflags(){
|
||||
$flags = db_query('SELECT fcid,fid,entity_type,entity_id,uid FROM {flag_lists_content}');
|
||||
|
||||
foreach ($flags as $key => $value) {
|
||||
// $entity = entity_load($value->entity_type, array($value->entity_id));
|
||||
$query = new EntityFieldQuery();
|
||||
$query
|
||||
->entityCondition('entity_type', $value->entity_type)
|
||||
->propertyCondition('nid', $value->entity_id);
|
||||
$entity = $query->execute();
|
||||
|
||||
if(!isset($entity['node'])){
|
||||
$missingentities[$value->fid] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
// Bail out early if there are no duplicates.
|
||||
if (!$missingentities) {
|
||||
return t('No missing entities in flags.');
|
||||
}else{
|
||||
dsm($missingentities);
|
||||
}
|
||||
|
||||
// delete flags with missing entities
|
||||
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.
|
||||
$output = t('@count missing entities in flag lists have been cleaned', array('@count'=> count($missingentities)));
|
||||
return $output;
|
||||
}
|
||||
|
||||
function materio_admin_fix_termref_fields_form(){
|
||||
drupal_set_title('Fix term reference fields', PASS_THROUGH);
|
||||
|
||||
|
Reference in New Issue
Block a user