You are here

function opigno_update_7102 in Opigno 7

Enable the course image field Add two new image styles for courses/classes

File

./opigno.install, line 189
Contains install instructions and logic

Code

function opigno_update_7102() {

  // Update new default image for course image.
  $source_dir = drupal_get_path('module', 'opigno') . '/img';
  $filename = 'opigno_course_default.jpg';
  $source = $source_dir . '/' . $filename;
  $field = field_info_field('opigno_course_image');
  opigno_content_set_default_image($field, $filename, $source);

  // Add the new image filters
  opigno_add_image_filters();

  // If the training catalogue is not in his default state, clone it (to keep
  //   the old version) and revert it before running the menu update.
  $training_catalogue_view = views_get_view('opigno_course_catalgue');
  if ($training_catalogue_view->type == 'Overridden') {
    $clone = $training_catalogue_view
      ->clone_view();

    // Clone and revert the old view
    $clone->name = $clone->name . '_cloned';
    $clone->human_name = $clone->human_name . ' CLONED';
    if (!empty($clone->display['page']->display_options['path'])) {
      $clone->display['page']->display_options['path'] .= '-cloned';
    }
    $clone
      ->save();
    drupal_set_message('Your view "' . $clone->human_name . '" has been cloned.');
  }

  // Change here the path for training catalogue. If it's not changed, the menu
  //   update will not work.
  if (!empty($training_catalogue_view->display['page']->display_options['path'])) {
    $training_catalogue_view->display['page']->display_options['path'] = 'training-catalogue';
    $training_catalogue_view
      ->save();
  }
  menu_rebuild();

  // Update the menu links to the new paths
  // Update my-courses to my-trainings and course-catalogue to training-catalogue
  $paths_to_update = array(
    'my-courses' => array(
      'path' => 'my-trainings',
      'title' => 'My trainings',
      'default_weight' => -45,
      'id' => 'main-navigation-item-my-courses',
      'updated' => false,
    ),
    'course-catalogue' => array(
      'path' => 'training-catalogue',
      'title' => 'Training catalogue',
      'default_weight' => -40,
      'id' => 'main-navigation-item-training-catalogue',
      'updated' => false,
    ),
  );
  foreach ($paths_to_update as $old_path => $new_values) {
    $mlid_query = db_select('menu_links', 'ml')
      ->fields('ml', array(
      'mlid',
    ))
      ->condition('link_path', $old_path)
      ->execute();
    while ($mlid = $mlid_query
      ->fetchField()) {
      if (!empty($mlid)) {
        $item = menu_link_load($mlid);
        $item['link_path'] = $new_values['path'];
        $item['router_path'] = $new_values['path'];
        $item['path'] = $new_values['path'];
        $item['tab-root'] = $new_values['path'];
        $item['href'] = $new_values['path'];
        $item['link_title'] = $new_values['title'];
        $item['title'] = $new_values['title'];
        menu_link_save($item);
        $paths_to_update[$old_path]['updated'] = true;
      }
    }

    // If the menu doesn't exists and the theme is Platon, create them.
    if ($paths_to_update[$old_path]['updated'] == false && variable_get('theme_default', null) == 'platon') {
      $item = array(
        'link_path' => $new_values['path'],
        'link_title' => $new_values['title'],
        'menu_name' => 'main-menu',
        'weight' => $new_values['default_weight'],
        'options' => array(
          'attributes' => array(
            'id' => $new_values['id'],
          ),
        ),
        'router_path' => $new_values['path'],
      );
      menu_link_save($item);
    }
  }

  // Install the new table
  $schema = opigno_get_latest_group_activity_schema();
  db_create_table('opigno_latest_group_activity', $schema['opigno_latest_group_activity']);
}