h5p.install 11.7 KB
Newer Older
falcon's avatar
falcon committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
<?php

/**
 * @file
 *  h5p.install php file
 *  Install and upgrade instructions for the h5p Drupal module.
 */

/**
 * Implementation of hook_install().
 */
function h5p_install() {
  drupal_install_schema('h5p');
}

/**
 * Implementation of hook_uninstall().
 */
function h5p_uninstall() {
  drupal_uninstall_schema('h5p');
falcon's avatar
falcon committed
21 22
  variable_del('h5p_export');
  variable_del('h5p_revisioning');
falcon's avatar
falcon committed
23 24 25 26 27 28
}

/**
 * Implementation of hook_schema().
 */
function h5p_schema() {
falcon's avatar
falcon committed
29
  $schema['h5p_nodes_libraries'] = array(
falcon's avatar
falcon committed
30 31
    'description' => 'Stores information about what h5p uses what libraries.',
    'fields' => array(
icc's avatar
icc committed
32 33
      'content_id' => array(
        'description' => 'Primary Key: The unique identifier for a node(vid by default).',
falcon's avatar
falcon committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'library_id' => array(
        'description' => 'The id of a h5p library this content uses',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'preloaded' => array(
        'description' => '0 if this library is dynamic, 1 if this library is to be preloaded',
        'type' => 'int',
        'size' => 'tiny',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 1,
      ),
falcon's avatar
falcon committed
52 53 54 55 56 57 58 59
      'drop_css' => array(
        'description' => '1 if this node does not want the library css included',
        'type' => 'int',
        'size' => 'tiny',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
falcon's avatar
falcon committed
60
    ),
icc's avatar
icc committed
61
    'primary key' => array('content_id', 'library_id'),
falcon's avatar
falcon committed
62 63
  );

falcon's avatar
falcon committed
64
  $schema['h5p_libraries'] = array(
falcon's avatar
falcon committed
65 66
    'description' => 'Stores information about what h5p uses what libraries.',
    'fields' => array(
falcon's avatar
falcon committed
67
      'library_id' => array(
falcon's avatar
falcon committed
68 69 70 71 72 73
        'description' => 'Primary Key: The id of the library.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'machine_name' => array(
falcon's avatar
falcon committed
74
        'description' => 'The library machine name',
falcon's avatar
falcon committed
75 76 77
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
falcon's avatar
falcon committed
78
        'default' => '',
falcon's avatar
falcon committed
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
      ),
      'title' => array(
        'description' => 'The human readable name of this library',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'major_version' => array(
        'description' => 'The version of this library',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'minor_version' => array(
        'description' => 'The minor version of this library',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'patch_version' => array(
        'description' => 'The patch version of this library',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'runnable' => array(
        'description' => 'Whether or not this library is executable.',
        'type' => 'int',
        'size' => 'tiny',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 1,
      ),
falcon's avatar
falcon committed
113 114 115 116 117 118 119 120
      'fullscreen' => array(
        'description' => 'Indicates if this library can be opened in fullscreen.',
        'type' => 'int',
        'size' => 'tiny',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
falcon's avatar
falcon committed
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
      'embed_types' => array(
        'description' => 'The allowed embed types for this library as a comma separated list',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'preloaded_js' => array(
        'description' => 'The preloaded js for this library as a comma separated list',
        'type' => 'text',
      ),
      'preloaded_css' => array(
        'description' => 'The preloaded css for this library as a comma separated list',
        'type' => 'text',
      ),
falcon's avatar
falcon committed
136 137 138 139
      'drop_library_css' => array(
        'description' => 'List of libraries that should not have CSS included if this library is used. Comma separated list.',
        'type' => 'text',
      ),
icc's avatar
icc committed
140 141 142 143 144
      'semantics' => array(
        'description' => 'The semantics definition in json format',
        'type' => 'text',
        'not null' => TRUE,
      ),
falcon's avatar
falcon committed
145 146 147
    ),
    'primary key' => array('library_id'),
  );
falcon's avatar
falcon committed
148

falcon's avatar
falcon committed
149
  $schema['h5p_libraries_libraries'] = array(
falcon's avatar
falcon committed
150 151 152 153 154 155 156 157
    'description' => 'Stores information about library dependencies.',
    'fields' => array(
      'library_id' => array(
        'description' => 'Primary Key: The id of a h5p library.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
falcon's avatar
falcon committed
158 159
      'required_library_id' => array(
        'description' => 'Primary Key: The id of a h5p library.',
falcon's avatar
falcon committed
160 161 162 163
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
icc's avatar
icc committed
164 165 166 167
      'dependency_type' => array(
        'description' => 'preloaded, dynamic, or editor',
        'type' => 'varchar',
        'length' => 255,
falcon's avatar
falcon committed
168 169 170
        'not null' => TRUE,
      ),
    ),
falcon's avatar
falcon committed
171
    'primary key' => array('library_id', 'required_library_id'),
falcon's avatar
falcon committed
172
  );
falcon's avatar
falcon committed
173

falcon's avatar
falcon committed
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
  $schema['h5p_libraries_languages'] = array(
    'description' => 'Stores translations for the languages.',
    'fields' => array(
      'library_id' => array(
        'description' => 'Primary Key: The id of a h5p library.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'language_code' => array(
        'description' => 'Primary Key: The language code.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'language_json' => array(
        'description' => 'The translations defined in json format',
        'type' => 'text',
        'not null' => TRUE,
      ),
    ),
    'primary key' => array('library_id', 'language_code'),
  );

falcon's avatar
falcon committed
198
  $schema['h5p_nodes'] = array(
falcon's avatar
falcon committed
199 200
    'description' => 'Stores information about where the h5p content is stored.',
    'fields' => array(
icc's avatar
icc committed
201 202
      'content_id' => array(
        'description' => 'Primary Key: The unique identifier for this node(vid by default).',
falcon's avatar
falcon committed
203 204 205 206 207 208 209 210 211 212 213 214 215 216
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'nid' => array(
        'description' => 'The {node}.nid of the h5p node.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'json_content' => array(
        'description' => 'The content in json format',
        'type' => 'text',
        'not null' => TRUE,
Svein-Tore Griff With's avatar
Svein-Tore Griff With committed
217
        'size' => 'big',
falcon's avatar
falcon committed
218 219 220 221 222 223 224 225
      ),
      'embed_type' => array(
        'description' => 'The embed type for this content',
        'type' => 'varchar',
        'length' => 127,
        'not null' => TRUE,
        'default' => '',
      ),
falcon's avatar
falcon committed
226
      'main_library_id' => array(
icc's avatar
icc committed
227
        'description' => 'The library we first instanciate for this node',
falcon's avatar
falcon committed
228 229
        'type' => 'int',
        'unsigned' => TRUE,
falcon's avatar
falcon committed
230 231
        'not null' => TRUE,
      ),
falcon's avatar
falcon committed
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
      'content_type' => array(
        'description' => 'Content type as defined in h5p.json',
        'type' => 'varchar',
        'length' => 127,
      ),
      'author' => array(
        'description' => 'Author as defined in h5p.json',
        'type' => 'varchar',
        'length' => 127,
      ),
      'license' => array(
        'description' => 'License as defined in h5p.json',
        'type' => 'varchar',
        'length' => 7,
      ),
      'meta_keywords' => array(
        'description' => 'Keywords as defined in h5p.json',
        'type' => 'text',
      ),
      'meta_description' => array(
        'description' => 'Meta description as defined in h5p.json',
        'type' => 'text',
      ),
falcon's avatar
falcon committed
255
    ),
icc's avatar
icc committed
256
    'primary key' => array('content_id'),
falcon's avatar
falcon committed
257 258 259 260 261 262 263 264 265 266 267
  );
  return $schema;
}

/**
 * Implementation of hook_requirements().
 */
function h5p_requirements($phase) {
  $requirements = array();

  if ($phase == 'runtime') {
icc's avatar
icc committed
268
    // TODO: Add check for zip library
falcon's avatar
falcon committed
269
    // File paths
falcon's avatar
falcon committed
270
    $h5p_path = file_create_path(file_directory_path() . '/' . variable_get('h5p_default_path', 'h5p'));
falcon's avatar
falcon committed
271
    $temp_path = $h5p_path . '/temp';
272
    $export_path = $h5p_path . '/exports';
falcon's avatar
falcon committed
273 274 275 276 277 278 279 280 281 282 283
    if (!file_check_directory($h5p_path, FILE_CREATE_DIRECTORY)) {
      $requirements['h5p_dirs'] = array(
        'value' => t('Missing directory.'),
        'severity' => REQUIREMENT_ERROR,
        'description' => t("The h5p module's package directory %h5p_path is missing.", array('%h5p_path' => $h5p_path)),
      );
    }
    else if (!file_check_directory($temp_path, FILE_CREATE_DIRECTORY)) {
      $requirements['h5p_dirs'] = array(
        'value' => t('Missing temp directory.'),
        'severity' => REQUIREMENT_ERROR,
falcon's avatar
falcon committed
284
        'description' => t("The h5p module's temp directory %temp_path is missing.", array('%temp_path' => $temp_path)),
falcon's avatar
falcon committed
285 286
      );
    }
287 288 289 290 291 292 293
    else if (!file_check_directory($export_path, FILE_CREATE_DIRECTORY)) {
      $requirements['h5p_dirs'] = array(
        'value' => t('Missing export directory.'),
        'severity' => REQUIREMENT_ERROR,
        'description' => t("The h5p module's export directory %export_path is missing.", array('%export_path' => $export_path)),
      );
    }
falcon's avatar
falcon committed
294 295 296 297 298 299 300 301 302 303
    else {
      $requirements['h5p_dirs'] = array(
        'value' => t('Exists (%path).', array('%path' => $h5p_path)),
        'severity' => REQUIREMENT_OK,
      );
    }
    $requirements['h5p_dirs']['title'] = t('h5p module directories');
  }

  return $requirements;
falcon's avatar
falcon committed
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
}

/**
 * Implementation of hook_update_N().
 */
function h5p_update_6100() {
  $ret = array();
  db_add_field($ret, 'h5p_libraries', 'fullscreen', array(
    'description' => 'Indicates if this library can be opened in fullscreen.',
    'type' => 'int',
    'size' => 'tiny',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  ));
  return $ret;
falcon's avatar
falcon committed
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
}

/**
 * Implementation of hook_update_N().
 */
function h5p_update_6101() {
  $ret = array();
  db_create_table($ret, 'h5p_libraries_languages', array(
    'description' => 'Stores translations for the languages.',
    'fields' => array(
      'library_id' => array(
        'description' => 'Primary Key: The id of a h5p library.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'language_code' => array(
        'description' => 'Primary Key: The language code.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'language_json' => array(
        'description' => 'The translations defined in json format',
        'type' => 'text',
        'not null' => TRUE,
      ),
    ),
    'primary key' => array('library_id', 'language_code'),
  ));
falcon's avatar
falcon committed
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
  return $ret;
}

/**
 * Implementation of hook_update_N().
 */
function h5p_update_6102() {
  $ret = array();
  db_add_field($ret, 'h5p_nodes', 'content_type', array(
    'description' => 'Content type as defined in h5p.json',
    'type' => 'varchar',
    'length' => 127,
  ));
  db_add_field($ret, 'h5p_nodes', 'author', array(
    'description' => 'Author as defined in h5p.json',
    'type' => 'varchar',
    'length' => 127,
  ));
  db_add_field($ret, 'h5p_nodes', 'license', array(
    'description' => 'License as defined in h5p.json',
    'type' => 'varchar',
    'length' => 7,
  ));
  db_add_field($ret, 'h5p_nodes', 'meta_keywords', array(
    'description' => 'Keywords as defined in h5p.json',
    'type' => 'text',
  ));
  db_add_field($ret, 'h5p_nodes', 'meta_description', array(
    'description' => 'Meta description as defined in h5p.json',
    'type' => 'text',
  ));
381

Svein-Tore Griff With's avatar
Svein-Tore Griff With committed
382 383 384 385 386 387 388 389 390 391 392 393 394 395
  return $ret;
}

/**
 * Implementation of hook_update_N().
 */
function h5p_update_6103() {
  $ret = array();
  db_change_field($ret, 'h5p_nodes', 'json_content', 'json_content', array(
    'description' => 'The content in json format',
    'type' => 'text',
    'not null' => TRUE,
    'size' => 'big',
  ));
falcon's avatar
falcon committed
396
  return $ret;
397 398 399 400 401 402 403 404 405
}

/**
 * Implementation of hook_update_N().
 */
function h5p_update_6104() {
  $ret = array();
  db_add_index($ret, 'files', 'filepath', array('filepath'));
  return $ret;
falcon's avatar
falcon committed
406
}