panels.install 19 KB

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