Skip to content

Instantly share code, notes, and snippets.

@oxyc
Created May 22, 2012 05:44
Show Gist options
  • Select an option

  • Save oxyc/2766883 to your computer and use it in GitHub Desktop.

Select an option

Save oxyc/2766883 to your computer and use it in GitHub Desktop.
#!/usr/bin/env drush
<?php // for syntaxhighlight
function active_comments_all() {
$result = db_query("SELECT node.nid FROM {node} WHERE node.type = 'tuote'");
$nids = array();
foreach($result as $record) {
$nids[] = $record->nid;
}
$nodes = node_load_multiple($nids);
foreach ($nodes as $node) {
$node->comment = 2;
node_save($node);
}
}
active_comments_all();
function trigger_save_nodes() {
$result = db_query("SELECT node.nid FROM {node} WHERE node.type = 'tuote' AND node.language = 'fi'");
$nids = array();
foreach($result as $record) {
$nids[] = $record->nid;
}
$nodes = node_load_multiple($nids);
foreach ($nodes as $node) {
node_save($node);
}
}
//trigger_save_nodes();
function tag_taxonomy_based_on_term() {
$terms = array(
321 => 339, // broiler
322 => 338, // kalkon
323 => 336, // nöt
324 => 334, // gris
);
foreach ($terms as $src => $dst) {
$nids = taxonomy_select_nodes($src, FALSE, FALSE);
$nodes = node_load_multiple($nids);
foreach ($nodes as $node) {
if ($node->language != 'fi') {
continue; // skip swedish, we rely on translation sync
}
$node->field_lihan_alkupera = array(
LANGUAGE_NONE => array(array('tid' => $dst))
);
print "$src -> $dst " . $node->title . "\n";
node_save($node);
}
}
}
//tag_taxonomy_based_on_term();
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);
}
}
// 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