summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakob Perry2017-02-04 02:10:49 (GMT)
committerJakob Perry2017-02-04 02:10:49 (GMT)
commit8a117f17b0e8f2b03452577f2209fafc9c9a6013 (patch)
tree7e02d6e7d08ebb0f2c69b2f8c1e381d9e181bd32
parent60906a022d5ae00a483a4de10375b92c6f394e18 (diff)
Revert Issue #2479879: Move 'panels_page_allowed_types' variable to a custom table.
-rw-r--r--includes/common.inc44
-rw-r--r--panels.install31
2 files changed, 27 insertions, 48 deletions
diff --git a/includes/common.inc b/includes/common.inc
index 9e150e3..fcecef2 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -196,7 +196,7 @@ class panels_allowed_layouts {
*/
function save() {
if (!is_null($this->module_name)) {
- variable_set($this->module_name . '_allowed_layouts', serialize($this));
+ variable_set($this->module_name . "_allowed_layouts", serialize($this));
}
}
@@ -272,11 +272,7 @@ function panels_common_settings($form, &$form_state, $module_name = 'panels_comm
// each type its own checkboxes set unless it's 'single' in which
// case it can go into our fake other set.
$available_content_types = ctools_content_get_all_types();
- $allowed_content_types = db_select('panels_allowed_types', 'pat')
- ->fields('pat', array('type', 'allowed'))
- ->condition('module', $module_name)
- ->execute()
- ->fetchAllKeyed();
+ $allowed_content_types = variable_get($module_name . '_allowed_types', array());
foreach ($available_content_types as $id => $types) {
foreach ($types as $type => $info) {
@@ -358,21 +354,21 @@ function panels_common_settings_submit($form, &$form_state) {
if (!$form_state['skip']) {
// Merge the broken apart array neatly back together.
$allowed_content_types = array();
- $content_types = $form_state['values']['allowed'];
- foreach ($content_types as $content_type) {
- $allowed_content_types = array_merge($allowed_content_types, $form_state['values']['content_types'][$content_type]['options']);
- foreach ($allowed_content_types as $type => $allowed) {
- $allowed = empty($allowed) ? 0 : 1;
- db_merge('panels_allowed_types')
- ->key(array('module' => $module_name, 'type' => $type))
- ->fields(array(
- 'module' => $module_name,
- 'type' => $type,
- 'allowed' => $allowed,
- ))
- ->execute();
+ foreach ($form_state['values']['allowed'] as $allowed) {
+ $values = $form_state['values']['content_types'][$allowed]['options'];
+ // If new content of the type is not added, storing a lisy of disabled
+ // content is not needed.
+ if (!$form_state['values']['panels_common_default'][$allowed]) {
+ $values = array_filter($values);
}
+ $allowed_content_types = array_merge($allowed_content_types, $values);
}
+ // Values from checkboxes are the same string as they key, but we only need
+ // to store the boolean value.
+ foreach ($allowed_content_types as &$value) {
+ $value = (bool) $value;
+ }
+ variable_set($module_name . '_allowed_types', $allowed_content_types);
}
drupal_set_message(t('Your changes have been saved.'));
}
@@ -382,13 +378,9 @@ function panels_common_settings_submit($form, &$form_state) {
*/
function panels_common_get_allowed_types($module, $contexts = array(), $has_content = FALSE, $default_defaults = array(), $default_allowed_types = array()) {
// Get a list of all types that are available
+
$default_types = variable_get($module . '_default', $default_defaults);
- $allowed_types = db_select('panels_allowed_types', 'pat')
- ->fields('pat', array('type', 'allowed'))
- ->condition('module', $module)
- ->execute()
- ->fetchAllKeyed();
- $allowed_types = !empty($allowed_types) ? $allowed_types : $default_allowed_types;
+ $allowed_types = variable_get($module . '_allowed_types', $default_allowed_types);
// By default, if they haven't gone and done the initial setup here,
// let all 'other' types (which will be all types) be available.
@@ -473,7 +465,7 @@ function panels_common_allowed_layouts_form_submit($form, &$form_state) {
* Get the allowed layout object for the given module.
*/
function panels_common_get_allowed_layout_object($module_name) {
- $allowed_layouts = unserialize(variable_get($module_name . '_allowed_layouts', serialize('')));
+ $allowed_layouts = unserialize(variable_get($module_name . "_allowed_layouts", serialize('')));
// if no parameter was provided, or the variable_get failed
if (!$allowed_layouts) {
diff --git a/panels.install b/panels.install
index 11cf7a4..0466a52 100644
--- a/panels.install
+++ b/panels.install
@@ -652,28 +652,15 @@ function panels_update_7307() {
db_create_table($table_name, $schema[$table_name]);
}
- // Read existing allowed settings and store them in a new table.
- $variables = db_select('variable', 'v')
- ->fields('v', array('name'))
- ->condition('name', '%' . db_like('_allowed_types'), 'LIKE')
- ->execute()
- ->fetchCol();
- foreach ($variables as $name) {
- $module = str_replace('_allowed_types', '', $name);
- $variable = variable_get($name);
- foreach ($variable as $type => $allowed) {
- $allowed = empty($allowed) ? 0 : 1;
- db_merge('panels_allowed_types')
- ->key(array('module' => $module, 'type' => $type))
- ->fields(array(
- 'module' => $module,
- 'type' => $type,
- 'allowed' => $allowed,
- ))
- ->execute();
- }
- variable_del($name);
- }
+ /*
+ The version of this update hook in release 3.8 included code that
+ converted storage of allowed_types configuration from variables to the new
+ table, and also deleted existing allowed_types configuration variables.
+ See https://www.drupal.org/node/2479879.
+
+ In order to prevent data loss on sites that had not yet updated to 3.8, the
+ conversion and variable-deletion code has been removed from this update hook.
+ */
}
/**