- Issue created by @scott_earnest
- Merge request !83Issue #3517235: View filters on rh_action with null values in database β (Open) created by scott_earnest
- πΊπΈUnited States scott_earnest
This may be helpful to someone - we wrote an update hook to batch update records that had null values:
/** * Rabbit Hole update to default for NULL values for nodes. */ function MY_MODULE_update_10001(&$sandbox) { // Set array of node ids to update in sandbox. if (!isset($sandbox['ids'])) { $ids = \Drupal::entityQuery('node') ->accessCheck(FALSE) ->condition('rh_action', NULL, 'IS NULL') ->sort('nid') ->execute(); $sandbox['ids'] = $ids; $sandbox['current'] = 0; if (empty($sandbox['ids'])) { $sandbox['#finished'] = 1; return; } } // Set batch size. $items_per_batch = 100; // Grab the working set based off of current position and range. $ids = array_slice($sandbox['ids'], $sandbox['current'], $items_per_batch); // Exit out if nothing to do. if (empty($ids)) { $sandbox['#finished'] = 1; return; } // Loop over node ids. foreach ($ids as $id) { $node = \Drupal::entityTypeManager()->getStorage('node')->load($id); // Set default values for NULL fields. $node->set('rh_action', 'bundle_default') ->set('rh_redirect_response', 301) ->set('rh_redirect_fallback_action', 'bundle_default'); $node->save(); $sandbox['current']++; } // Set the return message - either in progress or finished. if ($sandbox['current'] >= count($sandbox['ids'])) { $sandbox['#finished'] = 1; $message = 'Batch update for missing Rabbit Hole values completed'; $args = []; } else { $sandbox['#finished'] = ($sandbox['current'] / count($sandbox['ids'])); $message = 'Progress: @count / @total'; $args = [ '@count' => $sandbox['current'], '@total' => count($sandbox['ids']), ]; } // Return with message - will show progress of batch. return new \Drupal\Core\StringTranslation\TranslatableMarkup($message, $args); }
- πΊπΈUnited States scott_earnest
Sorry I don't currently have a site with Rabbit Hole v2 on it atm. Ticket will need work for that branch and testing. thanks!