Follow up for #1871772-108: Convert custom blocks to content entities

Problem/Motivation

+++ b/core/modules/block/block.install
@@ -194,6 +195,246 @@ function block_update_8006() {
+ db_create_table('custom_block', array(
...
+ db_create_table('custom_block_revision', array(
Normally we handle this case via hook_schema_0() implementations + update_module_enable(), but we can clean that up later.

Proposed resolution

Refactor upgrade path as indicated

Remaining tasks

Refactor upgrade path as indicated

Files: 
CommentFileSizeAuthor
#6 custom-block-update-1919910.6.interdiff.txt6.62 KBlarowlan
#6 custom-block-update-1919910.6.patch6.95 KBlarowlan
PASSED: [[SimpleTest]]: [MySQL] 52,280 pass(es).
[ View ]
#4 custom-block-update-1919910.4.patch7.2 KBlarowlan
PASSED: [[SimpleTest]]: [MySQL] 51,346 pass(es).
[ View ]

Comments

larowlan’s picture

Status:Active» Postponed
Issue tags:-Needs architectural review, -VDC+Novice
sun’s picture

Status:Postponed» Active
underq’s picture

Hi,

I think it's all right to not implement this hook_schema in block module but to implement it in custom_block module, and it's already done.

Tell me if I am wrong :)

larowlan’s picture

Status:Active» Needs review
StatusFileSize
new7.2 KB
PASSED: [[SimpleTest]]: [MySQL] 51,346 pass(es).
[ View ]

hi, yeah the tables are created in block.install in block_update_8007() but instead we should implement hook_schema_0() (which is a new hook for me!) in custom_block.install.

see http://api.drupal.org/api/drupal/core%21includes%21update.inc/function/u... for where this is invoked.

so the chain would be

block_update_8006() calls update_module_enable('custom_block')
which will in turn call custom_block_schema_0() (which needs to be added)
which will return the two tables and pass them back to update_module_enable() which will create the tables for us.

Then we can remove the two db_create_table() calls from block_update_8007()

Something like this

sun’s picture

+++ b/core/modules/block/custom_block/custom_block.install
@@ -109,3 +109,110 @@ function custom_block_schema() {
+  // The {custom_block} table.
+  $schema = array(
...
+    // The custom_block_revision} table.
+    'custom_block_revision' => array(

Can we use the usual schema array syntax here?

$schema['tablename'] = array(
  ...
);
return $schema;

We can probably just simply copy/paste the entire function body of custom_block_schema() right now.

larowlan’s picture

StatusFileSize
new6.95 KB
PASSED: [[SimpleTest]]: [MySQL] 52,280 pass(es).
[ View ]
new6.62 KB

Refactored as per #5

sun’s picture

Status:Needs review» Reviewed & tested by the community

Thanks! Let's move forward here. This issue blocks #1920862: Rename custom_block.module to block_content.module

webchick’s picture

Assigned:Unassigned» catch

I have no earthly idea what hook_schema_0() is and there are no docs. #1929816: Remove all references to/implementations of hook_schema_0()

Shooting this to catch, since he seems to have an understanding, so can likely tell whether this is proper use or not.

sun’s picture

catch’s picture

Status:Reviewed & tested by the community» Needs work

Yeah this is the correct usage as it stands. There's mountains of clean-up to do about enabling modules during the upgrade path, but we have two critical bugs open for those so at least this gets everything to the same level of brokenness.

No longer applies though.

tim.plunkett’s picture

Status:Needs work» Fixed

Er, it no longer applies because you committed it, it seems: http://drupalcode.org/project/drupal.git/commitdiff/b5f0af3

:)

Eric_A’s picture

Seems like the changes to block_update_8007() weren't committed. The branch doesn't seem to be broken, though.
Can anybody confirm that we now have a bug here?

@@ -202,104 +202,6 @@ function block_update_8006() {
  * only enabled during upgrade process.
  */
function block_update_8007() {
-  // Add the {custom_block} table.
-  db_create_table('custom_block', array(
-    'description' => 'Stores contents of custom-made blocks.',
-    'fields' => array(
-      'id' => array(
-        'type' => 'serial',
-        'unsigned' => TRUE,
-        'not null' => TRUE,
-        'description' => "The block's {custom_block}.id.",
-      ),
-      'uuid' => array(
-        'description' => 'Unique Key: Universally unique identifier for this entity.',
-        'type' => 'varchar',
-        'length' => 128,
-        'not null' => FALSE,
-      ),
-      'info' => array(
-        'type' => 'varchar',
-        'length' => 128,
-        'not null' => TRUE,
-        'default' => '',
-        'description' => 'Block description.',
-      ),
-      // Defaults to NULL in order to avoid a brief period of potential
-      // deadlocks on the index.
-      'revision_id' => array(
-        'description' => 'The current {block_custom_revision}.revision_id version identifier.',
-        'type' => 'int',
-        'unsigned' => TRUE,
-        'not null' => FALSE,
-        'default' => NULL,
-      ),
-      'type' => array(
-        'description' => 'The type of this custom block.',
-        'type' => 'varchar',
-        'length' => 32,
-        'not null' => TRUE,
-        'default' => '',
-      ),
-      'langcode' => array(
-        'description' => 'The {language}.langcode of this node.',
-        'type' => 'varchar',
-        'length' => 12,
-        'not null' => TRUE,
-        'default' => '',
-      ),
-    ),
-    'primary key' => array('id'),
-    'indexes' => array(
-      'block_custom_type'   => array(array('type', 4)),
-    ),
-    'unique keys' => array(
-      'revision_id' => array('revision_id'),
-      'uuid' => array('uuid'),
-      'info' => array('info'),
-    ),
-    'foreign keys' => array(
-      'custom_block_revision' => array(
-        'table' => 'custom_block_revision',
-        'columns' => array('revision_id' => 'revision_id'),
-      ),
-    ),
-  ));
-  // Add the {custom_block_revision} table.
-  db_create_table('custom_block_revision', array(
-    'description' => 'Stores contents of custom-made blocks.',
-    'fields' => array(
-      'id' => array(
-        'type' => 'int',
-        'unsigned' => TRUE,
-        'not null' => TRUE,
-        'default' => 0,
-        'description' => "The block's {custom_block}.id.",
-      ),
-      // Defaults to NULL in order to avoid a brief period of potential
-      // deadlocks on the index.
-      'revision_id' => array(
-        'description' => 'The current version identifier.',
-        'type' => 'serial',
-        'unsigned' => TRUE,
-        'not null' => TRUE,
-      ),
-      'log' => array(
-        'description' => 'The log entry explaining the changes in this version.',
-        'type' => 'text',
-        'not null' => TRUE,
-        'size' => 'big',
-      ),
-      'info' => array(
-        'type' => 'varchar',
-        'length' => 128,
-        'not null' => TRUE,
-        'default' => '',
-        'description' => 'Block description.',
-      ),
-    ),
-    'primary key' => array('revision_id'),
-  ));
   // Populate the {custom_block} and {custom_block_revision} table.
   $results = db_select('block_custom', 'bc')->fields('bc')->execute();

Automatically closed -- issue fixed for 2 weeks with no activity.