Procházet zdrojové kódy

fix bug : deleted entities crash site when in usser flag_lists 2

Bachir Soussi Chiadmi před 6 roky
rodič
revize
9ad0aa199f

+ 15 - 11
sites/all/modules/gui/materiobasemod/materio_admin.module

@@ -130,7 +130,8 @@ function materio_duplicatemails(){
 
 function materio_missingflags(){
   $flags = db_query('SELECT fcid,fid,entity_type,entity_id,uid FROM {flag_lists_content}');
-  
+
+  $missingentities = 0;
   foreach ($flags as $key => $value) {
     // $entity = entity_load($value->entity_type, array($value->entity_id));
     $query = new EntityFieldQuery();
@@ -139,25 +140,28 @@ function materio_missingflags(){
       ->propertyCondition('nid', $value->entity_id);
     $entity = $query->execute();
 
-    if(!isset($entity['node'])){
-      $missingentities[$value->fid] = $value;
+    if(!isset($entity[$value->entity_type])){
+      // $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.
   if (!$missingentities) {
     return t('No missing entities in flags.');
-  }else{
-    dsm($missingentities);
   }
+  // 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)));
-  }
+  // foreach ($missingentities as $fid => $value) {
+  //
+  // }
 
   // Turn the data we've got into markup.
   $output = t('@count missing entities in flag lists have been cleaned', array('@count'=> count($missingentities)));