panels.install 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. <?php
  2. /**
  3. * Test requirements for installation and running.
  4. */
  5. function panels_requirements($phase) {
  6. $function = "panels_requirements_$phase";
  7. return function_exists($function) ? $function() : array();
  8. }
  9. /**
  10. * Check install-time requirements.
  11. */
  12. function panels_requirements_install() {
  13. $requirements = array();
  14. $t = get_t();
  15. // Assume that if the user is running an installation profile that both
  16. // Panels and CTools are the same release.
  17. if (!(defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'install')) {
  18. // Apparently the install process doesn't include .module files,
  19. // so we need to force the issue in order for our versioning
  20. // check to work.
  21. if (!defined('PANELS_REQUIRED_CTOOLS_API')) {
  22. include_once drupal_get_path('module', 'panels') . '/panels.module';
  23. }
  24. // In theory we should check module_exists, but Drupal's gating should
  25. // actually prevent us from getting here otherwise.
  26. if (!defined('CTOOLS_API_VERSION')) {
  27. include_once drupal_get_path('module', 'ctools') . '/ctools.module';
  28. }
  29. if (!module_invoke('ctools', 'api_version', PANELS_REQUIRED_CTOOLS_API)) {
  30. $requirements['panels_ctools'] = array(
  31. 'title' => $t('CTools API Version'),
  32. 'value' => CTOOLS_API_VERSION,
  33. 'severity' => REQUIREMENT_ERROR,
  34. 'description' => t('The CTools API version is too old for Panels. Panels needs at least %version.', array('%version' => PANELS_REQUIRED_CTOOLS_API)),
  35. );
  36. }
  37. }
  38. return $requirements;
  39. }
  40. /**
  41. * Implements of hook_schema().
  42. */
  43. function panels_schema() {
  44. // This should always point to our 'current' schema. This makes it relatively
  45. // easy to keep a record of schema as we make changes to it.
  46. return panels_schema_8();
  47. }
  48. function panels_schema_8() {
  49. $schema = panels_schema_7();
  50. // Add the storage type and id columns.
  51. $schema['panels_display']['fields']['storage_type'] = array(
  52. 'type' => 'varchar',
  53. 'length' => 255,
  54. 'default' => '',
  55. );
  56. $schema['panels_display']['fields']['storage_id'] = array(
  57. 'type' => 'varchar',
  58. 'length' => 255,
  59. 'default' => '',
  60. );
  61. return $schema;
  62. }
  63. function panels_schema_7() {
  64. $schema = panels_schema_6();
  65. // Update field lengths to 255 chars.
  66. $schema['panels_pane']['fields']['subtype']['length'] = '255';
  67. $schema['panels_pane']['fields']['panel']['length'] = '255';
  68. $schema['panels_pane']['fields']['type']['length'] = '255';
  69. return $schema;
  70. }
  71. function panels_schema_6() {
  72. $schema = panels_schema_5();
  73. $schema['cache_panels'] = drupal_get_schema_unprocessed('system', 'cache');
  74. return $schema;
  75. }
  76. function panels_schema_5() {
  77. $schema = panels_schema_4();
  78. $schema['panels_display']['fields']['uuid'] = array(
  79. 'type' => 'char',
  80. 'length' => '36',
  81. );
  82. $schema['panels_display']['export']['key'] = 'uuid';
  83. $schema['panels_display']['export']['key name'] = 'UUID';
  84. $schema['panels_pane']['fields']['uuid'] = array(
  85. 'type' => 'char',
  86. 'length' => '36',
  87. );
  88. $schema['panels_pane']['export']['key'] = 'uuid';
  89. $schema['panels_pane']['export']['key name'] = 'UUID';
  90. return $schema;
  91. }
  92. function panels_schema_4() {
  93. $schema = panels_schema_3();
  94. $schema['panels_pane']['fields']['locks'] = array(
  95. 'type' => 'text',
  96. 'size' => 'big',
  97. 'serialize' => TRUE,
  98. 'object default' => array(),
  99. 'initial' => array(),
  100. );
  101. return $schema;
  102. }
  103. /**
  104. * Schema from the D6 version.
  105. */
  106. function panels_schema_3() {
  107. // Schema 3 is now locked. If you need to make changes, please create
  108. // schema 4 and add them.
  109. $schema = array();
  110. $schema['panels_display'] = array(
  111. 'export' => array(
  112. 'object' => 'panels_display',
  113. 'bulk export' => FALSE,
  114. 'export callback' => 'panels_export_display',
  115. 'can disable' => FALSE,
  116. 'identifier' => 'display',
  117. ),
  118. 'fields' => array(
  119. 'did' => array(
  120. 'type' => 'serial',
  121. 'not null' => TRUE,
  122. 'no export' => TRUE,
  123. ),
  124. 'layout' => array(
  125. 'type' => 'varchar',
  126. 'length' => '255',
  127. 'default' => '',
  128. ),
  129. 'layout_settings' => array(
  130. 'type' => 'text',
  131. 'size' => 'big',
  132. 'serialize' => TRUE,
  133. 'object default' => array(),
  134. 'initial' => array(),
  135. ),
  136. 'panel_settings' => array(
  137. 'type' => 'text',
  138. 'size' => 'big',
  139. 'serialize' => TRUE,
  140. 'object default' => array(),
  141. 'initial' => array(),
  142. ),
  143. 'cache' => array(
  144. 'type' => 'text',
  145. 'serialize' => TRUE,
  146. 'object default' => array(),
  147. 'initial' => array(),
  148. ),
  149. 'title' => array(
  150. 'type' => 'varchar',
  151. 'length' => '255',
  152. 'default' => '',
  153. ),
  154. 'hide_title' => array(
  155. 'type' => 'int',
  156. 'size' => 'tiny',
  157. 'default' => 0,
  158. 'no export' => TRUE,
  159. ),
  160. 'title_pane' => array(
  161. 'type' => 'int',
  162. 'default' => 0,
  163. 'no export' => TRUE,
  164. ),
  165. ),
  166. 'primary key' => array('did'),
  167. );
  168. $schema['panels_pane'] = array(
  169. 'export' => array(
  170. 'can disable' => FALSE,
  171. 'identifier' => 'pane',
  172. 'bulk export' => FALSE,
  173. ),
  174. 'fields' => array(
  175. 'pid' => array(
  176. 'type' => 'serial',
  177. 'not null' => TRUE,
  178. ),
  179. 'did' => array(
  180. 'type' => 'int',
  181. 'not null' => TRUE,
  182. 'default' => 0,
  183. 'no export' => TRUE,
  184. ),
  185. 'panel' => array(
  186. 'type' => 'varchar',
  187. 'length' => '32',
  188. 'default' => '',
  189. ),
  190. 'type' => array(
  191. 'type' => 'varchar',
  192. 'length' => '32',
  193. 'default' => '',
  194. ),
  195. 'subtype' => array(
  196. 'type' => 'varchar',
  197. 'length' => '64',
  198. 'default' => '',
  199. ),
  200. 'shown' => array(
  201. 'type' => 'int',
  202. 'size' => 'tiny',
  203. 'default' => 1,
  204. ),
  205. 'access' => array(
  206. 'type' => 'text',
  207. 'size' => 'big',
  208. 'serialize' => TRUE,
  209. 'object default' => array(),
  210. 'initial' => array(),
  211. ),
  212. 'configuration' => array(
  213. 'type' => 'text',
  214. 'size' => 'big',
  215. 'serialize' => TRUE,
  216. 'object default' => array(),
  217. 'initial' => array(),
  218. ),
  219. 'cache' => array(
  220. 'type' => 'text',
  221. 'size' => 'big',
  222. 'serialize' => TRUE,
  223. 'object default' => array(),
  224. 'initial' => array(),
  225. ),
  226. 'style' => array(
  227. 'type' => 'text',
  228. 'size' => 'big',
  229. 'serialize' => TRUE,
  230. 'object default' => array(),
  231. 'initial' => array(),
  232. ),
  233. 'css' => array(
  234. 'type' => 'text',
  235. 'size' => 'big',
  236. 'serialize' => TRUE,
  237. 'object default' => array(),
  238. 'initial' => array(),
  239. ),
  240. 'extras' => array(
  241. 'type' => 'text',
  242. 'size' => 'big',
  243. 'serialize' => TRUE,
  244. 'object default' => array(),
  245. 'initial' => array(),
  246. ),
  247. 'position' => array(
  248. 'type' => 'int',
  249. 'size' => 'small',
  250. 'default' => 0,
  251. ),
  252. ),
  253. 'primary key' => array('pid'),
  254. 'indexes' => array(
  255. 'did_idx' => array('did')
  256. ),
  257. );
  258. $schema['panels_renderer_pipeline'] = array(
  259. 'description' => 'Contains renderer pipelines for Panels. Each pipeline contains one or more renderers and access rules to select which renderer gets used.',
  260. 'export' => array(
  261. 'identifier' => 'pipeline',
  262. 'bulk export' => TRUE,
  263. 'primary key' => 'rpid',
  264. 'api' => array(
  265. 'owner' => 'panels',
  266. 'api' => 'pipelines',
  267. 'minimum_version' => 1,
  268. 'current_version' => 1,
  269. ),
  270. ),
  271. 'fields' => array(
  272. 'rpid' => array(
  273. 'type' => 'serial',
  274. 'description' => 'A database primary key to ensure uniqueness.',
  275. 'not null' => TRUE,
  276. 'no export' => TRUE,
  277. ),
  278. 'name' => array(
  279. 'type' => 'varchar',
  280. 'length' => '255',
  281. 'description' => 'Unique ID for this content. Used to identify it programmatically.',
  282. ),
  283. 'admin_title' => array(
  284. 'type' => 'varchar',
  285. 'length' => '255',
  286. 'description' => 'Administrative title for this pipeline.',
  287. ),
  288. 'admin_description' => array(
  289. 'type' => 'text',
  290. 'size' => 'big',
  291. 'description' => 'Administrative description for this pipeline.',
  292. 'object default' => '',
  293. ),
  294. 'weight' => array(
  295. 'type' => 'int',
  296. 'size' => 'small',
  297. 'default' => 0,
  298. ),
  299. 'settings' => array(
  300. 'type' => 'text',
  301. 'size' => 'big',
  302. 'description' => 'Serialized settings for the actual pipeline. The contents of this field are up to the plugin that uses it.',
  303. 'serialize' => TRUE,
  304. 'object default' => array(),
  305. ),
  306. ),
  307. 'primary key' => array('rpid'),
  308. );
  309. $schema['panels_layout'] = array(
  310. 'description' => 'Contains exportable customized layouts for this site.',
  311. 'export' => array(
  312. 'identifier' => 'layout',
  313. 'bulk export' => TRUE,
  314. 'primary key' => 'lid',
  315. 'api' => array(
  316. 'owner' => 'panels',
  317. 'api' => 'layouts',
  318. 'minimum_version' => 1,
  319. 'current_version' => 1,
  320. ),
  321. ),
  322. 'fields' => array(
  323. 'lid' => array(
  324. 'type' => 'serial',
  325. 'description' => 'A database primary key to ensure uniqueness.',
  326. 'not null' => TRUE,
  327. 'no export' => TRUE,
  328. ),
  329. 'name' => array(
  330. 'type' => 'varchar',
  331. 'length' => '255',
  332. 'description' => 'Unique ID for this content. Used to identify it programmatically.',
  333. ),
  334. 'admin_title' => array(
  335. 'type' => 'varchar',
  336. 'length' => '255',
  337. 'description' => 'Administrative title for this layout.',
  338. ),
  339. 'admin_description' => array(
  340. 'type' => 'text',
  341. 'size' => 'big',
  342. 'description' => 'Administrative description for this layout.',
  343. 'object default' => '',
  344. ),
  345. 'category' => array(
  346. 'type' => 'varchar',
  347. 'length' => '255',
  348. 'description' => 'Administrative category for this layout.',
  349. ),
  350. 'plugin' => array(
  351. 'type' => 'varchar',
  352. 'length' => '255',
  353. 'description' => 'The layout plugin that owns this layout.',
  354. ),
  355. 'settings' => array(
  356. 'type' => 'text',
  357. 'size' => 'big',
  358. 'description' => 'Serialized settings for the actual layout. The contents of this field are up to the plugin that uses it.',
  359. 'serialize' => TRUE,
  360. 'object default' => array(),
  361. ),
  362. ),
  363. 'primary key' => array('lid'),
  364. );
  365. return $schema;
  366. }
  367. /**
  368. * Change panels_display.layout to match the size of panels_layout.name.
  369. */
  370. function panels_update_7300() {
  371. // Load the schema.
  372. $schema = panels_schema_3();
  373. $table = 'panels_display';
  374. $field = 'layout';
  375. $spec = $schema[$table]['fields'][$field];
  376. // Re-define the column.
  377. db_change_field($table, $field, $field, $spec);
  378. return t('Changed the panels_display.layout field to the correct size.');
  379. }
  380. /**
  381. * Add lock field to panels_pane table.
  382. */
  383. function panels_update_7301() {
  384. // Load the schema.
  385. // Due to a previous failure, the field may already exist:
  386. $schema = panels_schema_4();
  387. $table = 'panels_pane';
  388. $field = 'locks';
  389. if (!db_field_exists($table, $field)) {
  390. $spec = $schema[$table]['fields'][$field];
  391. // Core does not properly respect 'initial' and 'serialize'.
  392. unset($spec['initial']);
  393. // Re-define the column.
  394. db_add_field($table, $field, $spec);
  395. return t('Added panels_pane.lock field.');
  396. }
  397. return t('panels_pane.lock field already existed, update skipped.');
  398. }
  399. /**
  400. * Adding universally unique identifiers to panels.
  401. *
  402. * Note: This update hook is not written well. It calls apis which uses the
  403. * most updated drupal database, causing missing columns or tables errors. To
  404. * mitigate the issue, we've added updates from 7303 and 7305. Future updates
  405. * should go below the 7305 update.
  406. *
  407. * See https://www.drupal.org/node/2787123 for more info.
  408. */
  409. function panels_update_7302() {
  410. if (!module_load_include('inc', 'ctools', 'includes/uuid')) {
  411. throw new DrupalUpdateException(t('Ctools UUID support not detected. You must update to a more recent version of the ctools module.'));
  412. }
  413. // Run the 7303 update first to avoid caching issues.
  414. // This *probably* should be placed right above update 7305, however it was
  415. // tested here and re-testing this update is difficult, so it stays here.
  416. panels_update_7303();
  417. // Load the schema.
  418. $schema = panels_schema_5();
  419. $msg = array();
  420. // Add the uuid column to the pane table.
  421. $table = 'panels_pane';
  422. $field = 'uuid';
  423. // Due to a previous failure, the column may already exist:
  424. if (!db_field_exists($table, $field)) {
  425. $spec = $schema[$table]['fields'][$field];
  426. db_add_field($table, $field, $spec);
  427. $msg[] = t('Added panels_pane.uuid column.');
  428. }
  429. // Add the uuid column to the display table.
  430. $table = 'panels_display';
  431. $field = 'uuid';
  432. // Due to a previous failure, the column may already exist:
  433. if (!db_field_exists($table, $field)) {
  434. $spec = $schema[$table]['fields'][$field];
  435. db_add_field($table, $field, $spec);
  436. $msg[] = t('Added panels_display.uuid column.');
  437. }
  438. if (empty($msg)) {
  439. $msg[] = t('UUID column already present in the panels_display & panels_pane tables.');
  440. }
  441. // Update all DB-based panes & displays to ensure that they all contain a UUID.
  442. $display_dids = db_select('panels_display')
  443. ->fields('panels_display', array('did'))
  444. ->condition(db_or()
  445. ->condition('uuid', '')
  446. ->isNull('uuid')
  447. )
  448. ->execute()
  449. ->fetchCol();
  450. // Check the panes as well, for paranoia.
  451. $pane_dids = db_select('panels_pane')
  452. ->distinct()
  453. ->fields('panels_pane', array('did'))
  454. ->condition(db_or()
  455. ->condition('uuid', '')
  456. ->isNull('uuid')
  457. )
  458. ->execute()
  459. ->fetchCol();
  460. $dids = array_unique(array_merge($display_dids, $pane_dids));
  461. // Before using panels_save_display(), we have to make sure any new fields
  462. // are added from future updates.
  463. panels_update_7305();
  464. // If the Panels module is disabled we don't have access to
  465. // panels_load_displays().
  466. if (!function_exists('panels_load_displays')) {
  467. module_load_include('module', 'panels');
  468. }
  469. if ($displays = panels_load_displays($dids)) {
  470. foreach ($displays as $display) {
  471. // A display save also triggers pane saves.
  472. panels_save_display($display);
  473. }
  474. $msg[] = t('Generated UUIDs for database-based panel displays and panes.');
  475. }
  476. else {
  477. $msg[] = t('No database-based panel displays or panes for which to generate UUIDs.');
  478. }
  479. return implode("\n", $msg);
  480. }
  481. /**
  482. * Add a custom cache table for Panels.
  483. */
  484. function panels_update_7303() {
  485. $schema = panels_schema_6();
  486. $table_name = 'cache_panels';
  487. if (!db_table_exists($table_name)) {
  488. db_create_table($table_name, $schema[$table_name]);
  489. }
  490. }
  491. /**
  492. * Update "panels_pane" table field lengths to 255 chars.
  493. */
  494. function panels_update_7304() {
  495. $schema = panels_schema_7();
  496. $update_fields = array(
  497. 'panels_pane' => array('subtype', 'panel', 'type'),
  498. );
  499. foreach($update_fields as $table => $fields) {
  500. foreach($fields as $field_name) {
  501. db_change_field($table, $field_name, $field_name, $schema[$table]['fields'][$field_name]);
  502. }
  503. }
  504. }
  505. /**
  506. * Add the "storage_type" and "storage_id" columns to "panels_display".
  507. */
  508. function panels_update_7305() {
  509. $schema = panels_schema_8();
  510. $new_fields = array(
  511. 'panels_display' => array('storage_type', 'storage_id'),
  512. );
  513. foreach ($new_fields as $table => $fields) {
  514. foreach ($fields as $field_name) {
  515. // Due to a previous failure, the column may already exist:
  516. if (!db_field_exists($table, $field_name)) {
  517. db_add_field($table, $field_name, $schema[$table]['fields'][$field_name]);
  518. }
  519. }
  520. }
  521. }
  522. /**
  523. * Set the storage type and id on existing page manager panels displays.
  524. */
  525. function panels_update_7306() {
  526. if (!db_table_exists('page_manager_handlers')) {
  527. return t('Skipping update - page_manager is not installed.');
  528. }
  529. // Get all page_manager_handlers that have a panels context.
  530. $result = db_query("SELECT pm.name, pm.conf FROM {page_manager_handlers} pm WHERE pm.handler = 'panel_context'");
  531. $page_manager_panels = array();
  532. foreach ($result as $row) {
  533. $conf = unserialize($row->conf);
  534. if (isset($conf['did'])) {
  535. $page_manager_panels[$conf['did']] = $row->name;
  536. }
  537. }
  538. if (!empty($page_manager_panels)) {
  539. // Check panels displays that only have empty storage types
  540. $result = db_query("SELECT pd.did FROM {panels_display} pd WHERE pd.did IN (:dids) AND storage_type = ''", array(':dids' => array_keys($page_manager_panels)));
  541. foreach ($result as $row) {
  542. db_update('panels_display')
  543. ->fields(array(
  544. 'storage_type' => 'page_manager',
  545. 'storage_id' => $page_manager_panels[$row->did],
  546. ))
  547. ->condition('did', $row->did)
  548. ->execute();
  549. }
  550. }
  551. }