patchinfo.install in PatchInfo 8.2
Same filename and directory in other branches
Install, update, and uninstall functions for the Patch Info module.
File
patchinfo.installView source
<?php
/**
* @file
* Install, update, and uninstall functions for the Patch Info module.
*/
use Drupal\Core\Database\Database;
/**
* Implements hook_schema().
*/
function patchinfo_schema() {
$schema = [];
$schema['patchinfo'] = [
'description' => 'Information on patches in modules',
'fields' => [
'module' => [
'description' => 'Machine readable name of module',
'type' => 'varchar',
'length' => '50',
'not null' => TRUE,
],
'id' => [
'description' => 'Index of patch in module',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
],
'url' => [
'description' => 'Patch URL',
'type' => 'text',
'not null' => TRUE,
],
'info' => [
'description' => 'Additional information',
'type' => 'text',
'not null' => TRUE,
],
'source_module' => [
'description' => 'Machine readable name of source module',
'type' => 'varchar',
'length' => '50',
'not null' => TRUE,
],
'source' => [
'description' => 'Source information',
'type' => 'text',
'not null' => TRUE,
],
],
'primary key' => [
'source_module',
'module',
'id',
],
];
return $schema;
}
/**
* Adds source_module field to patchinfo database table.
*/
function patchinfo_update_8201() {
$table = 'patchinfo';
$field = 'source_module';
$spec = [
'description' => 'Machine readable name of source module',
'type' => 'varchar',
'length' => '50',
'not null' => TRUE,
'initial' => '',
];
$database_connection = Database::getConnection();
if ($database_connection) {
$schema = $database_connection
->schema();
if ($schema) {
if ($schema
->tableExists($table)) {
if (!$schema
->fieldExists($table, $field)) {
$schema
->addField($table, $field, $spec);
$database_connection
->delete($table)
->condition('source_module', '')
->execute();
}
}
}
}
}
/**
* Adds source field to patchinfo database table.
*/
function patchinfo_update_8202() {
$table = 'patchinfo';
$field = 'source';
$spec = [
'description' => 'Source information',
'type' => 'text',
'not null' => TRUE,
'initial' => '',
];
$schema = Database::getConnection()
->schema();
if ($schema) {
if ($schema
->tableExists($table)) {
if (!$schema
->fieldExists($table, $field)) {
$schema
->addField($table, $field, $spec);
}
}
}
}
/**
* Adds source_module field to primary index of patchinfo database table.
*/
function patchinfo_update_8203() {
$table = 'patchinfo';
$index = 'PRIMARY';
$field = 'source_module';
$schema = Database::getConnection()
->schema();
if ($schema) {
if ($schema
->tableExists($table)) {
if ($schema
->indexExists($table, $index)) {
$schema
->dropIndex($table, $index);
}
if ($schema
->fieldExists($table, $field)) {
$schema
->addPrimaryKey($table, [
'source_module',
'module',
'id',
]);
}
}
}
}
/**
* Enable .info.yml patch source submodule for compatibility with 8.x-1.x.
*/
function patchinfo_update_8204() {
$module = 'patchinfo_source_info';
if (!\Drupal::service('module_handler')
->moduleExists($module)) {
\Drupal::service('module_installer')
->install([
$module,
], TRUE);
}
}
Functions
Name | Description |
---|---|
patchinfo_schema | Implements hook_schema(). |
patchinfo_update_8201 | Adds source_module field to patchinfo database table. |
patchinfo_update_8202 | Adds source field to patchinfo database table. |
patchinfo_update_8203 | Adds source_module field to primary index of patchinfo database table. |
patchinfo_update_8204 | Enable .info.yml patch source submodule for compatibility with 8.x-1.x. |