You are here

resource.install in D7 Media 6

File

resource/resource.install
View source
<?php

function resource_install() {
  drupal_install_schema('resource');
}
function resource_uninstall() {
  drupal_uninstall_schema('resource');
}
function resource_enable() {
  $path = file_directory_path();
  if (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC) {
    $scheme = 'public:';
  }
  else {
    $scheme = 'private:';
  }

  //db_query('INSERT INTO {file_backup} SELECT * FROM {files}');

  //db_query('DELETE FROM {files}');
  db_query("\n    INSERT INTO {resource} (rid, uid, name, url, mimetype, size, status, timestamp)\n       SELECT\n          fid, uid, filename, REPLACE(filepath, '%s', '%s'), filemime, filesize, status, timestamp\n       FROM {files}\n  ", $path, $scheme);
}
function resource_disable() {
  db_query('DELETE FROM {resource}');

  //db_query('INSERT INTO {files} SELECT * FROM {file_backup}');
}
function resource_schema() {
  $schema['resource'] = array(
    'description' => t('Stores information for Resources.'),
    'fields' => array(
      'rid' => array(
        'description' => t('Primary Key: Unique Resource ID.'),
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'uid' => array(
        'description' => t('The {users}.uid of the user who is associated with the resource.'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'name' => array(
        'description' => t('Name of the resource.'),
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'url' => array(
        'description' => t('URL of the resource.'),
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'mimetype' => array(
        'description' => t('The resource MIME type.'),
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'size' => array(
        'description' => t('The size of the resource in bytes.'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'status' => array(
        'description' => t('A flag indicating whether file is temporary (0) or permanent (1).'),
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'timestamp' => array(
        'description' => t('UNIX timestamp for when the file was added.'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'indexes' => array(
      'uid' => array(
        'uid',
      ),
      'status' => array(
        'status',
      ),
      'timestamp' => array(
        'timestamp',
      ),
    ),
    'primary key' => array(
      'rid',
    ),
  );
  return $schema;
}