Created
August 12, 2015 01:05
-
-
Save pi-ron/e6f3661f78047053f163 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Convert Text formats, change all Story Timeline nodes from panopoly text formats to parcel text formats. | |
| */ | |
| function feature_controller_update_1022(&$sandbox) { | |
| // If this is the first pass through this update function then set some variables. | |
| if (!isset($sandbox['total'])) { | |
| $result = db_query("SELECT id FROM eck_weblink WHERE type='weblink'"); | |
| $sandbox['total'] = $result->rowCount(); | |
| $sandbox['current'] = 0; | |
| } | |
| // How many nodes should be processed per pass. The higher this number is, the faster your update will | |
| // complete, but the more likely your server will run out of memory or timeout. | |
| $entities_per_pass = 10; | |
| // Get the nodes to process during this pass. | |
| $result = db_query_range("SELECT id FROM eck_weblink WHERE type='weblink'", $sandbox['current'], $entities_per_pass); | |
| while ($row = $result->fetchAssoc()) { | |
| // Load the node, change the body field input format, and save the node. | |
| $entity = entity_load('eck_weblink',$row['id']); | |
| if($entity->field_weblink_description[$entity->language][0]['format'] == 'panopoly_wysiwyg_text') { | |
| $entity->field_weblink_description[$entity->language][0]['format'] = 'parcel_wysiwyg_text'; | |
| } elseif ($entity->field_weblink_description[$entity->language][0]['format'] == 'panopoly_html_text') { | |
| $entity->field_weblink_description[$entity->language][0]['format'] = 'parcel_html_text'; | |
| } | |
| entity_save($entity); | |
| // Lets tell the site admin what we are doing. You could write to a log here, or a watchdog message or whatever... | |
| drupal_set_message(t('Updated body field text format for id:@id (@title)', array('@title' => $entity->title,'@id' => $entity->nid))); | |
| // Increment "current" by 1. | |
| $sandbox['current']++; | |
| } | |
| if($sandbox['total'] > 0) { | |
| // Set the value for finished. If current == total then finished will be 1, signifying we are done. | |
| $sandbox['#finished'] = ($sandbox['current'] / $sandbox['total']); | |
| } else { | |
| $sandbox['#finished'] = 1; | |
| } | |
| if ($sandbox['#finished'] === 1) { | |
| drupal_set_message(t('Weblink: Updated body field text format for @entities entities. DONE!!!', array('@entities' => $sandbox['total']))); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment