Commit 0e86a23d0881050168cea894f3a2bc00ca05d53a

Authored by Conrad Vermeulen
1 parent f26e96a1

KTS-2358

"php5 migration"
Updated. Removed & from &new. Added statics.

Committed By: Conrad Vermeulen
Reviewed By: Kevin Fourie

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@7196 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/workflow/workflowutil.inc.php
@@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
6 * License Version 1.1.2 ("License"); You may not use this file except in 6 * License Version 1.1.2 ("License"); You may not use this file except in
7 * compliance with the License. You may obtain a copy of the License at 7 * compliance with the License. You may obtain a copy of the License at
8 * http://www.knowledgetree.com/KPL 8 * http://www.knowledgetree.com/KPL
9 - * 9 + *
10 * Software distributed under the License is distributed on an "AS IS" 10 * Software distributed under the License is distributed on an "AS IS"
11 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 11 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
12 * See the License for the specific language governing rights and 12 * See the License for the specific language governing rights and
@@ -17,9 +17,9 @@ @@ -17,9 +17,9 @@
17 * (ii) the KnowledgeTree copyright notice 17 * (ii) the KnowledgeTree copyright notice
18 * in the same form as they appear in the distribution. See the License for 18 * in the same form as they appear in the distribution. See the License for
19 * requirements. 19 * requirements.
20 - * 20 + *
21 * The Original Code is: KnowledgeTree Open Source 21 * The Original Code is: KnowledgeTree Open Source
22 - * 22 + *
23 * The Initial Developer of the Original Code is The Jam Warehouse Software 23 * The Initial Developer of the Original Code is The Jam Warehouse Software
24 * (Pty) Ltd, trading as KnowledgeTree. 24 * (Pty) Ltd, trading as KnowledgeTree.
25 * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright 25 * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright
@@ -123,11 +123,11 @@ class KTWorkflowUtil { @@ -123,11 +123,11 @@ class KTWorkflowUtil {
123 /* WILL NOT RESET THE WORKFLOW if changing to the -same- workflow */ 123 /* WILL NOT RESET THE WORKFLOW if changing to the -same- workflow */
124 function changeWorkflowOnDocument($oWorkflow, $oDocument) { 124 function changeWorkflowOnDocument($oWorkflow, $oDocument) {
125 $oDocument =& KTUtil::getObject('Document', $oDocument); 125 $oDocument =& KTUtil::getObject('Document', $oDocument);
126 -  
127 - 126 +
  127 +
128 // fix for 1049: workflows reset on document move. 128 // fix for 1049: workflows reset on document move.
129 // this was the original purpose of "changeWorkflowOnDocument". 129 // this was the original purpose of "changeWorkflowOnDocument".
130 - if (is_null($oWorkflow)) { 130 + if (is_null($oWorkflow)) {
131 if ($oDocument->getWorkflowId() == null) { 131 if ($oDocument->getWorkflowId() == null) {
132 return true; // no definition. 132 return true; // no definition.
133 } 133 }
@@ -135,8 +135,8 @@ class KTWorkflowUtil { @@ -135,8 +135,8 @@ class KTWorkflowUtil {
135 if ($oDocument->getWorkflowId() == $oWorkflow->getId()) { 135 if ($oDocument->getWorkflowId() == $oWorkflow->getId()) {
136 return true; // bail out, essentially. 136 return true; // bail out, essentially.
137 } 137 }
138 - }  
139 - 138 + }
  139 +
140 return KTWorkflowUtil::startWorkflowOnDocument($oWorkflow, $oDocument); 140 return KTWorkflowUtil::startWorkflowOnDocument($oWorkflow, $oDocument);
141 } 141 }
142 // {{{ startWorkflowOnDocument 142 // {{{ startWorkflowOnDocument
@@ -169,7 +169,7 @@ class KTWorkflowUtil { @@ -169,7 +169,7 @@ class KTWorkflowUtil {
169 $oDocument->setWorkflowId($iWorkflowId); 169 $oDocument->setWorkflowId($iWorkflowId);
170 $oDocument->setWorkflowStateId($iStartStateId); 170 $oDocument->setWorkflowStateId($iStartStateId);
171 $sTransactionComments = sprintf(_kt("Workflow \"%s\" started."), $oWorkflow->getHumanName()); 171 $sTransactionComments = sprintf(_kt("Workflow \"%s\" started."), $oWorkflow->getHumanName());
172 - 172 +
173 } else { 173 } else {
174 $oDocument->setWorkflowId(null); 174 $oDocument->setWorkflowId(null);
175 $oDocument->setWorkflowStateId(null); 175 $oDocument->setWorkflowStateId(null);
@@ -180,20 +180,20 @@ class KTWorkflowUtil { @@ -180,20 +180,20 @@ class KTWorkflowUtil {
180 if (PEAR::isError($res)) { return $res; } 180 if (PEAR::isError($res)) { return $res; }
181 181
182 // create the document transaction record 182 // create the document transaction record
183 - $oDocumentTransaction = & new DocumentTransaction($oDocument, $sTransactionComments, 'ktcore.transactions.workflow_state_transition'); 183 + $oDocumentTransaction = new DocumentTransaction($oDocument, $sTransactionComments, 'ktcore.transactions.workflow_state_transition');
184 $oDocumentTransaction->create(); 184 $oDocumentTransaction->create();
185 185
186 186
187 // FIXME does this function as expected? 187 // FIXME does this function as expected?
188 - 188 +
189 KTPermissionUtil::updatePermissionLookup($oDocument); 189 KTPermissionUtil::updatePermissionLookup($oDocument);
190 - 190 +
191 if (isset($iStartStateId)) { 191 if (isset($iStartStateId)) {
192 $oTargetState = KTWorkflowState::get($iStartStateId); 192 $oTargetState = KTWorkflowState::get($iStartStateId);
193 - KTWorkflowUtil::informUsersForState($oTargetState, 193 + KTWorkflowUtil::informUsersForState($oTargetState,
194 KTWorkflowUtil::getInformedForState($oTargetState), $oDocument, $oUser, ''); 194 KTWorkflowUtil::getInformedForState($oTargetState), $oDocument, $oUser, '');
195 } 195 }
196 - 196 +
197 return $res; 197 return $res;
198 } 198 }
199 // }}} 199 // }}}
@@ -287,7 +287,7 @@ class KTWorkflowUtil { @@ -287,7 +287,7 @@ class KTWorkflowUtil {
287 } 287 }
288 288
289 if(!is_array($aActions)) return; 289 if(!is_array($aActions)) return;
290 - 290 +
291 $aOptions = array('noid' => true); 291 $aOptions = array('noid' => true);
292 foreach ($aActions as $sAction) { 292 foreach ($aActions as $sAction) {
293 $res = DBUtil::autoInsert($sTable, array( 293 $res = DBUtil::autoInsert($sTable, array(
@@ -316,7 +316,7 @@ class KTWorkflowUtil { @@ -316,7 +316,7 @@ class KTWorkflowUtil {
316 } 316 }
317 317
318 if(!is_array($aActions)) return; 318 if(!is_array($aActions)) return;
319 - 319 +
320 $aOptions = array('noid' => true); 320 $aOptions = array('noid' => true);
321 foreach ($aActions as $sAction) { 321 foreach ($aActions as $sAction) {
322 $res = DBUtil::autoInsert($sTable, array( 322 $res = DBUtil::autoInsert($sTable, array(
@@ -328,7 +328,7 @@ class KTWorkflowUtil { @@ -328,7 +328,7 @@ class KTWorkflowUtil {
328 } 328 }
329 } 329 }
330 return; 330 return;
331 - } 331 + }
332 332
333 // {{{ getEnabledActionsForState 333 // {{{ getEnabledActionsForState
334 /** 334 /**
@@ -405,7 +405,7 @@ class KTWorkflowUtil { @@ -405,7 +405,7 @@ class KTWorkflowUtil {
405 */ 405 */
406 function getWorkflowForDocument ($oDocument, $aOptions = null) { 406 function getWorkflowForDocument ($oDocument, $aOptions = null) {
407 $ids = KTUtil::arrayGet($aOptions, 'ids', false); 407 $ids = KTUtil::arrayGet($aOptions, 'ids', false);
408 - 408 +
409 if (is_a($oDocument, 'KTDocumentCore')) { 409 if (is_a($oDocument, 'KTDocumentCore')) {
410 $oDocument = $oDocument->getId(); 410 $oDocument = $oDocument->getId();
411 } 411 }
@@ -435,7 +435,7 @@ class KTWorkflowUtil { @@ -435,7 +435,7 @@ class KTWorkflowUtil {
435 * returning null if there is no workflow assigned. 435 * returning null if there is no workflow assigned.
436 */ 436 */
437 function getWorkflowStateForDocument ($oDocument, $aOptions = null) { 437 function getWorkflowStateForDocument ($oDocument, $aOptions = null) {
438 - 438 +
439 $ids = KTUtil::arrayGet($aOptions, 'ids', false); 439 $ids = KTUtil::arrayGet($aOptions, 'ids', false);
440 440
441 if (is_a($oDocument, 'KTDocumentCore')) { 441 if (is_a($oDocument, 'KTDocumentCore')) {
@@ -478,9 +478,9 @@ class KTWorkflowUtil { @@ -478,9 +478,9 @@ class KTWorkflowUtil {
478 $aTransitions = KTWorkflowUtil::getTransitionsFrom($oState); 478 $aTransitions = KTWorkflowUtil::getTransitionsFrom($oState);
479 $aEnabledTransitions = array(); 479 $aEnabledTransitions = array();
480 foreach ($aTransitions as $oTransition) { 480 foreach ($aTransitions as $oTransition) {
481 - 481 +
482 // keeping this around to make coding the replacements easier. 482 // keeping this around to make coding the replacements easier.
483 - 483 +
484 /* 484 /*
485 $iPermissionId = $oTransition->getGuardPermissionId(); 485 $iPermissionId = $oTransition->getGuardPermissionId();
486 if ($iPermissionId) { 486 if ($iPermissionId) {
@@ -500,11 +500,11 @@ class KTWorkflowUtil { @@ -500,11 +500,11 @@ class KTWorkflowUtil {
500 $iRoleId = $oTransition->getGuardRoleId(); 500 $iRoleId = $oTransition->getGuardRoleId();
501 if ($iRoleId) { 501 if ($iRoleId) {
502 $oRoleAllocation = RoleAllocation::getAllocationsForFolderAndRole($oDocument->getFolderID(), $iRoleId); 502 $oRoleAllocation = RoleAllocation::getAllocationsForFolderAndRole($oDocument->getFolderID(), $iRoleId);
503 - 503 +
504 if ($oRoleAllocation == null) { // no role allocation, no fulfillment. 504 if ($oRoleAllocation == null) { // no role allocation, no fulfillment.
505 continue; 505 continue;
506 } 506 }
507 - 507 +
508 if (!$oRoleAllocation->hasMember($oUser)) { 508 if (!$oRoleAllocation->hasMember($oUser)) {
509 continue; 509 continue;
510 } 510 }
@@ -517,7 +517,7 @@ class KTWorkflowUtil { @@ -517,7 +517,7 @@ class KTWorkflowUtil {
517 } 517 }
518 } 518 }
519 */ 519 */
520 - 520 +
521 $aGuardTriggers = KTWorkflowUtil::getGuardTriggersForTransition($oTransition); 521 $aGuardTriggers = KTWorkflowUtil::getGuardTriggersForTransition($oTransition);
522 if (PEAR::isError($aGuardTriggers)) { 522 if (PEAR::isError($aGuardTriggers)) {
523 return $aGuardTriggers; // error out? 523 return $aGuardTriggers; // error out?
@@ -555,7 +555,7 @@ class KTWorkflowUtil { @@ -555,7 +555,7 @@ class KTWorkflowUtil {
555 return $oWorkflow; 555 return $oWorkflow;
556 } 556 }
557 $oSourceState =& KTWorkflowUtil::getWorkflowStateForDocument($oDocument); 557 $oSourceState =& KTWorkflowUtil::getWorkflowStateForDocument($oDocument);
558 - 558 +
559 // walk the action triggers. 559 // walk the action triggers.
560 $aActionTriggers = KTWorkflowUtil::getActionTriggersForTransition($oTransition); 560 $aActionTriggers = KTWorkflowUtil::getActionTriggersForTransition($oTransition);
561 if (PEAR::isError($aActionTriggers)) { 561 if (PEAR::isError($aActionTriggers)) {
@@ -586,11 +586,11 @@ class KTWorkflowUtil { @@ -586,11 +586,11 @@ class KTWorkflowUtil {
586 586
587 // create the document transaction record 587 // create the document transaction record
588 $sTransactionComments = sprintf(_kt("Workflow state changed from %s to %s"), $sSourceState, $sTargetState); 588 $sTransactionComments = sprintf(_kt("Workflow state changed from %s to %s"), $sSourceState, $sTargetState);
589 - 589 +
590 if ($sComments) { 590 if ($sComments) {
591 $sTransactionComments .= _kt("; Reason given was: ") . $sComments; 591 $sTransactionComments .= _kt("; Reason given was: ") . $sComments;
592 } 592 }
593 - $oDocumentTransaction = & new DocumentTransaction($oDocument, $sTransactionComments, 'ktcore.transactions.workflow_state_transition'); 593 + $oDocumentTransaction = new DocumentTransaction($oDocument, $sTransactionComments, 'ktcore.transactions.workflow_state_transition');
594 $oDocumentTransaction->create(); 594 $oDocumentTransaction->create();
595 595
596 // walk the action triggers. 596 // walk the action triggers.
@@ -611,13 +611,13 @@ class KTWorkflowUtil { @@ -611,13 +611,13 @@ class KTWorkflowUtil {
611 // {{{ informUsersForState 611 // {{{ informUsersForState
612 function informUsersForState($oState, $aInformed, $oDocument, $oUser, $sComments) { 612 function informUsersForState($oState, $aInformed, $oDocument, $oUser, $sComments) {
613 // say no to duplicates. 613 // say no to duplicates.
614 - 614 +
615 KTWorkflowNotification::clearNotificationsForDocument($oDocument); 615 KTWorkflowNotification::clearNotificationsForDocument($oDocument);
616 616
617 $aUsers = array(); 617 $aUsers = array();
618 $aGroups = array(); 618 $aGroups = array();
619 $aRoles = array(); 619 $aRoles = array();
620 - 620 +
621 foreach (KTUtil::arrayGet($aInformed,'user',array()) as $iUserId) { 621 foreach (KTUtil::arrayGet($aInformed,'user',array()) as $iUserId) {
622 $oU = User::get($iUserId); 622 $oU = User::get($iUserId);
623 if (PEAR::isError($oU) || ($oU == false)) { 623 if (PEAR::isError($oU) || ($oU == false)) {
@@ -626,7 +626,7 @@ class KTWorkflowUtil { @@ -626,7 +626,7 @@ class KTWorkflowUtil {
626 $aUsers[$oU->getId()] = $oU; 626 $aUsers[$oU->getId()] = $oU;
627 } 627 }
628 } 628 }
629 - 629 +
630 foreach (KTUtil::arrayGet($aInformed,'group',array()) as $iGroupId) { 630 foreach (KTUtil::arrayGet($aInformed,'group',array()) as $iGroupId) {
631 $oG = Group::get($iGroupId); 631 $oG = Group::get($iGroupId);
632 if (PEAR::isError($oG) || ($oG == false)) { 632 if (PEAR::isError($oG) || ($oG == false)) {
@@ -635,7 +635,7 @@ class KTWorkflowUtil { @@ -635,7 +635,7 @@ class KTWorkflowUtil {
635 $aGroups[$oG->getId()] = $oG; 635 $aGroups[$oG->getId()] = $oG;
636 } 636 }
637 } 637 }
638 - 638 +
639 foreach (KTUtil::arrayGet($aInformed,'role',array()) as $iRoleId) { 639 foreach (KTUtil::arrayGet($aInformed,'role',array()) as $iRoleId) {
640 $oR = Role::get($iRoleId); 640 $oR = Role::get($iRoleId);
641 if (PEAR::isError($oR) || ($oR == false)) { 641 if (PEAR::isError($oR) || ($oR == false)) {
@@ -644,9 +644,9 @@ class KTWorkflowUtil { @@ -644,9 +644,9 @@ class KTWorkflowUtil {
644 $aRoles[] = $oR; 644 $aRoles[] = $oR;
645 } 645 }
646 } 646 }
647 -  
648 -  
649 - 647 +
  648 +
  649 +
650 // FIXME extract this into a util - I see us using this again and again. 650 // FIXME extract this into a util - I see us using this again and again.
651 // start with roles ... roles _only_ ever contain groups. 651 // start with roles ... roles _only_ ever contain groups.
652 foreach ($aRoles as $oRole) { 652 foreach ($aRoles as $oRole) {
@@ -662,11 +662,11 @@ class KTWorkflowUtil { @@ -662,11 +662,11 @@ class KTWorkflowUtil {
662 $oRoleAllocation = RoleAllocation::getAllocationsForFolderAndRole($oDocument->getFolderID(), $oRole->getId()); 662 $oRoleAllocation = RoleAllocation::getAllocationsForFolderAndRole($oDocument->getFolderID(), $oRole->getId());
663 } 663 }
664 if (is_null($oRoleAllocation) || PEAR::isError($oRoleAllocation)) { 664 if (is_null($oRoleAllocation) || PEAR::isError($oRoleAllocation)) {
665 - continue; 665 + continue;
666 } 666 }
667 $aRoleUsers = $oRoleAllocation->getUsers(); 667 $aRoleUsers = $oRoleAllocation->getUsers();
668 $aRoleGroups = $oRoleAllocation->getGroups(); 668 $aRoleGroups = $oRoleAllocation->getGroups();
669 - 669 +
670 foreach ($aRoleUsers as $id => $oU) { 670 foreach ($aRoleUsers as $id => $oU) {
671 $aUsers[$id] = $oU; 671 $aUsers[$id] = $oU;
672 } 672 }
@@ -674,27 +674,27 @@ class KTWorkflowUtil { @@ -674,27 +674,27 @@ class KTWorkflowUtil {
674 $aGroups[$id] = $oGroup; 674 $aGroups[$id] = $oGroup;
675 } 675 }
676 } 676 }
677 -  
678 -  
679 - 677 +
  678 +
  679 +
680 // we now have a (potentially overlapping) set of groups, which may 680 // we now have a (potentially overlapping) set of groups, which may
681 // have subgroups. 681 // have subgroups.
682 // 682 //
683 // what we need to do _now_ is build a canonical set of groups, and then 683 // what we need to do _now_ is build a canonical set of groups, and then
684 // generate the singular user-base. 684 // generate the singular user-base.
685 - 685 +
686 $aGroupMembershipSet = GroupUtil::buildGroupArray(); 686 $aGroupMembershipSet = GroupUtil::buildGroupArray();
687 $aAllIds = array_keys($aGroups); 687 $aAllIds = array_keys($aGroups);
688 foreach ($aGroups as $id => $oGroup) { 688 foreach ($aGroups as $id => $oGroup) {
689 $aAllIds = kt_array_merge($aGroupMembershipSet[$id], $aAllIds); 689 $aAllIds = kt_array_merge($aGroupMembershipSet[$id], $aAllIds);
690 } 690 }
691 - 691 +
692 foreach ($aAllIds as $id) { 692 foreach ($aAllIds as $id) {
693 if (!array_key_exists($id, $aGroups)) { 693 if (!array_key_exists($id, $aGroups)) {
694 $aGroups[$id] = Group::get($id); 694 $aGroups[$id] = Group::get($id);
695 } 695 }
696 } 696 }
697 - 697 +
698 // now, merge this (again) into the user-set. 698 // now, merge this (again) into the user-set.
699 foreach ($aGroups as $oGroup) { 699 foreach ($aGroups as $oGroup) {
700 $aNewUsers = $oGroup->getMembers(); 700 $aNewUsers = $oGroup->getMembers();
@@ -705,9 +705,9 @@ class KTWorkflowUtil { @@ -705,9 +705,9 @@ class KTWorkflowUtil {
705 } 705 }
706 } 706 }
707 } 707 }
708 -  
709 -  
710 - // and done. 708 +
  709 +
  710 + // and done.
711 foreach ($aUsers as $oU) { 711 foreach ($aUsers as $oU) {
712 if (!PEAR::isError($oU)) { 712 if (!PEAR::isError($oU)) {
713 KTWorkflowNotification::newNotificationForDocument($oDocument, $oU, $oState, $oUser, $sComments); 713 KTWorkflowNotification::newNotificationForDocument($oDocument, $oU, $oState, $oUser, $sComments);
@@ -750,7 +750,7 @@ class KTWorkflowUtil { @@ -750,7 +750,7 @@ class KTWorkflowUtil {
750 return KTPermissionUtil::getAllowedForDescriptor($iDescriptorId); 750 return KTPermissionUtil::getAllowedForDescriptor($iDescriptorId);
751 } 751 }
752 // }}} 752 // }}}
753 - 753 +
754 // retrieves the triggers for a given transition in their WorkflowTrigger form. 754 // retrieves the triggers for a given transition in their WorkflowTrigger form.
755 function getTriggersForTransition($oTransition) { 755 function getTriggersForTransition($oTransition) {
756 $oKTWorkflowTriggerRegistry =& KTWorkflowTriggerRegistry::getSingleton(); 756 $oKTWorkflowTriggerRegistry =& KTWorkflowTriggerRegistry::getSingleton();
@@ -766,106 +766,106 @@ class KTWorkflowUtil { @@ -766,106 +766,106 @@ class KTWorkflowUtil {
766 } 766 }
767 return $aTriggers; 767 return $aTriggers;
768 } 768 }
769 - 769 +
770 function getGuardTriggersForTransition($oTransition) { 770 function getGuardTriggersForTransition($oTransition) {
771 $aTriggers = KTWorkflowUtil::getTriggersForTransition($oTransition); 771 $aTriggers = KTWorkflowUtil::getTriggersForTransition($oTransition);
772 - if (PEAR::isError($aTriggers)) {  
773 - return $aTriggers; 772 + if (PEAR::isError($aTriggers)) {
  773 + return $aTriggers;
774 } 774 }
775 $aGuards = array(); 775 $aGuards = array();
776 foreach ($aTriggers as $oTrigger) { 776 foreach ($aTriggers as $oTrigger) {
777 $aInfo = $oTrigger->getInfo(); 777 $aInfo = $oTrigger->getInfo();
778 - if ($aInfo['guard']) { 778 + if ($aInfo['guard']) {
779 $aGuards[] = $oTrigger; 779 $aGuards[] = $oTrigger;
780 } 780 }
781 } 781 }
782 return $aGuards; 782 return $aGuards;
783 } 783 }
784 - 784 +
785 function getActionTriggersForTransition($oTransition) { 785 function getActionTriggersForTransition($oTransition) {
786 $aTriggers = KTWorkflowUtil::getTriggersForTransition($oTransition); 786 $aTriggers = KTWorkflowUtil::getTriggersForTransition($oTransition);
787 - if (PEAR::isError($aTriggers)) {  
788 - return $aTriggers; 787 + if (PEAR::isError($aTriggers)) {
  788 + return $aTriggers;
789 } 789 }
790 $aGuards = array(); 790 $aGuards = array();
791 foreach ($aTriggers as $oTrigger) { 791 foreach ($aTriggers as $oTrigger) {
792 $aInfo = $oTrigger->getInfo(); 792 $aInfo = $oTrigger->getInfo();
793 - if ($aInfo['action']) { 793 + if ($aInfo['action']) {
794 $aGuards[] = $oTrigger; 794 $aGuards[] = $oTrigger;
795 } 795 }
796 } 796 }
797 return $aGuards; 797 return $aGuards;
798 } 798 }
799 - 799 +
800 800
801 function replaceState($oState, $oReplacement) { 801 function replaceState($oState, $oReplacement) {
802 $state_id = KTUtil::getId($oState); 802 $state_id = KTUtil::getId($oState);
803 $replacement_id = KTUtil::getId($oReplacement); 803 $replacement_id = KTUtil::getId($oReplacement);
804 - 804 +
805 // we need to convert: 805 // we need to convert:
806 // - documents 806 // - documents
807 // - transitions 807 // - transitions
808 // before we do a delete. 808 // before we do a delete.
809 - $doc = KTUtil::getTableName('document_metadata_version'); 809 + $doc = KTUtil::getTableName('document_metadata_version');
810 $aDocQuery = array( 810 $aDocQuery = array(
811 "UPDATE $doc SET workflow_state_id = ? WHERE workflow_state_id = ?", 811 "UPDATE $doc SET workflow_state_id = ? WHERE workflow_state_id = ?",
812 array($replacement_id, $state_id), 812 array($replacement_id, $state_id),
813 - ); 813 + );
814 $res = DBUtil::runQuery($aDocQuery); 814 $res = DBUtil::runQuery($aDocQuery);
815 if (PEAR::isError($res)) { return $res; } 815 if (PEAR::isError($res)) { return $res; }
816 - 816 +
817 $wf = KTUtil::getTableName('workflow_transitions'); 817 $wf = KTUtil::getTableName('workflow_transitions');
818 $aTransitionQuery = array( 818 $aTransitionQuery = array(
819 "UPDATE $wf SET target_state_id = ? WHERE workflow_state_id = ?", 819 "UPDATE $wf SET target_state_id = ? WHERE workflow_state_id = ?",
820 array($replacement_id, $state_id), 820 array($replacement_id, $state_id),
821 - );  
822 - $res = DBUtil::runQuery($aTransitionQuery); 821 + );
  822 + $res = DBUtil::runQuery($aTransitionQuery);
823 if (PEAR::isError($res)) { return $res; } 823 if (PEAR::isError($res)) { return $res; }
824 - 824 +
825 $wf = KTUtil::getTableName('workflow_state_transitions'); 825 $wf = KTUtil::getTableName('workflow_state_transitions');
826 $aTransitionQuery = array( 826 $aTransitionQuery = array(
827 "DELETE FROM $wf WHERE state_id = ?", 827 "DELETE FROM $wf WHERE state_id = ?",
828 array($state_id), 828 array($state_id),
829 - );  
830 - $res = DBUtil::runQuery($aTransitionQuery); 829 + );
  830 + $res = DBUtil::runQuery($aTransitionQuery);
831 if (PEAR::isError($res)) { return $res; } 831 if (PEAR::isError($res)) { return $res; }
832 - 832 +
833 Document::clearAllCaches(); 833 Document::clearAllCaches();
834 - KTWorkflowTransitions::clearAllCaches(); 834 + KTWorkflowTransitions::clearAllCaches();
835 } 835 }
836 -} 836 +}
837 837
838 class KTWorkflowTriggerRegistry { 838 class KTWorkflowTriggerRegistry {
839 var $triggers; 839 var $triggers;
840 - 840 +
841 function KTWorkflowTriggerRegistry() { 841 function KTWorkflowTriggerRegistry() {
842 $this->triggers = array(); 842 $this->triggers = array();
843 - }  
844 -  
845 - // {{{ getSingleton  
846 - function &getSingleton () {  
847 - if (!KTUtil::arrayGet($GLOBALS['_KT_PLUGIN'], 'oKTWorkflowTriggerRegistry')) {  
848 - $GLOBALS['_KT_PLUGIN']['oKTWorkflowTriggerRegistry'] = new KTWorkflowTriggerRegistry;  
849 - }  
850 - return $GLOBALS['_KT_PLUGIN']['oKTWorkflowTriggerRegistry'];  
851 } 843 }
852 - // }}}  
853 - 844 +
  845 + static function &getSingleton () {
  846 + static $singleton=null;
  847 + if (is_null($singleton))
  848 + {
  849 + $singleton = new KTWorkflowTriggerRegistry();
  850 + }
  851 + return $singleton;
  852 + }
  853 +
854 function registerWorkflowTrigger($sNamespace, $sClassname, $sPath) { 854 function registerWorkflowTrigger($sNamespace, $sClassname, $sPath) {
855 $this->triggers[$sNamespace] = array('class' => $sClassname, 'path' => $sPath); 855 $this->triggers[$sNamespace] = array('class' => $sClassname, 'path' => $sPath);
856 } 856 }
857 - 857 +
858 function getWorkflowTrigger($sNamespace) { 858 function getWorkflowTrigger($sNamespace) {
859 $aInfo = KTUtil::arrayGet($this->triggers, $sNamespace, null); 859 $aInfo = KTUtil::arrayGet($this->triggers, $sNamespace, null);
860 if (is_null($aInfo)) { 860 if (is_null($aInfo)) {
861 return PEAR::raiseError(sprintf(_kt("Unable to find workflow trigger: %s"), $sNamespace)); 861 return PEAR::raiseError(sprintf(_kt("Unable to find workflow trigger: %s"), $sNamespace));
862 - }  
863 - 862 + }
  863 +
864 require_once($aInfo['path']); 864 require_once($aInfo['path']);
865 865
866 return new $aInfo['class']; 866 return new $aInfo['class'];
867 } 867 }
868 - 868 +
869 // get a keyed list of workflow triggers 869 // get a keyed list of workflow triggers
870 870
871 function listWorkflowTriggers() { 871 function listWorkflowTriggers() {
@@ -877,5 +877,5 @@ class KTWorkflowTriggerRegistry { @@ -877,5 +877,5 @@ class KTWorkflowTriggerRegistry {
877 // FIXME do we want to order this alphabetically? 877 // FIXME do we want to order this alphabetically?
878 return $triggerlist; 878 return $triggerlist;
879 } 879 }
880 -} 880 +}
881 881