workflow.deprecated.inc 23 KB

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