brandfolder-8.x-1.x-dev/brandfolder.install
brandfolder.install
<?php
/**
* @file
* Install, update and uninstall functions for the Brandfolder module.
*/
use Drupal\Core\Utility\UpdateException;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\brandfolder\Plugin\media\Source\BrandfolderImage;
/**
* Implements hook_schema().
*/
function brandfolder_schema() {
$schema = [];
$schema['brandfolder_file'] = [
'description' => 'Stores information about managed files that live in Brandfolder.',
'fields' => [
'fid' => [
'description' => 'The Drupal file ID.',
'type' => 'varchar',
'length' => 32,
// This is an important piece of data, but will not be present when
// we initially add a record to this table during the attachment/file
// mapping process.
'not null' => FALSE,
'default' => '',
],
'bf_attachment_id' => [
'description' => 'The Brandfolder attachment ID.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
],
'bf_asset_id' => [
'description' => 'The Brandfolder asset ID.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
],
'cdn_id' => [
'description' => 'An Organizational or Brandfolder-level identifier used in CDN URLs.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
],
'uri' => [
'description' => 'The file URI.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'binary' => TRUE,
],
'filesize' => [
'description' => 'The size of the file in bytes.',
'type' => 'int',
'size' => 'big',
'unsigned' => TRUE,
'not null' => FALSE,
'default' => 0,
],
'width' => [
'description' => 'The width of the file in pixels.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
'default' => 0,
],
'height' => [
'description' => 'The height of the file in pixels.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
'default' => 0,
],
'mime_type' => [
'description' => 'The file MIME type.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
],
'timestamp' => [
'description' => 'UNIX timestamp of when the file was added.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
'default' => 0,
],
],
'primary key' => ['bf_attachment_id'],
'indexes' => [
'fid' => [
'fid',
],
'uri' => [
'uri',
],
],
// For documentation purposes only; foreign keys are not created in the
// database.
'foreign keys' => [
'managed_file' => [
'table' => 'file_managed',
'columns' => [
'fid' => 'fid',
],
],
],
];
return $schema;
}
/**
* Implements hook_install().
*
* @throws \Drupal\Core\Utility\UpdateException
*/
//function brandfolder_install() {
// // @todo: Ensure 'bf://' scheme is fully accessible/usable upon module installation.
//
// // @todo: Pre-create certain default BF media types, with fields?
//}
/**
* Implements hook_uninstall().
*/
//function brandfolder_uninstall() {
// // @todo: Delete or flag all files using the bf:// file scheme.
// // @todo: Delete or flag all media entities that have a Brandfolder media source.
// // @todo: Update all fields using the BF scheme and/or the Brandfolder Browser widget, attempting to reconfigure them to use reasonable alternatives.
// // @todo: Ensure 'bf' is removed from the list of public file schemas.
//}
/**
* Install the Key module. We will be using that module to manage API keys henceforth (this was previously optional via config override). After running this update, go to the Brandfolder settings page (/admin/config/media/brandfolder) to reconfigure your API keys, at which point the old config entries will be deleted.
*/
function brandfolder_update_10601() {
$installer = \Drupal::service('module_installer');
// Install the Key module.
$installer->install(['key']);
}
