Created
April 27, 2012 06:12
-
-
Save oxyc/2506389 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
| #!/usr/bin/env drush | |
| function insert_bool_value_based_on_query() { | |
| // where kuva exists | |
| //$result = db_query("SELECT entity_id FROM {field_data_field_horeca_kuva} WHERE language = 'fi'"); | |
| // where kuva does not exist | |
| $result = db_query("SELECT node.nid FROM {node} LEFT JOIN {field_data_field_horeca_kuva} h ON node.nid = h.entity_id WHERE node.type = 'tuote' AND h.field_horeca_kuva_fid IS null AND node.language = 'fi'"); | |
| $nids = array(); | |
| foreach($result as $record) { | |
| $nids[] = $record->nid; | |
| } | |
| $nodes = node_load_multiple($nids); | |
| foreach ($nodes as $node) { | |
| $node->field_is_consumer = array( | |
| LANGUAGE_NONE => array(array('value' => 1)) | |
| ); | |
| print $node->title ."\n"; | |
| node_save($node); | |
| } | |
| } | |
| insert_bool_value_based_on_query(); | |
| // Migrate terms in one vocab to the same but another tid | |
| function migrate_terms_to_same_vocab_term() { | |
| $terms = array( | |
| 27 => 318, | |
| 28 => 319, | |
| 29 => 320 | |
| ); | |
| foreach ($terms as $src => $dst) { | |
| $nids = taxonomy_select_nodes($src, FALSE, FALSE); | |
| $process = array(); | |
| foreach ($nids as $nid) { | |
| $translations = translation_node_get_translations($nid); | |
| foreach ($translations as $translation) { | |
| $process[] = $translation->nid; | |
| print $translation->nid . "\n"; | |
| } | |
| } | |
| $nodes = node_load_multiple($process); | |
| foreach ($nodes as $node) { | |
| $update = new stdClass(); | |
| $update->nid = $node->nid; | |
| $update->type = $node->type; | |
| $update->field_erikoisruokavalio = $node->field_erikoisruokavalio; | |
| $update->field_ominaisuudet = $node->field_ominaisuudet; | |
| foreach ($node->field_ominaisuudet as $lang => $values) { | |
| foreach ($values as $idx =>$value) { | |
| $update->field_erikoisruokavalio[$lang][] = array( | |
| 'tid' => $dst | |
| ); | |
| unset($update->field_ominaisuudet[$lang][$idx]); | |
| } | |
| } | |
| field_attach_presave('node', $update); | |
| field_attach_update('node', $update); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment