You are here

function opigno_lms_update_7114 in Opigno LMS 7

Update the H5P libraries Update the permissions to access the dashboard page Update the group permissions to access the quiz Update the default theme for the new version of CKEditor

File

./opigno_lms.install, line 960
Install, update and uninstall functions for the Opigno LMS installation profile.

Code

function opigno_lms_update_7114(&$sandbox) {

  // Installs latest H5P Libraries
  if (module_exists("h5p")) {
    drupal_flush_all_caches();
    $path = file_get_contents(drupal_get_path("profile", "opigno_lms") . "/h5plib/libraries.h5p");
    $temporary_file_path = 'public://' . variable_get('h5p_default_path', 'h5p') . '/temp/' . uniqid('h5p-');
    $prepare = file_prepare_directory($temporary_file_path, FILE_CREATE_DIRECTORY);
    $temporary_file_name = $temporary_file_path . "/libraries.h5p";
    $file = file_save_data($path, $temporary_file_name, FILE_EXISTS_REPLACE);
    $_SESSION['h5p_upload'] = drupal_realpath($file->uri);
    $_SESSION['h5p_upload_folder'] = drupal_realpath($temporary_file_path);
    $validator = _h5p_get_instance('validator');
    $isvalid = $validator
      ->isValidPackage(TRUE, FALSE);
    $h5p_core = _h5p_get_instance('storage');
    $save_package = $h5p_core
      ->savePackage(NULL, NULL, TRUE);
    unset($_SESSION['h5p_upload'], $_SESSION['h5p_upload_folder']);
  }

  // Install the tincan question type module
  if (!module_exists('opigno_tincan_question_type')) {
    module_enable(array(
      'opigno_tincan_question_type',
    ));
  }

  // Install the DOMPDF module (required for the new version of Print)
  module_enable(array(
    'print_pdf_dompdf',
  ));

  // Change the role to access the homepage dashboard
  $dashboard_page = homebox_get_page('dashboard');
  if (!empty($dashboard_page->settings['roles'][0]) && $dashboard_page->settings['roles'][0] == 'authenticated user') {
    $dashboard_page->settings['roles'][0] = 'anonymous user';
    $dashboard_page->settings['roles'][1] = 'authenticated user';
    homebox_save_page($dashboard_page);
  }
  menu_rebuild();

  // Menu rebuild needed for the new access settings.
  // Changes the og permissions ads access quiz to class

  /* Default permission */
  og_invalidate_cache();
  $roles = og_roles('node', 'class', $gid = 0, $force_group = FALSE, $include_all = TRUE);
  foreach ($roles as $index => $role) {
    if ($role == 'member') {
      og_role_grant_permissions($index, array(
        'access quiz',
      ));
    }
  }

  /* Existing group permissions */
  $existing_classes = node_load_multiple(array(), array(
    'type' => "class",
  ));
  foreach ($existing_classes as $classid => $class) {
    $roles = og_roles("node", "class", $classid, $force_group = FALSE, $include_all = TRUE);
    foreach ($roles as $index => $role) {
      if ($role == 'member') {
        og_role_grant_permissions($index, array(
          'access quiz',
        ));
      }
    }
  }

  // Update the default theme for CKEditor (no more KAMA, now it's MOONO-LISA)

  /* Get the settings for the ckeditor */
  $profile = db_select('wysiwyg', 'w')
    ->condition('format', 'html')
    ->condition('editor', 'ckeditor')
    ->fields('w')
    ->execute()
    ->fetchAllAssoc('format');
  if (!empty($profile['html']->settings)) {
    $settings = unserialize($profile['html']->settings);

    /* Change the default theme if it's the good version of wysiwyg and if the theme is the old default one */
    if ($settings['theme'] == 'advanced' && $settings['_profile_preferences']['version'] == '4.6.1.580bcaf') {
      $settings['theme'] = 'moono-lisa';
    }
    db_update('wysiwyg')
      ->condition('format', 'html')
      ->condition('editor', 'ckeditor')
      ->fields(array(
      'settings' => serialize($settings),
    ))
      ->execute();
  }
  drupal_flush_all_caches();
}