|
@@ -12,18 +12,12 @@ function tripal_update_all_urls_and_titles($bundle_id, $update, $type) {
|
|
|
$entity_table = 'chado_'.$bundle_id;
|
|
|
$entities = db_select($entity_table, 'e')
|
|
|
->fields('e', array('entity_id'))
|
|
|
- ->execute()->fetchAll();
|
|
|
- $num_entities = count($entities);
|
|
|
+ ->orderBy('entity_id', 'ASC')
|
|
|
+ ->execute();
|
|
|
+ $num_entities = $entities->rowCount();
|
|
|
// Parse the $update variable for tokens and load those tokens.
|
|
|
preg_match_all("/\[[^\]]*\]/", $update, $bundle_tokens);
|
|
|
- // Get the queue so we can add to it. Use a
|
|
|
- // descriptive name. It's ok if it doesn't exist yet.
|
|
|
- $queue = DrupalQueue::get('entityQueue');
|
|
|
- // Push all the items into the queue, one at a time.
|
|
|
- // You can push any data in with (arrays, objects, etc).
|
|
|
- foreach ($entities as $entity) {
|
|
|
- $queue->createItem($entity);
|
|
|
- }
|
|
|
+
|
|
|
$fields = array();
|
|
|
foreach ($bundle_tokens as $bundle_token) {
|
|
|
foreach ($bundle_token as $token) {
|
|
@@ -32,10 +26,11 @@ function tripal_update_all_urls_and_titles($bundle_id, $update, $type) {
|
|
|
$fields[] = $field_array['id'];
|
|
|
}
|
|
|
}
|
|
|
- $i = 0;
|
|
|
+
|
|
|
+ $i = 1;
|
|
|
// Pull items out one at a time.
|
|
|
- while ($entity = $queue->claimItem()) {
|
|
|
- $arg = tripal_load_entity('TripalEntity', [$entity->data->entity_id], FALSE, $fields);
|
|
|
+ while ($entity = $entities->fetchObject()) {
|
|
|
+ $arg = tripal_load_entity('TripalEntity', [$entity->entity_id], FALSE, $fields);
|
|
|
if ($type == 'alias') {
|
|
|
if (!empty($arg)) {
|
|
|
if (is_array($arg)) {
|
|
@@ -44,6 +39,7 @@ function tripal_update_all_urls_and_titles($bundle_id, $update, $type) {
|
|
|
// Get the entity controller and clear the cache if requested (default).
|
|
|
$ec = entity_get_controller('TripalEntity');
|
|
|
$ec->setAlias($ent, $update);
|
|
|
+ $ec->resetCache();
|
|
|
}
|
|
|
}
|
|
|
elseif ($type == 'title') {
|
|
@@ -54,14 +50,16 @@ function tripal_update_all_urls_and_titles($bundle_id, $update, $type) {
|
|
|
|
|
|
$ec = entity_get_controller('TripalEntity');
|
|
|
$ec->setTitle($ent, $update);
|
|
|
+ $ec->resetCache();
|
|
|
}
|
|
|
}
|
|
|
- $i++;
|
|
|
// Check if 50 items have been updated, if so print message.
|
|
|
- if ($i < $num_entities) {
|
|
|
- print $i . "/" . $num_entities . " entities have been updated.\r";
|
|
|
+ if ($i <= $num_entities) {
|
|
|
+ $mem = number_format(memory_get_usage());
|
|
|
+ print $i . "/" . $num_entities . " entities have been updated. Memory usage: $mem bytes.\r";
|
|
|
}
|
|
|
- // Good, we succeeded. Delete the item as it is no longer needed.
|
|
|
- $queue->deleteItem($entity);
|
|
|
+ $i++;
|
|
|
}
|
|
|
+
|
|
|
+ print "\nDone.";
|
|
|
}
|