You are here

gallery_assist.install in Gallery Assist 7

Same filename and directory in other branches
  1. 6 gallery_assist.install

Install, update and uninstall functions for the Gallery Assist module.

File

gallery_assist.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the Gallery Assist module.
 */

/**
 * Implements hook_schema().
 */
function gallery_assist_schema() {
  $schema['gallery_assist'] = array(
    'description' => 'Gallery Assist principal table.',
    'fields' => array(
      'gid' => array(
        'description' => 'The primary identifier for a gallery.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'gref' => array(
        'description' => 'The reference ID to the gallery, used by translations.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'ref' => array(
        'description' => 'The reference identifier to the node, used by translations.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'lang' => array(
        'description' => 'The language code by translations.',
        'type' => 'varchar',
        'length' => 8,
        'not null' => TRUE,
        'default' => '',
      ),
      'nid' => array(
        'description' => 'The primary identifier from the node.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'uid' => array(
        'description' => 'The user ID.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'ganame' => array(
        'description' => 'The gallery name.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'description' => array(
        'description' => 'Gallery description on profiles. Will come later...',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'in_profile' => array(
        'description' => 'Apears in the section of user profile -My Pictures-. Will come later...',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'ga_public_status' => array(
        'description' => 'The public status of the gallery which can be set from owner or editor at the node editing.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'show_title' => array(
        'description' => 'Show images titles by gallery group view.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'show_in_homepage_block' => array(
        'description' => 'Image boxes shadow toggle.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'gallery_assist_weight' => array(
        'description' => 'Weight of the gallery container by displaying the page.',
        'type' => 'int',
        'default' => -50,
      ),
      'data' => array(
        'description' => 'Contains the configuration data for the display galleries in the user profile. Will come later...',
        'type' => 'text',
        'size' => 'big',
        'not null' => TRUE,
      ),
      'count' => array(
        'description' => 'Extra amount information. Needed for views.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'gid',
    ),
  );
  $schema['gallery_assist_item'] = array(
    'description' => 'Table of the gallery assist items.',
    'fields' => array(
      'pid' => array(
        'description' => 'The primary identifier for a gallery item.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'nid' => array(
        'description' => 'The primary identifier from the node.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'ref' => array(
        'description' => 'The reference ID to the node.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'gid' => array(
        'description' => 'The gallery ID.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'gref' => array(
        'description' => 'The reference ID to the gallery, used by translations.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'sid' => array(
        'description' => 'The gallery ID.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 1,
      ),
      'uid' => array(
        'description' => 'The user ID.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'fid' => array(
        'description' => 'The file ID in the files table.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'filename' => array(
        'description' => 'The filename in the files table.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'opath' => array(
        'description' => 'The path to the original images.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'ppath' => array(
        'description' => 'The path to the previews images.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'tpath' => array(
        'description' => 'The path to the thumbnails images.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'weight' => array(
        'description' => 'Set the items order.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'copyright' => array(
        'description' => 'Copyright of images if needed.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'comments' => array(
        'description' => 'Allow comments to images from galleries displayed in user profile. Will come later...',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'cover' => array(
        'description' => 'The cover image of this gallery',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'aid' => array(
        'description' => 'The alias (pathauto) identifier',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'created' => array(
        'description' => 'The Unix timestamp when file was uploaded.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'changed' => array(
        'description' => 'The Unix timestamp when params from the file was changed.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'type' => array(
        'description' => 'Item type.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => 'item',
      ),
      'type_value' => array(
        'description' => 'Necessary param if type is not item.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    'primary key' => array(
      'pid',
    ),
  );
  $schema['gallery_assist_translated'] = array(
    'description' => 'Table for the multilingual manage of the fields title, caption or description etc of gallery assist items.',
    'fields' => array(
      'did' => array(
        'description' => 'The primary identifier for a translation.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'nid' => array(
        'description' => 'The primary identifier from the node.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'gid' => array(
        'description' => 'The gallery ID.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'gref' => array(
        'description' => 'The reference ID to the gallery, used by translations.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'pid' => array(
        'description' => 'The primary identifier for a gallery item.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'lang' => array(
        'description' => 'The language code by translations.',
        'type' => 'varchar',
        'length' => 8,
        'not null' => TRUE,
        'default' => '',
      ),
      'ptitle' => array(
        'description' => 'The gallery item name.',
        'type' => 'varchar',
        'length' => 100,
        'not null' => TRUE,
        'default' => '',
      ),
      'palt' => array(
        'description' => 'The filename of the gallery item image displayed as img alt.',
        'type' => 'varchar',
        'length' => 100,
        'not null' => TRUE,
        'default' => '',
      ),
      'pdescription' => array(
        'description' => 'The gallery item description text.',
        'type' => 'text',
        'size' => 'big',
        'not null' => TRUE,
      ),
      'format' => array(
        'description' => 'The filter format for the pdescription.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'did',
    ),
  );
  $schema['gallery_assist_modules_settings'] = array(
    'description' => 'Table to manage of the fields title, caption or description etc of gallery assist items.',
    'fields' => array(
      'gam' => array(
        'description' => 'The primary identifier for setting entries.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'nid' => array(
        'description' => 'The primary identifier from the node.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'ref' => array(
        'description' => 'The reference ID from the node, used by translations.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'gid' => array(
        'description' => 'The gallery ID.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'gref' => array(
        'description' => 'The reference ID from the gallery, used by translations.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'module' => array(
        'description' => 'The modules settings data.',
        'type' => 'varchar',
        'length' => 150,
        'not null' => TRUE,
        'default' => '',
      ),
      'data' => array(
        'description' => 'The modules settings data.',
        'type' => 'text',
        'size' => 'big',
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'gam',
    ),
  );
  $schema['cache_gallery_assist_data'] = drupal_get_schema_unprocessed('system', 'cache');
  $schema['cache_gallery_assist_data']['description'] = 'Cache table for gallery_assist to store pre-rendered queries, results, and display output.';
  $schema['cache_gallery_assist_data']['fields']['serialized']['default'] = 1;
  return $schema;
}

/**
 * Implements hook_uninstall().
 */
function gallery_assist_uninstall() {
  $t = get_t();

  // Remove the Gallery Assist directory and all gallery folders in it.
  $path = file_default_scheme() . '://gallery_assist';
  file_unmanaged_delete_recursive($path);

  // Delete all gallery assist nodes form the node and the node_revisions tables.
  $nodes = db_select('node', 'n')
    ->fields('n', array(
    'nid',
  ))
    ->condition('type', 'gallery_assist')
    ->execute()
    ->fetchCol();
  node_delete_multiple($nodes);

  // Delete all gallery assist settings variables.
  db_delete('variable')
    ->condition('name', db_like('gallery_assist_') . '%', 'LIKE')
    ->execute();
  drupal_set_message($t('The module Gallery Assist was uninstalled sucessfull. <br />Articles from type "Gallery" are removed too. <br />Articles with assigned gallery-functionality can are removed (if desired) using the <a href="@conten_admin">content</a> administration.', array(
    '@conten_admin' => url('admin/content'),
  )));
  watchdog('action', $t('The module Gallery Assist was uninstalled sucessfull.<br />Articles from type "Gallery" and articles with assigned gallery-functionality can are removed (if desired) using the content and structure administration.'));
}

/**
 * Implements hook_install()
 */
function gallery_assist_install() {
  $t = get_t();

  // Add the node type.
  _gallery_assist_install_type_create();

  // Create the users gallery_assist directory if the user has the right permission.
  $path = file_default_scheme() . '://gallery_assist';
  if (file_prepare_directory($path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
    drupal_set_message($t("The Gallery Assist enviroment has been created sucessfull."));
    watchdog('action', $t('The Gallery Assist enviroment has been created sucessfull.'));
  }
  else {
    drupal_set_message($t("It was not possible to create the gallery folder. Check file permissions, umask settings etc."), 'error');
    watchdog('error', $t('It was not possible to create the gallery folder. Check file permissions, umask settings etc.'));
  }
  variable_set('gallery_assist_directory', $path);

  // Create at install the gallery enviroment from super-user and from installator.
  $upath = variable_get('gallery_assist_directory', false) . '/' . 1;
  if (file_prepare_directory($upath, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
    watchdog('info', t('Gallery enviroment for the "super-admin" has bin created successfull.'));
    global $user;
    if ($user->uid != 1) {
      $path = $settings['ga']['ga_directory'] . '/' . $user->uid;
      if (file_prepare_directory($path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
        watchdog('info', t('Gallery enviroment for user @user was created successfull.', array(
          '@user',
          $user->name,
        )));
      }
      else {
        watchdog('error', $t('It was not possible to create the user galleries folder. Check file permissions, umask settings etc.'));
      }
    }
  }
  else {
    watchdog('error', $t('It was not possible to create the user galleries folder. Check file permissions, umask settings etc.'));
  }

  // One of the basic features of this module is the assign gallery-funktionality.
  // The set the variable at this point is the best method to develop efecctiv and simplified module code.
  // (I mean with this the Assignment-Functionality)
  module_load_include('inc', 'gallery_assist', 'gallery_assist_variables');
  variable_set('gallery_assist_directory', $path);
  variable_set('gallery_assist_default', 1);
  variable_set('gallery_assist_default_data', gallery_assist_default_settings());
  watchdog('action', $t('The module Gallery Assist has bin installed sucessfull.'));
}

/**
 * Create the additional node type 'Gallery' which will become assigned the gallery functionality at install.
 */
function _gallery_assist_install_type_create() {
  $t = get_t();

  // Prepare node type "Gallery".
  $node_type = array(
    'type' => 'gallery_assist',
    'name' => t('Gallery'),
    'base' => 'node_content',
    'description' => t('A <em>Gallery</em> is a article type similar in the form to a <em>Story</em> or a <em>Page</em> and is expanded with  gallery functionalities.'),
    'custom' => 1,
    'modified' => 1,
    'locked' => 0,
    'title_label' => 'Gallery title',
  );

  // In case the module was in the past installed or will be reinstalled do nothing
  $result = db_query("SELECT count(type) count FROM {node_type} WHERE type = :ntype", array(
    ':ntype' => 'node_type',
  ))
    ->fetchAssoc();
  if ($result['count'] == 0) {
    $type = node_type_set_defaults($node_type);
    node_type_save($type);
    node_add_body_field($type);
  }

  // Assign the gallery functionality.
  variable_set('gallery_assist_gallery_assist', 1);
  module_load_include('inc', 'gallery_assist', 'gallery_assist_variables');
  variable_set('gallery_assist_gallery_assist_data', gallery_assist_default_settings());

  // Set allow variables.
  // Allow variables: Administrators can deside and set which parameters gallery-owners can manage in the node edit form.
  gallery_assist_settings_allowed();
  watchdog('action', $t('A content type "Gallery" has bin created and got the gallery functionality from the Gallery Assist module.'));
}

Functions

Namesort descending Description
gallery_assist_install Implements hook_install()
gallery_assist_schema Implements hook_schema().
gallery_assist_uninstall Implements hook_uninstall().
_gallery_assist_install_type_create Create the additional node type 'Gallery' which will become assigned the gallery functionality at install.