You are here

function oa_tour_bootstrap_tour_presave in Open Atrium Tours 7.2

Implements hook_bootstrap_tour_presave().

File

./oa_tour.module, line 195
Code for the Open Atrium Bootstrap Tour customizations.

Code

function oa_tour_bootstrap_tour_presave($tour) {

  // Convert existing tours spaces to new tours fields.
  if (!empty($tour->old_tour['btid']) && db_table_exists('bootstrap_tour_old')) {
    $query = db_select('bootstrap_tour_old', 'b')
      ->fields('b', array(
      'spaces',
    ))
      ->condition('b.btid', $tour->old_tour['btid']);
    $spaces = $query
      ->execute()
      ->fetchColumn();
    if ($spaces) {

      // Since this condition only happens during an update, features revert
      // likely hasn;t happened yet so we gotta revert ourselves.
      if (!field_info_field('field_bootstrap_tour_spaces')) {
        features_revert_module('oa_tour');
        if (!field_info_field('field_bootstrap_tour_spaces')) {
          watchdog('oa_tour', 'Unable to create bootstrap spaces field', array(), WATCHDOG_ERROR);
          return;
        }
      }
      foreach (explode(',', $spaces) as $nid) {
        $tour->field_bootstrap_tour_spaces[LANGUAGE_NONE][] = array(
          'target_id' => $nid,
        );
      }
    }
  }
}