Ignore:
Timestamp:
08/17/10 16:17:12 (14 years ago)
Author:
viani
Message:

Ticket #1135 - Merged r1990:3166 from /trunk/workflow into /branches/2.2/workflow

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2/workflow/inc/engine/src/API/Instance.php

    r795 r3167  
    11<?php 
    22require_once (GALAXIA_LIBRARY.SEP.'src'.SEP.'common'.SEP.'Base.php'); 
    3 require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'common' . SEP . 'WfSecurity.php'); 
    43require_once(GALAXIA_LIBRARY . SEP . 'src' . SEP . 'ProcessManager' . SEP . 'ActivityManager.php'); 
    54 
     
    8685  var $parentLock = false; 
    8786  /** 
    88    * @var int $parentActivityId The activity ID of the parent instance 
    89    * @access public 
    90    */ 
    91   var $parentActivityId; 
    92   /** 
    9387   * @var int $parentInstanceId The instance ID of the parent instance 
    9488   * @access public 
     
    141135 
    142136  var $activityID = null; 
    143   function Instance($db)  
     137  function Instance()  
    144138  { 
    145139    $this->child_name = 'Instance'; 
    146     parent::Base($db); 
     140    parent::Base(); 
    147141  } 
    148142 
     
    491485    return ''; 
    492486  } 
    493   
     487 
    494488  /** 
    495489   * Creates a new instance. 
     
    504498  function _createNewInstance($activityId,$user) { 
    505499    // Creates a new instance setting up started, ended, user, status and owner 
    506     $pid = $this->getOne('select wf_p_id from '.GALAXIA_TABLE_PREFIX.'activities where wf_activity_id=?',array((int)$activityId)); 
     500    $pid = $this->getOne('SELECT wf_p_id FROM '.GALAXIA_TABLE_PREFIX.'activities WHERE wf_activity_id=?',array((int)$activityId)); 
    507501    $this->pId = $pid; 
    508502    $this->setStatus('active'); 
     
    511505    $this->setStarted($now); 
    512506    $this->setOwner($user); 
    513      
    514     $query = 'insert into '.GALAXIA_TABLE_PREFIX.'instances 
    515       (wf_started,wf_ended,wf_status,wf_p_id,wf_owner,wf_properties)  
    516       values(?,?,?,?,?,?)'; 
    517     $this->query($query,array($now,0,'active',$pid,$user,$this->security_cleanup(Array(),false))); 
    518     $this->instanceId = $this->getOne('select max(wf_instance_id) from '.GALAXIA_TABLE_PREFIX.'instances  
    519                       where wf_started=? and wf_owner=?',array((int)$now,$user)); 
     507 
     508    //Get the id of new instance, before insert values in table and use this value from main table and relationship tables. 
     509    $this->instanceId = $this->getOne("SELECT nextval('seq_egw_wf_instances')"); 
    520510    $iid=$this->instanceId; 
    521      
     511 
     512    $query = 'INSERT INTO '.GALAXIA_TABLE_PREFIX.'instances 
     513                (wf_instance_id, wf_started,wf_ended,wf_status,wf_p_id,wf_owner,wf_properties) 
     514              VALUES 
     515                (?,?,?,?,?,?,?)'; 
     516 
     517    $this->query($query,array((int)$iid, $now,0,'active',$pid,$user,$this->security_cleanup(Array(),false))); 
     518 
    522519    // Then add in ".GALAXIA_TABLE_PREFIX."instance_activities an entry for the 
    523520    // activity the user and status running and started now 
    524     $query = 'insert into '.GALAXIA_TABLE_PREFIX.'instance_activities (wf_instance_id,wf_activity_id,wf_user, 
    525             wf_started,wf_status) values(?,?,?,?,?)'; 
     521    $query = 'INSERT INTO '.GALAXIA_TABLE_PREFIX.'instance_activities 
     522                (wf_instance_id,wf_activity_id,wf_user,wf_started,wf_status) 
     523              VALUES 
     524                (?,?,?,?,?)'; 
    526525    $this->query($query,array((int)$iid,(int)$activityId,$user,(int)$now,'running')); 
    527526 
    528527    if (($this->isChildInstance) && (!is_null($this->parentInstanceId))) 
    529528    { 
    530       $query = 'INSERT INTO '.GALAXIA_TABLE_PREFIX.'interinstance_relations(wf_parent_instance_id, wf_parent_activity_id, wf_child_instance_id, wf_parent_lock) VALUES(?,?,?,?)'; 
    531       $this->query($query,array((int) $this->parentInstanceId, (int) $this->parentActivityId, (int) $iid, (int) (($this->parentLock) ? 1 : 0))); 
    532     } 
    533      
     529      $query = 'INSERT INTO '.GALAXIA_TABLE_PREFIX.'interinstance_relations 
     530                  (wf_parent_instance_id, wf_child_instance_id, wf_parent_lock) 
     531                VALUES 
     532                  (?,?,?)'; 
     533      $this->query($query,array((int) $this->parentInstanceId, (int) $iid, (int) (($this->parentLock) ? 1 : 0))); 
     534    } 
     535 
    534536    //update database with other datas stored in the object 
    535537    return $this->sync(); 
    536538  } 
    537    
     539 
    538540  /** 
    539541   * Sets the name of this instance 
     
    11411143    return $this->__activity_completed; 
    11421144  } 
    1143   
     1145 
    11441146  /** 
    11451147   * This function can be called by the instance object himself (for automatic activities) 
    1146    * or by the WfRuntime object. In interactive activities code users use complete() --without args--  
    1147    * which refer to the WfRuntime->complete() function which call this one.  
     1148   * or by the WfRuntime object. In interactive activities code users use complete() --without args-- 
     1149   * which refer to the WfRuntime->complete() function which call this one. 
    11481150   * In non-interactive activities a call to a complete() will generate errors because the engine 
    11491151   * does it his own way as I said first. 
     
    11611163  { 
    11621164    //$this->db-> 
    1163     $result = $this->query("SELECT 1 FROM " . GALAXIA_TABLE_PREFIX . "instances i, " . GALAXIA_TABLE_PREFIX . "interinstance_relations ir WHERE (ir.wf_child_instance_id = i.wf_instance_id) AND (i.wf_status IN ('active', 'exception')) AND (ir.wf_parent_lock = 1) AND (ir.wf_parent_instance_id = ?) AND (ir.wf_parent_activity_id = ?)", array($this->instanceId, $activityId)); 
     1165    $result = $this->query("SELECT 1 FROM " . GALAXIA_TABLE_PREFIX . "instances i, " . GALAXIA_TABLE_PREFIX . "interinstance_relations ir WHERE (ir.wf_child_instance_id = i.wf_instance_id) AND (i.wf_status IN ('active', 'exception')) AND (ir.wf_parent_lock = 1) AND (ir.wf_parent_instance_id = ?)", array($this->instanceId)); 
    11641166    if ($result->numRows() > 0) 
    11651167      die("Esta instância está aguardando que outras instâncias, das quais depende, sejam finalizadas."); 
     
    11691171    //The complete() is in a transaction, it will be completly done or not at all 
    11701172    $this->db->StartTrans(); 
    1171      
     1173 
    11721174    //lock rows and ensure access is granted 
    1173     if (!(isset($this->security))) $this->security =& new WfSecurity($this->db);  
     1175    if (!(isset($this->security))) $this->security = &Factory::getInstance('WfSecurity'); 
    11741176    if (!($this->security->checkUserAction($activityId,$this->instanceId,'complete'))) 
    11751177    { 
     
    15511553    { 
    15521554      //we check rights for this user on the next activity 
    1553       if (!(isset($this->security))) $this->security =& new WfSecurity($this->db);  
     1555      if (!(isset($this->security))) $this->security = &Factory::getInstance('WfSecurity'); 
    15541556      if ($this->security->checkUserAccess($the_next_user,$activityId)) 
    15551557      { 
     
    15601562    { 
    15611563      // then check to see if there is a default user 
    1562       $activity_manager =& new ActivityManager($this->db); 
     1564      $activity_manager = &Factory::newInstance('ActivityManager'); 
    15631565      //get_default_user will give us '*' if there is no default_user or if the default user has no role 
    15641566      //mapped anymore 
Note: See TracChangeset for help on using the changeset viewer.