You are here

function opigno_lms_update_7110 in Opigno LMS 7

Install the updated h5p libraries

File

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

Code

function opigno_lms_update_7110(&$sandbox) {

  // Installs latest H5P Libraries
  if (module_exists("h5p")) {
    $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']);
  }

  /////////////////////////////////////////////////////////////////////
  $roles = user_roles(FALSE, NULL);
  foreach ($roles as $rid => $rolename) {
    if ($rolename == "student manager" || $rolename == "administrator" || $rolename == "forum administrator") {
      user_role_grant_permissions($rid, array(
        'access opigno statistics pages',
      ));
    }
  }

  // Create a statistic link in the main menu.
  $item = array(
    'link_title' => st('Statistics'),
    'link_path' => 'admin/opigno-statistics',
    'menu_name' => 'main-menu',
    'options' => array(
      'attributes' => array(
        'id' => 'main-navigation-item-statistics',
      ),
    ),
    'hidden' => 1,
    'weight' => 49,
  );
  menu_link_save($item);
  opigno_lms_refresh_strings_and_import(array(
    'field',
  ));
  drupal_flush_all_caches();
}