workflow.install 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the workflow module.
  5. */
  6. /**
  7. * Implements hook_enable().
  8. */
  9. function workflow_enable() {
  10. $message = t('Thanks for using Workflow. To maintain workflows, enable the
  11. <a href="!url_ui">Workflow UI module</a>. To add a Workflow Field to your
  12. entity, enable the <a href="!url_field">Workflow Field module</a>.',
  13. array(
  14. '!url_ui' => url('admin/config/modules'),
  15. '!url_field' => url('admin/config/modules'),
  16. )
  17. );
  18. drupal_set_message($message);
  19. }
  20. /**
  21. * Implements hook_uninstall().
  22. */
  23. function workflow_uninstall() {
  24. variable_del('workflow_states_per_page');
  25. // Delete type-workflow mapping variables.
  26. foreach (node_type_get_types() as $type => $name) {
  27. variable_del('workflow_' . $type);
  28. }
  29. }
  30. /**
  31. * Implements hook_requirements().
  32. *
  33. * Let admins know that Workflow is in use.
  34. *
  35. * @todo: extend workflow_requirements() for use with Workflow Field API.
  36. */
  37. function workflow_requirements($phase) {
  38. $requirements = array();
  39. switch ($phase) {
  40. case 'install':
  41. break;
  42. case 'update':
  43. break;
  44. case 'runtime':
  45. // Show info on admin/reports/status.
  46. $types = db_query('SELECT wid, type FROM {workflow_type_map} WHERE wid <> 0 ORDER BY type')->fetchAllKeyed();
  47. // If there are no types, then just bail.
  48. if (count($types) == 0) {
  49. return;
  50. }
  51. // Let's make it look nice.
  52. if (count($types) == 1) {
  53. $type_list = current($types);
  54. }
  55. else {
  56. $last = array_pop($types);
  57. if (count($types) > 2) {
  58. $type_list = implode(', ', $types) . ', and ' . $last;
  59. }
  60. else {
  61. $type_list = current($types) . ' and ' . $last;
  62. }
  63. }
  64. $t = get_t();
  65. $requirements['workflow'] = array(
  66. 'title' => $t('Workflow'),
  67. 'value' => $t('Workflow is active on the @types content types.', array('@types' => $type_list)),
  68. 'severity' => REQUIREMENT_OK,
  69. );
  70. break;
  71. }
  72. return $requirements;
  73. }
  74. /**
  75. * Implements hook_schema().
  76. */
  77. function workflow_schema() {
  78. $schema['workflows'] = array(
  79. 'description' => 'Workflows',
  80. 'fields' => array(
  81. 'wid' => array(
  82. 'description' => 'The primary identifier for a workflow.',
  83. 'type' => 'serial',
  84. 'not null' => TRUE,
  85. ),
  86. 'name' => array(
  87. 'description' => 'The machine-readable name of this workflow.',
  88. 'type' => 'varchar',
  89. 'length' => '255',
  90. 'not null' => TRUE,
  91. 'default' => '',
  92. ),
  93. 'label' => array(
  94. 'description' => 'The human-readable name of this workflow.',
  95. 'type' => 'varchar',
  96. 'length' => 255,
  97. 'not null' => TRUE,
  98. 'default' => '',
  99. 'translatable' => TRUE,
  100. ),
  101. 'status' => array(
  102. 'type' => 'int',
  103. 'not null' => TRUE,
  104. // Set the default to ENTITY_CUSTOM without using the constant as it is
  105. // not safe to use it at this point.
  106. 'default' => 0x01,
  107. 'size' => 'tiny',
  108. 'description' => 'The exportable status of the entity.',
  109. ),
  110. 'module' => array(
  111. 'description' => 'The name of the providing module if the entity has been defined in code.',
  112. 'type' => 'varchar',
  113. 'length' => 255,
  114. 'not null' => FALSE,
  115. ),
  116. 'tab_roles' => array(
  117. 'description' => 'The role IDs that can access the workflow tabs on node pages.',
  118. 'type' => 'varchar',
  119. 'length' => '255',
  120. 'not null' => TRUE,
  121. 'default' => '',
  122. 'serialize' => TRUE,
  123. ),
  124. 'options' => array(
  125. 'description' => 'Additional settings for the workflow.',
  126. 'type' => 'text',
  127. 'size' => 'big',
  128. 'not null' => FALSE,
  129. 'serialize' => TRUE,
  130. ),
  131. ),
  132. 'primary key' => array('wid'),
  133. 'unique keys' => array('name' => array('name')),
  134. );
  135. $schema['workflow_type_map'] = array(
  136. 'fields' => array(
  137. 'type' => array(
  138. 'description' => 'The {node_type}.type the workflow is used on.',
  139. 'type' => 'varchar',
  140. 'length' => '255',
  141. 'not null' => TRUE,
  142. 'default' => '',
  143. ),
  144. 'wid' => array(
  145. 'description' => 'The {workflows}.wid this record affects.',
  146. 'type' => 'int',
  147. 'unsigned' => TRUE,
  148. 'not null' => TRUE,
  149. 'default' => 0,
  150. 'disp-width' => '10',
  151. ),
  152. ),
  153. 'indexes' => array(
  154. 'type' => array('type', 'wid'),
  155. ),
  156. );
  157. $schema['workflow_transitions'] = array(
  158. 'fields' => array(
  159. 'tid' => array(
  160. 'description' => 'The primary identifier for a workflow transition.',
  161. 'type' => 'serial',
  162. 'not null' => TRUE,
  163. ),
  164. 'name' => array(
  165. 'description' => 'The machine-readable name of this transition.',
  166. 'type' => 'varchar',
  167. 'length' => '32',
  168. // 'not null' => TRUE,
  169. 'default' => '',
  170. ),
  171. 'label' => array(
  172. 'description' => 'The human-readable name of this transition.',
  173. 'type' => 'varchar',
  174. 'length' => '128',
  175. 'not null' => TRUE,
  176. 'default' => '',
  177. 'translatable' => TRUE,
  178. ),
  179. 'sid' => array(
  180. 'description' => 'The {workflow_states}.sid start state.',
  181. 'type' => 'int',
  182. 'unsigned' => TRUE,
  183. 'not null' => TRUE,
  184. 'default' => 0,
  185. 'disp-width' => '10',
  186. ),
  187. 'target_sid' => array(
  188. 'description' => 'The {workflow_states}.sid target state.',
  189. 'type' => 'int',
  190. 'unsigned' => TRUE,
  191. 'not null' => TRUE,
  192. 'default' => 0,
  193. 'disp-width' => '10',
  194. ),
  195. 'roles' => array(
  196. 'description' => 'The {role}.sid that a user must have to perform transition.',
  197. 'type' => 'varchar',
  198. 'length' => '255',
  199. 'not null' => FALSE,
  200. 'serialize' => TRUE,
  201. ),
  202. ),
  203. 'primary key' => array('tid'),
  204. 'indexes' => array(
  205. 'sid' => array('sid'),
  206. 'target_sid' => array('target_sid'),
  207. ),
  208. );
  209. $schema['workflow_states'] = array(
  210. 'fields' => array(
  211. 'sid' => array(
  212. 'description' => 'The primary identifier for a workflow state.',
  213. 'type' => 'serial',
  214. 'not null' => TRUE,
  215. ),
  216. 'wid' => array(
  217. 'description' => 'The {workflows}.wid this state is part of.',
  218. 'type' => 'int',
  219. 'unsigned' => TRUE,
  220. 'not null' => TRUE,
  221. 'default' => 0,
  222. 'disp-width' => '10',
  223. ),
  224. 'name' => array(
  225. 'description' => 'The machine-readable name of this state.',
  226. 'type' => 'varchar',
  227. 'length' => '255',
  228. // 'not null' => TRUE,
  229. 'default' => '',
  230. ),
  231. 'state' => array(
  232. 'description' => 'The human-readable name of this state.',
  233. 'type' => 'varchar',
  234. 'length' => '255',
  235. 'not null' => TRUE,
  236. 'default' => '',
  237. 'translatable' => TRUE,
  238. ),
  239. 'weight' => array(
  240. 'description' => 'The weight (order) of the state.',
  241. 'type' => 'int',
  242. 'size' => 'tiny',
  243. 'not null' => TRUE,
  244. 'default' => 0,
  245. 'disp-width' => '4',
  246. ),
  247. 'sysid' => array(
  248. 'description' => 'The type of state, usually either WORKFLOW_CREATION or empty.',
  249. 'type' => 'int',
  250. 'size' => 'tiny',
  251. 'not null' => TRUE,
  252. 'default' => 0,
  253. 'disp-width' => '4',
  254. ),
  255. 'status' => array(
  256. 'description' => 'Whether the current state is active still.',
  257. 'type' => 'int',
  258. 'size' => 'tiny',
  259. 'not null' => TRUE,
  260. 'default' => 1,
  261. 'disp-width' => '4',
  262. ),
  263. ),
  264. 'primary key' => array('sid'),
  265. 'indexes' => array(
  266. 'sysid' => array('sysid'),
  267. 'wid' => array('wid'),
  268. ),
  269. );
  270. $schema['workflow_scheduled_transition'] = array(
  271. 'fields' => array(
  272. 'tid' => array(
  273. 'description' => 'The unique ID for this record.',
  274. 'type' => 'serial',
  275. 'not null' => TRUE,
  276. ),
  277. 'entity_type' => array(
  278. 'description' => 'The type of entity this transition belongs to.',
  279. 'type' => 'varchar',
  280. 'length' => 255,
  281. 'not null' => TRUE,
  282. 'default' => '',
  283. ),
  284. 'nid' => array(
  285. 'description' => 'The entity ID of the object this transition belongs to.',
  286. 'type' => 'int',
  287. 'unsigned' => TRUE,
  288. 'not null' => TRUE,
  289. 'default' => 0,
  290. 'disp-width' => '10',
  291. ),
  292. 'field_name' => array(
  293. 'description' => 'The name of the field the transition relates to.',
  294. 'type' => 'varchar',
  295. 'length' => 32,
  296. 'not null' => TRUE,
  297. 'default' => '',
  298. ),
  299. 'language' => array(
  300. 'description' => 'The {languages}.language of the entity.',
  301. 'type' => 'varchar',
  302. 'length' => 32,
  303. 'not null' => TRUE,
  304. 'default' => '',
  305. ),
  306. 'delta' => array(
  307. 'description' => 'The sequence number for this data item, used for multi-value fields',
  308. 'type' => 'int',
  309. 'unsigned' => TRUE,
  310. 'not null' => TRUE,
  311. 'default' => 0,
  312. ),
  313. 'old_sid' => array(
  314. 'description' => 'The {workflow_states}.sid this state starts at.',
  315. 'type' => 'int',
  316. 'unsigned' => TRUE,
  317. 'not null' => TRUE,
  318. 'default' => 0,
  319. 'disp-width' => '10',
  320. ),
  321. 'sid' => array(
  322. 'description' => 'The {workflow_states}.sid this state transitions to.',
  323. 'type' => 'int',
  324. 'unsigned' => TRUE,
  325. 'not null' => TRUE,
  326. 'default' => 0,
  327. 'disp-width' => '10',
  328. ),
  329. 'uid' => array(
  330. 'description' => 'The user who scheduled this state transition.',
  331. 'type' => 'int',
  332. 'unsigned' => TRUE,
  333. 'not null' => TRUE,
  334. 'default' => 0,
  335. 'disp-width' => '10',
  336. ),
  337. 'scheduled' => array(
  338. 'description' => 'The date this transition is scheduled for.',
  339. 'type' => 'int',
  340. 'unsigned' => TRUE,
  341. 'not null' => TRUE,
  342. 'default' => 0,
  343. 'disp-width' => '10',
  344. ),
  345. 'comment' => array(
  346. 'description' => 'The comment explaining this transition.',
  347. 'type' => 'text',
  348. 'size' => 'big',
  349. 'not null' => FALSE,
  350. ),
  351. ),
  352. 'primary key' => array('tid'),
  353. 'indexes' => array(
  354. 'entity_type' => array('entity_type'),
  355. 'entity_id' => array('entity_type', 'nid'),
  356. ),
  357. );
  358. $schema['workflow_node_history'] = array(
  359. 'fields' => array(
  360. 'hid' => array(
  361. 'description' => 'The unique ID for this record.',
  362. 'type' => 'serial',
  363. 'not null' => TRUE,
  364. ),
  365. 'entity_type' => array(
  366. 'description' => 'The type of entity this transition belongs to.',
  367. 'type' => 'varchar',
  368. 'length' => 255,
  369. 'not null' => TRUE,
  370. 'default' => '',
  371. ),
  372. 'nid' => array(
  373. 'description' => 'The {node}.nid this record is for.',
  374. 'type' => 'int',
  375. 'unsigned' => TRUE,
  376. 'not null' => TRUE,
  377. 'default' => 0,
  378. 'disp-width' => '10',
  379. ),
  380. 'revision_id' => array(
  381. 'description' => 'The current version identifier.',
  382. 'type' => 'int',
  383. 'unsigned' => TRUE,
  384. 'not null' => FALSE,
  385. 'default' => NULL,
  386. ),
  387. 'field_name' => array(
  388. 'description' => 'The name of the field the transition relates to.',
  389. 'type' => 'varchar',
  390. 'length' => 32,
  391. 'not null' => TRUE,
  392. 'default' => '',
  393. ),
  394. 'language' => array(
  395. 'description' => 'The {languages}.language of the entity.',
  396. 'type' => 'varchar',
  397. 'length' => 32,
  398. 'not null' => TRUE,
  399. 'default' => '',
  400. ),
  401. 'delta' => array(
  402. 'description' => 'The sequence number for this data item, used for multi-value fields',
  403. 'type' => 'int',
  404. 'unsigned' => TRUE,
  405. 'not null' => TRUE,
  406. 'default' => 0,
  407. ),
  408. 'old_sid' => array(
  409. 'description' => 'The {workflow_states}.sid this transition started as.',
  410. 'type' => 'int',
  411. 'unsigned' => TRUE,
  412. 'not null' => TRUE,
  413. 'default' => 0,
  414. 'disp-width' => '10',
  415. ),
  416. 'sid' => array(
  417. 'description' => 'The {workflow_states}.sid this transition transitioned to.',
  418. 'type' => 'int',
  419. 'unsigned' => TRUE,
  420. 'not null' => TRUE,
  421. 'default' => 0,
  422. 'disp-width' => '10',
  423. ),
  424. 'uid' => array(
  425. 'description' => 'The {users}.uid who made this transition.',
  426. 'type' => 'int',
  427. 'unsigned' => TRUE,
  428. 'not null' => TRUE,
  429. 'default' => 0,
  430. 'disp-width' => '10',
  431. ),
  432. 'stamp' => array(
  433. 'description' => 'The unique stamp for this transition.',
  434. 'type' => 'int',
  435. 'unsigned' => TRUE,
  436. 'not null' => TRUE,
  437. 'default' => 0,
  438. 'disp-width' => '10',
  439. ),
  440. 'comment' => array(
  441. 'description' => 'The comment explaining this transition.',
  442. 'type' => 'text',
  443. 'size' => 'big',
  444. 'not null' => FALSE,
  445. ),
  446. ),
  447. 'primary key' => array('hid'),
  448. 'indexes' => array(
  449. 'sid' => array('entity_type', 'nid', 'sid'),
  450. 'nid' => array('nid'),
  451. ),
  452. );
  453. $schema['workflow_node'] = array(
  454. 'fields' => array(
  455. 'nid' => array(
  456. 'description' => 'The {node}.nid this record is for.',
  457. 'type' => 'int',
  458. 'unsigned' => TRUE,
  459. 'not null' => TRUE,
  460. 'default' => 0,
  461. 'disp-width' => '10',
  462. ),
  463. 'sid' => array(
  464. 'description' => 'The {workflow_states}.sid that this node is currently in.',
  465. 'type' => 'int',
  466. 'unsigned' => TRUE,
  467. 'not null' => TRUE,
  468. 'default' => 0,
  469. 'disp-width' => '10',
  470. ),
  471. 'uid' => array(
  472. 'description' => 'The {users}.uid who triggered this state.',
  473. 'type' => 'int',
  474. 'unsigned' => TRUE,
  475. 'not null' => TRUE,
  476. 'default' => 0,
  477. 'disp-width' => '10',
  478. ),
  479. 'stamp' => array(
  480. 'description' => 'The unique stamp for the transition.',
  481. 'type' => 'int',
  482. 'unsigned' => TRUE,
  483. 'not null' => TRUE,
  484. 'default' => 0,
  485. 'disp-width' => '11',
  486. ),
  487. ),
  488. 'primary key' => array('nid'),
  489. 'indexes' => array(
  490. 'nid' => array('nid', 'sid'),
  491. ),
  492. );
  493. return $schema;
  494. }
  495. /**
  496. * Require highest 6.x release.
  497. */
  498. function workflow_update_last_removed() {
  499. return 6101;
  500. }
  501. /**
  502. * Table update from 6 to 7.
  503. *
  504. * Adding a unique key for fields (already held unique in code).
  505. */
  506. function workflow_update_7000() {
  507. if (!db_index_exists('workflows', 'name')) {
  508. db_add_unique_key('workflows', 'name', array('name'));
  509. }
  510. if (!db_index_exists('workflow_states', 'wid_state')) {
  511. db_add_unique_key('workflow_states', 'wid_state', array('wid', 'state'));
  512. }
  513. }
  514. /**
  515. * Add userid to scheduled transition table.
  516. */
  517. function workflow_update_7002() {
  518. db_add_field('workflow_scheduled_transition', 'uid', array(
  519. 'description' => 'The user who scheduled this state transition.',
  520. 'type' => 'int',
  521. 'unsigned' => TRUE,
  522. 'not null' => TRUE,
  523. 'default' => 0,
  524. 'disp-width' => '10',
  525. 'initial' => 0,
  526. ));
  527. }
  528. /**
  529. * Add Entity field capabilities to workflow_scheduled_transition table.
  530. */
  531. function workflow_update_7003() {
  532. $field = array(
  533. 'description' => 'The type of entity this transition belongs to.',
  534. 'type' => 'varchar',
  535. 'length' => 255,
  536. 'not null' => TRUE,
  537. 'default' => '',
  538. );
  539. if (!db_field_exists('workflow_scheduled_transition', 'entity_type')) {
  540. db_add_field('workflow_scheduled_transition', 'entity_type', $field);
  541. }
  542. if (!db_field_exists('workflow_node_history', 'entity_type')) {
  543. db_add_field('workflow_node_history', 'entity_type', $field);
  544. }
  545. $field = array(
  546. 'description' => 'The name of the field the transition relates to.',
  547. 'type' => 'varchar',
  548. 'length' => 32,
  549. 'not null' => TRUE,
  550. 'default' => '',
  551. );
  552. if (!db_field_exists('workflow_scheduled_transition', 'field_name')) {
  553. db_add_field('workflow_scheduled_transition', 'field_name', $field);
  554. }
  555. if (!db_field_exists('workflow_node_history', 'field_name')) {
  556. db_add_field('workflow_node_history', 'field_name', $field);
  557. }
  558. $field = array(
  559. 'description' => 'The {languages}.language of the entity.',
  560. 'type' => 'varchar',
  561. 'length' => 32,
  562. 'not null' => TRUE,
  563. 'default' => '',
  564. );
  565. if (!db_field_exists('workflow_scheduled_transition', 'language')) {
  566. db_add_field('workflow_scheduled_transition', 'language', $field);
  567. }
  568. if (!db_field_exists('workflow_node_history', 'language')) {
  569. db_add_field('workflow_node_history', 'language', $field);
  570. }
  571. $field = array(
  572. 'description' => 'The sequence number for this data item, used for multi-value fields',
  573. 'type' => 'int',
  574. 'unsigned' => TRUE,
  575. 'not null' => TRUE,
  576. 'default' => 0,
  577. );
  578. if (!db_field_exists('workflow_scheduled_transition', 'delta')) {
  579. db_add_field('workflow_scheduled_transition', 'delta', $field);
  580. }
  581. if (!db_field_exists('workflow_node_history', 'delta')) {
  582. db_add_field('workflow_node_history', 'delta', $field);
  583. }
  584. db_drop_index('workflow_scheduled_transition', 'nid');
  585. db_drop_index('workflow_scheduled_transition', 'entity_id');
  586. db_drop_index('workflow_scheduled_transition', 'entity_type');
  587. db_add_index('workflow_scheduled_transition', 'entity_id', array('entity_type', 'nid'));
  588. db_add_index('workflow_scheduled_transition', 'entity_type', array('entity_type'));
  589. db_drop_index('workflow_node_history', 'nid');
  590. db_drop_index('workflow_node_history', 'sid');
  591. db_add_index('workflow_node_history', 'sid', array('entity_type', 'nid', 'sid'));
  592. }
  593. /**
  594. * Update scheduled state transitions with no association to "node".
  595. */
  596. function workflow_update_7004() {
  597. db_update('workflow_scheduled_transition')
  598. ->fields(array(
  599. 'entity_type' => 'node',
  600. 'language' => LANGUAGE_NONE,
  601. 'delta' => '0',
  602. )
  603. )
  604. ->execute();
  605. }
  606. /**
  607. * Enable Workflow Node module. See https:\/\/drupal.org\/node\/2122541 .
  608. */
  609. function workflow_update_7005() {
  610. module_enable(array('workflownode'));
  611. }
  612. /**
  613. * Set historical records with no associated entity to "node".
  614. *
  615. * Otherwise, they won't show up in the Workflow tab.
  616. */
  617. function workflow_update_7006() {
  618. db_update('workflow_node_history')
  619. ->fields(array(
  620. 'entity_type' => 'node',
  621. )
  622. )
  623. ->condition('entity_type', '')
  624. ->execute();
  625. }
  626. /**
  627. * Convert roles to entity-like arrays.
  628. */
  629. function workflow_update_7007() {
  630. // For this update, do not use the Workflow API, since some table fields are
  631. // not present yet. Also, do not move to the 'floating' hook_update_N().
  632. $schema = workflow_schema();
  633. // Change length from 60 to 255, to create a 'standard' Roles field,
  634. // like workflow_transitions-roles.
  635. $table = 'workflows';
  636. $fields = $schema[$table]['fields'];
  637. db_change_field($table, 'tab_roles', 'tab_roles', $fields['tab_roles']);
  638. // Save field workflows-tab_roles in serialized array (using explode for the last time).
  639. $query = "SELECT * FROM {workflows} w ";
  640. $result = db_query($query);
  641. foreach ($result as $record) {
  642. // Replace role ID 'author' by '-1'.
  643. // Update workflow->tab_roles to serializable array.
  644. $roles = $record->tab_roles;
  645. // Allow reprocessing this hook, by checking if this is an array.
  646. if (!(strpos($roles, 'a:') === 0)) {
  647. $roles = str_replace('author', '-1', $roles);
  648. $record->tab_roles = empty($roles) ? array() : explode(',', $roles);
  649. $num_updated = db_update('workflows')
  650. ->fields(array(
  651. 'tab_roles' => serialize($record->tab_roles),
  652. ))
  653. ->condition('wid', $record->wid, '=')
  654. ->execute();
  655. }
  656. }
  657. // Save field workflow_transitions-roles in serialized array (using explode for the last time).
  658. // Replace role ID 'author' by '-1'.
  659. $query = "SELECT wt.tid, wt.roles FROM {workflow_transitions} wt";
  660. $result = db_query($query);
  661. foreach ($result as $record) {
  662. $roles = $record->roles;
  663. // Allow reprocessing this hook, by checking if this is an array.
  664. if (!(strpos($roles, 'a:') === 0)) {
  665. $roles = str_replace('author', '-1', $roles);
  666. $record->roles = empty($roles) ? array() : explode(',', $roles);
  667. $num_updated = db_update('workflow_transitions')
  668. ->fields(array(
  669. 'roles' => serialize($record->roles),
  670. ))
  671. ->condition('tid', $record->tid, '=')
  672. ->execute();
  673. }
  674. }
  675. }
  676. /**
  677. * Add Revision to workflow history table.
  678. *
  679. * There is no update for current states.
  680. */
  681. // function workflow_update_7008() {
  682. // // This is moved to the general hook_update_N().
  683. // }
  684. /**
  685. * Remove invalid transitions.
  686. */
  687. function workflow_update_7014() {
  688. // Some error in cloning Workflows generated superfluous, invalid Transitions.
  689. $num_deleted = db_delete('workflow_transitions')
  690. ->condition('sid', 0)
  691. ->execute();
  692. }
  693. /**
  694. * Add database fields. Make Workflow entity-aware, exportable.
  695. */
  696. function workflow_update_7015() {
  697. $schema = workflow_schema();
  698. // Update the Workflow table.
  699. $table = 'workflows';
  700. $fields = $schema[$table]['fields'];
  701. if (!db_field_exists($table, 'label')) {
  702. db_add_field($table, 'label', $fields['label']);
  703. }
  704. if (!db_field_exists($table, 'status')) {
  705. db_add_field($table, 'status', $fields['status']);
  706. }
  707. if (!db_field_exists($table, 'module')) {
  708. db_add_field($table, 'module', $fields['module']);
  709. }
  710. // Update the WorkflowConfigTransitions table.
  711. $table = 'workflow_transitions';
  712. $fields = $schema[$table]['fields'];
  713. if (!db_field_exists($table, 'label')) {
  714. db_add_field($table, 'label', $fields['label']);
  715. }
  716. if (!db_field_exists($table, 'name')) {
  717. db_add_field($table, 'name', $fields['name']);
  718. }
  719. // Update the WorkflowStates table.
  720. $table = 'workflow_states';
  721. $fields = $schema[$table]['fields'];
  722. if (!db_field_exists($table, 'name')) {
  723. db_add_field($table, 'name', $fields['name']);
  724. }
  725. // Update the WorkflowHistory table.
  726. $table = 'workflow_node_history';
  727. $fields = $schema[$table]['fields'];
  728. // This is moved from hook_update_7008().
  729. if (!db_field_exists($table, 'revision_id')) {
  730. db_add_field($table, 'revision_id', $fields['revision_id']);
  731. }
  732. // Load&save workflows, to populate the label.
  733. // Do this after all db-updates!!
  734. // Do not use workflow_*() functions.
  735. foreach (entity_load('Workflow') as $workflow) {
  736. $workflow->save();
  737. // Load&save workflow states, to populate the state name.
  738. foreach ($workflow->getStates(TRUE, TRUE) as $state) {
  739. $state->save();
  740. }
  741. }
  742. // The update system is going to flush all caches,
  743. // including the updated Rules Action, so nothing to do here.
  744. }
  745. /**
  746. * Add an index to {workflow_node_history}.nid.
  747. */
  748. function workflow_update_7016() {
  749. if (db_field_exists('workflow_node_history', 'nid') && !db_index_exists('workflow_node_history', 'nid')) {
  750. db_add_index('workflow_node_history', 'nid', array('nid'));
  751. }
  752. }
  753. /**
  754. * Add/correct a primary key to {workflow_scheduled_transition}.
  755. */
  756. function workflow_update_7017() {
  757. // Drop existing primary key.
  758. db_drop_primary_key('workflow_scheduled_transition');
  759. // Add new primary key.
  760. $spec = array(
  761. 'type' => 'serial',
  762. 'not null' => TRUE,
  763. );
  764. $keys_new = array(
  765. 'primary key' => array('tid'),
  766. );
  767. if (!db_field_exists('workflow_scheduled_transition', 'tid') ) {
  768. db_add_field('workflow_scheduled_transition', 'tid', $spec, $keys_new);
  769. }
  770. else {
  771. db_change_field('workflow_scheduled_transition', 'tid', 'tid', $spec, $keys_new);
  772. }
  773. return t('Added tid primary key to {workflow_scheduled_transition}');
  774. }
  775. /**
  776. * Enable the List module, newly added as a dependency.
  777. */
  778. function workflow_update_7200() {
  779. module_enable(array('list'));
  780. }