workflow.deprecated.inc 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. <?php
  2. /**
  3. * @file
  4. * Contains contains per-class functions, that are deprecated.
  5. *
  6. * Usage: The new code can be tested, by removing this file-include from workflow.module.
  7. */
  8. /**
  9. * Deprecated functions related to table {workflows}.
  10. *
  11. * These are replaced by methods of class Workflow.
  12. */
  13. /**
  14. * Get all workflows.
  15. *
  16. * @deprecated: workflow_get_workflows --> workflow_load_multiple
  17. */
  18. function workflow_get_workflows() {
  19. return workflow_load_multiple();
  20. }
  21. /**
  22. * Get a specific workflow, wid is a unique ID.
  23. *
  24. * @deprecated: workflow_get_workflows_by_wid --> workflow_load_single
  25. */
  26. function workflow_get_workflows_by_wid($wid, $reset = FALSE) {
  27. return workflow_load_single($wid, $reset);
  28. }
  29. /**
  30. * Get a specific workflow, name is a unique ID.
  31. *
  32. * @deprecated: workflow_get_workflows_by_name --> workflow_load_by_name
  33. */
  34. function workflow_get_workflows_by_name($name) {
  35. return workflow_load_by_name($name);
  36. }
  37. /**
  38. * Helper function, to get the label of a given workflow.
  39. *
  40. * @deprecated: workflow_get_wid_label --> workflow_label
  41. */
  42. function workflow_get_wid_label($wid) {
  43. $label = t('Unknown workflow');
  44. if (empty($wid)) {
  45. $label = t('No workflow');
  46. }
  47. elseif ($workflow = workflow_load_single($wid)) {
  48. $label = $workflow->label();
  49. }
  50. return $label;
  51. }
  52. /**
  53. * Return the ID of the creation state for this workflow.
  54. *
  55. * @param mixed $wid
  56. * The ID of the workflow.
  57. *
  58. * @return int
  59. *
  60. * @deprecated: workflow_get_creation_state_by_wid($wid) --> $workflow->getCreationSid().
  61. */
  62. function workflow_get_creation_state_by_wid($wid) {
  63. $sid = 0;
  64. if ($workflow = workflow_load_single($wid)) {
  65. $sid = $workflow->getCreationSid();
  66. }
  67. return $sid;
  68. }
  69. /**
  70. * Return the ID of the creation state given a content type.
  71. *
  72. * @param string $type
  73. * The type of the content.
  74. */
  75. //function workflow_get_creation_state_by_type($type) {
  76. // $sid = FALSE;
  77. //
  78. // if ($workflow = workflow_get_workflows_by_type($type, 'node')) {
  79. // $sid = $workflow->getCreationSid();
  80. // }
  81. // return $sid;
  82. //}
  83. /**
  84. * Given information, update or insert a new workflow. Returns data by ref. (like node_save).
  85. *
  86. * @deprecated: workflow_update_workflows() --> Workflow->save()
  87. */
  88. //function workflow_update_workflows(&$data, $create_creation_state = TRUE) {
  89. // $data = (object) $data;
  90. // if (isset($data->tab_roles) && is_array($data->tab_roles)) {
  91. // $data->tab_roles = serialize($data->tab_roles);
  92. // }
  93. //
  94. // if (isset($data->wid) && workflow_load_single($data->wid)) {
  95. // drupal_write_record('workflows', $data, 'wid');
  96. // }
  97. // else {
  98. // drupal_write_record('workflows', $data);
  99. // if ($create_creation_state) {
  100. // $state_data = array(
  101. // 'wid' => $data->wid,
  102. // 'state' => t(WORKFLOW_CREATION_STATE_NAME),
  103. // 'sysid' => WORKFLOW_CREATION,
  104. // 'weight' => WORKFLOW_CREATION_DEFAULT_WEIGHT,
  105. // );
  106. //
  107. // workflow_update_workflow_states($state_data);
  108. // // @TODO consider adding state data to return here as part of workflow data structure.
  109. // // That way we could past structs and transitions around as a data object as a whole.
  110. // // Might make clone easier, but it might be a little hefty for our needs?
  111. // }
  112. // }
  113. //}
  114. /**
  115. * Given a wid, delete the workflow and its data.
  116. *
  117. * @deprecated: workflow_delete_workflows_by_wid() --> Workflow::delete().
  118. */
  119. function workflow_delete_workflows_by_wid($wid) {
  120. $workflow = workflow_load_single($wid);
  121. $workflow->delete();
  122. }
  123. /**
  124. * Deprecated functions related to table {workflow_states}.
  125. *
  126. * These are replaced by methods of class WorkflowState.
  127. */
  128. /**
  129. * Get all active states in the system.
  130. *
  131. * @return array
  132. * A keyed array $id => $name, of all active states.
  133. *
  134. * @deprecated: workflow_get_workflow_states_all() --> Workflow::getOptions()
  135. */
  136. function workflow_get_workflow_states_all() {
  137. // Get all states, only where active.
  138. return workflow_get_workflow_state_names($wid = 0, $grouped = FALSE, $all = FALSE);
  139. }
  140. /**
  141. * Menu access control callback. Determine access to Workflow tab.
  142. *
  143. * @deprecated workflow_node_tab_access() --> workflow_tab_access().
  144. */
  145. function workflow_node_tab_access($node = NULL) {
  146. if ($node == NULL) {
  147. return FALSE;
  148. }
  149. return workflow_tab_access('node', $node);
  150. }
  151. /**
  152. * Get the states current user can move to for a given node.
  153. *
  154. * @param object $node
  155. * The node to check.
  156. * @param bool $force
  157. * A switch to enable access to all states (e.g., for Rules).
  158. * @param State $state
  159. * The predetermined state object (v7.x-1.3: new parameter for Workflow Field).
  160. *
  161. * @return array
  162. * Array of transitions.
  163. *
  164. * @deprecated workflow_field_choices() --> WorkflowState->getOptions()
  165. */
  166. function workflow_field_choices($node, $force = FALSE, $state = NULL) {
  167. global $user; // Alert: In 7.x-2.4, getOptions() has a new $user parameter.
  168. $choices = array();
  169. if (!$node) {
  170. // If no node is given, no result. (e.g., on a Field settings page.)
  171. return $choices;
  172. }
  173. if ($state) {
  174. // This is used in Field API. A state object is already passed in.
  175. }
  176. else {
  177. // This is used in Node API.
  178. $field_name = ''; // An explicit var is needed.
  179. $current_sid = workflow_node_current_state($node, 'node', $field_name);
  180. $state = workflow_state_load_single($current_sid);
  181. }
  182. return $state->getOptions('node', $node, '', $user, $force);
  183. }
  184. /**
  185. * Determine if the Workflow Form must be shown.
  186. * If not, a formatter must be shown, since there are no valid options.
  187. *
  188. * @param mixed $sid
  189. * the current state ID.
  190. * @param Workflow $workflow
  191. * the workflow object (might be derived from $sid).
  192. * @param array $options
  193. * an array with $id => $label options, as determined in WorkflowState->getOptions().
  194. *
  195. * @return bool $show_widget
  196. * TRUE = a form must be shown; FALSE = no form, a formatter must be shown instead.
  197. *
  198. * @deprecated workflow_show_form() --> WorkflowState->showWidget()
  199. */
  200. // function workflow_show_form($sid, $workflow, array $options) {
  201. // $state = workflow_state_load_single($sid);
  202. // return !$state->showWidget($options);
  203. // }
  204. /**
  205. * Validate target state and either execute a transition immediately or schedule
  206. * a transition to be executed later by cron.
  207. *
  208. * @param object $entity
  209. * @param string $new_sid
  210. * An integer; the target state ID.
  211. * @param bool $force
  212. * Allows bypassing permissions, primarily for Rules.
  213. * @param array $field
  214. * The field structure for the operation.
  215. *
  216. * @deprecated: workflow_transition --> WorkflowDefaultWidget::submit()
  217. */
  218. function workflow_transition($entity, $new_sid, $force = FALSE, $field = array()) {
  219. $entity_type = 'node'; // Entity support is in workflow_transition --> WorkflowDefaultWidget::submit()
  220. // @todo: do not use widget:submit directly, use workflow_entity_save instead.
  221. $widget = new WorkflowDefaultWidget($field, $instance = array(), $entity_type, $entity);
  222. $form = array();
  223. $form_state = array();
  224. $items = array();
  225. $items[0]['workflow'] = (array) $entity;
  226. $items[0]['workflow']['workflow_sid'] = $new_sid;
  227. $widget->submit($form, $form_state, $items, $force);
  228. }
  229. /**
  230. * Get all states in the system by content type.
  231. */
  232. function workflow_get_workflow_states_by_type($type) {
  233. $query = "SELECT ws.sid, ws.wid, ws.state, ws.weight, ws.sysid "
  234. . "FROM {workflow_type_map} wtm "
  235. . "INNER JOIN {workflow_states} ws ON ws.wid = wtm.wid "
  236. . "WHERE wtm.type = :type AND ws.status = 1 "
  237. . "ORDER BY ws.weight, ws.sid ";
  238. $query_array = array(':type' => $type);
  239. $results = db_query($query, $query_array);
  240. return $results->fetchAll();
  241. }
  242. /**
  243. * Get all states in the system, with options to filter, only where a workflow exists.
  244. *
  245. * @deprecated: workflow_get_workflow_states() --> WorkflowState::getStates()
  246. * @deprecated: workflow_get_workflow_states_by_wid() --> WorkflowState::getStates()
  247. */
  248. function workflow_get_workflow_states($options = array()) {
  249. // Build the basic query.
  250. $query = db_select('workflow_states', 'ws');
  251. $query->leftJoin('workflows', 'w', 'w.wid = ws.wid');
  252. $query->fields('ws');
  253. $query->addField('w', 'wid');
  254. $query->addField('w', 'name');
  255. // Spin through the options and add conditions.
  256. foreach ($options as $column => $value) {
  257. $query->condition('ws.' . $column, $value);
  258. }
  259. // Set the sorting order.
  260. $query->orderBy('ws.wid');
  261. $query->orderBy('ws.weight');
  262. // Just for grins, add a tag that might result in modifications.
  263. $query->addTag('workflow_states');
  264. // Give them the answer.
  265. return $query->execute()->fetchAllAssoc('sid');
  266. }
  267. /**
  268. * Get all states in the system, with options to filter, only where a workflow exists.
  269. *
  270. * @deprecated: workflow_get_workflow_states_by_wid --> Workflow->getOptions
  271. */
  272. function workflow_get_workflow_states_by_wid($wid, $options = array()) {
  273. $options['wid'] = $wid;
  274. return workflow_get_workflow_states($options);
  275. }
  276. /**
  277. * Given a sid, return a workflow. Sids are a unique id.
  278. *
  279. * @deprecated: workflow_get_workflow_by_sid --> workflow_state_load_single
  280. */
  281. function workflow_get_workflow_by_sid($sid) {
  282. return db_query("SELECT w.wid, w.name, w.tab_roles, w.options FROM {workflow_states} s
  283. INNER JOIN {workflows} w ON w.wid=s.wid WHERE sid = :sid ",
  284. array(':sid' => $sid))->fetchObject();
  285. }
  286. /**
  287. * Given a sid, return a state. Sids are a unique id.
  288. *
  289. * @deprecated: workflow_get_workflow_states_by_sid --> workflow_state_load_single
  290. */
  291. function workflow_get_workflow_states_by_sid($sid, $options = array()) {
  292. static $sids = array();
  293. if (!isset($sids[$sid])) {
  294. $states = workflow_get_workflow_states(array('sid' => $sid));
  295. $sids[$sid] = reset($states);
  296. }
  297. return $sids[$sid];
  298. }
  299. /**
  300. * Given a sid, return all other states in that workflow.
  301. *
  302. * @deprecated: replaced by WorkflowState::getStates($sid)
  303. */
  304. function workflow_get_other_states_by_sid($sid) {
  305. $query = "SELECT sid, state "
  306. . "FROM {workflow_states} "
  307. . "WHERE wid = (SELECT wid FROM {workflow_states} WHERE sid = :sid AND status = 1 AND sysid = 0) ";
  308. return db_query($query, array(':sid' => $sid))->fetchAllKeyed();
  309. }
  310. /**
  311. * Given a wid and state, return a state. Wids / states are a unique id.
  312. */
  313. function workflow_get_workflow_states_by_wid_state($wid, $state) {
  314. $options = array(
  315. 'state' => $state,
  316. 'wid' => $wid,
  317. );
  318. return workflow_get_workflow_states($options);
  319. }
  320. /**
  321. * Given a sid, delete the state and all associated data.
  322. *
  323. * @deprecated: workflow_delete_workflow_states_by_sid($sid, $new_sid, $true_delete) --> WorkflowState->delete()
  324. */
  325. function workflow_delete_workflow_states_by_sid($sid, $new_sid = FALSE, $true_delete = FALSE) {
  326. if ($state = workflow_state_load_single($sid)) {
  327. $state->delete($new_sid, $true_delete);
  328. }
  329. }
  330. /**
  331. * Save (update/insert) a Workflow State into table {workflow_states}.
  332. *
  333. * @deprecated: workflow_update_workflow_states() --> WorkflowState->save()
  334. */
  335. function workflow_update_workflow_states(&$data) {
  336. $data = (object) $data;
  337. if (!isset($data->sysid)) {
  338. $data->sysid = 0;
  339. }
  340. if (!isset($data->status)) {
  341. $data->status = 1;
  342. }
  343. if (isset($data->sid) && workflow_state_load_single($data->sid)) {
  344. drupal_write_record('workflow_states', $data, 'sid');
  345. }
  346. else {
  347. drupal_write_record('workflow_states', $data);
  348. }
  349. }
  350. /**
  351. * Functions related to table workflow_transitions.
  352. */
  353. /**
  354. * Given a wid get the transitions.
  355. *
  356. * @deprecated: workflow_get_workflow_transitions_by_wid() ==> Workflow->loadTransitions()
  357. */
  358. function workflow_get_workflow_transitions_by_wid($wid) {
  359. static $transitions;
  360. if (!isset($transitions[$wid])) {
  361. $query = 'SELECT t.tid, t.sid, t.target_sid, t.roles, s1.wid '
  362. . 'FROM {workflow_transitions} t '
  363. . 'INNER JOIN {workflow_states} s1 ON t.sid=s1.sid '
  364. . 'INNER JOIN {workflow_states} s2 ON t.target_sid=s2.sid '
  365. . 'WHERE s1.wid = :wid AND s2.wid = :wid';
  366. $transitions[$wid] = db_query('SELECT t.*, s1.wid FROM {workflow_transitions} AS t INNER JOIN {workflow_states} AS s1 ON t.sid=s1.sid INNER JOIN {workflow_states} AS s2 ON t.target_sid=s2.sid WHERE s1.wid = :wid AND s2.wid = :wid',
  367. array(':wid' => $wid))->fetchAll();
  368. }
  369. return $transitions[$wid];
  370. }
  371. /**
  372. * Given a tid, get the transition. It is a unique object, only one return.
  373. */
  374. function workflow_get_workflow_transitions_by_tid($tid) {
  375. static $transitions;
  376. if (!isset($transitions[$tid])) {
  377. $transitions[$tid] = db_query('SELECT tid, sid, target_sid, roles FROM {workflow_transitions} WHERE tid = :tid',
  378. array(':tid' => $tid))->fetchObject();
  379. }
  380. return $transitions[$tid];
  381. }
  382. /**
  383. * Given a sid, get the transition.
  384. *
  385. * @deprecated: workflow_get_workflow_transitions_by_sid --> workflow_state_load_single
  386. */
  387. //function workflow_get_workflow_transitions_by_sid($sid) {
  388. // static $transitions;
  389. // if (!isset($transitions[$sid])) {
  390. // $transitions[$sid] = db_query('SELECT tid, sid, target_sid, roles FROM {workflow_transitions} WHERE sid = :sid',
  391. // array(':sid' => $sid))->fetchAll();
  392. // }
  393. // return $transitions[$sid];
  394. //}
  395. /**
  396. * Given a target_sid, get the transition.
  397. *
  398. * @deprecated: workflow_get_workflow_transitions_by_sid --> Workflow::getTransitionsByTargetSid
  399. */
  400. //function workflow_get_workflow_transitions_by_target_sid($target_sid) {
  401. // static $transitions;
  402. // if (!isset($transitions[$target_sid])) {
  403. // $transitions[$target_sid] = db_query('SELECT tid, sid, target_sid, roles FROM {workflow_transitions} WHERE target_sid = :target_sid',
  404. // array(':target_sid' => $target_sid))->fetchAll();
  405. // }
  406. // return $transitions[$target_sid];
  407. //}
  408. /**
  409. * Given a sid get any transition involved.
  410. *
  411. * @deprecated
  412. */
  413. //function workflow_get_workflow_transitions_by_sid_involved($sid) {
  414. // $results = db_query('SELECT tid, sid, target_sid, roles FROM {workflow_transitions} WHERE sid = :sid OR target_sid = :sid', array(':sid' => $sid));
  415. // return $results->fetchAll();
  416. //}
  417. /**
  418. * Given a role string get any transition involved.
  419. *
  420. * @deprecated
  421. */
  422. //function workflow_get_workflow_transitions_by_roles($roles) {
  423. // $results = db_query('SELECT tid, sid, target_sid, roles FROM {workflow_transitions} WHERE roles LIKE :roles', array(':roles' => $roles));
  424. // return $results->fetchAll();
  425. //}
  426. /**
  427. * Given a sid and target_sid, get the transition. This will be unique.
  428. *
  429. * @deprecated: workflow_get_workflow_transitions_by_sid_target_sid ==> $workflow->getTransitionsBySidTargetSid
  430. */
  431. //function workflow_get_workflow_transitions_by_sid_target_sid($sid, $target_sid) {
  432. // $results = db_query('SELECT tid, sid, target_sid, roles FROM {workflow_transitions} WHERE sid = :sid AND target_sid = :target_sid', array(':sid' => $sid, ':target_sid' => $target_sid));
  433. // return $results->fetchObject();
  434. //}
  435. /**
  436. * Given a tid, delete the transition.
  437. *
  438. * @deprecated: workflow_delete_workflow_transitions_by_tid ==> entity_delete($transition)
  439. */
  440. function workflow_delete_workflow_transitions_by_tid($tid) {
  441. // Notify any interested modules before we delete, in case data is needed.
  442. module_invoke_all('workflow', 'transition delete', $tid, NULL, NULL, FALSE);
  443. return db_delete('workflow_transitions')->condition('tid', $tid)->execute();
  444. }
  445. /**
  446. * Given a sid and target_sid, get the transition. This will be unique.
  447. */
  448. function workflow_delete_workflow_transitions_by_roles($roles) {
  449. // NOTE: This allows us to send notifications out.
  450. foreach (workflow_get_workflow_transitions_by_roles($roles) as $transition) {
  451. workflow_delete_workflow_transitions_by_tid($transition->tid);
  452. }
  453. }
  454. /**
  455. * Given data, insert or update a workflow_transitions.
  456. *
  457. * @deprecated: workflow_update_workflow_transitions() ==> entity_save('WorkflowConfigTransition', $transition)
  458. */
  459. //function workflow_update_workflow_transitions(&$data) {
  460. // $data = (object) $data;
  461. // $transition = workflow_get_workflow_transitions_by_sid_target_sid($data->sid, $data->target_sid);
  462. // if ($transition) {
  463. // $roles = explode(',', $transition->roles);
  464. // foreach (explode(',', $data->roles) as $role) {
  465. // if (array_search($role, $roles) === FALSE) {
  466. // $roles[] = $role;
  467. // }
  468. // }
  469. // $transition->roles = implode(',', $roles);
  470. // drupal_write_record('workflow_transitions', $transition, 'tid');
  471. // $data = $transition;
  472. // }
  473. // else {
  474. // drupal_write_record('workflow_transitions', $data);
  475. // }
  476. //}
  477. /**
  478. * Given a tid and new roles, update them.
  479. *
  480. * @todo - this should be refactored out, and the update made a full actual update.
  481. */
  482. //function workflow_update_workflow_transitions_roles($tid, $roles) {
  483. // return db_update('workflow_transitions')->fields(array('roles' => implode(',', $roles)))->condition('tid', $tid, '=')->execute();
  484. //}
  485. /**
  486. * Get allowable transitions for a given workflow state.
  487. *
  488. * Typical use:
  489. * "global $user;
  490. * "$possible = workflow_allowable_transitions($sid, 'to', $user->roles);
  491. *
  492. * If the state ID corresponded to the state named "Draft", $possible now
  493. * contains the states that the current user may move to from the Draft state.
  494. *
  495. * @param $sid
  496. * The ID of the state in question.
  497. * @param $dir
  498. * The direction of the transition: 'to' or 'from' the state denoted by $sid.
  499. * When set to 'to' all the allowable states that may be moved to are
  500. * returned; when set to 'from' all the allowable states that may move to the
  501. * current state are returned.
  502. * @param mixed $roles
  503. * Array of ints (and possibly the string 'author') representing the user's
  504. * roles. If the string 'ALL' is passed (instead of an array) the role
  505. * constraint is ignored (this is the default for backwards compatibility).
  506. *
  507. * @return array
  508. * Associative array of ($sid => $state_name), excluding current state.
  509. *
  510. * @deprecated: workflow_allowable_transitions() => Workflow::getTransitionsBySid()
  511. */
  512. //function workflow_allowable_transitions($sid, $dir = 'to', $roles = 'ALL') {
  513. // $transitions = array();
  514. //
  515. // // Main query from transitions table.
  516. // $query = db_select('workflow_transitions', 't')
  517. // ->fields('t', array('tid'));
  518. //
  519. // if ($dir == 'to') {
  520. // $query->innerJoin('workflow_states', 's', 's.sid = t.target_sid');
  521. // $query->addField('t', 'target_sid', 'state_id');
  522. // $query->condition('t.sid', $sid);
  523. // }
  524. // else {
  525. // $query->innerJoin('workflow_states', 's', 's.sid = t.sid');
  526. // $query->addField('t', 'sid', 'state_id');
  527. // $query->condition('t.target_sid', $sid);
  528. // }
  529. //
  530. // $query->addField('s', 'state', 'state_name');
  531. // $query->addField('s', 'weight', 'state_weight');
  532. // $query->addField('s', 'sysid');
  533. // $query->condition('s.status', 1);
  534. //
  535. // // Now let's get the current state.
  536. // $query2 = db_select('workflow_states', 's');
  537. // $query2->addField('s', 'sid', 'tid');
  538. // $query2->addField('s', 'sid', 'state_id');
  539. // $query2->addField('s', 'state', 'state_name');
  540. // $query2->addField('s', 'weight', 'state_weight');
  541. // $query2->addField('s', 'sysid');
  542. // $query2->condition('s.status', 1);
  543. // $query2->condition('s.sid', $sid);
  544. //
  545. // $query2->orderBy('state_weight');
  546. // $query2->orderBy('state_id');
  547. //
  548. // // Add the union of the two queries.
  549. // $query->union($query2, 'UNION');
  550. //
  551. // $results = $query->execute();
  552. //
  553. // foreach ($results as $transition) {
  554. // if ($roles == 'ALL' // Superuser.
  555. // || $sid == $transition->state_id // Include current state for same-state transitions.
  556. // || workflow_transition_allowed($transition->tid, $roles)) {
  557. // $transitions[] = $transition;
  558. // // $transitions[$transition->tid] = $transition; //@todo
  559. // }
  560. // }
  561. // return $transitions;
  562. //}
  563. /**
  564. * See if a transition is allowed for a given role.
  565. *
  566. * @param int $tid
  567. * A transition ID.
  568. * @param mixed $role
  569. * A single role (int or string 'author') or array of roles.
  570. *
  571. * @return bool
  572. * TRUE if the role is allowed to do the transition.
  573. *
  574. * @deprecated: workflow_transition_allowed => WorkflowConfigTransition::isAllowed
  575. */
  576. function workflow_transition_allowed($tid, $role = NULL) {
  577. $config_transitions = entity_load('WorkflowConfigTransition', array($tid));
  578. $config_transition = reset($config_transitions);
  579. if ($role) {
  580. if (!is_array($role)) {
  581. $role = array($role);
  582. }
  583. $allowed = $config_transition->roles;
  584. return array_intersect($role, $allowed) == TRUE;
  585. }
  586. }
  587. /**
  588. * Deprecated functions related to table {workflow_scheduled_transition}.
  589. *
  590. * These are replaced by methods of class WorkflowScheduledTransition.
  591. */
  592. /**
  593. * Given a node, get all scheduled transitions for it.
  594. *
  595. * @deprecated: workflow_get_workflow_scheduled_transition_by_nid() --> WorkflowScheduledTransition::load()
  596. */
  597. function workflow_get_workflow_scheduled_transition_by_nid($nid) {
  598. return WorkflowScheduledTransition::load('node', $nid);
  599. }
  600. /**
  601. * Given a timeframe, get all scheduled transitions.
  602. *
  603. * @deprecated: workflow_get_workflow_scheduled_transition_by_between() --> WorkflowScheduledTransition::loadBetween()
  604. */
  605. function workflow_get_workflow_scheduled_transition_by_between($start = 0, $end = REQUEST_TIME) {
  606. return WorkflowScheduledTransition::loadBetween($start, $end);
  607. }
  608. /**
  609. * Insert a new scheduled transition. Only one transition at a time (for now).
  610. *
  611. * @deprecated: workflow_insert_workflow_scheduled_transition() --> WorkflowScheduledTransition::save()
  612. */
  613. function workflow_insert_workflow_scheduled_transition($data) {
  614. $data = (object) $data;
  615. workflow_delete_workflow_scheduled_transition_by_nid($data->nid);
  616. drupal_write_record('workflow_scheduled_transition', $data);
  617. }
  618. /**
  619. * Given a node, delete transitions for it.
  620. *
  621. * @deprecated: workflow_delete_workflow_scheduled_transition_by_nid() --> WorkflowScheduledTransition::delete()
  622. */
  623. // function workflow_delete_workflow_scheduled_transition_by_nid($nid) {
  624. // return WorkflowScheduledTransition::deleteById('node', $nid);
  625. // }
  626. /**
  627. * Deprecated functions related to table {workflow_node}.
  628. */
  629. /**
  630. * Given nid, update the new stamp. This probably can be refactored. Called by workflow_execute_transition().
  631. *
  632. * @deprecated: this is micro-optimalisation.
  633. */
  634. function workflow_update_workflow_node_stamp($nid, $new_stamp) {
  635. return db_update('workflow_node')->fields(array('stamp' => $new_stamp))->condition('nid', $nid, '=')->execute();
  636. }
  637. /**
  638. * Deprecated functions related to table {workflow_node_history}.
  639. */
  640. /**
  641. * Get most recent transition for a node.
  642. *
  643. * @deprecated: workflow_get_recent_node_history() --> workflow_transition_load_single()
  644. */
  645. function workflow_get_recent_node_history($nid) {
  646. $field_name = '';
  647. return workflow_transition_load_single('node', $nid, $field_name);
  648. }
  649. /**
  650. * Get all recorded history for a node id.
  651. *
  652. * Since this may return a lot of data, a limit is included to allow for only one result.
  653. */
  654. function workflow_get_workflow_node_history_by_nid($nid, $limit = NULL) {
  655. $field_name = '';
  656. return workflow_transition_load_multiple('node', array($nid), $field_name, $limit);
  657. }
  658. /**
  659. * Given data, insert a new history. Always insert.
  660. *
  661. * @deprecated: workflow_insert_workflow_node_history() --> WorkflowTransition::save()
  662. */
  663. function workflow_insert_workflow_node_history($data) {
  664. $data = (object) $data;
  665. if (isset($data->hid)) {
  666. unset($data->hid);
  667. }
  668. // Check for no transition.
  669. if ($data->old_sid == $data->sid) {
  670. // Make sure we haven't already inserted history for this update.
  671. $last_history = workflow_get_workflow_node_history_by_nid($data->nid, 1);
  672. if (isset($last_history) && $last_history->stamp == REQUEST_TIME) {
  673. return;
  674. }
  675. }
  676. drupal_write_record('workflow_node_history', $data);
  677. }