panels.install 19 KB

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