filebrowser-8.x-2.x-dev/filebrowser.install

filebrowser.install
<?php

/* This file is part of "filebrowser".
 *    Copyright 2016, YagoSoft
 *    Author : Joop Sint Jago
 *    eMail  : j.sintjago@bad_xs4all.nl (remove bad_ before sending an email)
 *    Site   : http://yagosoft.com
 *
 * "filebrowser" is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * "filebrowser" is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with "filebrowser"; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

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

use Drupal\Core\Config\FileStorage;
use Drupal\Core\Database\Database;

/**
 * Implements hook_install()
 */
function filebrowser_install() {
  // Do not allow to delete the dir_listing node type.
  $locked = Drupal::state()->get('node.type.locked');
  $locked['dir_listing'] = 'dir_listing';
  Drupal::state()->set('node.type.locked', $locked);
}

/**
 * Implements hook_uninstall().
 */
function filebrowser_uninstall() {
  // Clear filebrowser data out of the cache.
  Drupal::cache('data')->deleteAll();
}

function filebrowser_schema() {
  $schema['filebrowser_nodes'] = [
    'description' => 'Stores filebrowser specific data for each node',
    'fields' => [
      'nid' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'nid of the node holding this filebrowser',
      ],
      'folder_path' => [
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
        'description' => 'uri to the exposed directory',
      ],
      'properties' => [
        'type' => 'blob',
        'not null' => TRUE,
        'size' => 'big',
        'description' => 'serialised data containing the filebrowser settings for this node',
      ],
      'external_host' => [
        'type' => 'varchar',
        'description' => "External host",
        'length' => 256,
        'not null' => FALSE,
      ],
    ],
    'primary key' => ['nid'],
  ];

  $schema['filebrowser_content'] = [
    'description' => 'contains information about the file. one row per file',
    'fields' => [
      'nid' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'nid of the node holding this file',
      ],
      'fid' => [
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'id of this file',
      ],
      'root' => [
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
        'description' => 'relative root of this file',
      ],
      'path' => [
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
        'description' => 'path to the file',
      ],
      'file_data' => [
        'type' => 'blob',
        'not null' => TRUE,
        'size' => 'big',
        'description' => 'serialised field containing file data',
      ],
    ],

    'primary key' => ['fid'],
    'unique keys' => [
      'nid_fid' => ['nid', 'fid'],
      'fid' => ['fid'],
    ],
  ];

  return $schema;
}

/**
 * Convert file_browser_metadata_entity into blob.
 */
function filebrowser_update_9101() {
  $entity_type_id = 'filebrowser_metadata_entity';
  $content_schema = [
    'type' => 'blob',
    'not null' => FALSE,
  ];
  $fields = [
    'filebrowser_metadata_entity' => 'content',
    'filebrowser_content' => 'file_data',
    'filebrowser_nodes' => 'properties',
  ];
  Database::setActiveConnection();
  $schema = Database::getConnection()->schema();
  foreach ($fields as $table => $field) {
    $schema->changeField($table, $field, $field, $content_schema);
  }
  $field = 'content';
  $entity_type_manager = Drupal::entityTypeManager();
  $entity_type = $entity_type_manager->getDefinition($entity_type_id);
  $class = $entity_type->getClass();
  $fields = $class::baseFieldDefinitions($entity_type);
  $content_definition = $fields['content'];
  Drupal::entityDefinitionUpdateManager()
    ->installFieldStorageDefinition($field, $entity_type_id, 'filebrowser', $content_definition);
}

/**
 * Add overwrite_breadcrumb to Filebrowser settings configuration.
 */
function filebrowser_update_9102() {
  $module_path = Drupal::service('module_handler')->getModule('filebrowser')->getPath();
  $source = new FileStorage($module_path . '/config/install');
  /** @var \Drupal\Core\Config\StorageInterface $active_storage */
  $active_storage = Drupal::service('config.storage');
  $active_storage->write('filebrowser.settings', $source->read('filebrowser.settings'));
}

/**
 * update database schema to include external_host
 */
function filebrowser_update_9103() {
  $external_host = [
    'type' => 'varchar',
    'description' => "External host",
    'length' => 256,
    'not null' => FALSE,
  ];
  Database::setActiveConnection();
  $schema = Database::getConnection()->schema();
  $schema->addField('filebrowser_nodes', 'external_host', $external_host);
}

/**
 * Add update active configuration to include new setting: external_host.
 */
function filebrowser_update_9104() {
  $module_path = Drupal::service('module_handler')->getModule('filebrowser')->getPath();
  $source = new FileStorage($module_path . '/config/install');
  /** @var \Drupal\Core\Config\StorageInterface $active_storage */
  $active_storage = Drupal::service('config.storage');
  $active_storage->write('filebrowser.settings', $source->read('filebrowser.settings'));
}

/**
 * Add uid (user id) base field to filebrowser_metadata_entity entity.
 */
function filebrowser_update_9105() {
  $entity_type_id = 'filebrowser_metadata_entity';
  $field_name = 'uid';
  $update_manager = \Drupal::entityDefinitionUpdateManager();

  // Get the updated field definition from the entity class.
  $entity_type = \Drupal::entityTypeManager()->getDefinition($entity_type_id);
  $field_definition = $entity_type->getClass()::baseFieldDefinitions($entity_type)[$field_name];

  // Install the new field storage definition.
  $update_manager->installFieldStorageDefinition(
    $field_name,
    $entity_type_id,
    $entity_type->getProvider(),
    $field_definition
  );

  \Drupal::logger('filebrowser')->notice("Installed 'user_id' field on $entity_type_id entity.");
}

/**
 * filebrowser_update_9106(): No-op.
 * This is a re-write.
 */
function filebrowser_update_9106() {
  // Intentionally left blank.
}

/**
 * filebrowser_update_9107(): No-op
 * This is a re-write.
 */
function filebrowser_update_9107() {
  // intentionally left blank
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc