Skip to content

Instantly share code, notes, and snippets.

@bdunogier
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdunogier/b47784a14a9cc946a0c6 to your computer and use it in GitHub Desktop.
Save bdunogier/b47784a14a9cc946a0c6 to your computer and use it in GitHub Desktop.
Scripts to publish multiple versions in parallel
<?php
list(, , $contentId, $versionNumber ) = $argv;
$behaviour = new ezpContentPublishingBehaviour();
$behaviour->isTemporary = false;
$behaviour->disableAsynchronousPublishing = !(bool)getenv( 'EZ_USE_AP' );
print_r( $behaviour );
ezpContentPublishingBehaviour::setBehaviour( $behaviour );
eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentId, 'version' => $versionNumber ) );
echo "Done publishing {$contentId}v{$versionNumber}";
<?php
/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributd with this source code.
*/
/** @var eZContentObjectVersion[] $versions */
$versions = array();
echo "# asynchronous-publishing: " . ( getenv( 'EZ_USE_AP' ) ? 'ON' : 'OFF' ) . "\n\n";
echo "Creating content object version 1 in eng-GB... ";
$content = createContent();
echo " #" . $content->attribute( 'id' ) . "\n";
echo "Publishing... ";
eZOperationHandler::execute(
'content', 'publish', array( 'object_id' => $content->attribute( 'id' ), 'version' => 1 )
);
echo "done\n";
foreach ( array( 'dut-NL', 'fin-FI', 'fre-FR', 'ger-DE' ) as $locale )
{
echo "Adding version in $locale... ";
$versions[] = updateContent( $content, $locale );
echo " v" . $versions[count($versions)-1]->attribute('version'). "\n";
}
$pidArray = array();
foreach ( $versions as $version )
{
$contentId = $content->attribute( 'id' );
$versionNumber = $version->attribute( 'version' );
/*eZOperationHandler::execute(
'content', 'publish', array( 'object_id' => $contentId, 'version' => $versionNumber )
);*/
/*if ( pcntl_fork() > 0)
{
continue;
}*/
// echo `php bin/php/ezexec.php publishversion.php $contentId $versionNumber`;
echo "Sending v$versionNumber for publishing\n";
passthru( "php bin/php/ezexec.php publishversion.php $contentId $versionNumber >> var/log/publishing/$contentId.$versionNumber.log 2>&1 &" );
// eZExecution::cleanExit();
// exit;
}
$status = 0;
pcntl_waitpid( -1, $status );
/**
* @return eZContentObject
*/
function createContent()
{
$class = eZContentClass::fetchByIdentifier( 'folder' );
$content = $class->instantiate( 14, 1, false, 'eng-GB' );
$dataMap = $content->attribute( 'data_map' );
$dataMap['name']->fromString( __METHOD__ );
$nodeAssignment = eZNodeAssignment::create(
array(
'contentobject_id' => $content->attribute( 'id' ),
'contentobject_version' => 1,
'parent_node' => 2,
'is_main' => 1
)
);
$nodeAssignment->store();
return $content;
}
/**
* @param eZContentObject $content
* @return eZContentObjectVersion
*/
function updateContent( $content, $locale )
{
$version = $content->createNewVersionIn( $locale );
$version->setAttribute( 'modified', time() );
$version->setAttribute( 'status', eZContentObjectVersion::STATUS_DRAFT );
$version->store();
/** @var eZContentObjectAttribute[] $dataMap */
$dataMap = $version->dataMap();
$dataMap['name']->fromString( __METHOD__ . " [$locale]" );
return $version;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment