added list of deleted entities from flag list content

This commit is contained in:
Bachir Soussi Chiadmi 2015-09-27 19:50:44 +02:00
parent f0cb6175c1
commit 50c3e1c7d7
2 changed files with 56 additions and 7 deletions

View File

@ -115,7 +115,7 @@ function flag_lists_add_js($type = NULL) {
$query->fields('f')
->fields('fl')
->condition('fl.type', $type);
$row = $query->execute()
->fetchObject();
@ -176,7 +176,7 @@ function flag_lists_form($form, $form_state, $name = NULL, $type = NULL) {
$title_string_name = variable_get('flag_lists_name', 'list');
$title_string = t('Edit your "@title" @name title', array('@title' => $flag->get_title(), '@name' => $title_string_name));
drupal_set_title();
$form['edit'] = array(
'#type' => 'hidden',
'#value' => TRUE,
@ -248,7 +248,7 @@ function flag_lists_form_submit($form, $form_state, $account = NULL) {
$query->fields('f')
->fields('fl')
->condition('fl.type', $type);
$row = $query->execute()
->fetchObject();
@ -597,3 +597,44 @@ function flag_lists_generate_lists_form_submit($form, &$form_state) {
}
/**
* Clean lists from deleted enties
*/
function flag_list_clean_deleted(){
drupal_set_title(t('Flag lists Clean'));
$output = '<p>' . t('This page shows all the deleted entityties id from flag lists.') . '</p>';
$total = 0;
$list = "<ul>";
$query = db_select('flag_lists_content');
$query->fields('flag_lists_content', array('entity_id', 'entity_type'));
$query->distinct();
$items = $query->execute()->fetchAll();
if ($items) {
foreach ($items as $key => $value) {
$entity = entity_load($value->entity_type, array($value->entity_id), array(), true);
// dsm($entity);
// break;
if(!isset($entity[$value->entity_id])){
$list .= "<li>".$value->entity_type ." <em>". $value->entity_id."</em> have been deleted does not exists anymore.</li>";
$total++;
}
// db_delete('flag_lists_content')
// ->condition('entity_type', $value->entity_type)
// ->condition('entity_id', $value->entity_id)
// ->execute();
// watchdog('flag_lists', t('Deleted entry @fcid from flat_lists_content', array('@fcid' => $value->fcid)));
// }
}
}
$list .= "</ul>";
$output .= "<p><strong>".$total ."</strong> entities have been deleted.</p>";
$output .= $list;
return $output;
}

View File

@ -56,6 +56,16 @@ function flag_lists_menu() {
'type' => MENU_LOCAL_TASK,
'weight' => 3,
);
$items[FLAG_ADMIN_PATH . '/lists/clean'] = array(
'title' => 'Clean lists from deleted entities',
'page callback' => 'flag_list_clean_deleted',
'access callback' => 'user_access',
'access arguments' => array('administer flags'),
'file' => 'flag_lists.admin.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 4,
);
if (module_exists('devel_generate')) {
$items['admin/config/development/generate/flag-lists'] = array(
'title' => 'Generate lists',
@ -1278,7 +1288,7 @@ $flags['fl_template'] = array(
);
return $flags;
}
/**
@ -1590,7 +1600,7 @@ function flag_lists_fix_link(&$link, $action) {
->condition('entity_type', $type);
$query->fields('flag_lists_content', array('fcid', 'fid', 'uid', 'sid'));
$items = $query->execute()->fetchAll();
if ($items) {
foreach ($items as $key => $value) {
db_delete('flag_lists_content')
@ -1773,5 +1783,3 @@ function flag_lists_entity_delete($entity, $type) {
}
}
}