patchinfo-8.x-2.x-dev/patchinfo.install
patchinfo.install
<?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);
}
}
