diff --git a/panels.install b/panels.install index 6a4b63f..2a405ce 100644 --- a/panels.install +++ b/panels.install @@ -428,8 +428,6 @@ function panels_update_7302(&$sandbox) { $msg[] = t('Added panels_pane.uuid column.'); } - drupal_get_schema($table, TRUE); - // Add the uuid column to the display table. $table = 'panels_display'; $field = 'uuid'; @@ -440,8 +438,6 @@ function panels_update_7302(&$sandbox) { $msg[] = t('Added panels_display.uuid column.'); } - drupal_get_schema($table, TRUE); - if (empty($msg)) { $msg[] = t('UUID column already present in the panels_display & panels_pane tables.'); } @@ -452,11 +448,11 @@ function panels_update_7302(&$sandbox) { // Initialize information needed by the batch update system. if (!isset($sandbox['progress'])) { $sandbox['progress'] = 0; - $sandbox['max'] = db_query('SELECT COUNT(DISTINCT pd.did) FROM panels_display pd -LEFT JOIN panels_pane pp ON pp.did = pd.did + $sandbox['max'] = db_query('SELECT COUNT(DISTINCT pd.did) FROM {panels_display} pd +LEFT JOIN {panels_pane} pp ON pp.did = pd.did WHERE pd.uuid = \'\' OR pd.uuid IS NULL OR pp.uuid = \'\' OR pp.uuid IS NULL -ORDER BY pd.did;') - ->fetchField(); +ORDER BY pd.did') + ->fetchField(); // If there's no data, don't bother with the extra work. if (empty($sandbox['max'])) { $msg[] = t('No database-based panel displays or panes for which to generate UUIDs.'); @@ -467,11 +463,11 @@ ORDER BY pd.did;') // Process records in groups of 500. $limit = 500; - $dids = db_query_range('SELECT DISTINCT pd.did FROM panels_display pd -LEFT JOIN panels_pane pp ON pp.did = pd.did + $dids = db_query_range('SELECT DISTINCT pd.did FROM {panels_display} pd +LEFT JOIN {panels_pane} pp ON pp.did = pd.did WHERE pd.uuid = \'\' OR pd.uuid IS NULL OR pp.uuid = \'\' OR pp.uuid IS NULL -ORDER BY pd.did;', 0, $limit) - ->fetchCol(); +ORDER BY pd.did', 0, $limit) + ->fetchCol(); // If the Panels module is disabled we don't have access to // panels_load_displays(). @@ -481,7 +477,7 @@ ORDER BY pd.did;', 0, $limit) if ($displays = panels_load_displays($dids)) { foreach ($displays as $display) { // A display save also triggers pane saves. - panels_save_display($display); + _panels_update_uuid($display); } } @@ -511,3 +507,43 @@ function panels_update_7303() { db_create_table($table_name, $schema[$table_name]); } } + +/** + * Update panels displays and panes UUID without drupal_write_record. + * + * @see panels_save_display(). + */ +function _panels_update_uuid($display) { + // Update the panel display. + if (empty($display->uuid) || !ctools_uuid_is_valid($display->uuid)) { + $display->uuid = ctools_uuid_generate(); + } + + db_query('UPDATE {panels_display} SET uuid = :uuid WHERE did = :did', array( + ':uuid' => $display->uuid, + ':did' => $display->did, + )); + + // Update all its panes. + foreach ($display->panels as $id => $panes) { + foreach ((array) $panes as $pid) { + if (!isset($display->content[$pid])) { + continue; + } + $pane = $display->content[$pid]; + + if (empty($pane->uuid) || !ctools_uuid_is_valid($pane->uuid)) { + $pane->uuid = ctools_uuid_generate(); + } + + db_query('UPDATE {panels_pane} SET uuid = :uuid WHERE pid = :pid', array( + ':uuid' => $pane->uuid, + ':pid' => $pane->pid, + )); + } + } + + // Clear any cached content for this display. + ctools_include('plugins', 'panels'); + panels_clear_cached_content($display); +}