Rearrange the pane dropdown menus to be better organized and look a little nicer.
[project/panels.git] / panels.install
CommitLineData
19a9c34c
EM
1<?php
2// $Id$
3
4/**
5 * Test requirements for installation and running.
6 */
7function panels_requirements($phase) {
8 $requirements = array();
9 $t = get_t();
b94f7c7d
EM
10 // Assume that if the user is running an installation profile that both
11 // Panels and CTools are the same release.
12 if ($phase == 'install' && !(defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'install')) {
19a9c34c
EM
13 // apparently the install process doesn't include .module files,
14 // so we need to force the issue in order for our versioning
15 // check to work.
16 if (!defined('PANELS_REQUIRED_CTOOLS_API')) {
17 include_once drupal_get_path('module', 'panels') . '/panels.module';
18 }
19
20 // In theory we should check module_exists, but Drupal's gating should
21 // actually prevent us from getting here otherwise.
22 if (!defined('CTOOLS_API_VERSION')) {
23 include_once drupal_get_path('module', 'ctools') . '/ctools.module';
24 }
25 if (!module_invoke('ctools', 'api_version', PANELS_REQUIRED_CTOOLS_API)) {
26 $requirements['panels_ctools'] = array(
27 'title' => $t('CTools API Version'),
28 'value' => CTOOLS_API_VERSION,
29 'severity' => REQUIREMENT_ERROR,
30 'description' => t('The CTools API version is too old for Panels. Panels needs at least %version.', array('%version' => PANELS_REQUIRED_CTOOLS_API))
31 );
32 }
33 }
34 return $requirements;
35}
36
37/**
38 * Implementation of hook_schema().
39 */
40function panels_schema() {
41 // This should always point to our 'current' schema. This makes it relatively easy
42 // to keep a record of schema as we make changes to it.
4bac51cf
EM
43 return panels_schema_2();
44}
45
46/**
47 * Schema that adds the title_pane field.
48 */
49function panels_schema_2() {
50 $schema = panels_schema_1();
51
52 $schema['panels_display']['fields']['title_pane'] = array(
53 'type' => 'int',
54 'default' => 0,
55 );
56
57 return $schema;
19a9c34c
EM
58}
59
60/**
61 * Schema version 1 for Panels in D6.
62 *
63 * Schema v1 is now LOCKED; any changes should be done via panels_schema_2.
64 */
65function panels_schema_1() {
66 $schema = array();
67
68 $schema['panels_display'] = array(
69 'export' => array(
70 'object' => 'panels_display',
71 'bulk export' => FALSE,
72 'can disable' => FALSE,
73 'identifier' => 'display',
74 ),
75 'fields' => array(
76 'did' => array(
77 'type' => 'serial',
78 'not null' => TRUE,
79 'no export' => TRUE,
80 ),
81 'layout' => array(
82 'type' => 'varchar',
83 'length' => '32',
84 'default' => '',
85 ),
86 'layout_settings' => array(
87 'type' => 'text',
88 'size' => 'big',
89 'serialize' => TRUE,
90 'object default' => array(),
91 'initial ' => array(),
92 ),
93 'panel_settings' => array(
94 'type' => 'text',
95 'size' => 'big',
96 'serialize' => TRUE,
97 'object default' => array(),
98 'initial ' => array(),
99 ),
100 'cache' => array(
101 'type' => 'text',
102 'serialize' => TRUE,
103 'object default' => array(),
104 'initial ' => array(),
105 ),
106 'title' => array(
107 'type' => 'varchar',
108 'length' => '255',
109 'default' => '',
110 ),
111 'hide_title' => array(
112 'type' => 'int',
113 'size' => 'tiny',
114 'default' => 0,
115 ),
116 ),
117 'primary key' => array('did'),
118 );
119
120 $schema['panels_pane'] = array(
121 'export' => array(
122 'can disable' => FALSE,
123 'identifier' => 'pane',
124 'bulk export' => FALSE,
125 ),
126 'fields' => array(
127 'pid' => array(
128 'type' => 'serial',
129 'not null' => TRUE,
130 ),
131 'did' => array(
132 'type' => 'int',
133 'not null' => TRUE,
134 'default' => 0,
135 'no export' => TRUE,
136 ),
137 'panel' => array(
138 'type' => 'varchar',
139 'length' => '32',
140 'default' => '',
141 ),
142 'type' => array(
143 'type' => 'varchar',
144 'length' => '32',
145 'default' => '',
146 ),
147 'subtype' => array(
148 'type' => 'varchar',
149 'length' => '64',
150 'default' => '',
151 ),
152 'shown' => array(
153 'type' => 'int',
154 'size' => 'tiny',
155 'default' => 1,
156 ),
157 'access' => array(
158 'type' => 'text',
159 'size' => 'big',
160 'serialize' => TRUE,
161 'object default' => array(),
162 'initial ' => array(),
163 ),
164 'configuration' => array(
165 'type' => 'text',
166 'size' => 'big',
167 'serialize' => TRUE,
168 'object default' => array(),
169 'initial ' => array(),
170 ),
171 'cache' => array(
172 'type' => 'text',
173 'size' => 'big',
174 'serialize' => TRUE,
175 'object default' => array(),
176 'initial ' => array(),
177 ),
178 'style' => array(
179 'type' => 'text',
180 'size' => 'big',
181 'serialize' => TRUE,
182 'object default' => array(),
183 'initial ' => array(),
184 ),
185 'css' => array(
186 'type' => 'text',
187 'size' => 'big',
188 'serialize' => TRUE,
189 'object default' => array(),
190 'initial ' => array(),
191 ),
192 'extras' => array(
193 'type' => 'text',
194 'size' => 'big',
195 'serialize' => TRUE,
196 'object default' => array(),
197 'initial ' => array(),
198 ),
199 'position' => array(
200 'type' => 'int',
201 'size' => 'small',
202 'default' => 0,
203 ),
204 ),
205 'primary key' => array('pid'),
206 'indexes' => array(
207 'did_idx' => array('did')
208 ),
209 );
210
211 return $schema;
212}
213
214/**
215 * Implementation of hook_install().
216 */
217function panels_install() {
218 drupal_install_schema('panels');
219}
220
221/**
222 * Implementation of hook_uninstall().
223 */
224function panels_uninstall() {
225 drupal_uninstall_schema('panels');
226}
227
228function panels_update_1000() {
229 // Panels D6 2 had *no* update functions in it, so the schema version is
230 // completely wrong. If we run this update with no schema version, we
231 // were actually that version and we must therefore skip to the proper
232 // update.
233 if (db_table_exists('panels_pane')) {
234 $GLOBALS['SKIP_PANELS_UPDATES'] = TRUE;
235 return array();
236 }
237 $ret = array();
238
239 $ret[] = update_sql("ALTER TABLE {panels_info} RENAME {panels_page}");
240 $ret[] = update_sql("ALTER TABLE {panels_page} CHANGE COLUMN did pid int(10) NOT NULL DEFAULT 0;");
241 $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN did int(10) NOT NULL DEFAULT 0 AFTER pid");
242 $ret[] = update_sql("UPDATE {panels_page} SET did = pid");
243
244 $max_pid = db_result(db_query("SELECT MAX(pid) FROM {panels_page}"));
245 if ($max_pid) {
246 $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{panels_page}_pid', $max_pid)");
247 }
248
249 $ret[] = update_sql("ALTER TABLE {panels_area} RENAME {panels_pane}");
250 $ret[] = update_sql("ALTER TABLE {panels_pane} ADD COLUMN pid int(10) NOT NULL DEFAULT 0 FIRST");
251 $ret[] = update_sql("ALTER TABLE {panels_pane} CHANGE area panel varchar(32)");
252 $result = db_query("SELECT * FROM {panels_pane}");
253 while ($pane = db_fetch_object($result)) {
254 $count++;
255 $ret[] = update_sql("UPDATE {panels_pane} SET pid = $count WHERE did = $pane->did AND panel = '$pane->panel' AND position = $pane->position");
256 }
257 if ($count) {
258 $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{panels_pane}_pid', $count)");
259 }
260
261 $ret[] = update_sql(<<<EOT
262 CREATE TABLE {panels_display} (
263 did INT(10) NOT NULL DEFAULT 0 PRIMARY KEY,
264 layout VARCHAR(32)
265 ) /*!40100 DEFAULT CHARACTER SET utf8 */
266EOT
267 );
268 $result = db_query("SELECT did, layout FROM {panels_page}");
269 $max_did = 0;
270 while ($display = db_fetch_object($result)) {
271 $ret[] = update_sql("INSERT INTO {panels_display} VALUES ($display->did, '$display->layout')");
272 if ($display->did > $max_did) {
273 $max_did = $display->did;
274 }
275 }
276 $ret[] = update_sql("ALTER TABLE {panels_page} DROP COLUMN layout");
277 if ($max_did) {
278 $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{panels_display}_did', $max_did)");
279 }
280 return $ret;
281}
282
283function panels_update_1001() {
284 if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
285 return array();
286 }
287 $ret = array();
288 $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN no_blocks int(1)");
289 $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN menu int(1) DEFAULT 0");
290 $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN menu_tab int(1)");
291 $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN menu_tab_weight int(4)");
292 $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN menu_title varchar(255)");
293 $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN menu_tab_default int(1)");
294 $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN menu_tab_default_parent_type varchar(10)");
295 $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN menu_parent_title varchar(255)");
296 $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN menu_parent_tab_weight int(4)");
297 return $ret;
298}
299
300// Create a field for the layout settings
301function panels_update_1002() {
302 if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
303 return array();
304 }
305 $ret = array();
306 $ret[] = update_sql("ALTER TABLE {panels_display} ADD COLUMN layout_settings longtext");
307 $ret[] = update_sql("ALTER TABLE {panels_pane} ADD COLUMN access varchar(128) AFTER type");
308 $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN css longtext AFTER css_id");
309 return $ret;
310}
311
312// Create a field for the panel settings.
313function panels_update_1003() {
314 if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
315 return array();
316 }
317 $ret = array();
318 $ret[] = update_sql("ALTER TABLE {panels_display} ADD COLUMN panel_settings longtext");
319 return $ret;
320}
321
322// Kept up updates from older versions of Panels 2 for D5 to smooth updates.
323// Create a field for the panel settings.
324// Renumbering to proper numbering scheme.
325function panels_update_5204() {
326 if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
327 return array();
328 }
329 $ret = array();
330 $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN name varchar(255) UNIQUE");
331 $ret[] = update_sql("ALTER TABLE {panels_display} ADD COLUMN name varchar(255) UNIQUE");
332 // Give all our panels a name.
333 $ret[] = update_sql("UPDATE {panels_page} SET name = CONCAT('panel_page_', pid)");
334 $ret[] = update_sql("UPDATE {panels_display} SET name = CONCAT('display_', did)");
335 return $ret;
336}
337
338// Add the arguments field
339function panels_update_5205() {
340 if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
341 return array();
342 }
343 $ret = array();
344 $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN arguments longtext");
345 return $ret;
346}
347
348// Add a field so that panes can remember their subtype so we can retrieve
349// context information about it.
350function panels_update_5206() {
351 if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
352 return array();
353 }
354 $ret = array();
355 $ret[] = update_sql("ALTER TABLE {panels_pane} ADD COLUMN subtype varchar(64)");
356 return $ret;
357}
358
359// Add fields for displays and extra contexts
360function panels_update_5207() {
361 if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
362 return array();
363 }
364 $ret = array();
365 $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN displays longtext");
366 $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN contexts longtext");
367 return $ret;
368}
369
370// Correct the mistaken {panels_display}_id when it should be {panels_display}_did
371function panels_update_5208() {
372 if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
373 return array();
374 }
375 $ret = array();
376 $count = db_result(db_query("SELECT MAX(did) FROM {panels_display}"));
377 $ret[] = update_sql("DELETE FROM {sequences} WHERE name = '{panels_display}_did'");
378 $ret[] = update_sql("DELETE FROM {sequences} WHERE name = '{panels_display}_id'");
379 if ($count) {
380 $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{panels_display}_did',
381 $count)");
382 }
383
384 return $ret;
385}
386
387// Update argument, relationship and context code to be more correct.
388function panels_update_5209() {
389 if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
390 return array();
391 }
392 $ret = array();
393 $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN relationships longtext");
394 $result = db_query("SELECT * FROM {panels_page}");
395
396 // This code removed due to call to panels_get_argument(). People with
397 // older versions will just have to suffer.
398 return $ret;
399 panels_load_include('plugins');
400
401 while ($page = db_fetch_object($result)) {
402 $args = unserialize($page->arguments);
403 $arguments = $ids = $keywords = array();
404 if (!empty($args)) {
405 // Update each argument
406 foreach ($args as $id => $argument) {
407 $name = $argument['name'];
408 $info = panels_get_argument($name);
409 if (!$info) {
410 continue;
411 }
412 // Make sure the id is valid
413 if (empty($argument['id'])) {
414 if (empty($ids[$name])) {
415 $ids[$name] = 1;
416 }
417 else {
418 $ids[$name]++;
419 }
420
421 $argument['id'] = $ids[$name];
422 }
423
424 // Give it an identifier if it doesn't already have one
425 if (empty($argument['identifier'])) {
426 $argument['identifier'] = $info['title'] . ($id > 1 ? ' ' . $id : '');
427 error_log($argument['identifier']);
428 }
429
430 // Give it a unique keyword if it doesn't already have one
431 if (empty($argument['keyword'])) {
432 $keyword = $base = $info['keyword'];
433 $count = 0;
434 while (!empty($keywords[$keyword])) {
435 $keyword = $base . '_' . ++$count;
436 }
437 $keywords[$keyword] = TRUE;
438 $argument['keyword'] = $keyword;
439 error_log($argument['keyword']);
440 }
441 $arguments[$id] = $argument;
442 }
443 }
444 // Move old relationships (stored as contexts) to relationships, where
445 // the belong
446 $rels = unserialize($page->contexts);
447 // Not resetting $keywords!
448 $relationships = $ids = array();
449 if (!empty($rels)) {
450 foreach ($rels as $id => $relationship) {
451 $name = $relationship['name'];
452 $info = panels_get_relationship($name);
453 if (!$info) {
454 continue;
455 }
456 // Make sure the id is valid
457 if (empty($relationship['id'])) {
458 if (empty($ids[$name])) {
459 $ids[$name] = 1;
460 }
461 else {
462 $ids[$name]++;
463 }
464
465 $relationship['id'] = $ids[$name];
466 }
467
468 // Give it an identifier if it doesn't already have one
469 if (empty($relationship['identifier'])) {
470 $relationship['identifier'] = $info['title'] . ($id > 1 ? ' ' . $id : '');
471 }
472
473 // Give it a unique keyword if it doesn't already have one
474 if (empty($relationship['keyword'])) {
475 $keyword = $base = $info['keyword'];
476 $count = 0;
477 while (!empty($keywords[$keyword])) {
478 $keyword = $base . '_' . ++$count;
479 }
480 $keywords[$keyword] = TRUE;
481 $relationship['keyword'] = $keyword;
482 }
483 $relationships[$id] = $relationship;
484 }
485 }
486 db_query("UPDATE {panels_page} " .
487 "SET arguments = '%s', " .
488 "relationships = '%s', " .
489 "contexts = '%s' " .
490 "WHERE pid = $page->pid", serialize($arguments), serialize($relationships), serialize(array()), $page->pid
491 );
492 }
493 return $ret;
494}
495
496function panels_update_5210() {
497 if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
498 return array();
499 }
500 $ret = array();
501 $ret[] = update_sql("UPDATE {system} SET weight = 10 WHERE name = 'panels'");
502 return $ret;
503}
504
505/**
506 * Force a menu update
507 */
508function panels_update_5211() {
509// menu_rebuild();
510 return array();
511}
512
513/**
514 * Add a field to store pane caching information.
515 */
516function panels_update_5213() {
517 if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
518 return array();
519 }
520 $ret = array();
521 switch ($GLOBALS['db_type']) {
522 case 'mysql':
523 case 'mysqli':
524 $ret[] = update_sql("ALTER TABLE {panels_pane} ADD COLUMN cache longtext AFTER configuration");
525 $ret[] = update_sql("ALTER TABLE {panels_display} ADD COLUMN cache longtext AFTER panel_settings");
526 break;
527
528 case 'pgsql':
529 db_add_column($ret, 'panels_pane', 'cache', 'text');
530 db_add_column($ret, 'panels_display', 'cache', 'text');
531 }
532 return $ret;
533}
534
535/**
536 * Create a new table for object caching. This isn't part of the cache
537 * system.
538 */
539function panels_update_5214() {
540 if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
541 return array();
542 }
543 $ret = array();
544 return $ret;
545 switch ($GLOBALS['db_type']) {
546 case 'mysql':
547 case 'mysqli':
548 $ret[] = update_sql(<<<EOT
549 CREATE TABLE {panels_object_cache} (
550 sid varchar(64),
551 did integer,
552 obj varchar(255),
553 timestamp integer,
554 data text,
555 KEY (sid, obj, did),
556 KEY (timestamp)
557 ) /*!40100 DEFAULT CHARACTER SET utf8 */
558EOT
559 );
560 case 'pgsql':
561 }
562 return !empty($ret) ? $ret : $ret;
563}
564
565/**
566 * Increase the size of the data column in the {panels_object_cache} table
567 * on MySQL.
568 *
569 * Also gets rid of some duplicate indexes resulting the CREATE TABLE queries
570 * in the install() of schema 5214
571 */
572function panels_update_5215() {
573 if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
574 return array();
575 }
576 $ret = array();
577 switch ($GLOBALS['db_type']) {
578 case 'mysql':
579 case 'mysqli':
580 $ret[] = update_sql("ALTER TABLE {panels_pane} ADD PRIMARY KEY (pid)");
581 break;
582
583 case 'pgsql':
584 $ret[] = update_sql("ALTER TABLE {panels_pane} ADD PRIMARY KEY (pid)");
585 }
586 return $ret;
587}
588
589/**
590 * Adds the 'shown' field to the panels_pane table in order to accomodate
591 * the new show/hide panes feature.
592 */
593function panels_update_5216() {
594 if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
595 return array();
596 }
597 $ret = array();
598 switch ($GLOBALS['db_type']) {
599 case 'mysql':
600 case 'mysqli':
601 $ret[] = update_sql("ALTER TABLE {panels_pane} ADD COLUMN shown int(1) DEFAULT 1 AFTER subtype");
602 $ret[] = update_sql("ALTER TABLE {panels_display} ADD COLUMN title varchar(128) AFTER cache");
603 $ret[] = update_sql("ALTER TABLE {panels_display} ADD COLUMN hide_title int(1) AFTER title");
604 $ret[] = update_sql("ALTER TABLE {panels_display} DROP COLUMN name");
605 $ret[] = update_sql("ALTER TABLE {panels_pane} ADD COLUMN visibility text AFTER access");
606 break;
607
608 case 'pgsql':
609 db_add_column($ret, 'panels_pane', 'shown', 'tinyint', array('default' => 1));
610 db_add_column($ret, 'panels_display', 'title', 'varchar(128)');
611 db_add_column($ret, 'panels_display', 'hide_title', 'tinyint', array('default' => 0));
612 $ret = update_sql("ALTER TABLE {panels_display} DROP name");
613 db_add_column($ret, 'panels_pane', 'visibility', 'text');
614 }
615 return $ret;
616}
617
618/**
619 * Add the switcher fields to the database
620 */
621function panels_update_5217() {
622 if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
623 return array();
624 }
625 $ret = array();
626 switch ($GLOBALS['db_type']) {
627 case 'mysql':
628 case 'mysqli':
629 $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN switcher_type varchar(128) AFTER no_blocks");
630 $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN switcher_name varchar(128) AFTER no_blocks");
631 $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN switcher_options longtext AFTER switcher_type");
632 break;
633
634 case 'pgsql':
635 db_add_column($ret, 'panels_page', 'switcher_type', 'varchar(128)');
636 db_add_column($ret, 'panels_page', 'switcher_name', 'varchar(128)');
637 db_add_column($ret, 'panels_page', 'switcher_options', 'text');
638 }
639 return $ret;
640}
641
642
643/**
644 * Oversight in 5216: 'tinyint' is not a field type in pgsql; the type we wanted
645 * was 'smallint.'
646 */
647function panels_update_5218() {
648 if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
649 return array();
650 }
651 $ret = array();
652 switch ($GLOBALS['db_type']) {
653 case 'mysql':
654 case 'mysqli':
655 $ret[] = array('success' => TRUE, 'query' => t('Update #5218 only has changes for PostgreSQL. There are no updates for MySQL databases - since you\'re running MySQL, you should consider this update successful.'));
656 break;
657
658 case 'pgsql':
659 db_add_column($ret, 'panels_pane', 'shown', 'smallint', array('default' => 1));
660 db_add_column($ret, 'panels_display', 'hide_title', 'smallint', array('default' => 0));
661 $ret[] = array('success' => TRUE, 'query' => t('You can disregard failed attempts to add new columns in update #5216 as long as the two queries preceding this text were successful.'));
662 }
663 return $ret;
664}
665
666/**
667 * Update from 5.x v2
668 */
669function panels_update_5299() {
670 if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
671 return array();
672 }
673 $ret = array();
674 // Fetch schema version 1.
675 $schema = panels_schema_1();
676
677 // Certain really old versions of Panels had errors that would cause invalid
678 // panes to be written. This wipes them so that the conversion won't fail:
679 $ret[] = update_sql("DELETE FROM {panels_pane} WHERE pid = 0");
680
681 // update pid and did to be serial
682 db_drop_primary_key($ret, 'panels_pane');
683 db_change_field($ret, 'panels_pane', 'pid', 'pid', $schema['panels_pane']['fields']['pid'], array('primary key' => array('pid')));
684 db_drop_primary_key($ret, 'panels_display');
685 db_change_field($ret, 'panels_display', 'did', 'did', $schema['panels_display']['fields']['did'], array('primary key' => array('did')));
686
687 drupal_set_message(t('Please note that the Panels upgrade from Drupal 5 to Drupal 6 is far from perfect, especially where Views and CCK are involved. Please check all your panels carefully and compare them against the originals. You may need to do some rework to regain your original functionality.'));
688
689 return $ret;
690}
691
692/**
693 * Update from 6.x v2.
694 */
695function panels_update_6290() {
19a9c34c 696 $ret = array();
39d2e0e6
EM
697 if (!module_exists('panels')) {
698 $ret['#abort'] = array('success' => FALSE, 'query' => t('The Panels module cannot be updated while disabled. If you wish to update Panels, please enable it. If you do not wish to update Panels, please uninstall it.'));
699 return $ret;
700 }
19a9c34c
EM
701
702 // Fetch schema version 1.
703 $schema = panels_schema_1();
704
705 // Update size of pane 'access' field.
706 db_change_field($ret, 'panels_pane', 'access', 'access', $schema['panels_pane']['fields']['access']);
707
708 // Remove the no longer used visibility field
709 if (db_column_exists('panels_pane', 'visibility')) {
710 db_drop_field($ret, 'panels_pane', 'visibility');
711 }
712
713 // Remove panels_object_cache table
714 if (db_table_exists('panels_object_cache')) {
715 db_drop_table($ret, 'panels_object_cache');
716 }
717
718 // Doublecheck that ctools is enabled. If not, automatically disable the module.
719 if (!module_exists('ctools')) {
720 // Try to enable it:
721 drupal_install_modules(array('ctools'));
722
723 // If that fails, shut off all Panels.
724 if (!module_exists('ctools')) {
725 drupal_set_message(t('Panels now requires the Chaos Tool Suite (ctools) module to function. Panels has been disabled until you can add this module.'));
726 module_disable(array('panels', 'panels_mini', 'panels_export', 'panels_node', 'panels_simple_cache'));
727 }
728 }
729
730 if (!module_exists('page_manager') && db_table_exists('panels_page')) {
731 drupal_set_message('Page manager module has been automatically enabled to replace the Panels pages module.');
732 drupal_install_modules(array('page_manager'));
733 }
734
735 $ret[] = update_sql("DELETE FROM {system} WHERE name IN ('panels_page', 'panels_views')");
736
737 return $ret;
738}
739
740/**
741 * Special update function for the alpha2 to alpha3 transition after
742 * I messed it up.
743 */
744function panels_update_6291() {
745 $ret = array();
39d2e0e6
EM
746 if (!module_exists('panels')) {
747 $ret['#abort'] = array('success' => FALSE, 'query' => t('The Panels module cannot be updated while disabled. If you wish to update Panels, please enable it. If you do not wish to update Panels, please uninstall it.'));
748 return $ret;
749 }
750
19a9c34c
EM
751 // Fetch schema version 1.
752 $schema = panels_schema_1();
753
754
755 // Add some new fields
756 db_add_field($ret, 'panels_pane', 'style', $schema['panels_pane']['fields']['style']);
757 db_add_field($ret, 'panels_pane', 'css', $schema['panels_pane']['fields']['css']);
758 db_add_field($ret, 'panels_pane', 'extras', $schema['panels_pane']['fields']['extras']);
759
760 return $ret;
761}
762
763/**
764 * Update panels pane fields using batch API.
765 */
766function panels_update_6292(&$sandbox) {
767 $ret = array();
39d2e0e6
EM
768 if (!module_exists('panels')) {
769 $ret['#abort'] = array('success' => FALSE, 'query' => t('The Panels module cannot be updated while disabled. If you wish to update Panels, please enable it. If you do not wish to update Panels, please uninstall it.'));
770 return $ret;
771 }
19a9c34c
EM
772
773 if (!isset($sandbox['progress'])) {
774 $sandbox['progress'] = 0;
775 // We'll -1 to disregard the uid 0...
776 $sandbox['max'] = db_result(db_query('SELECT COUNT(*) FROM {panels_pane}'));
777 }
778
779 // configuration
780 $result = db_query_range("SELECT pid, access, configuration FROM {panels_pane} ORDER BY pid ASC", $sandbox['progress'], 20);
781 while ($pane = db_fetch_object($result)) {
782 // access
783 if (!empty($pane->access)) {
784 $rids = explode(', ', $pane->access);
785 // For safety, eliminate any non-numeric rids, as we occasionally had
786 // problems with nulls and such getting in here:
787 foreach ($rids as $id => $rid) {
788 if (!is_numeric($rid)) {
789 unset($rids[$id]);
790 }
791 }
792
793 if (empty($rids)) {
794 $pane->access = array();
795 }
796 else {
797 // The old access style was just a role based system, so let's convert
798 // it to that.
799 $pane->access = array(
800 'plugins' => array(
801 array(
802 'name' => 'role',
803 'context' => 'logged-in-user',
804 'settings' => array(
805 'rids' => array_values($rids),
806 )
807 ),
808 ),
809 );
810 }
811 }
812 else {
813 $pane->access = array();
814 }
815
816 // Move style from configuration.
817 $pane->configuration = unserialize($pane->configuration);
818 $pane->style = array();
819 if (!empty($pane->configuration['style'])) {
820 $pane->style['style'] = $pane->configuration['style'];
821 unset($pane->configuration['style']);
822 }
823
824 $pane->css = array();
825 // Move css configuration from configuration
826 if (isset($pane->configuration['css_id'])) {
827 $pane->css['css_id'] = $pane->configuration['css_id'];
828 unset($pane->configuration['css_id']);
829 }
830
831 if (isset($pane->configuration['css_class'])) {
832 $pane->css['css_class'] = $pane->configuration['css_class'];
833 unset($pane->configuration['css_class']);
834 }
835
836 // Make sure extras is an array. This isn't used by anything in Panels
837 // yet, so an empty array is just fine.
838 $pane->extras = array();
839 db_query("UPDATE {panels_pane} SET " .
840 "access = '%s', css = '%s', style = '%s', configuration = '%s', extras = '%s'" .
841 " WHERE pid = %d",
842 serialize($pane->access),
843 serialize($pane->css),
844 serialize($pane->style),
845 serialize($pane->configuration),
846 serialize($pane->extras),
847 $pane->pid);
848
849 $sandbox['progress']++;
850 }
851
852 $ret['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
853 if ($ret['#finished'] === 1) {
854 $ret[] = array('success' => TRUE, 'query' => t('Panel panes were updated'));
855 }
856 return $ret;
857}
858
859/**
860 * Update panels display fields using batch API.
861 */
862function panels_update_6293(&$sandbox) {
863 $ret = array();
39d2e0e6
EM
864 if (!module_exists('panels')) {
865 $ret['#abort'] = array('success' => FALSE, 'query' => t('The Panels module cannot be updated while disabled. If you wish to update Panels, please enable it. If you do not wish to update Panels, please uninstall it.'));
866 return $ret;
867 }
19a9c34c
EM
868
869 if (!isset($sandbox['progress'])) {
870 $sandbox['progress'] = 0;
871 // We'll -1 to disregard the uid 0...
872 $sandbox['max'] = db_result(db_query('SELECT COUNT(*) FROM {panels_display}'));
873 }
874
875 // configuration
876 $result = db_query_range("SELECT did, panel_settings FROM {panels_display} ORDER BY did ASC", $sandbox['progress'], 20);
877 while ($display = db_fetch_object($result)) {
878 if (empty($display->panel_settings)) {
879 $display->panel_settings = array();
880 }
881 else {
882 $display->panel_settings = unserialize($display->panel_settings);
883 if (!is_array($display->panel_settings)) {
884 $display->panel_settings = array();
885 }
886 }
887
888 if (isset($display->panel_settings['panel'])) {
889 foreach ($display->panel_settings['panel'] as $key => $settings) {
890 $display->panel_settings[$key] = $settings;
891 }
892 unset($display->panel_settings['panel']);
893 }
894
895 if (isset($display->panel_settings['individual'])) {
896 unset($display->panel_settings['individual']);
897 }
898
899 db_query("UPDATE {panels_display} SET " .
900 "panel_settings = '%s'" .
901 " WHERE did = %d",
902 serialize($display->panel_settings),
903 $display->did);
904
905 $sandbox['progress']++;
906 }
907
908 $ret['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
909 if ($ret['#finished'] === 1) {
910 $ret[] = array('success' => TRUE, 'query' => t('Panel displays were updated'));
911 }
912 return $ret;
913}
914
915/**
916 * Establish a baseline schema version for 6.x-3.x
917 */
918function panels_update_6300() {
919 return array();
920}
921
922function panels_update_6302() {
923 $ret = array();
39d2e0e6
EM
924 if (!module_exists('panels')) {
925 $ret['#abort'] = array('success' => FALSE, 'query' => t('The Panels module cannot be updated while disabled. If you wish to update Panels, please enable it. If you do not wish to update Panels, please uninstall it.'));
926 return $ret;
927 }
19a9c34c
EM
928
929 if (!module_exists('page_manager') && db_table_exists('panels_page')) {
930 $ret['#abort'] = array('success' => FALSE, 'query' => t('Conversion of panels pages cannot be completed without page manager module from CTools installed. Please install CTools, activate page manager, and attempt the update again.'));
931 return $ret;
932 }
933
934 if (!db_table_exists('panels_page')) {
935 return $ret;
936 }
937
938 // Store the node edit handlers because we merged the edit/add path and we
939 // need to be able to keep these together to make sure the names work ok.
940 $node_edit_handlers = array();
941 page_manager_get_task('page');
942 $result = db_query("SELECT * FROM {panels_page}");
943 while ($p = db_fetch_object($result)) {
944 $page = page_manager_page_new();
945 $page->default_handlers = array();
946 // Should we check for uniqueness here? It doesn't seem really
947 // plausible that there could be page manager pages already.
948 $page->name = $p->name;
949 $page->task = 'page'; // could become custom later.
950 $page->subtask = $p->name;
951 $page->admin_title = $p->name;
952 $page->path = $p->path;
953 // convert access
954 if (!empty($p->access)) {
955 $rids = explode(', ', $p->access);
956 // For safety, eliminate any non-numeric rids, as we occasionally had
957 // problems with nulls and such getting in here:
958 foreach ($rids as $id => $rid) {
959 if (!is_numeric($rid)) {
960 unset($rids[$id]);
961 }
962 }
963
964 if (empty($rids)) {
965 $page->access = array();
966 }
967 else {
968 // The old access style was just a role based system, so let's convert
969 // it to that.
970 $page->access = array(
971 'plugins' => array(
972 array(
973 'name' => 'role',
974 'context' => 'logged-in-user',
975 'settings' => array(
976 'rids' => array_values($rids),
977 )
978 ),
979 ),
980 );
981 }
982 }
983
984 // Convert menu stuff.
985 $page->menu = array(
986 'type' => 'none',
987 'title' => '',
988 'weight' => 0,
989 'name' => 'navigation',
990 'parent' => array(
991 'type' => 'none',
992 'title' => '',
993 'weight' => 0,
994 'name' => 'navigation',
995 ),
996 );
997
998 if ($p->menu) {
999 if ($p->menu_tab) {
1000 if ($p->menu_tab_default) {
1001 $page->menu['type'] = 'default tab';
1002 $page->menu['parent']['type'] = $p->menu_tab_default_parent_type;
1003 $page->menu['parent']['title'] = $p->menu_parent_title;
1004 $page->menu['parent']['weight'] = $p->menu_parent_tab_weight;
1005 }
1006 else {
1007 $page->menu['type'] = 'tab';
1008 }
1009 }
1010 else {
1011 $page->menu['type'] = 'normal';
1012 }
1013
1014 $page->menu['title'] = $p->menu_title;
1015 $page->menu['weight'] = $p->menu_tab_weight;
1016 }
1017
1018 $page->conf = array();
1019 $displays = unserialize($p->displays);
1020 $arguments = unserialize($p->arguments);
1021
1022 foreach ($arguments as $id => $argument) {
1023 $page->arguments[$argument['keyword']] = array(
1024 'name' => $argument['name'],
1025 'identifier' => $argument['identifier'],
1026 'title' => $argument['title'],
1027 'id' => $argument['id'],
1028 'settings' => isset($argument['argument_settings']) ? $argument['argument_settings'] : array(),
1029 );
1030
1031 $match = FALSE;
1032 $bits = explode('/', $page->path);
1033 foreach ($bits as $pos => $bit) {
1034 if ($bit == '%') {
1035 $bits[$pos] = '%' . $argument['keyword'];
1036 $match = TRUE;
1037 $page->path = implode('/', $bits);
1038 break;
1039 }
1040 }
1041
1042 if (!$match) {
1043 if ($argument['default'] == '404') {
1044 $page->path .= '/%' . $argument['keyword'];
1045 }
1046 else {
1047 $page->path .= '/!' . $argument['keyword'];
1048 }
1049 }
1050
1051 // save this for later use.
1052 $arguments[$id]['context'] = 'argument_' . $argument['name'] . '_' . $argument['id'];
1053 }
1054
1055 // Reset the task type here if it's one of our overrides. This ensures
1056 // that we get the right names.
1057 switch ($p->path) {
1058 case 'node/%':
1059 $page->task = 'node_view';
1060 $page->subtask = '';
a5a75857 1061 variable_set('page_manager_node_view_disabled', FALSE);
19a9c34c
EM
1062 break;
1063 case 'node/add/%':
1064 // It seems nearly impossible to actually upgrade this properly.
1065 continue;
1066 case 'node/%/edit':
1067 // Could we get conflicts here if they had both?
1068 $page->task = 'node_edit';
1069 $page->subtask = '';
a5a75857 1070 variable_set('page_manager_node_edit_disabled', FALSE);
19a9c34c
EM
1071 break;
1072 case 'taxonomy/term':
1073 case 'taxonomy/term/%':
1074 $page->task = 'term_view';
1075 $page->subtask = '';
1076 if ($arguments[0]['name'] == 'term') {
1077 variable_set('page_manager_term_view_type', 'single');
1078 }
a5a75857 1079 variable_set('page_manager_term_view_disabled', FALSE);
19a9c34c
EM
1080 break;
1081 case 'user/%':
1082 $page->task = 'user_view';
1083 $page->subtask = '';
a5a75857 1084 variable_set('page_manager_user_view_disabled', FALSE);
19a9c34c
EM
1085 break;
1086 // There is no default here.
1087 }
1088
1089 if (empty($displays)) {
1090 // only one display on this panel, mak
1091 $cache = new stdClass();
1092 if ($page->task != 'node_edit') {
1093 $cache->handlers = array();
1094 }
1095 else {
1096 $cache->handlers = $node_edit_handlers;
1097 }
1098 _panels_update_create_handler($page, $p, NULL, array('did' => $p->did, 'title' => t('Panel')), $arguments, 0, $cache);
1099 $page->default_handlers = $cache->handlers;
1100 }
1101 else {
1102 // for each display we need to create a new handler.
1103 $weight = 0;
1104 $cache = new stdClass();
1105 if ($page->task != 'node_edit') {
1106 $cache->handlers = array();
1107 }
1108 else {
1109 $cache->handlers = $node_edit_handlers;
1110 $weight = count($cache->handlers) + 1;
1111 }
1112 foreach ($displays as $origin => $info) {
1113 if (!isset($info['argument_id'])) {
1114 $info['argument_id'] = 0;
1115 }
1116
1117 _panels_update_create_handler($page, $p, $origin, $info, $arguments, $weight++, $cache);
1118 }
1119
1120 // Also add the primary display as a default with no selector.
1121// _panels_update_create_handler($page, $p, NULL, array('did' => $p->did, 'title' => t('Default')), $arguments, $weight++, $cache);
1122 $page->default_handlers = $cache->handlers;
1123 }
1124
1125 if ($page->task != 'page') {
1126 // just save the handlers.
1127 foreach ($cache->handlers as $name => $handler) {
1128 page_manager_save_task_handler($handler);
1129
1130 // Keep all node edit handlers for later use.
1131 if ($page->task == 'node_edit') {
1132 $node_edit_handlers[$name] = $handler;
1133 }
1134 }
1135 }
1136 else {
1137 page_manager_page_save($page);
1138 }
1139 }
1140
1141 $ret[] = update_sql("DROP TABLE {panels_page}");
1142
1143 // Update a couple of pane types that changed and are easily moved:
1144 switch ($GLOBALS['db_type']) {
1145 case 'mysql':
1146 case 'mysqli':
1147 $ret[] = update_sql("UPDATE {panels_pane} SET type = CONCAT(type, '_', subtype) WHERE type = 'node_form'");
1148 break;
1149
1150 case 'pgsql':
1151 $ret[] = update_sql("UPDATE {panels_pane} SET type = type || '_' || subtype WHERE type = 'node_form'");
1152 }
1153 $ret[] = update_sql("UPDATE {panels_pane} SET type = 'node_form_path' WHERE type = 'node_form_url_path'");
1154
1155 if (module_exists('ctools') && !module_exists('views_content') && db_result(db_query("SELECT pid FROM {panels_pane} WHERE type = 'views'"))) {
1156 drupal_install_modules(array('views_content'));
1157 }
1158
1159 return $ret;
1160}
1161
1162function _panels_update_create_handler($page, $p, $origin, $info, $arguments, $weight, &$cache) {
1163 $task = page_manager_get_task($page->task);
1164 $task_name = 'page-' . $page->name;
1165 $plugin = page_manager_get_task_handler('panel_context');
1166 $handler = page_manager_new_task_handler($plugin);
1167
1168 $handler->weight = $weight;
1169 $handler->task = $page->task;
a5a75857
EM
1170 if ($page->task == 'page') {
1171 $handler->subtask = $page->name;
1172 }
19a9c34c
EM
1173 $handler->export_type = EXPORT_IN_DATABASE;
1174 $handler->type = t('Normal');
1175
1176 $handler->name = page_manager_handler_get_name($task_name, $cache->handlers, $handler);
39d2e0e6 1177
19a9c34c
EM
1178 $handler->conf['css'] = $p->css;
1179 $handler->conf['css_id'] = $p->css_id;
1180 $handler->conf['no_blocks'] = $p->no_blocks;
1181 if (!empty($info['did']) && is_numeric($info['did'])) {
1182 $handler->conf['did'] = $info['did'];
1183 }
1184 else {
1185 $d = panels_load_display($p->did);
1186 if ($d) {
1187 $display_code = panels_export_display($d);
1188 eval($display_code);
1189
1190 $handler->conf['did'] = 'new';
1191 $handler->conf['display'] = $display;
1192 }
1193 }
1194 $handler->conf['title'] = !empty($info['title']) ? $info['title'] : '';
1195 $handler->conf['contexts'] = unserialize($p->contexts);
1196 $handler->conf['relationships'] = unserialize($p->relationships);
1197
1198 if ($origin && strpos($origin, '-')) {
1199 $handler->conf['access'] = array(
1200 'logic' => 'and',
1201 'plugins' => array(),
1202 );
1203
1204 // Only 4 types of arguments supported having their own displays:
1205 // nid, node_add_form, node_edit_form and term. 3 of those simply used
1206 // node type and the last simply used vocabulary.
1207 list($junk, $key) = explode('-', $origin);
1208 if ($key && $key != 'default') {
1209 if ($arguments[$info['argument_id']]['name'] == 'term') {
1210 $handler->conf['access']['plugins'][] = array(
1211 'name' => 'term_vocabulary',
1212 'context' => $arguments[$info['argument_id']]['context'],
1213 'settings' => array(
1214 'vids' => array($key),
1215 ),
1216 );
1217 }
1218 else {
1219 $handler->conf['access']['plugins'][] = array(
1220 'name' => 'node_type',
1221 'context' => $arguments[$info['argument_id']]['context'],
1222 'settings' => array(
1223 'type' => array($key),
1224 ),
1225 );
1226 }
1227 }
1228 else {
1229 // make sure defaults float to the bottom:
1230 $handler->weight += 100;
1231 }
1232 }
1233 $cache->handlers[$handler->name] = $handler;
1234
1235 return $handler;
1236}
1237
1238/**
1239 * Ensure the panels_simple_cache module does not exist.
1240 */
1241function panels_update_6303() {
1242 $ret = array();
1243 if (module_exists('panels_simple_cache')) {
1244 drupal_set_message(t('Your installation contains a module that no longer exists. When updating modules, you should always remove the module directory first, then replace it with the new code. The "Panels Simple Cache" module is being automatically disabled for you. Please do not re-enable it as it will cause your system to crash.'));
1245 $ret[] = update_sql("DELETE FROM {system} WHERE name = 'panels_simple_cache'");
1246 }
1247
1248 return $ret;
1249}
1250
1251/**
1252 * Ensure that users are informed about the page manager module.
1253 */
1254function panels_update_6304() {
1255 if (!module_exists('page_manager')) {
1256 drupal_set_message(t('The delegator module has been replaced by the Page Manager module. You should enable the page manager module to ensure that any panel pages you have will not be lost.'));
1257 }
1258
1259 return array();
1260}
4bac51cf
EM
1261
1262/**
1263 * Add the title_pane field.
1264 */
1265function panels_update_6305() {
1266 $ret = array();
1267
1268 // Fetch schema version 2.
1269 $schema = panels_schema_2();
1270
1271 // Add new field
1272 db_add_field($ret, 'panels_display', 'title_pane', $schema['panels_display']['fields']['title_pane']);
1273
1274 return $ret;
1275}