commit 92d4639ea64fc086487466f25bdbe1c98a485f55 Author: mradcliffe Date: Wed Feb 20 16:17:45 2013 -0500 Issue #1258026 by mradcliffe: Fix DB update to not rely on Entity API or Schema API. diff --git a/userpoints.install b/userpoints.install index 3f460cb..b399eb0 100644 --- a/userpoints.install +++ b/userpoints.install @@ -408,11 +408,50 @@ function userpoints_update_7004(&$sandbox) { /** * Add userpoints transaction type table, and default bundle. */ -function userpoints_update_7100() { +function userpoints_update_7200() { // Add transaction type table from schema. - $txn_type_table = drupal_get_schema('userpoints_txn_type', TRUE); - db_add_table('userpoints_txn_type', $txn_type_table); + $txn_type_schema = array( + 'description' => 'Userpoints transaction type', + 'fields' => array( + 'id' => array( + 'description' => 'Transaction type id', + 'type' => 'serial', + 'not null' => TRUE, + ), + 'name' => array( + 'description' => 'Machine name', + 'type' => 'varchar', + 'length' => 100, + 'not null' => TRUE, + ), + 'label' => array( + 'description' => 'Human-readable name', + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + ), + 'status' => array( + 'description' => 'Type status used by Entity API', + 'type' => 'int', + 'size' => 'tiny', + 'not null' => TRUE, + 'default' => 0x01, + ), + 'module' => array( + 'description' => 'Module owner of type used by Entity API', + 'type' => 'varchar', + 'length' => 100, + 'not null' => FALSE, + ), + ), + 'primary key' => array('id'), + 'unique keys' => array( + 'name' => array('name'), + ), + ); + + db_create_table('userpoints_txn_type', $txn_type_schema); // Add bundle column to transaction table. $type_field = array( @@ -432,13 +471,24 @@ function userpoints_update_7100() { 'module' => 'userpoints', ); - $bundle = new UserpointsTransactionType($bundle_info); - $bundle->save(); + // Create the default userpoints bundle. + $insert = db_insert('userpoints_txn_type') + ->fields(array('name', 'label', 'status', 'module')); + $insert->values(array( + 'name' => 'userpoints', + 'label' => st('Default'), + 'status' => 0x02, + 'module' => 'userpoints', + )); + $insert->execute(); variable_set('userpoints_default_bundle', 'userpoints'); // Update all transactions. - db_update('userpoints_txn')->fields(array('type' => 'userpoints'))->execute(); + $updated = db_update('userpoints_txn') + ->fields(array('type' => 'userpoints')) + ->execute(); - return t('Created userpoints_txn_type table, added bundle column to userpoints_txn table, and add default bundle.'); + $updated_plural = format_plural($updated, '1 transaction', '@count transactions'); + return t('Created userpoints_txn_type table, added bundle column to userpoints_txn table, and add default bundle to !count.', array('!count' => $updated_plural)); } commit 0c60da3c5721f917ec4e05f34d4ce3a07aad7eae Author: mradcliffe Date: Sat Feb 23 13:56:07 2013 -0500 Issue #1258026 by mradcliffe: Fix not recognized schema by calling entity info cache clear directly. diff --git a/userpoints.install b/userpoints.install index b399eb0..8fc9068 100644 --- a/userpoints.install +++ b/userpoints.install @@ -453,24 +453,6 @@ function userpoints_update_7200() { db_create_table('userpoints_txn_type', $txn_type_schema); - // Add bundle column to transaction table. - $type_field = array( - 'description' => 'Bundle', - 'type' => 'varchar', - 'length' => 100, - 'not null' => TRUE, - ); - db_add_field('userpoints_txn', 'type', $type_field); - - // Create the default userpoints bundle that is defined in - // userpoints_entity_info(). - $bundle_info = array( - 'name' => 'userpoints', - 'label' => st('Default'), - 'status' => 0x02, // Default bundle - 'module' => 'userpoints', - ); - // Create the default userpoints bundle. $insert = db_insert('userpoints_txn_type') ->fields(array('name', 'label', 'status', 'module')); @@ -483,10 +465,19 @@ function userpoints_update_7200() { $insert->execute(); variable_set('userpoints_default_bundle', 'userpoints'); - // Update all transactions. - $updated = db_update('userpoints_txn') - ->fields(array('type' => 'userpoints')) - ->execute(); + // Add bundle column to transaction table. + $type_field = array( + 'description' => 'Bundle', + 'type' => 'varchar', + 'length' => 100, + 'not null' => TRUE, + 'default' => 'userpoints', + ); + db_add_field('userpoints_txn', 'type', $type_field); + + // For some reason schema cache needs to be cleared. + drupal_get_schema(); + cache_clear_all(); $updated_plural = format_plural($updated, '1 transaction', '@count transactions'); return t('Created userpoints_txn_type table, added bundle column to userpoints_txn table, and add default bundle to !count.', array('!count' => $updated_plural)); commit a3d8b2a34555c91b3273d1af34f653183c8accd2 Author: mradcliffe Date: Sat Feb 23 14:16:46 2013 -0500 Issue #1258026 by mradcliffe: Previous commit message. diff --git a/userpoints.install b/userpoints.install index 8fc9068..0de878e 100644 --- a/userpoints.install +++ b/userpoints.install @@ -410,6 +410,9 @@ function userpoints_update_7004(&$sandbox) { */ function userpoints_update_7200() { + // Clear entity info cache to get updated schema. + entity_info_cache_clear(); + // Add transaction type table from schema. $txn_type_schema = array( 'description' => 'Userpoints transaction type', @@ -475,10 +478,6 @@ function userpoints_update_7200() { ); db_add_field('userpoints_txn', 'type', $type_field); - // For some reason schema cache needs to be cleared. - drupal_get_schema(); - cache_clear_all(); - $updated_plural = format_plural($updated, '1 transaction', '@count transactions'); return t('Created userpoints_txn_type table, added bundle column to userpoints_txn table, and add default bundle to !count.', array('!count' => $updated_plural)); }