Skip to content

Instantly share code, notes, and snippets.

@lkacenja
Last active August 29, 2015 14:27
Show Gist options
  • Save lkacenja/00ce1ea0eeaed92ad109 to your computer and use it in GitHub Desktop.
Save lkacenja/00ce1ea0eeaed92ad109 to your computer and use it in GitHub Desktop.
<?php
function drush_om_timeslot_scheduler_migrate_scheduling_rules($count, $old_field_name, $new_field_name) {
$watermark = variable_get('om_timeslot_scheduler_rules_migration_watermark', 0);
$query = db_select('node', 'n');
$query->fields('n', array());
$query->condition('type', 'om_timeslot_event', '=');
$query->range($watermark, $count);
$resource = $query->execute();
$updates_performed = FALSE;
$map = drush_om_timeslot_scheduler_scheduling_rule_map();
while ($row = $resource->fetchObject()) {
$node = node_load($row->nid);
$l = $node->language;
if (!empty($node->{$old_field_name}[$l][0]['value'])) {
$new_value = $map[$node->{$old_field_name}[$l][0]['value']];
$node->{$new_field_name} = array($l => array(array('value' => $new_value)));
node_save($node);
$updates_performed = TRUE;
}
}
if ($updates_performed == TRUE) {
variable_set('om_timeslot_scheduler_rules_migration_watermark', $watermark + $count);
}
else {
variable_set('om_timeslot_scheduler_rules_migration_watermark', 0);
}
}
function drush_om_timeslot_scheduler_scheduling_rule_map() {
return array(
'fewest_aired_shows_scheduling_rule' => 'Drupal\om_timeslot_scheduler\Scheduling\Rules\SchedulingRuleLeastAiredContent',
'least_aired_shows_with_language_scheduling_rule' => 'Drupal\om_timeslot_scheduler\Scheduling\Rules\SchedulingRuleLeastAiredContent',
'highest_bayesian_average_rule' => 'Drupal\om_timeslot_scheduler\Scheduling\Rules\SchedulingRuleHighestRatedContent',
'least_aired_show_in_project_scheduling_rule' => 'Drupal\om_timeslot_scheduler\Scheduling\Rules\SchedulingRuleLeastAiredContentProject',
'locally_produced_shows_scheduling_rule' => 'Drupal\om_timeslot_scheduler\Scheduling\Rules\SchedulingRuleNewestLocalContent',
'newest_episode_in_project_scheduling_rule' => 'Drupal\om_timeslot_scheduler\Scheduling\Rules\SchedulingRuleNewestContentProject',
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment