panels.install 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  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_6();
  47. }
  48. function panels_schema_6() {
  49. $schema = panels_schema_5();
  50. $schema['cache_panels'] = drupal_get_schema_unprocessed('system', 'cache');
  51. return $schema;
  52. }
  53. function panels_schema_5() {
  54. $schema = panels_schema_4();
  55. $schema['panels_display']['fields']['uuid'] = array(
  56. 'type' => 'char',
  57. 'length' => '36',
  58. );
  59. $schema['panels_display']['export']['key'] = 'uuid';
  60. $schema['panels_display']['export']['key name'] = 'UUID';
  61. $schema['panels_pane']['fields']['uuid'] = array(
  62. 'type' => 'char',
  63. 'length' => '36',
  64. );
  65. $schema['panels_pane']['export']['key'] = 'uuid';
  66. $schema['panels_pane']['export']['key name'] = 'UUID';
  67. return $schema;
  68. }
  69. function panels_schema_4() {
  70. $schema = panels_schema_3();
  71. $schema['panels_pane']['fields']['locks'] = array(
  72. 'type' => 'text',
  73. 'size' => 'big',
  74. 'serialize' => TRUE,
  75. 'object default' => array(),
  76. 'initial' => array(),
  77. );
  78. return $schema;
  79. }
  80. /**
  81. * Schema from the D6 version.
  82. */
  83. function panels_schema_3() {
  84. // Schema 3 is now locked. If you need to make changes, please create
  85. // schema 4 and add them.
  86. $schema = array();
  87. $schema['panels_display'] = array(
  88. 'export' => array(
  89. 'object' => 'panels_display',
  90. 'bulk export' => FALSE,
  91. 'export callback' => 'panels_export_display',
  92. 'can disable' => FALSE,
  93. 'identifier' => 'display',
  94. ),
  95. 'fields' => array(
  96. 'did' => array(
  97. 'type' => 'serial',
  98. 'not null' => TRUE,
  99. 'no export' => TRUE,
  100. ),
  101. 'layout' => array(
  102. 'type' => 'varchar',
  103. 'length' => '255',
  104. 'default' => '',
  105. ),
  106. 'layout_settings' => array(
  107. 'type' => 'text',
  108. 'size' => 'big',
  109. 'serialize' => TRUE,
  110. 'object default' => array(),
  111. 'initial' => array(),
  112. ),
  113. 'panel_settings' => array(
  114. 'type' => 'text',
  115. 'size' => 'big',
  116. 'serialize' => TRUE,
  117. 'object default' => array(),
  118. 'initial' => array(),
  119. ),
  120. 'cache' => array(
  121. 'type' => 'text',
  122. 'serialize' => TRUE,
  123. 'object default' => array(),
  124. 'initial' => array(),
  125. ),
  126. 'title' => array(
  127. 'type' => 'varchar',
  128. 'length' => '255',
  129. 'default' => '',
  130. ),
  131. 'hide_title' => array(
  132. 'type' => 'int',
  133. 'size' => 'tiny',
  134. 'default' => 0,
  135. 'no export' => TRUE,
  136. ),
  137. 'title_pane' => array(
  138. 'type' => 'int',
  139. 'default' => 0,
  140. 'no export' => TRUE,
  141. ),
  142. ),
  143. 'primary key' => array('did'),
  144. );
  145. $schema['panels_pane'] = array(
  146. 'export' => array(
  147. 'can disable' => FALSE,
  148. 'identifier' => 'pane',
  149. 'bulk export' => FALSE,
  150. ),
  151. 'fields' => array(
  152. 'pid' => array(
  153. 'type' => 'serial',
  154. 'not null' => TRUE,
  155. ),
  156. 'did' => array(
  157. 'type' => 'int',
  158. 'not null' => TRUE,
  159. 'default' => 0,
  160. 'no export' => TRUE,
  161. ),
  162. 'panel' => array(
  163. 'type' => 'varchar',
  164. 'length' => '32',
  165. 'default' => '',
  166. ),
  167. 'type' => array(
  168. 'type' => 'varchar',
  169. 'length' => '32',
  170. 'default' => '',
  171. ),
  172. 'subtype' => array(
  173. 'type' => 'varchar',
  174. 'length' => '64',
  175. 'default' => '',
  176. ),
  177. 'shown' => array(
  178. 'type' => 'int',
  179. 'size' => 'tiny',
  180. 'default' => 1,
  181. ),
  182. 'access' => array(
  183. 'type' => 'text',
  184. 'size' => 'big',
  185. 'serialize' => TRUE,
  186. 'object default' => array(),
  187. 'initial' => array(),
  188. ),
  189. 'configuration' => array(
  190. 'type' => 'text',
  191. 'size' => 'big',
  192. 'serialize' => TRUE,
  193. 'object default' => array(),
  194. 'initial' => array(),
  195. ),
  196. 'cache' => array(
  197. 'type' => 'text',
  198. 'size' => 'big',
  199. 'serialize' => TRUE,
  200. 'object default' => array(),
  201. 'initial' => array(),
  202. ),
  203. 'style' => array(
  204. 'type' => 'text',
  205. 'size' => 'big',
  206. 'serialize' => TRUE,
  207. 'object default' => array(),
  208. 'initial' => array(),
  209. ),
  210. 'css' => array(
  211. 'type' => 'text',
  212. 'size' => 'big',
  213. 'serialize' => TRUE,
  214. 'object default' => array(),
  215. 'initial' => array(),
  216. ),
  217. 'extras' => array(
  218. 'type' => 'text',
  219. 'size' => 'big',
  220. 'serialize' => TRUE,
  221. 'object default' => array(),
  222. 'initial' => array(),
  223. ),
  224. 'position' => array(
  225. 'type' => 'int',
  226. 'size' => 'small',
  227. 'default' => 0,
  228. ),
  229. ),
  230. 'primary key' => array('pid'),
  231. 'indexes' => array(
  232. 'did_idx' => array('did')
  233. ),
  234. );
  235. $schema['panels_renderer_pipeline'] = array(
  236. 'description' => 'Contains renderer pipelines for Panels. Each pipeline contains one or more renderers and access rules to select which renderer gets used.',
  237. 'export' => array(
  238. 'identifier' => 'pipeline',
  239. 'bulk export' => TRUE,
  240. 'primary key' => 'rpid',
  241. 'api' => array(
  242. 'owner' => 'panels',
  243. 'api' => 'pipelines',
  244. 'minimum_version' => 1,
  245. 'current_version' => 1,
  246. ),
  247. ),
  248. 'fields' => array(
  249. 'rpid' => array(
  250. 'type' => 'serial',
  251. 'description' => 'A database primary key to ensure uniqueness.',
  252. 'not null' => TRUE,
  253. 'no export' => TRUE,
  254. ),
  255. 'name' => array(
  256. 'type' => 'varchar',
  257. 'length' => '255',
  258. 'description' => 'Unique ID for this content. Used to identify it programmatically.',
  259. ),
  260. 'admin_title' => array(
  261. 'type' => 'varchar',
  262. 'length' => '255',
  263. 'description' => 'Administrative title for this pipeline.',
  264. ),
  265. 'admin_description' => array(
  266. 'type' => 'text',
  267. 'size' => 'big',
  268. 'description' => 'Administrative description for this pipeline.',
  269. 'object default' => '',
  270. ),
  271. 'weight' => array(
  272. 'type' => 'int',
  273. 'size' => 'small',
  274. 'default' => 0,
  275. ),
  276. 'settings' => array(
  277. 'type' => 'text',
  278. 'size' => 'big',
  279. 'description' => 'Serialized settings for the actual pipeline. The contents of this field are up to the plugin that uses it.',
  280. 'serialize' => TRUE,
  281. 'object default' => array(),
  282. ),
  283. ),
  284. 'primary key' => array('rpid'),
  285. );
  286. $schema['panels_layout'] = array(
  287. 'description' => 'Contains exportable customized layouts for this site.',
  288. 'export' => array(
  289. 'identifier' => 'layout',
  290. 'bulk export' => TRUE,
  291. 'primary key' => 'lid',
  292. 'api' => array(
  293. 'owner' => 'panels',
  294. 'api' => 'layouts',
  295. 'minimum_version' => 1,
  296. 'current_version' => 1,
  297. ),
  298. ),
  299. 'fields' => array(
  300. 'lid' => array(
  301. 'type' => 'serial',
  302. 'description' => 'A database primary key to ensure uniqueness.',
  303. 'not null' => TRUE,
  304. 'no export' => TRUE,
  305. ),
  306. 'name' => array(
  307. 'type' => 'varchar',
  308. 'length' => '255',
  309. 'description' => 'Unique ID for this content. Used to identify it programmatically.',
  310. ),
  311. 'admin_title' => array(
  312. 'type' => 'varchar',
  313. 'length' => '255',
  314. 'description' => 'Administrative title for this layout.',
  315. ),
  316. 'admin_description' => array(
  317. 'type' => 'text',
  318. 'size' => 'big',
  319. 'description' => 'Administrative description for this layout.',
  320. 'object default' => '',
  321. ),
  322. 'category' => array(
  323. 'type' => 'varchar',
  324. 'length' => '255',
  325. 'description' => 'Administrative category for this layout.',
  326. ),
  327. 'plugin' => array(
  328. 'type' => 'varchar',
  329. 'length' => '255',
  330. 'description' => 'The layout plugin that owns this layout.',
  331. ),
  332. 'settings' => array(
  333. 'type' => 'text',
  334. 'size' => 'big',
  335. 'description' => 'Serialized settings for the actual layout. The contents of this field are up to the plugin that uses it.',
  336. 'serialize' => TRUE,
  337. 'object default' => array(),
  338. ),
  339. ),
  340. 'primary key' => array('lid'),
  341. );
  342. return $schema;
  343. }
  344. /**
  345. * Change panels_display.layout to match the size of panels_layout.name.
  346. */
  347. function panels_update_7300() {
  348. // Load the schema.
  349. $schema = panels_schema_3();
  350. $table = 'panels_display';
  351. $field = 'layout';
  352. $spec = $schema[$table]['fields'][$field];
  353. // Re-define the column.
  354. db_change_field($table, $field, $field, $spec);
  355. return t('Changed the panels_display.layout field to the correct size.');
  356. }
  357. /**
  358. * Add lock field to panels_pane table.
  359. */
  360. function panels_update_7301() {
  361. // Load the schema.
  362. // Due to a previous failure, the field may already exist:
  363. $schema = panels_schema_4();
  364. $table = 'panels_pane';
  365. $field = 'locks';
  366. if (!db_field_exists($table, $field)) {
  367. $spec = $schema[$table]['fields'][$field];
  368. // Core does not properly respect 'initial' and 'serialize'.
  369. unset($spec['initial']);
  370. // Re-define the column.
  371. db_add_field($table, $field, $spec);
  372. return t('Added panels_pane.lock field.');
  373. }
  374. return t('panels_pane.lock field already existed, update skipped.');
  375. }
  376. /**
  377. * Adding universally unique identifiers to panels.
  378. */
  379. function panels_update_7302() {
  380. if (!module_load_include('inc', 'ctools', 'includes/uuid')) {
  381. throw new DrupalUpdateException(t('Ctools UUID support not detected. You must update to a more recent version of the ctools module.'));
  382. }
  383. // Load the schema.
  384. $schema = panels_schema_5();
  385. $msg = array();
  386. // Add the uuid column to the pane table.
  387. $table = 'panels_pane';
  388. $field = 'uuid';
  389. // Due to a previous failure, the column may already exist:
  390. if (!db_field_exists($table, $field)) {
  391. $spec = $schema[$table]['fields'][$field];
  392. db_add_field($table, $field, $spec);
  393. $msg[] = t('Added panels_pane.uuid column.');
  394. }
  395. // Add the uuid column to the display table.
  396. $table = 'panels_display';
  397. $field = 'uuid';
  398. // Due to a previous failure, the column may already exist:
  399. if (!db_field_exists($table, $field)) {
  400. $spec = $schema[$table]['fields'][$field];
  401. db_add_field($table, $field, $spec);
  402. $msg[] = t('Added panels_display.uuid column.');
  403. }
  404. if (empty($msg)) {
  405. $msg[] = t('UUID column already present in the panels_display & panels_pane tables.');
  406. }
  407. // Update all DB-based panes & displays to ensure that they all contain a UUID.
  408. $display_dids = db_select('panels_display')
  409. ->fields('panels_display', array('did'))
  410. ->condition(db_or()
  411. ->condition('uuid', '')
  412. ->isNull('uuid')
  413. )
  414. ->execute()
  415. ->fetchCol();
  416. // Check the panes as well, for paranoia.
  417. $pane_dids = db_select('panels_pane')
  418. ->distinct()
  419. ->fields('panels_pane', array('did'))
  420. ->condition(db_or()
  421. ->condition('uuid', '')
  422. ->isNull('uuid')
  423. )
  424. ->execute()
  425. ->fetchCol();
  426. $dids = array_unique(array_merge($display_dids, $pane_dids));
  427. // If the Panels module is disabled we don't have access to
  428. // panels_load_displays().
  429. if (!function_exists('panels_load_displays')) {
  430. module_load_include('module', 'panels');
  431. }
  432. if ($displays = panels_load_displays($dids)) {
  433. foreach ($displays as $display) {
  434. // A display save also triggers pane saves.
  435. panels_save_display($display);
  436. }
  437. $msg[] = t('Generated UUIDs for database-based panel displays and panes.');
  438. }
  439. else {
  440. $msg[] = t('No database-based panel displays or panes for which to generate UUIDs.');
  441. }
  442. return implode("\n", $msg);
  443. }
  444. /**
  445. * Add a custom cache table for Panels.
  446. */
  447. function panels_update_7303() {
  448. $schema = panels_schema_6();
  449. $table_name = 'cache_panels';
  450. if (!db_table_exists($table_name)) {
  451. db_create_table($table_name, $schema[$table_name]);
  452. }
  453. }