Beispiel #1
0
function removeSelectedGroups($http, &$groups, $base)
{
    if ($http->hasPostVariable("DeleteGroupButton")) {
        if (eZHTTPPersistence::splitSelected($base, $groups, $http, "id", $keepers, $rejects)) {
            $groups = $keepers;
            foreach ($rejects as $reject) {
                $group_id = $reject->attribute("id");
                // Remove all workflows in current group
                $list_in_group = eZWorkflowGroupLink::fetchWorkflowList(0, $group_id, $asObject = true);
                $workflow_list = eZWorkflow::fetchList();
                $list = array();
                foreach ($workflow_list as $workflow) {
                    foreach ($list_in_group as $group) {
                        $id = $workflow->attribute("id");
                        $workflow_id = $group->attribute("workflow_id");
                        if ($id === $workflow_id) {
                            $list[] = $workflow;
                        }
                    }
                }
                foreach ($list as $workFlow) {
                    eZTrigger::removeTriggerForWorkflow($workFlow->attribute('id'));
                    $workFlow->remove();
                }
                $reject->remove();
                eZWorkflowGroupLink::removeGroupMembers($group_id);
            }
        }
    }
}
Beispiel #2
0
 public function getReport()
 {
     // quick and dirty: use same data as for the web
     $tpl = sysInfoTools::eZTemplateFactory();
     $tpl->setVariable('title', 'Workflows Report');
     $workflows = eZWorkflow::fetchList();
     $triggers = eZTrigger::fetchList();
     $tpl->setVariable('workflows', $workflows);
     $tpl->setVariable('triggers', $triggers);
     $htmlReport = $tpl->fetch("design:sysinfo/workflowsreport.tpl");
     return $htmlReport;
 }
Beispiel #3
0
}
$moduleName = '*';
$functionName = '*';
if ($http->hasPostVariable('RemoveButton')) {
    if ($http->hasPostVariable('DeleteIDArray')) {
        $deleteIDArray = $http->postVariable('DeleteIDArray');
        $db = eZDB::instance();
        $db->begin();
        foreach ($deleteIDArray as $deleteID) {
            eZTrigger::remove($deleteID);
        }
        $db->commit();
    }
}
$tpl = eZTemplate::factory();
$triggers = eZTrigger::fetchList(array('module' => $moduleName, 'function' => $functionName));
$showModuleList = false;
$showFunctionList = false;
$functionList = array();
$moduleList = array();
if ($moduleName == '*') {
    $showModuleList = true;
    $ini = eZINI::instance('module.ini');
    $moduleList = $ini->variable('ModuleSettings', 'ModuleList');
} elseif ($functionName == '*') {
    $mod = eZModule::exists($moduleName);
    $functionList = array_keys($mod->attribute('available_functions'));
    eZDebug::writeNotice($functionList, "functions");
    $showFunctionList = true;
}
$tpl->setVariable('current_module', $moduleName);
    $limit = $limitList[$limitId];
}
$viewParameters = array('offset' => $offset);
$plist = eZWorkflowProcess::fetchList($conds, true, $offset, $limit);
$plistCount = eZWorkflowProcess::count(eZWorkflowProcess::definition(), $conds);
$totalProcessCount = 0;
$outList2 = array();
foreach ($plist as $p) {
    $mementoMain = eZOperationMemento::fetchMain($p->attribute('memento_key'));
    $mementoChild = eZOperationMemento::fetchChild($p->attribute('memento_key'));
    if (!$mementoMain or !$mementoChild) {
        continue;
    }
    $mementoMainData = $mementoMain->data();
    $mementoChildData = $mementoChild->data();
    $triggers = eZTrigger::fetchList(array('module_name' => $mementoChildData['module_name'], 'function_name' => $mementoChildData['operation_name'], 'name' => $mementoChildData['name']));
    if (count($triggers) > 0) {
        $trigger = $triggers[0];
        if (is_object($trigger)) {
            $nkey = $trigger->attribute('module_name') . '/' . $trigger->attribute('function_name') . '/' . $trigger->attribute('name');
            if (!isset($outList2[$nkey])) {
                $outList2[$nkey] = array('trigger' => $trigger, 'process_list' => array());
            }
            $outList2[$nkey]['process_list'][] = $p;
            $totalProcessCount++;
        }
    }
}
// Template handling
$tpl = eZTemplate::factory();
$tpl->setVariable("module", $Module);
Beispiel #5
0
    $Module->run('edit', $params);
    return;
}
if ($http->hasPostVariable('DeleteButton') and $http->hasPostVariable('Workflow_id_checked')) {
    if ($http->hasPostVariable('CurrentGroupID')) {
        // If CurrentGroupID variable exist, delete in that group only:
        $groupID = $http->postVariable('CurrentGroupID');
        $workflowIDs = $http->postVariable('Workflow_id_checked');
        foreach ($workflowIDs as $workflowID) {
            // for all workflows which are tagged for deleting:
            $workflow = eZWorkflow::fetch($workflowID);
            if ($workflow) {
                $workflowInGroups = $workflow->attribute('ingroup_list');
                if (count($workflowInGroups) == 1) {
                    //remove entry from eztrigger table also, if it exists there.
                    eZTrigger::removeTriggerForWorkflow($workflowID);
                    // if there is only one group which the workflow belongs to, delete (=disable) it:
                    eZWorkflow::setIsEnabled(false, $workflowID);
                } else {
                    // if there is more than 1 group, remove only from the group:
                    eZWorkflowFunctions::removeGroup($workflowID, 0, array($groupID));
                }
            } else {
                // just for sure :-)
                eZWorkflow::setIsEnabled(false, $workflowID);
            }
        }
    } else {
        // if there is no CurrentGroupID variable, disable every group in variable Workflow_id_checked:
        eZWorkflow::setIsEnabled(false, $http->postVariable('Workflow_id_checked'));
    }
 function createTrigger($workflowID)
 {
     return eZTrigger::createNew('content', 'publish', 'b', $workflowID);
 }
Beispiel #7
0
 static function createNew($moduleName, $functionName, $connectType, $workflowID, $name = false)
 {
     if (!$name) {
         if ($connectType == 'b') {
             $name = 'pre_';
         } else {
             if ($connectType == 'a') {
                 $name = 'post_';
             }
         }
         $name .= $functionName;
     }
     $trigger = new eZTrigger(array('module_name' => $moduleName, 'function_name' => $functionName, 'connect_type' => $connectType, 'workflow_id' => $workflowID, 'name' => $name));
     $trigger->store();
     return $trigger;
 }
 /**
  * Executes an operation trigger
  *
  * @param array $bodyReturnValue The current return value
  * @param array $body Body data for the trigger being executed
  * @param array $operationParameterDefinitions Operation parameters definition
  * @param array $operationParameters Operation parameters values
  * @param int $bodyCallCount Number of times the body was called
  * @param array $currentLoopData Memento data for the operation
  * @param bool $triggerRestored Boolean that indicates if operation data (memento) was restored
  * @param string $operationName The operation name
  * @param array $operationKeys Additional parameters. Only used by looping so far.
  * @return
  */
 function executeTrigger(&$bodyReturnValue, $body, $operationParameterDefinitions, $operationParameters, &$bodyCallCount, $currentLoopData, $triggerRestored, $operationName, &$operationKeys)
 {
     $triggerName = $body['name'];
     $triggerKeys = $body['keys'];
     $status = eZTrigger::runTrigger($triggerName, $this->ModuleName, $operationName, $operationParameters, $triggerKeys);
     if ($status['Status'] == eZTrigger::WORKFLOW_DONE || $status['Status'] == eZTrigger::NO_CONNECTED_WORKFLOWS) {
         ++$bodyCallCount['loop_run'][$triggerName];
         return eZModuleOperationInfo::STATUS_CONTINUE;
     } else {
         if ($status['Status'] == eZTrigger::STATUS_CRON_JOB || $status['Status'] == eZTrigger::FETCH_TEMPLATE || $status['Status'] == eZTrigger::FETCH_TEMPLATE_REPEAT || $status['Status'] == eZTrigger::REDIRECT) {
             $bodyMemento = $this->storeBodyMemento($triggerName, $triggerKeys, $operationKeys, $operationParameterDefinitions, $operationParameters, $bodyCallCount, $currentLoopData, $operationName);
             $workflowProcess = $status['WorkflowProcess'];
             if ($workflowProcess !== null) {
                 $workflowProcess->setAttribute('memento_key', $bodyMemento->attribute('memento_key'));
                 $workflowProcess->store();
             }
             $bodyReturnValue['result'] = $status['Result'];
             if ($status['Status'] == eZTrigger::REDIRECT) {
                 $bodyReturnValue['redirect_url'] = $status['Result'];
             }
             if ($status['Status'] == eZTrigger::FETCH_TEMPLATE_REPEAT) {
                 // Hack for project issue #14371 (fetch template repeat)
                 // The object version's status is set to REPEAT so that it can
                 // be submitted again
                 if ($operationName == 'publish' && $this->ModuleName == 'content') {
                     eZContentOperationCollection::setVersionStatus($operationParameters['object_id'], $operationParameters['version'], eZContentObjectVersion::STATUS_REPEAT);
                 }
                 return eZModuleOperationInfo::STATUS_REPEAT;
             } else {
                 return eZModuleOperationInfo::STATUS_HALTED;
             }
         } else {
             if ($status['Status'] == eZTrigger::WORKFLOW_CANCELLED or $status['Status'] == eZTrigger::WORKFLOW_RESET) {
                 return eZModuleOperationInfo::STATUS_CANCELLED;
                 $bodyReturnValue['result'] = $status['Result'];
             }
         }
     }
 }
 /**
  * Helper function used to remove a workflow.
  * Will remove the workflow, its events, its triggers and its group link.
  *
  * @param eZWorkflow $workflow
  * @return void
  */
 protected function removeWorkflow(eZWorkflow $workflow)
 {
     // Remove trigger
     eZTrigger::removeTriggerForWorkflow($workflow->attribute('id'));
     // remove the workflow, its events and the group link
     eZWorkflow::removeEvents(false, $workflow->attribute('id'), $workflow->attribute('version'));
     eZWorkflow::removeWorkflow($this->workflow->attribute('id'), $workflow->attribute('version'));
     eZWorkflowGroupLink::removeWorkflowMembers($workflow->attribute('id'), $workflow->attribute('version'));
 }
Beispiel #10
0
<?php

$workflows = eZWorkflow::fetchList();
$triggers = eZTrigger::fetchList();
$tpl->setVariable('workflows', $workflows);
$tpl->setVariable('triggers', $triggers);
    function execute( $xml )
    {
        $workflowGroupList = $xml->getElementsByTagName( 'WorkflowGroup' );
        $user              = eZUser::currentUser();
        $userID            = $user->attribute( "contentobject_id" );

        foreach ( $workflowGroupList as $workflowGroupNode )
        {
            $groupName        = $workflowGroupNode->getAttribute( 'name' );
            $referenceID      = $workflowGroupNode->getAttribute( 'referenceID' );
            $groupExistAction = $workflowGroupNode->getAttribute( 'groupExistAction' );
            $workflowGroup    = null;

            if ( $groupExistAction == 'keep' )
            {
                $workflowGroupList = eZWorkflowGroup::fetchList();
                foreach ( $workflowGroupList as $workflowGroupItem )
                {
                    if ( $workflowGroupItem->attribute( 'name' ) == $groupName )
                    {
                        $workflowGroup = $workflowGroupItem;
                        break;
                    }
                }
            }
            if ( $workflowGroup !== null )
            {
                $this->writeMessage( "\tWorkflow Group '$groupName' already exists." , 'notice' );
            }
            else
            {
                $this->writeMessage( "\tWorkflow Group '$groupName' will be created." , 'notice' );
                $workflowGroup = eZWorkflowGroup::create( $userID );
                $workflowGroup->setAttribute( "name", $groupName );
                $workflowGroup->store();
            }

            $WorkflowGroupID = $workflowGroup->attribute( "id" );
            $refArray        = array();

            if ( $referenceID )
            {
                $refArray[$referenceID] = $WorkflowGroupID;
            }
            $this->addReference( $refArray );

            $workflowList = $workflowGroupNode->getElementsByTagName( 'Workflow' );
            foreach ( $workflowList as $workflowNode )
            {
                $refArray = array();

                $workflowName        = $workflowNode->getAttribute( 'name' );
                $workflowTypeString  = $workflowNode->getAttribute( 'workflowTypeString' );
                $referenceID         = $workflowNode->getAttribute( 'referenceID' );
                $workflowExistAction = $workflowNode->getAttribute( 'workflowExistAction' );
                $WorkflowID          = $workflowNode->getAttribute( 'id' );
                $workflow            = null;
                $hasWorkflowDraft    = false;
                $db                  = eZDB::instance();

                if ( !$workflowExistAction )
                {
                    $workflowExistAction = 'extend';
                }

                if ( $WorkflowID )
                {
                    $workflow = eZWorkflow::fetch( $WorkflowID, true, 1 );
                    if ( !is_object( $workflow ) )
                    {
                        $workflow = eZWorkflow::fetch( $WorkflowID, true, 0 );
                        if ( is_object( $workflow ) )
                        {
                            $workflowGroups = eZWorkflowGroupLink::fetchGroupList( $WorkflowID, 0, true );

                            $db->begin();
                            foreach ( $workflowGroups as $workflowGroup )
                            {
                                $groupID   = $workflowGroup->attribute( "group_id" );
                                $groupName = $workflowGroup->attribute( "group_name" );
                                $ingroup   = eZWorkflowGroupLink::create( $WorkflowID, 1, $groupID, $groupName );

                                $ingroup->store();
                            }
                            $db->commit();

                        }
                        else
                        {
                            $this->writeMessage( "\tFailed to fetch workflow with ID '$WorkflowID'." , 'notice' );
                            $workflow = null;
                        }
                    }
                }

                $db->begin();

                if ( $workflow === null )
                {
                    $this->writeMessage( "\tWorkflow '$workflowName' will be created." , 'notice' );
                    $workflow = eZWorkflow::create( $userID );
                    $workflow->setAttribute( "name",  $workflowName );
                    if ( $workflowTypeString )
                    {
                        $workflow->setAttribute( "workflow_type_string",  $workflowTypeString );
                    }
                    $workflow->store();
                    $ingroup = eZWorkflowGroupLink::create( $workflow->attribute( "id" ), $workflow->attribute( "version" ), $WorkflowGroupID, $groupName );
                    $ingroup->store();
                }
                else
                {
                    $hasWorkflowDraft = true;
                    switch ( $workflowExistAction )
                    {
                        case 'extend':
                        {
                            $this->writeMessage( "\tExtending existing workflow '" . $workflow->attribute( 'name' ) . "'." , 'notice' );
                        }
                        break;
                        case 'replace':
                        {
                            $this->writeMessage( "\tReplacing existing workflow '" . $workflow->attribute( 'name' ) . "'." , 'notice' );
                            eZWorkflow::removeEvents( false, $workflow->attribute( "id" ), $workflow->attribute( "version" ) );
                        }
                        break;
                        default:
                        {
                            $this->writeMessage( "\tUnknown workflowExistAction '" . $workflowExistAction . "'." , 'notice' );
                        }
                    }
                }

                $WorkflowID      = $workflow->attribute( "id" );
                $WorkflowVersion = $workflow->attribute( "version" );

                $db->commit();

                if ( $referenceID )
                {
                    $refArray[$referenceID] = $WorkflowID;
                }

                $eventList     = $workflow->fetchEvents();
                $eventNodeList = $workflowNode->getElementsByTagName( 'Event' );
                $maxPlacement  = -1;

                foreach ( $eventList as $event )
                {
                    if ( $event->attribute( 'placement' ) > $maxPlacement )
                    {
                        $maxPlacement = $event->attribute( 'placement' );
                    }
                }

                foreach ( $eventNodeList as $eventNode )
                {
                    $description        = $eventNode->getAttribute( 'description' );
                    $workflowTypeString = $eventNode->getAttribute( 'workflowTypeString' );
                    $placement          = $eventNode->getAttribute( 'placement' );
                    $event              = eZWorkflowEvent::create( $WorkflowID, $workflowTypeString );
                    $eventType          = $event->eventType();

                    $db->begin();

                    $workflow->store( $eventList );
                    $eventType->initializeEvent( $event );

                    if ( is_numeric( $placement ) )
                    {
                        $eventType->setAttribute( 'placement', (int)$placement );
                    }
                    else
                    {
                        ++$maxPlacement;
                        $eventType->setAttribute( 'placement', $maxPlacement );
                    }

                    $eventDataNode = $eventNode->getElementsByTagName( 'Data' )->item( 0 );

                    if ( $eventDataNode )
                    {
                        $attributes = $eventDataNode->childNodes;
                        foreach ( $attributes as $attribute )
                        {
                            if ( $event->hasAttribute( $attribute->nodeName ) )
                            {
                                $data = $this->parseAndReplaceStringReferences( $attribute->textContent );
                                $event->setAttribute( $attribute->nodeName, $data );
                            }
                        }
                    }
                    $event->store();

                    $db->commit();

                    $eventList[] = $event;

                }

                // Discard existing events, workflow version 1 and store version 0
                $db->begin();

                $workflow->store( $eventList ); // store changes.

                // Remove old version 0 first
                eZWorkflowGroupLink::removeWorkflowMembers( $WorkflowID, 0 );

                $workflowgroups = eZWorkflowGroupLink::fetchGroupList( $WorkflowID, 1 );
                foreach( $workflowgroups as $workflowgroup )
                {
                    $workflowgroup->setAttribute("workflow_version", 0 );
                    $workflowgroup->store();
                }
                // Remove version 1
                eZWorkflowGroupLink::removeWorkflowMembers( $WorkflowID, 1 );

                eZWorkflow::removeEvents( false, $WorkflowID, 0 );
                $workflow->removeThis( true );
                $workflow->setVersion( 0, $eventList );
                $workflow->adjustEventPlacements( $eventList );
                $workflow->storeDefined( $eventList );
                $workflow->cleanupWorkFlowProcess();

                $db->commit();


                if ( $referenceID )
                {
                    $refArray[$referenceID] = $WorkflowID;
                }
                $this->addReference( $refArray );
            }
        }

        $triggerList = $xml->getElementsByTagName( 'Trigger' );
        foreach ( $triggerList as $triggerNode )
        {
            $module      = $triggerNode->getAttribute( 'module' );
            $operation   = $triggerNode->getAttribute( 'operation' );
            $connectType = $triggerNode->getAttribute( 'connectType' );
            $workflowID  = $this->getReferenceID( $triggerNode->getAttribute( 'workflowID' ) );

            $this->writeMessage( "\tTrigger '$module/$operation/$connectType' will be created/updated." , 'notice' );

            if ( $connectType == 'before' )
            {
                $connectType = 'b';
            }
            else
            {
                $connectType = 'a';
            }

            $parameters = array();
            $parameters['module']      = $module;
            $parameters['function']    = $operation;
            $parameters['connectType'] = $connectType;

            $triggerList = eZTrigger::fetchList( $parameters );

            if ( count( $triggerList ) )
            {
                $trigger = $triggerList[0];
                $trigger->setAttribute( 'workflow_id', $workflowID );
                $trigger->store();
            }
            else
            {
                $db = eZDB::instance();
                $db->begin();
                $newTrigger = eZTrigger::createNew( $module, $operation, $connectType, $workflowID );
                $db->commit();
            }
        }
    }