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/class.run_activity.inc.php

    r795 r3167  
    1010        \**************************************************************************/ 
    1111 
     12        require_once(dirname(__FILE__) . SEP . 'common.inc.php');                                /* including common deifinitions */ 
    1213        require_once(dirname(__FILE__) . SEP . 'class.WorkflowUtils.inc.php'  ); /* superclass source code       */ 
    1314        require_once(dirname(__FILE__) . SEP . 'class.basecontroller.inc.php' ); /* module controller            */ 
    1415        require_once(dirname(__FILE__) . SEP . 'class.basemodel.inc.php'      ); /* module logic                 */ 
    15         require_once(dirname(__FILE__) . SEP . 'class.process_factory.inc.php'); /* module process factory class */ 
    16         require_once(dirname(__FILE__) . SEP . 'class.utils.security.php'     ); /* sanitizes input data         */ 
    1716 
    1817        /** 
     
    169168                var $agents = Array(); 
    170169 
    171                 /* CELEPAR */ 
    172170                /** 
    173171                 * @var object $smarty holds a Smarty instance 
     
    195193         */ 
    196194                var $isChildInstance = false; 
    197  
     195                /** 
     196                 * @var object Stores a 'workflow_smarty' object 
     197         * @access private 
     198         */ 
    198199                private $workflowSmarty = null; 
    199                 /* CELEPAR */ 
     200                /** 
     201                 * @var object Log Object 
     202         * @access private 
     203         */ 
     204                private $logger = null; 
     205 
    200206                /** 
    201207                 * Constructor 
     
    206212                { 
    207213                        parent::WorkflowUtils(); 
    208                         $this->runtime          = CreateObject('workflow.workflow_wfruntime'); 
     214 
     215                        /** 
     216                         * We should always use newInstance to instantiate 
     217                         * 'workflow_wfruntime' 
     218                         */ 
     219                        $this->runtime                  = &Factory::newInstance('workflow_wfruntime'); 
    209220                        $this->runtime->setDebug(_DEBUG); 
    210                         //$this->base_activity  = CreateObject('workflow.workflow_baseactivity'); 
    211                         //$this->process                = CreateObject('workflow.workflow_process'); 
    212                         $this->GUI              = CreateObject('workflow.workflow_gui'); 
    213                         $this->categories       = CreateObject('phpgwapi.categories'); 
    214  
    215                         $this->workflowSmarty = CreateObject('workflow.workflow_smarty', false); 
     221                        $this->GUI                              = &Factory::getInstance('workflow_gui'); 
     222                        $this->categories               = &Factory::getInstance('categories'); 
     223 
     224                        $this->workflowSmarty   = &Factory::getInstance('workflow_smarty', false); 
     225 
     226                        // never configure a log of type "firebug" here. This will make goAjax stop running well =( 
     227                        $this->logger                   = &Factory::getInstance('Logger', array('file')); 
     228 
    216229                        // TODO: open a new connection to the database under a different username to allow privilege handling on tables 
    217                         /* CELEPAR */ 
    218230                        unset($this->db); 
    219231                } 
     
    232244                function go($activity_id=0, $iid=0, $auto=0) 
    233245                { 
     246                        $totalTime = microtime(true); 
     247 
    234248                        $result=Array(); 
    235249 
     
    301315                        $this->process_version  = $this->process->getVersion(); 
    302316                        $this->activity_name    = $activity->getName(); 
    303                         $this->user_name        = $GLOBALS['phpgw']->accounts->id2name($GLOBALS['user']); 
     317                        $this->user_name                = $GLOBALS['phpgw']->accounts->id2name($GLOBALS['user']); 
    304318                        $this->view_activity    = $this->GUI->gui_get_process_view_activity($this->process_id); 
    305319 
     
    315329                        $GLOBALS['workflow']['wf_user_id']                                      =& $GLOBALS['user']; 
    316330                        $GLOBALS['workflow']['wf_view_activity']                        =& $this->view_activity; 
     331                        $GLOBALS['workflow']['wf_webserver_url']                        = $GLOBALS['phpgw_info']['server']['webserver_url']; 
    317332                        $GLOBALS['workflow']['wf_workflow_path']                        = $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.'workflow'; 
    318333                        $GLOBALS['workflow']['wf_resources_path']                       = $GLOBALS['phpgw_info']['server']['webserver_url'] . SEP . 'workflow/redirect.php?pid=' . $this->process_id . '&file='; 
    319                         $GLOBALS['workflow']['wf_default_resources_path']       = $GLOBALS['workflow']['factory']->getInstance('TemplateServer')->generateLink('processes'); 
    320                         $GLOBALS['workflow']['wf_workflow_resources_path']      = $GLOBALS['workflow']['factory']->getInstance('TemplateServer')->generateLink(''); 
     334                        $GLOBALS['workflow']['wf_default_resources_path']       = Factory::getInstance('TemplateServer')->generateLink('processes'); 
     335                        $GLOBALS['workflow']['wf_workflow_resources_path']      = Factory::getInstance('TemplateServer')->generateLink(''); 
    321336                        $GLOBALS['workflow']['wf_activity_url']                         = $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.'index.php?menuaction=workflow.'.get_class($this).'.go&activity_id='.$activity_id; 
    322                         $GLOBALS['workflow']['wf_user_cnname']                          = $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getName($GLOBALS['user']); 
     337                        $GLOBALS['workflow']['wf_user_cnname']                          = Factory::getInstance('WorkflowLDAP')->getName($GLOBALS['user']); 
    323338                        $GLOBALS['workflow']['wf_back_link']                            = $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.'workflow'.SEP.'index.php?start_tab=1'; 
    324339                        $GLOBALS['workflow']['wf_js_path']                                      = $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.'workflow'.SEP.'js'.SEP.'jscode'; 
     
    330345                        $wf =& $GLOBALS['workflow']; 
    331346 
    332                         /* CELEPAR */ 
    333347                        /* path to the local functions developed by Celepar */ 
    334348                        $functions = PHPGW_SERVER_ROOT . SEP . 'workflow' . SEP . 'inc' . SEP . 'local' . SEP . 'functions' . SEP . 'local.functions.php'; 
     
    336350                        /* activate local functions */ 
    337351                        require_once($functions); 
    338                         /* CELEPAR */ 
    339352 
    340353                        //get configuration options with default values if no init was done before 
     
    375388 
    376389                                /* check some permissions */ 
    377                                 if (($newUser == '*') || (!$this->runtime->checkUserRun($newUser)) || ($GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getName($newUser) === false)) 
     390                                if (($newUser == '*') || (!$this->runtime->checkUserRun($newUser)) || (Factory::getInstance('WorkflowLDAP')->getName($newUser) === false)) 
    378391                                { 
    379392                                        $_SESSION['phpgw_info']['workflow']['user_groups'] = $actualUserGroups; 
     
    385398                                        return false; 
    386399                                } 
    387                                 $smarty = CreateObject('workflow.process_smarty'); 
     400                                $smarty = Factory::getInstance('process_smarty'); 
    388401                        } 
    389402 
     
    396409                                $this->download_mode = get_var('download_mode', array('POST','GET'), false); 
    397410 
    398                                 /* #celepar# smarty code*/ 
    399  
    400                                 $smarty = CreateObject('workflow.process_smarty'); 
     411                                $smarty = Factory::getInstance('process_smarty'); 
    401412 
    402413                                $smarty->template_dir  = GALAXIA_PROCESSES.SEP.$this->process->getNormalizedName().SEP.'code'.SEP.'templates'; 
     
    418429                                $smarty->assign('wf_back_link',$GLOBALS['workflow']['wf_back_link']); 
    419430                                $smarty->assign('wf_activity_url',$GLOBALS['workflow']['wf_activity_url']); 
    420                                  
     431 
    421432                                /* register the prefilter smarty plugin wf_default_template */ 
    422433                                $smarty->load_filter('pre', 'wf_default_template'); 
     
    430441 
    431442                        /* BEGIN WORKFLOW MVC SETTINGS */ 
    432                         $env = array( );                                           //create settings vector 
     443                        $env = array();                                            //create settings vector 
    433444                        $env['view']          =& $smarty;                          //view layer instance 
    434445                        $env['template_file'] =& $_template_name;                  //template file to be shown 
    435                         $env['dao']           =& wf_create_object('wf_db');        //data access object instance 
     446                        $env['dao']                       =& Factory::newInstance('wf_db');    //data access object instance 
    436447                        $env['workflow']      =& $GLOBALS['workflow'];             //workflow environment information 
    437448                        $env['instance']      =& $instance;                        //process manager instance 
    438449                        $env['activity']      =& $activity;                        //activity manager instance 
    439                         $security             =& new SecurityUtils();              //input sanitizer class 
     450                        $security             =& Factory::newInstance('SecurityUtils');              //input sanitizer class 
    440451                        $env['request']       =& $security->process($_REQUEST);    //sanitizes input data from client 
    441                         $env['factory']       =& new ProcessFactory();             //instantiation controller class 
    442                         $env['natural']           =& wf_create_object('wf_natural');   //data access object instance for mainframe 
     452                        $env['factory']       =& Factory::getInstance('ProcessWrapperFactory');  //instantiation controller class 
     453                        $env['natural']           =& Factory::newInstance('wf_natural');   //data access object instance for mainframe 
    443454                        /* END WORKFLOW MVC SETTINGS */ 
    444455 
    445456                        $GLOBALS['workflow_env'] = &$env; 
    446                         //echo "<br><br><br><br><br>Including $source <br>In request: <pre>";print_r($_REQUEST);echo "</pre>"; 
    447                         //[__leave_activity] is setted if needed in the xxx_pre code or by the user in his code 
    448                         // HERE the user code is 'executed'. Note that we do not use include_once or require_once because 
    449                         //it could the same code several times with automatic activities looping in the graph and it still 
    450                         //need to be executed 
     457 
     458                        /** 
     459                         * [__leave_activity] is setted if needed in the xxx_pre code or by the user in his code 
     460                         * HERE the user code is 'executed'. Note that we do not use include_once or require_once because 
     461                         * it could the same code several times with automatic activities looping in the graph and it still 
     462                         * need to be executed 
     463                         */ 
    451464                        $_engineProcessCodeDirectory = GALAXIA_PROCESSES . SEP . $this->process->getNormalizedName(). SEP . 'code'; 
    452465                        $_engineCompilerDirectory = GALAXIA_LIBRARY . SEP . 'compiler'; 
     
    471484 
    472485                        /* activate the security policy */ 
    473                         $GLOBALS['workflow']['factory']->getInstance('WorkflowSecurity')->enableSecurityPolicy(); 
     486                        Factory::getInstance('WorkflowSecurity')->enableSecurityPolicy(); 
     487 
     488                        /** 
     489                         * Here we are going to use our new Security static class. 
     490                         * From now, the factory frontend (static) will forward 
     491                         * the messages for the process factory instead of Workflow 
     492                         * factory. 
     493                        */ 
     494                        Security::enable(); 
    474495 
    475496                        /* include the files */ 
     497                        $processTime = microtime(true); 
     498 
    476499                        foreach ($_engineFiles as $_engineFile) 
    477                                 require $_engineFile; 
     500                                require_once $_engineFile; 
     501 
     502                        $processTime = (microtime(true) - $processTime); 
    478503 
    479504                        unset($GLOBALS['workflow_env']); 
     
    517542                        } 
    518543 
     544                        $totalTime = (microtime(true) - $totalTime); 
     545 
     546                        $logTime = sprintf("GO [pid=%s,iid=%s,uid=%s,aid=%s] [eng=%ss,proc=%ss]", 
     547                                                                $this->process_id, 
     548                                                                $this->instance_id, 
     549                                                                $GLOBALS['user'], 
     550                                                                $this->activity_id, 
     551                                                                number_format(($totalTime - $processTime),3), 
     552                                                                number_format($processTime,3) ); 
     553 
     554                        $this->logger->debug($logTime); 
     555 
    519556                        // TODO: process instance comments 
    520  
    521557                        $instructions = $this->runtime->handle_postUserCode(_DEBUG); 
    522558                        switch($instructions['action']) 
     
    582618                function goAjax($activity_id=0, $iid=0, $auto=0) 
    583619                { 
     620                        $totalTime = microtime(true); 
     621 
    584622                        $result=Array(); 
    585623 
     
    660698                        $GLOBALS['workflow']['wf_workflow_path']                        = $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.'workflow'; 
    661699                        $GLOBALS['workflow']['wf_resources_path']                       = $GLOBALS['phpgw_info']['server']['webserver_url'] . SEP . 'workflow/redirect.php?pid=' . $this->process_id . '&file='; 
    662                         $GLOBALS['workflow']['wf_default_resources_path']       = $GLOBALS['workflow']['factory']->getInstance('TemplateServer')->generateLink('processes'); 
    663                         $GLOBALS['workflow']['wf_workflow_resources_path']      = $GLOBALS['workflow']['factory']->getInstance('TemplateServer')->generateLink(''); 
     700                        $GLOBALS['workflow']['wf_default_resources_path']       = Factory::getInstance('TemplateServer')->generateLink('processes'); 
     701                        $GLOBALS['workflow']['wf_workflow_resources_path']      = Factory::getInstance('TemplateServer')->generateLink(''); 
    664702                        $GLOBALS['workflow']['wf_activity_url']                         = $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.'index.php?menuaction=workflow.'.get_class($this).'.go&activity_id='.$activity_id; 
    665                         $GLOBALS['workflow']['wf_user_cnname']                          = $GLOBALS['workflow']['factory']->getInstance('WorkflowLDAP')->getName($GLOBALS['user']); 
     703                        $GLOBALS['workflow']['wf_user_cnname']                          = Factory::getInstance('WorkflowLDAP')->getName($GLOBALS['user']); 
    666704                        $GLOBALS['workflow']['wf_back_link']                            = $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.'workflow'.SEP.'index.php?start_tab=1'; 
    667705                        $GLOBALS['workflow']['wf_js_path']                                      = $GLOBALS['phpgw_info']['server']['webserver_url'].SEP.'workflow'.SEP.'js'.SEP.'jscode'; 
     
    672710                                unset($GLOBALS['workflow']['wf_instance_url']); 
    673711 
    674                         /* CELEPAR */ 
    675712                        /* activate local functions */ 
    676713                        require_once(PHPGW_SERVER_ROOT . SEP . 'workflow' . SEP . 'inc' . SEP . 'local' . SEP . 'functions' . SEP . 'local.functions.php'); 
    677                         /* CELEPAR */ 
    678714 
    679715                        //get configuration options with default values if no init was done before 
     
    693729 
    694730                        /* BEGIN WORKFLOW MVC SETTINGS */ 
    695                         $env = array( );                                           //create settings vector 
    696                         $env['dao']           =& wf_create_object('wf_db');        //data access object instance 
     731                        $env = array();                                            //create settings vector 
     732                        $env['dao']                       =& Factory::newInstance('wf_db');    //data access object instance 
    697733                        $env['workflow']      =& $GLOBALS['workflow'];             //workflow environment information 
    698734                        $env['instance']      =& $instance;                        //process manager instance 
    699735                        $env['activity']      =& $activity;                        //activity manager instance 
    700                         $security             =& new SecurityUtils();              //input sanitizer class 
     736                        $security             =& Factory::newInstance('SecurityUtils'); //input sanitizer class 
    701737                        $env['request']       =& $security->process($_REQUEST); //sanitizes input data from client 
    702                         $env['factory']       =& new ProcessFactory();                     //instantiation controller class 
    703                         $env['natural']           =& wf_create_object('wf_natural');   //data access object instance for mainframe 
     738                        $env['factory']       =& Factory::newInstance('ProcessWrapperFactory');  //instantiation controller class 
     739                        $env['natural']           =& Factory::newInstance('wf_natural');   //data access object instance for mainframe 
    704740                        /* END WORKFLOW MVC SETTINGS */ 
    705741 
     
    711747 
    712748                        /* activate the security policy */ 
    713                         $GLOBALS['workflow']['factory']->getInstance('WorkflowSecurity')->enableSecurityPolicy(); 
     749                        Factory::getInstance('WorkflowSecurity')->enableSecurityPolicy(); 
     750 
     751                        /** 
     752                         * here we are going to use our new Security static class. 
     753                         * From now, the factory frontend (static) will forward 
     754                         * the messages for the process factory instead of Workflow 
     755                         * factory. Note that this is the same comment as the previous 
     756                         * function... boooring.. 
     757                         */ 
     758                        Security::enable(); 
    714759 
    715760                        $GLOBALS['workflow_env'] = &$env; 
    716                         $nc = new NanoController(); 
     761                        $nc = &Factory::newInstance('NanoController'); 
    717762                        $nc->setClassPath(GALAXIA_PROCESSES . SEP . $this->process->getNormalizedName(). SEP . 'code'); 
     763 
     764                        $processTime = microtime(true); 
    718765                        $nc->iterateOverVirtualRequests(); 
     766                        $processTime = microtime(true) - $processTime; 
     767 
    719768                        $nc->outputResultData(); 
    720769                        unset($GLOBALS['workflow_env']); 
     
    722771                        if (!is_null($iid)) 
    723772                                $instance->instance->sync(); 
     773 
     774                        $totalTime = microtime(true) - $totalTime; 
     775 
     776                        $logTime = sprintf("GOAJAX [pid=%s,iid=%s,uid=%s,aid=%s] [eng=%ss,proc=%ss]", 
     777                                                                $this->process_id, 
     778                                                                $this->instance_id, 
     779                                                                $GLOBALS['user'], 
     780                                                                $this->activity_id, 
     781                                                                number_format(($totalTime - $processTime),3), 
     782                                                                number_format($processTime,3) ); 
     783 
     784                        $this->logger->debug($logTime); 
    724785                } 
    725786 
     
    850911                { 
    851912                        $headerConfig = 0; 
    852                         if (!$this->download_mode) 
     913                        if (!$this->download_mode and !$this->print_mode) 
    853914                        { 
    854915                                $headerConfig |= workflow_smarty::SHOW_HEADER | workflow_smarty::SHOW_FOOTER; 
Note: See TracChangeset for help on using the changeset viewer.