You are here

uc_option_image.install in Ubercart Option Images 6

Same filename and directory in other branches
  1. 7 uc_option_image.install

Provides install and uninstall hooks.

File

uc_option_image.install
View source
<?php

/**
 * @file
 * Provides install and uninstall hooks.
 */

/**
 * Implements hook_install().
 *   Adds default option image to file system.
 */
function uc_option_image_install() {
  $default_image_path = drupal_get_path('module', 'uc_option_image') . '/no_image.png';
  $default_image_name = 'option_image_0_0_0';
  $file_path = db_result(db_query("SELECT fid from {files} WHERE filename = '%s' AND filepath = '%s'", $default_image_name, $default_image_path));

  // Make sure image doesn't already exist in the files table.
  if (!$file_path) {
    $info = image_get_info($default_image_path);
    $file = (object) array(
      'uid' => 1,
      'filename' => $default_image_name,
      'filepath' => $default_image_path,
      'filemime' => $info['file_mime'],
      'filesize' => $info['file_size'],
      'status' => FILE_STATUS_PERMANENT,
    );
    drupal_write_record('files', $file);
  }
}

/**
 * Implements hook_uninstall().
 *   Removes default option image to file system and variables.
 */
function uc_option_image_uninstall() {

  // Remove default option image.
  $default_image_path = drupal_get_path('module', 'uc_option_image') . '/no_image.png';
  $default_image_name = 'option_image_0_0_0';
  db_query("DELETE FROM {files} WHERE filename = '%s' AND filepath = '%s'", $default_image_name, $default_image_path);

  // Remove variables.
  variable_del('uc_option_image_attributes');
  variable_del('uc_option_image_effect');
  variable_del('uc_option_image_js');
  variable_del('uc_option_image_node_weight');
  variable_del('uc_option_image_page_size');
  variable_del('uc_option_image_preview_size');
  variable_del('uc_option_image_teaser_size');
}

Functions

Namesort descending Description
uc_option_image_install Implements hook_install(). Adds default option image to file system.
uc_option_image_uninstall Implements hook_uninstall(). Removes default option image to file system and variables.