You are here

bynder.install in Bynder 7

Install, update and uninstall functions for the Media: Bynder module.

File

bynder.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the Media: Bynder module.
 */

/**
 * Implements hook_schema().
 */
function bynder_schema() {
  $schema['bynder_media_entity'] = array(
    'description' => 'Table to store Bynder media information.',
    'fields' => array(
      'id' => array(
        'type' => 'serial',
        'unsigned' => true,
        'not null' => true,
      ),
      'bynder_id' => array(
        'description' => 'Bynder asset unique identifier.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => true,
        'default' => '',
      ),
      'fid' => array(
        'description' => 'Drupal file identifier.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => true,
        'default' => '',
      ),
      'bynder_hash_id' => array(
        'description' => 'Bynder hash identifier.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => true,
        'default' => '',
      ),
      'name' => array(
        'description' => 'The title of the asset.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => true,
        'default' => '',
      ),
      'description' => array(
        'description' => 'The description of the asset.',
        'type' => 'text',
        'size' => 'big',
        'not null' => false,
      ),
      'derivatives' => array(
        'description' => 'Derivative information.',
        'type' => 'text',
        'not null' => false,
        'size' => 'big',
        'serialize' => true,
      ),
    ),
    'primary key' => array(
      'id',
    ),
  );
  $schema['bynder_media_usage'] = array(
    'description' => 'Associates stored Bynder assets with file and node ids.',
    'fields' => array(
      'id' => array(
        'type' => 'serial',
        'unsigned' => true,
        'not null' => true,
      ),
      'bynder_entity_id' => array(
        'description' => 'Bynder Drupal Entity identifier.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => true,
        'default' => '',
      ),
      'bynder_id' => array(
        'description' => 'Bynder asset unique identifier.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => true,
        'default' => '',
      ),
      'fid' => array(
        'description' => 'Drupal file identifier.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => true,
        'default' => '',
      ),
      'nid' => array(
        'description' => 'The node identifier.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => false,
        'default' => '',
      ),
      'processed' => array(
        'description' => 'Logs if the usage entry was sent to Bynder.',
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0,
      ),
      'uri' => array(
        'description' => 'The media usage page url in Drupal.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
        'default' => '',
      ),
      'title' => array(
        'description' => 'The node title.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
        'default' => '',
      ),
    ),
    'primary key' => array(
      'id',
    ),
  );
  $schema['cache_bynder'] = drupal_get_schema_unprocessed('system', 'cache');
  return $schema;
}

/**
 * Syncing old Bynder module media to new format.
 */
function bynder_update_7100() {
  composer_manager_register_autoloader();

  // Run Bynder file sync
  try {
    sync_old_bynder_media(true);
  } catch (Exception $e) {
    watchdog('bynder', $e
      ->getMessage());
  }
}

/**
 * Adding Bynder Media Usage table if not existing.
 */
function bynder_update_7101() {
  if (!db_table_exists('bynder_media_usage')) {
    $schema['bynder_media_usage'] = array(
      'description' => 'Associates stored Bynder assets with file and node ids.',
      'fields' => array(
        'id' => array(
          'type' => 'serial',
          'unsigned' => true,
          'not null' => true,
        ),
        'bynder_entity_id' => array(
          'description' => 'Bynder Drupal Entity identifier.',
          'type' => 'varchar',
          'length' => 255,
          'not null' => true,
          'default' => '',
        ),
        'bynder_id' => array(
          'description' => 'Bynder asset unique identifier.',
          'type' => 'varchar',
          'length' => 255,
          'not null' => true,
          'default' => '',
        ),
        'fid' => array(
          'description' => 'Drupal file identifier.',
          'type' => 'varchar',
          'length' => 255,
          'not null' => true,
          'default' => '',
        ),
        'nid' => array(
          'description' => 'The node identifier.',
          'type' => 'varchar',
          'length' => 255,
          'not null' => true,
          'default' => '',
        ),
      ),
      'primary key' => array(
        'id',
      ),
    );
    db_create_table('bynder_media_usage', $schema['bynder_media_usage']);
  }
}

/**
 * Updating description field length.
 */
function bynder_update_7102() {
  try {
    db_change_field('bynder_media_entity', 'description', 'description', [
      'description' => 'The description of the asset.',
      'type' => 'text',
      'size' => 'big',
      'not null' => false,
    ]);
  } catch (Exception $e) {
    watchdog('bynder', $e
      ->getMessage());
  }
}

/**
 * Implements hook_uninstall().
 */
function bynder_uninstall() {
  variable_del('bynder_url');
  variable_del('bynder_oauth_consumer');
  variable_del('bynder_oauth_consumer_secret');
  variable_del('bynder_oauth_token');
  variable_del('bynder_oauth_token_secret');
  variable_del('bynder_derivatives');
  drupal_uninstall_schema("bynder");
}

Functions

Namesort descending Description
bynder_schema Implements hook_schema().
bynder_uninstall Implements hook_uninstall().
bynder_update_7100 Syncing old Bynder module media to new format.
bynder_update_7101 Adding Bynder Media Usage table if not existing.
bynder_update_7102 Updating description field length.