/** * initialize a test method */ public function setUp() { TaoPhpUnitTestRunner::initTest(); error_reporting(E_ALL); if (is_null($this->userService)) { $this->userService = wfEngine_models_classes_UserService::singleton(); } $login = '******'; $pass = '******'; $langResource = tao_models_classes_LanguageService::singleton()->getLanguageByCode(DEFAULT_LANG); $userData = array(PROPERTY_USER_LOGIN => $login, PROPERTY_USER_PASSWORD => core_kernel_users_Service::getPasswordHash()->encrypt($pass), PROPERTY_USER_DEFLG => $langResource, PROPERTY_USER_MAIL => '*****@*****.**', PROPERTY_USER_FIRSTNAME => 'Sammy', PROPERTY_USER_LASTNAME => 'Norville Rogers', PROPERTY_USER_ROLES => INSTANCE_ROLE_WORKFLOW); if (!$this->userService->loginAvailable($login)) { $this->fail('test login already taken'); } $userClass = new core_kernel_classes_Class(CLASS_WORKFLOWUSER); $this->currentUser = $userClass->createInstanceWithProperties($userData); $this->assertTrue($this->userService->loginUser($login, $pass)); $this->service = wfEngine_models_classes_NotificationService::singleton(); }
/** * Short description of method performTransition * * @access public * @author Somsack Sipasseuth, <*****@*****.**> * @param Resource processExecution * @param Resource activityExecution * @return mixed */ public function performTransition(core_kernel_classes_Resource $processExecution, core_kernel_classes_Resource $activityExecution) { $returnValue = null; $session = PHPSession::singleton(); $session->setAttribute("activityExecutionUri", $activityExecution->getUri()); //check if the transition is possible, e.g. process is not finished if ($this->isFinished($processExecution)) { return false; } //init the services $activityDefinitionService = wfEngine_models_classes_ActivityService::singleton(); $connectorService = wfEngine_models_classes_ConnectorService::singleton(); $userService = wfEngine_models_classes_UserService::singleton(); $notificationService = wfEngine_models_classes_NotificationService::singleton(); $currentUser = $userService->getCurrentUser(); //set the activity execution of the current user as finished: if ($activityExecution->exists()) { $this->activityExecutionService->finish($activityExecution); } else { throw new Exception("cannot find the activity execution of the current activity {$activityBeforeTransition->getUri()} in perform transition"); } $activityBeforeTransition = $this->activityExecutionService->getExecutionOf($activityExecution); $nextConnector = $activityDefinitionService->getUniqueNextConnector($activityBeforeTransition); if (wfEngine_models_classes_ActivityCardinalityService::singleton()->isCardinality($nextConnector)) { $nextConnector = wfEngine_models_classes_ActivityCardinalityService::singleton()->getDestination($nextConnector); } $newActivities = array(); if (!is_null($nextConnector)) { $newActivities = $this->getNewActivities($processExecution, $activityExecution, $nextConnector); } else { //final activity: $this->finish($processExecution); return array(); } if ($newActivities === false) { //means that the process must be paused before transition: transition condition not fullfilled $this->pause($processExecution); return false; } // The actual transition starts here: $newActivityExecutions = array(); if (!is_null($nextConnector)) { //trigger the forward transition: $newActivityExecutions = $this->activityExecutionService->moveForward($activityExecution, $nextConnector, $newActivities, $processExecution); //trigger the notifications $notificationService->trigger($nextConnector, $activityExecution, $processExecution); } //transition done from here: now get the following activities: //if the connector is not a parallel one, let the user continue in his current branch and prevent the pause: $uniqueNextActivityExecution = null; if (!is_null($nextConnector)) { if ($connectorService->getType($nextConnector)->getUri() != INSTANCE_TYPEOFCONNECTORS_PARALLEL) { if (count($newActivityExecutions) == 1) { //TODO: could do a double check here: if($newActivities[0] is one of the activty found in the current tokens): if ($this->activityExecutionService->checkAcl(reset($newActivityExecutions), $currentUser, $processExecution)) { $uniqueNextActivityExecution = reset($newActivityExecutions); } } } } $setPause = true; $authorizedActivityExecutions = array(); if (!count($newActivities) || $activityDefinitionService->isFinal($activityBeforeTransition)) { //there is no following activity so the process ends here: $this->finish($processExecution); return array(); } elseif (!is_null($uniqueNextActivityExecution)) { //we are certain that the next activity would be for the user so return it: $authorizedActivityExecutions[$uniqueNextActivityExecution->getUri()] = $uniqueNextActivityExecution; $setPause = false; } else { foreach ($newActivityExecutions as $activityExecutionAfterTransition) { //check if the current user is allowed to execute the activity if ($this->activityExecutionService->checkAcl($activityExecutionAfterTransition, $currentUser, $processExecution)) { $authorizedActivityExecutions[$activityExecutionAfterTransition->getUri()] = $activityExecutionAfterTransition; $setPause = false; } else { continue; } } } $returnValue = array(); //finish actions on the authorized acitivty definitions foreach ($authorizedActivityExecutions as $uri => $activityExecutionAfterTransition) { // Last but not least ... is the next activity a machine activity ? // if yes, we perform the transition. /* * @todo to be tested */ $activityAfterTransition = $this->activityExecutionService->getExecutionOf($activityExecutionAfterTransition); if ($activityDefinitionService->isHidden($activityAfterTransition)) { //required to create an activity execution here with: $currentUser = $userService->getCurrentUser(); if (is_null($currentUser)) { throw new wfEngine_models_classes_ProcessExecutionException("No current user found!"); } $activityExecutionResource = $this->initCurrentActivityExecution($processExecution, $activityExecutionAfterTransition, $currentUser, true); //force execution of the ghost actiivty //service not executed? use curl request? if (!is_null($activityExecutionResource)) { $followingActivityExecutions = $this->performTransition($processExecution, $activityExecutionResource); if (is_array($followingActivityExecutions)) { foreach ($followingActivityExecutions as $followingActivityExec) { $returnValue[$followingActivityExec->getUri()] = $followingActivityExec; } } } else { throw new wfEngine_models_classes_ProcessExecutionException('the activity execution cannot be created for the hidden activity'); } } else { $returnValue[$uri] = $activityExecutionAfterTransition; } } if ($setPause) { $this->pause($processExecution); } else { if (!$this->isFinished($processExecution)) { $this->resume($processExecution); } } return $returnValue; }
* This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; under version 2 * of the License (non-upgradable). * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Copyright (c) 2007-2010 (original work) Public Research Centre Henri Tudor & University of Luxembourg) (under the project TAO-QUAL); * 2008-2010 (update and modification) Deutsche Institut für Internationale Pädagogische Forschung (under the project TAO-TRANSFER); * 2009-2012 (update and modification) Public Research Centre Henri Tudor (under the project TAO-SUSTAIN & TAO-DEV); * */ /** * @author CRP Henri Tudor - TAO Team - {@link http://www.tao.lu} * @license GPLv2 http://www.opensource.org/licenses/gpl-2.0.php * @package wfEngine */ require_once dirname(__FILE__) . '/../includes/raw_start.php'; set_time_limit(0); //connec to the api common_user_auth_Service::singleton()->startSession(new core_kernel_users_GenerisUser(new core_kernel_classes_Resource(TAO_INSTALLATOR))); $notificationService = wfEngine_models_classes_NotificationService::singleton(); $sent = $notificationService->sendNotifications(new tao_helpers_transfert_MailAdapter()); print "\n{$sent} sent notifications\n";