How-to trigger a workflow using the Public API: compariso...
Versions Compared
Old Version 11
changes.mady.by.user Bertrand Dunogier
Saved on May 24, 2013
compared with
New Version 12
changes.mady.by.user Bertrand Dunogier
Saved on May 24, 2013
- Previous Change: Difference between versions 10 and 11
- Next Change: Difference between versions 12 and 13
- View Page History
Key
- This line was added.
- This line was removed.
- Formatting was changed.
...
| Code Block | ||
|---|---|---|
|
||
/**
* @param $contentId
* @param $versionId
* @return bool true if the operation was completed, false if it was interrupted
*/
protected function runLegacyPublish( $contentId, $versionId, $runAsUserId = null )
{
$legacyKernel = $this->getLegacyKernel();
return $legacyKernel->runCallback(
function () use ( $contentId, $versionId, $runAsUserId )
{
$script = \eZScript::instance( array( 'use-modules' => true ) );
$script->initialize();
$db = \eZDB::instance();
$transactionCounter = $db->transactionCounter();
if ( $runAsUserId )
{
\eZUser::setCurrentlyLoggedInUser( \eZUser::fetch( $runAsUserId ), $runAsUserId );
}
$operationResult = \eZOperationHandler::execute(
'content', 'publish', array( 'object_id' => $contentId, 'version' => $versionId )
);
if ( ( array_key_exists( 'status', $operationResult ) && $operationResult['status'] != \eZModuleOperationInfo::STATUS_CONTINUE ) )
{
// Required by https://jira.ez.no/browse/EZP-20558
for ( $i = 0, $counter = ( $db->transactionCounter() - $transactionCounter ); $i < $counter; ++$i )
{
$db->commit();
}
return false;
}
return true;
}
);
}
|
Any Legacy code can be executed this way. While it is a backward compatibility feature, it is considered good practice to work around missing features. It is however not recommended to rely heavily on
| Note | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||
| Public API code is always executed as a user, by default anonymous. Since workflows are often user dependent (Approval is), it is important that this code is executed as an editor, or as a user who will trigger the workflow.
Of course, this isn't required when using Public API code in controllers, since those will use the currently-logged in user. Legacy code also requires a user By default, code in LegacyKernel::runCallback() calls is executed as anonymous. You'll have to log the executing user manually on legacy as well.
|
...
Comments
Add a comment