Created
October 11, 2017 13:18
-
-
Save vladdancer/4e01e531572354660dda1efa9b4f203d to your computer and use it in GitHub Desktop.
Drupal 7, Drush. Bulk update changed time for specific product displays using drush
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 | |
// drush php-script update_product_displays.drush | |
$time = time(); | |
$prev_timestamp = $time - (15 * 60); | |
$efq = new EntityFieldQuery(); | |
$efq | |
// Conditions on the entity - its type and its bundle ("sub-type") | |
->entityCondition('entity_type', 'node') | |
->entityCondition('bundle', array('product_with_palette', 'product_display')) | |
->propertyCondition('changed', $prev_timestamp, '<'); | |
// Execute, returning an array of arrays. | |
$result = $efq->execute(); | |
// Ensure we've got some node results. | |
if (!isset($result['node'])) { | |
drush_log("No nodes to process.", "ok"); | |
return; | |
} | |
// Iterate over the result, loading each node at a time. | |
foreach($result['node'] as $nid => $stub_node) { | |
// Load the full node and wrap it with entity_metadata_wrapper(). | |
$node = node_load($nid); | |
$node->changed = $time; | |
node_save($node); | |
// Log our progress. | |
drush_log("Processed nid={$nid}", "ok"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment