workflow.install 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the workflow module.
  5. *
  6. */
  7. /**
  8. * Implements hook_install().
  9. */
  10. function workflow_install() {
  11. }
  12. /**
  13. * Implements hook_uninstall().
  14. */
  15. function workflow_uninstall() {
  16. variable_del('workflow_states_per_page');
  17. // Delete type-workflow mapping variables.
  18. foreach (node_type_get_types() as $type => $name) {
  19. variable_del('workflow_' . $type);
  20. }
  21. }
  22. /**
  23. * Implements hook_schema().
  24. */
  25. function workflow_schema() {
  26. $schema['workflows'] = array(
  27. 'description' => 'Workflows',
  28. 'fields' => array(
  29. 'wid' => array(
  30. 'description' => 'The primary identifier for a node.',
  31. 'type' => 'serial',
  32. 'not null' => TRUE
  33. ),
  34. 'name' => array(
  35. 'description' => 'The name of the workflow (used as machine name for features intergration).',
  36. 'type' => 'varchar',
  37. 'length' => '255',
  38. 'not null' => TRUE,
  39. 'default' => ''
  40. ),
  41. 'tab_roles' => array(
  42. 'description' => 'The role IDs that can access the workflow tabs on node pages.',
  43. 'type' => 'varchar',
  44. 'length' => '60',
  45. 'not null' => TRUE,
  46. 'default' => ''
  47. ),
  48. 'options' => array(
  49. 'description' => 'Additional settings for the workflow.',
  50. 'type' => 'text',
  51. 'size' => 'big',
  52. 'not null' => FALSE
  53. ),
  54. ),
  55. 'primary key' => array('wid'),
  56. 'unique keys' => array('name' => array('name')),
  57. );
  58. $schema['workflow_type_map'] = array(
  59. 'fields' => array(
  60. 'type' => array(
  61. 'description' => 'The {node_type}.type the workflow is used on.',
  62. 'type' => 'varchar',
  63. 'length' => '255',
  64. 'not null' => TRUE,
  65. 'default' => ''
  66. ),
  67. 'wid' => array(
  68. 'description' => 'The {workflows}.wid this record affects.',
  69. 'type' => 'int',
  70. 'unsigned' => TRUE,
  71. 'not null' => TRUE,
  72. 'default' => 0,
  73. 'disp-width' => '10'
  74. ),
  75. ),
  76. 'indexes' => array(
  77. 'type' => array('type', 'wid'),
  78. ),
  79. );
  80. $schema['workflow_transitions'] = array(
  81. 'fields' => array(
  82. 'tid' => array(
  83. 'description' => 'The primary identifier for a workflow transition.',
  84. 'type' => 'serial',
  85. 'not null' => TRUE
  86. ),
  87. 'sid' => array(
  88. 'description' => 'The {workflow_states}.sid start state.',
  89. 'type' => 'int',
  90. 'unsigned' => TRUE,
  91. 'not null' => TRUE,
  92. 'default' => 0,
  93. 'disp-width' => '10'
  94. ),
  95. 'target_sid' => array(
  96. 'description' => 'The {workflow_states}.sid target state.',
  97. 'type' => 'int',
  98. 'unsigned' => TRUE,
  99. 'not null' => TRUE,
  100. 'default' => 0,
  101. 'disp-width' => '10'
  102. ),
  103. 'roles' => array(
  104. 'description' => 'The {role}.sid that a user must have to perform transition.',
  105. 'type' => 'varchar',
  106. 'length' => '255',
  107. 'not null' => FALSE,
  108. ),
  109. ),
  110. 'primary key' => array('tid'),
  111. 'indexes' => array(
  112. 'sid' => array('sid'),
  113. 'target_sid' => array('target_sid'),
  114. ),
  115. );
  116. $schema['workflow_states'] = array(
  117. 'fields' => array(
  118. 'sid' => array(
  119. 'description' => 'The primary identifier for a workflow state.',
  120. 'type' => 'serial',
  121. 'not null' => TRUE,
  122. ),
  123. 'wid' => array(
  124. 'description' => 'The {workflows}.wid this state is part of.',
  125. 'type' => 'int',
  126. 'unsigned' => TRUE,
  127. 'not null' => TRUE,
  128. 'default' => 0,
  129. 'disp-width' => '10'
  130. ),
  131. 'state' => array(
  132. 'description' => 'The name of the state.',
  133. 'type' => 'varchar',
  134. 'length' => '255',
  135. 'not null' => TRUE,
  136. 'default' => '',
  137. ),
  138. 'weight' => array(
  139. 'description' => 'The weight (order) of the state.',
  140. 'type' => 'int',
  141. 'size' => 'tiny',
  142. 'not null' => TRUE,
  143. 'default' => 0,
  144. 'disp-width' => '4',
  145. ),
  146. 'sysid' => array(
  147. 'description' => 'The type of state, usually either WORKFLOW_CREATION or empty.',
  148. 'type' => 'int',
  149. 'size' => 'tiny',
  150. 'not null' => TRUE,
  151. 'default' => 0,
  152. 'disp-width' => '4',
  153. ),
  154. 'status' => array(
  155. 'description' => 'Whether the current state is active still.',
  156. 'type' => 'int',
  157. 'size' => 'tiny',
  158. 'not null' => TRUE,
  159. 'default' => 1,
  160. 'disp-width' => '4',
  161. ),
  162. ),
  163. 'primary key' => array('sid'),
  164. 'indexes' => array(
  165. 'sysid' => array('sysid'),
  166. 'wid' => array('wid')
  167. ),
  168. );
  169. $schema['workflow_scheduled_transition'] = array(
  170. 'fields' => array(
  171. 'nid' => array(
  172. 'description' => 'The {node}.nid this transition is scheduled for.',
  173. 'type' => 'int',
  174. 'unsigned' => TRUE,
  175. 'not null' => TRUE,
  176. 'default' => 0,
  177. 'disp-width' => '10',
  178. ),
  179. 'old_sid' => array(
  180. 'description' => 'The {workflow_states}.sid this state starts at.',
  181. 'type' => 'int',
  182. 'unsigned' => TRUE,
  183. 'not null' => TRUE,
  184. 'default' => 0,
  185. 'disp-width' => '10',
  186. ),
  187. 'sid' => array(
  188. 'description' => 'The {workflow_states}.sid this state transitions to.',
  189. 'type' => 'int',
  190. 'unsigned' => TRUE,
  191. 'not null' => TRUE,
  192. 'default' => 0,
  193. 'disp-width' => '10',
  194. ),
  195. 'uid' => array(
  196. 'description' => 'The user who scheduled this state transition.',
  197. 'type' => 'int',
  198. 'unsigned' => TRUE,
  199. 'not null' => TRUE,
  200. 'default' => 0,
  201. 'disp-width' => '10',
  202. ),
  203. 'scheduled' => array(
  204. 'description' => 'The date this transition is scheduled for.',
  205. 'type' => 'int',
  206. 'unsigned' => TRUE,
  207. 'not null' => TRUE,
  208. 'default' => 0,
  209. 'disp-width' => '10',
  210. ),
  211. 'comment' => array(
  212. 'description' => 'The comment explaining this transition.',
  213. 'type' => 'text',
  214. 'size' => 'big',
  215. 'not null' => FALSE,
  216. ),
  217. ),
  218. 'indexes' => array(
  219. 'nid' => array('nid')
  220. ),
  221. );
  222. $schema['workflow_node_history'] = array(
  223. 'fields' => array(
  224. 'hid' => array(
  225. 'description' => 'The unique ID for this record.',
  226. 'type' => 'serial',
  227. 'not null' => TRUE
  228. ),
  229. 'nid' => array(
  230. 'description' => 'The {node}.nid this record is for.',
  231. 'type' => 'int',
  232. 'unsigned' => TRUE,
  233. 'not null' => TRUE,
  234. 'default' => 0,
  235. 'disp-width' => '10',
  236. ),
  237. 'old_sid' => array(
  238. 'description' => 'The {workflow_states}.sid this transition started as.',
  239. 'type' => 'int',
  240. 'unsigned' => TRUE,
  241. 'not null' => TRUE, '
  242. default' => 0,
  243. 'disp-width' => '10',
  244. ),
  245. 'sid' => array(
  246. 'description' => 'The {workflow_states}.sid this transition transitioned to.',
  247. 'type' => 'int',
  248. 'unsigned' => TRUE,
  249. 'not null' => TRUE,
  250. 'default' => 0,
  251. 'disp-width' => '10',
  252. ),
  253. 'uid' => array(
  254. 'description' => 'The {users}.uid who made this transition.',
  255. 'type' => 'int',
  256. 'unsigned' => TRUE,
  257. 'not null' => TRUE,
  258. 'default' => 0,
  259. 'disp-width' => '10',
  260. ),
  261. 'stamp' => array(
  262. 'description' => 'The unique stamp for this transition.',
  263. 'type' => 'int',
  264. 'unsigned' => TRUE,
  265. 'not null' => TRUE,
  266. 'default' => 0,
  267. 'disp-width' => '10',
  268. ),
  269. 'comment' => array(
  270. 'description' => 'The comment explaining this transition.',
  271. 'type' => 'text',
  272. 'size' => 'big',
  273. 'not null' => FALSE,
  274. ),
  275. ),
  276. 'primary key' => array('hid'),
  277. 'indexes' => array(
  278. 'nid' => array('nid', 'sid'),
  279. ),
  280. );
  281. $schema['workflow_node'] = array(
  282. 'fields' => array(
  283. 'nid' => array(
  284. 'description' => 'The {node}.nid this record is for.',
  285. 'type' => 'int',
  286. 'unsigned' => TRUE,
  287. 'not null' => TRUE,
  288. 'default' => 0,
  289. 'disp-width' => '10',
  290. ),
  291. 'sid' => array(
  292. 'description' => 'The {workflow_states}.sid that this node is currently in.',
  293. 'type' => 'int',
  294. 'unsigned' => TRUE,
  295. 'not null' => TRUE,
  296. 'default' => 0,
  297. 'disp-width' => '10',
  298. ),
  299. 'uid' => array(
  300. 'description' => 'The {users}.uid who triggered this state.',
  301. 'type' => 'int',
  302. 'unsigned' => TRUE,
  303. 'not null' => TRUE,
  304. 'default' => 0,
  305. 'disp-width' => '10',
  306. ),
  307. 'stamp' => array(
  308. 'description' => 'The unique stamp for the transition.',
  309. 'type' => 'int',
  310. 'unsigned' => TRUE,
  311. 'not null' => TRUE,
  312. 'default' => 0,
  313. 'disp-width' => '11',
  314. ),
  315. ),
  316. 'primary key' => array('nid'),
  317. 'indexes' => array(
  318. 'nid' => array('nid', 'sid'),
  319. ),
  320. );
  321. return $schema;
  322. }
  323. /**
  324. * Require highest 6.x release.
  325. */
  326. function workflow_update_last_removed() {
  327. return 6101;
  328. }
  329. /**
  330. * Table update from 6 to 7. Adding a unique key for fields (already held unique in code).
  331. */
  332. function workflow_update_7000() {
  333. if (!db_index_exists('workflows', 'name')) {
  334. db_add_unique_key('workflows', 'name', array('name'));
  335. }
  336. if (!db_index_exists('workflow_states', 'wid_state')) {
  337. db_add_unique_key('workflow_states', 'wid_state', array('wid', 'state'));
  338. }
  339. }
  340. /**
  341. * Initialize all workflows to show watchdog messages.
  342. */
  343. function workflow_update_7001() {
  344. // Get all workflows.
  345. $workflows = workflow_get_workflows();
  346. foreach ($workflows as $workflow) {
  347. // Add the option.
  348. $workflow->options['watchdog_log'] = 1;
  349. // Serialize the options array.
  350. $workflow->options = serialize($workflow->options);
  351. // Update the workflow without creating a creation state.
  352. workflow_update_workflows($workflow, FALSE);
  353. }
  354. }
  355. /**
  356. * Add userid to scheduled transition table.
  357. */
  358. function workflow_update_7002() {
  359. db_add_field('workflow_scheduled_transition', 'uid', array(
  360. 'description' => 'The user who scheduled this state transition.',
  361. 'type' => 'int',
  362. 'unsigned' => TRUE,
  363. 'not null' => TRUE,
  364. 'default' => 0,
  365. 'disp-width' => '10',
  366. 'initial' => 0,
  367. ));
  368. }