Loading codes_pool.install 0 → 100644 +32 −0 Original line number Diff line number Diff line <?php /** * @file * Installation functionality of the codes_pool module. */ use Drupal\Core\Database\Database; use Drupal\codes_pool\Plugin\codes_pool\CodesStorage; /** * Add index to codes pool tables. */ function codes_pool_update_8001() { $schema = Database::getConnection()->schema(); $bundles = array_keys(\Drupal::service('entity_type.bundle.info')->getBundleInfo('codes_pool_collection')); $database_storage = new CodesStorage\Database(); $spec = $database_storage->schemaDefinition(); foreach ($bundles as $bundle) { $table = 'codes_pool_csv_' . $bundle; if ($schema->tableExists($table)) { if (!$schema->indexExists($table, 'entity_id_status')) { $schema->addIndex($table, 'entity_id_status', ['entity_id', 'status'], $spec); } if (!$schema->indexExists($table, 'code')) { $schema->addIndex($table, 'code', ['code'], $spec); } } } } src/Plugin/codes_pool/CodesStorage/Database.php +4 −4 Original line number Diff line number Diff line Loading @@ -196,8 +196,8 @@ class Database implements CodesStorageInterface { * * @internal */ protected function schemaDefinition() { $schema = [ public function schemaDefinition() { return [ 'description' => 'Codes pool table.', 'fields' => [ 'id' => [ Loading Loading @@ -240,10 +240,10 @@ class Database implements CodesStorageInterface { ], 'indexes' => [ 'status' => ['status'], 'entity_id_status' => ['entity_id', 'status'], 'code' => ['code'] ], ]; return $schema; } } Loading
codes_pool.install 0 → 100644 +32 −0 Original line number Diff line number Diff line <?php /** * @file * Installation functionality of the codes_pool module. */ use Drupal\Core\Database\Database; use Drupal\codes_pool\Plugin\codes_pool\CodesStorage; /** * Add index to codes pool tables. */ function codes_pool_update_8001() { $schema = Database::getConnection()->schema(); $bundles = array_keys(\Drupal::service('entity_type.bundle.info')->getBundleInfo('codes_pool_collection')); $database_storage = new CodesStorage\Database(); $spec = $database_storage->schemaDefinition(); foreach ($bundles as $bundle) { $table = 'codes_pool_csv_' . $bundle; if ($schema->tableExists($table)) { if (!$schema->indexExists($table, 'entity_id_status')) { $schema->addIndex($table, 'entity_id_status', ['entity_id', 'status'], $spec); } if (!$schema->indexExists($table, 'code')) { $schema->addIndex($table, 'code', ['code'], $spec); } } } }
src/Plugin/codes_pool/CodesStorage/Database.php +4 −4 Original line number Diff line number Diff line Loading @@ -196,8 +196,8 @@ class Database implements CodesStorageInterface { * * @internal */ protected function schemaDefinition() { $schema = [ public function schemaDefinition() { return [ 'description' => 'Codes pool table.', 'fields' => [ 'id' => [ Loading Loading @@ -240,10 +240,10 @@ class Database implements CodesStorageInterface { ], 'indexes' => [ 'status' => ['status'], 'entity_id_status' => ['entity_id', 'status'], 'code' => ['code'] ], ]; return $schema; } }