You are here

mee.install in Scald: Media Management made easy 7

MEE installer.

File

modules/fields/mee/mee.install
View source
<?php

/**
 * @file
 * MEE installer.
 */

/**
 * Implements hook_schema().
 */
function mee_schema() {
  $schema['mee_resource'] = array(
    'fields' => array(
      'entity_type' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'entity_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'revision_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'atom_sid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'field' => array(
        'type' => 'varchar',
        'length' => 31,
        'not null' => TRUE,
        'default' => '',
      ),
      'delta' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'weight' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'required' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'copyright' => array(
        'type' => 'text',
      ),
    ),
    'primary key' => array(
      'entity_type',
      'entity_id',
      'revision_id',
      'atom_sid',
      'field',
      'delta',
    ),
  );
  return $schema;
}

/**
 * Implements hook_install().
 */
function mee_install() {

  // default mee storage format to 'embed_div' - see mee_update_7002
  variable_set('mee_store_format', 'embed_div');
}

/**
 * Upgrade MEE module to 7.x.
 */
function mee_update_7000() {
  db_rename_table('mee_ressources', 'mee_resource');

  // @todo Migrate MEE CCK fields to text_with_summary
}

/**
 * Change the mee_ressource schema to support all entity types.
 */
function mee_update_7001(&$sandbox) {
  if (!isset($sandbox['progress'])) {
    db_drop_primary_key('mee_resource');
    db_add_field('mee_resource', 'entity_type', array(
      'type' => 'varchar',
      'length' => 128,
      'not null' => TRUE,
      'default' => '',
    ));
    db_add_field('mee_resource', 'revision_id', array(
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => FALSE,
    ));
    db_change_field('mee_resource', 'content_nid', 'entity_id', array(
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
      'default' => 0,
    ));
    db_add_field('mee_resource', 'delta', array(
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
      'default' => 0,
    ));
    $sandbox['progress'] = 0;
    $sandbox['current_nid'] = 0;
    $sandbox['max'] = db_query("SELECT COUNT(DISTINCT entity_id) FROM {mee_resource}")
      ->fetchField();
  }
  $query = db_select('mee_resource', 'm');
  $query
    ->leftJoin('node', 'n', 'm.entity_id=n.nid');
  $ids = $query
    ->fields('m', array(
    'entity_id',
  ))
    ->fields('n', array(
    'vid',
  ))
    ->condition('m.entity_id', $sandbox['current_nid'], '>')
    ->orderBy('m.entity_id', 'ASC')
    ->distinct()
    ->range(0, 50)
    ->execute()
    ->fetchAllKeyed(0, 1);
  foreach ($ids as $nid => $vid) {
    db_update('mee_resource')
      ->fields(array(
      'entity_type' => 'node',
      'revision_id' => $vid,
    ))
      ->condition('entity_id', $nid)
      ->execute();
    $sandbox['progress']++;
    $sandbox['current_nid'] = $nid;
  }
  $finished = empty($sandbox['max']) ? TRUE : $sandbox['progress'] == $sandbox['max'];
  if ($finished) {
    db_add_primary_key('mee_resource', array(
      'entity_type',
      'entity_id',
      'revision_id',
      'atom_sid',
      'field',
      'delta',
    ));
  }
  $sandbox['#finished'] = $finished;
}

/**
 * Explicitly default mee storage format to 'sas' for existing sites.
 */
function mee_update_7002() {
  if (variable_get('mee_store_format', 'undefined') == 'undefined') {
    variable_set('mee_store_format', 'sas');
  }
}

/**
 * Update plugins paths in CKEditor profiles.
 */
function mee_update_7003() {
  if (module_exists('ckeditor')) {
    module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib');
    $profiles_list = ckeditor_profile_input_formats();
    $plugins_list = ckeditor_load_plugins();
    foreach ($profiles_list as $_profile => $_inputs) {
      $changed = FALSE;
      $profile = ckeditor_profile_load($_profile);
      if (!isset($profile->settings['loadPlugins'])) {
        continue;
      }
      foreach (array_keys((array) $profile->settings['loadPlugins']) as $plugin_name) {
        if (in_array($plugin_name, array(
          'dnd',
          'dndck4',
        ))) {
          $profile->settings['loadPlugins'][$plugin_name] = $plugins_list[$plugin_name];
          $changed = TRUE;
        }
      }
      if ($changed === TRUE) {
        db_update('ckeditor_settings')
          ->fields(array(
          'settings' => serialize($profile->settings),
        ))
          ->condition('name', $profile->name, '=')
          ->execute();
      }
    }
  }
}

Functions

Namesort descending Description
mee_install Implements hook_install().
mee_schema Implements hook_schema().
mee_update_7000 Upgrade MEE module to 7.x.
mee_update_7001 Change the mee_ressource schema to support all entity types.
mee_update_7002 Explicitly default mee storage format to 'sas' for existing sites.
mee_update_7003 Update plugins paths in CKEditor profiles.