Skip to content

Instantly share code, notes, and snippets.

@yanniboi
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save yanniboi/acf877aa0e293e5e5fc2 to your computer and use it in GitHub Desktop.

Select an option

Save yanniboi/acf877aa0e293e5e5fc2 to your computer and use it in GitHub Desktop.
Unpublish CD and DVD talks
<?php
/**
* Unpublish CD and DVD mediums fro talks.
*/
function sss_tweaks_update_7002(&$sandbox) {
$query = "SELECT nid FROM {node} WHERE type='talks'";
// Set up vars.
if (!isset($sandbox['total'])) {
$result = db_query($query);
$sandbox['total'] = $result->rowCount();
$sandbox['current'] = 0;
}
$range = 50;
// Get the nodes to process during this pass.
$result = db_query_range($query, $sandbox['current'], $range);
while ($row = $result->fetchAssoc()) {
// Load the node, edit its title, and save the node.
$wrapper = entity_metadata_wrapper('node', $row['nid']);
if (!empty($wrapper->field_product->value())) {
foreach ($wrapper->field_product->value() as $product) {
if ($product->title == 'CD' || $product->title == 'DVD') {
$product->status = 0;
commerce_product_save($product);
}
}
}
// @TODO Log progress.
$sandbox['current']++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment