You are here

apigee_api_catalog.install in Apigee API Catalog 8.2

Same filename and directory in other branches
  1. 8 apigee_api_catalog.install

Copyright 2019 Google Inc.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation.

This program 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 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

File

apigee_api_catalog.install
View source
<?php

/**
 * @file
 * Copyright 2019 Google Inc.
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License version 2 as published by the
 * Free Software Foundation.
 *
 * This program 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 this program; if not, write to the Free Software Foundation, Inc., 51
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

/**
 * @file
 * Install file for Apigee API Catalog.
 */

/**
 * Implements hook_requirements().
 */
function apigee_api_catalog_requirements($phase) {

  // Prevent installation alongside of the `apigee_edge_apidocs` module.
  if ($phase === 'install' && \Drupal::moduleHandler()
    ->moduleExists('apigee_edge_apidocs')) {
    return [
      'apigee_api_catalog_module_conflict' => [
        'title' => t('Apigee API Catalog'),
        'description' => t('The "Apigee Edge API Docs" module is currently installed. It is deprecated and should be uninstalled before installing the Apigee API Catalog module.'),
        'severity' => REQUIREMENT_ERROR,
      ],
    ];
  }
  return [];
}

/**
 * Update the length of the name field.
 */
function apigee_api_catalog_update_8701() {
  $entity_type_id = 'apidoc';
  $field_name = 'name';
  $field_length = 255;
  $definition_update_manager = \Drupal::entityDefinitionUpdateManager();
  $last_installed_schema_repository = \Drupal::service('entity.last_installed_schema.repository');
  $entity_type = $definition_update_manager
    ->getEntityType($entity_type_id);

  // Update the field storage definition.

  /** @var \Drupal\Core\Field\FieldStorageDefinitionInterface[] $field_storage_definitions */
  $field_storage_definitions = $last_installed_schema_repository
    ->getLastInstalledFieldStorageDefinitions($entity_type_id);
  $field_storage_definitions[$field_name]
    ->setSetting('max_length', $field_length);
  $definition_update_manager
    ->updateFieldableEntityType($entity_type, $field_storage_definitions, $sandbox);
  $definition = \Drupal::entityTypeManager()
    ->getDefinition($entity_type_id);
  $data_table = $definition
    ->getDataTable();
  $revision_data_table = $definition
    ->getRevisionDataTable();
  $entity_storage_schema_sql = \Drupal::keyValue('entity.storage_schema.sql');
  $schema_key = "{$entity_type_id}.field_schema_data.{$field_name}";
  if ($field_schema_data = $entity_storage_schema_sql
    ->get($schema_key)) {

    // Update storage schema for data table.
    $field_schema_data[$data_table]['fields'][$field_name]['length'] = $field_length;

    // Update storage schema for the revision table.
    if ($revision_data_table) {
      $field_schema_data[$revision_data_table]['fields'][$field_name]['length'] = $field_length;
    }
    $entity_storage_schema_sql
      ->set($schema_key, $field_schema_data);

    // Update the base database field.
    $schema = \Drupal::database()
      ->schema();
    $schema
      ->changeField($data_table, $field_name, $field_name, $field_schema_data[$data_table]['fields'][$field_name]);

    // Update schema for the revision table.
    if ($revision_data_table) {
      $schema
        ->changeField($revision_data_table, $field_name, $field_name, $field_schema_data[$revision_data_table]['fields'][$field_name]);
    }
  }
}

/**
 * Set module schema to 8801.
 */
function apigee_api_catalog_update_8801() {

  // Empty - only needed to set the 2.x module schema number.
}

/**
 * Create API Doc node type and fields if updating from 1.x.
 */
function apigee_api_catalog_update_8802() {
  return \Drupal::service('apigee_api_catalog.updates')
    ->update8802();
}

/**
 * Recreate other fields added to the API Doc entity onto the API Doc node type if updating from 1.x.
 */
function apigee_api_catalog_update_8803() {
  return \Drupal::service('apigee_api_catalog.updates')
    ->update8803();
}

/**
 * Convert API Doc entities to nodes (migrating data) if updating from 1.x.
 */
function apigee_api_catalog_update_8804(&$sandbox) {
  return \Drupal::service('apigee_api_catalog.updates')
    ->update8804($sandbox);
}

/**
 * Deprecated step.
 */
function apigee_api_catalog_update_8805() {

  //  return \Drupal::service('apigee_api_catalog.updates')->update8805();
}

/**
 * Re-install if needed deprecated API Doc entity definition.
 */
function apigee_api_catalog_update_8806() {
  return \Drupal::service('apigee_api_catalog.updates')
    ->update8806();
}

/**
 * Removed required atttribute for field_apidoc_spec_file_source.
 */
function apigee_api_catalog_update_8807() {
  return \Drupal::service('apigee_api_catalog.updates')
    ->update8807();
}

Functions

Namesort descending Description
apigee_api_catalog_requirements Implements hook_requirements().
apigee_api_catalog_update_8701 Update the length of the name field.
apigee_api_catalog_update_8801 Set module schema to 8801.
apigee_api_catalog_update_8802 Create API Doc node type and fields if updating from 1.x.
apigee_api_catalog_update_8803 Recreate other fields added to the API Doc entity onto the API Doc node type if updating from 1.x.
apigee_api_catalog_update_8804 Convert API Doc entities to nodes (migrating data) if updating from 1.x.
apigee_api_catalog_update_8805 Deprecated step.
apigee_api_catalog_update_8806 Re-install if needed deprecated API Doc entity definition.
apigee_api_catalog_update_8807 Removed required atttribute for field_apidoc_spec_file_source.