Skip to content

Instantly share code, notes, and snippets.

@Decipher
Created September 12, 2012 03:25
Show Gist options
  • Select an option

  • Save Decipher/3704112 to your computer and use it in GitHub Desktop.

Select an option

Save Decipher/3704112 to your computer and use it in GitHub Desktop.
Combination patch for Homebox module: 1776062 + 1781742 + 1781796
diff --git a/homebox.install b/homebox.install
index 20f0b91..43eb740 100644
--- a/homebox.install
+++ b/homebox.install
@@ -148,3 +148,162 @@ function homebox_update_6003() {
return $return;
}
+
+/**
+ * Update from 1.3.
+ */
+function homebox_update_6300() {
+ $ret = array();
+ $blocks = array();
+
+ if (db_table_exists('homebox_default')) {
+ variable_set('homebox_version', 2);
+ $pages = homebox_pages();
+
+ // Update machine name.
+ foreach ($pages as $page) {
+ $ret[] = update_sql("UPDATE {homebox_pages} SET name = '{$page->pid}' WHERE pid = {$page->pid}");
+ }
+
+ // Modify 'homebox_pages' table.
+ db_drop_field($ret, 'homebox_pages', 'pid');
+ db_add_field($ret, 'homebox_pages', 'settings', array(
+ 'type' => 'blob',
+ 'size' => 'big',
+ 'not null' => TRUE,
+ 'serialize' => TRUE,
+ 'object default' => array()
+ ));
+ db_add_primary_key($ret, 'homebox_pages', array('name'));
+
+ // Migrate settings from variables and other.
+ foreach ($pages as $page) {
+ // Get URL alias.
+ $path = drupal_get_path_alias("homebox/{$page->pid}");
+ path_set_alias("homebox/{$page->pid}");
+
+ // Build default settings.
+ $settings = array(
+ 'title' => $page->name,
+ 'path' => $path,
+ 'menu' => TRUE,
+ 'enabled' => TRUE,
+ 'auto_save' => TRUE,
+ 'full' => FALSE,
+ 'roles' => array(
+ 0 => 'authenticated user',
+ ),
+ 'regions' => variable_get("homebox_column_count_{$page->pid}", 1),
+ 'cache' => variable_get("homebox_cache_enabled_{$page->pid}", FALSE),
+ 'color' => variable_get("homebox_users_use_colors_{$page->pid}", FALSE),
+ 'colors' => array(),
+ 'widths' => array(),
+ 'blocks' => array(),
+ );
+
+ // Widths.
+ for ($i = 0; $i < $settings['regions']; $i++) {
+ $settings['widths'][$i + 1] = 100 / $settings['regions'];
+ }
+
+ // Colors.
+ for ($i = 0; $i < HOMEBOX_NUMBER_OF_COLOURS; $i++) {
+ $settings['colors'][$i] = variable_get("homebox_color_{$page->pid}_{$i}", '#E4F0F8');
+ variable_del("homebox_color_{$page->pid}_{$i}");
+ }
+
+ // Blocks.
+ $results = db_query('SELECT * FROM {homebox_default} WHERE pid = %d', $page->pid);
+ while ($result = db_fetch_object($results)) {
+ if (!isset($blocks[$result->bid])) {
+ $blocks[$result->bid] = db_fetch_object(db_query('SELECT * FROM {blocks} WHERE bid = %d', $result->bid));
+ }
+ $block = $blocks[$result->bid];
+ $settings['blocks']["{$block->module}_{$block->delta}"] = array(
+ 'module' => $block->module,
+ 'delta' => $block->delta,
+ 'region' => $result->region,
+ 'movable' => $result->movable,
+ 'status' => $result->status,
+ 'open' => $result->open,
+ 'closable' => TRUE,
+ 'title' => '',
+ 'weight' => $result->weight,
+ );
+ }
+
+ // Write settings to database.
+ db_query("UPDATE {homebox_pages} SET settings = '%s' WHERE name = '%s'", serialize($settings), $page->pid);
+
+ // Cleanup.
+ variable_del("homebox_column_count_{$page->pid}");
+ variable_del("homebox_users_use_colors_{$page->pid}");
+ variable_del("homebox_cache_enabled_{$page->pid}");
+ }
+
+ // Build user settings array().
+ $results = db_query('SELECT * FROM {homebox_users}');
+ $user_settings = array();
+ while ($result = db_fetch_object($results)) {
+ if (!isset($blocks[$result->bid])) {
+ $blocks[$result->bid] = db_fetch_object(db_query('SELECT * FROM {blocks} WHERE bid = %d', $result->bid));
+ }
+ $block = $blocks[$result->bid];
+ $user_settings[$result->uid][$result->pid]["{$block->module}_{$block->delta}"] = array(
+ 'module' => $block->module,
+ 'delta' => $block->delta,
+ 'region' => $result->region,
+ // 'movable' => ,
+ 'status' => $result->status,
+ 'open' => $result->open,
+ 'closable' => TRUE,
+ 'title' => '',
+ 'weight' => $result->weight,
+ 'color' => !empty($result->color) ? $result->color : 'default',
+ );
+ }
+
+ // Modify 'homebox_users' table.
+ db_query('DELETE FROM {homebox_users}');
+ db_drop_field($ret, 'homebox_users', 'pid');
+ db_drop_field($ret, 'homebox_users', 'bid');
+ db_drop_field($ret, 'homebox_users', 'region');
+ db_drop_field($ret, 'homebox_users', 'weight');
+ db_drop_field($ret, 'homebox_users', 'status');
+ db_drop_field($ret, 'homebox_users', 'color');
+ db_drop_field($ret, 'homebox_users', 'open');
+ db_add_field($ret, 'homebox_users', 'name', array(
+ 'type' => 'varchar',
+ 'length' => 64,
+ 'not null' => TRUE,
+ 'default' => ''
+ ));
+ db_add_field($ret, 'homebox_users', 'settings', array(
+ 'type' => 'blob',
+ 'size' => 'big',
+ 'not null' => TRUE,
+ 'serialize' => TRUE,
+ 'object default' => array()
+ ));
+ db_drop_primary_key($ret, 'homebox_users');
+ db_add_primary_key($ret, 'homebox_users', array('uid', 'name'));
+ drupal_flush_all_caches();
+
+ // Write user settings to database.
+ foreach ($user_settings as $uid => $names) {
+ foreach ($names as $name => $settings) {
+ $values = array(
+ 'uid' => $uid,
+ 'name' => $name,
+ 'settings' => $settings,
+ );
+ drupal_write_record('homebox_users', $values);
+ }
+ }
+
+ // Drop 'homebox_default' table.
+ db_drop_table($ret, 'homebox_default');
+ }
+
+ return $ret;
+}
diff --git a/homebox.module b/homebox.module
index 75cd1ce..e314adb 100644
--- a/homebox.module
+++ b/homebox.module
@@ -354,6 +354,9 @@ function homebox_build($page) {
}
}
+ // Allow other module to alter allowed blocks.
+ drupal_alter('homebox_allowed_blocks', $allowed_blocks, $page);
+
// Sort each region/column based on key value
for ($i = 1; $i <= count($regions); $i++) {
ksort($regions[$i]);
@@ -503,13 +506,16 @@ function homebox_prepare_block($block_key, $page) {
// Get the edit form early, in case it changes the block.
if (module_hook($block_settings['module'], 'homebox_block_edit_form')) {
- $block->edit_form = drupal_get_form('homebox_block_edit_' . $block_settings['module'] . '_' . $block_settings['delta'] . '_form', $page, (object) $block_settings);
- // Prepend messages the form may have generated.
- $block->edit_form = theme('status_messages', 'error') . $block->edit_form;
-
- // Apply user settings, they may have changed from the form submission.
- if (isset($_POST['form_id']) && $user_settings = _homebox_get_user_settings($page)) {
- $block_settings = homebox_merge_settings($block_settings, $user_settings[$block_key]);
+ $form = module_invoke($block_settings['module'], 'homebox_block_edit_form', (object) $block_settings);
+ if (!empty($form)) {
+ $block->edit_form = drupal_get_form('homebox_block_edit_' . $block_settings['module'] . '_' . $block_settings['delta'] . '_form', $page, (object) $block_settings);
+ // Prepend messages the form may have generated.
+ $block->edit_form = theme('status_messages', 'error') . $block->edit_form;
+
+ // Apply user settings, they may have changed from the form submission.
+ if (isset($_POST['form_id']) && $user_settings = _homebox_get_user_settings($page)) {
+ $block_settings = homebox_merge_settings($block_settings, $user_settings[$block_key]);
+ }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment