How to add related object programmatically ...
To add a list of object as an object relation through CLI, this code is not perfect and may remove any existing object relations you have.
Here is an example eZ Publish PHP CLI Script which shows how to use this feature.
<?php /** * tmp * * @package tmp * @author Olav Frengstad <[email protected]> */ require_once 'autoload.php'; $cli = eZCLI::instance(); $script = eZScript::instance( array( 'description' => 'test script', 'use-modules' => true, 'use-extensions' => true, ) ); $script->startup(); $config = $argumentConfig = ''; $optionHelp = $arguments = false; $useStandardOptions = array( 'user' => true, 'siteaccess' => true, ); $options = $script->getOptions( $config, $argumentConfig, $optionHelp, $arguments, $useStandardOptions ); $script->initialize(); $user = eZUser::fetchByName('admin'); if ( !$user ) { $user = eZUser::currentUser(); } $rel = array(153); $object = eZContentObject::fetch( 154 ); $object->appendInputRelationList( $rel,eZContentObject::RELATION_LINK ); $object->commitInputRelations($object->CurrentVersion); $object->store(); $script->shutdown();
To run it save the file in your ez directory (preferably put it in an extension) and call it:
$ php relation.php --siteaccess <your-siteaccess-name>
Article provided by eZpedia
All text is available under the terms of the GNU Free Documentation License
Powered by eZ Publish 6.0.2stable
Hosted by USA eZ Publish Community Partner : Brookins Consulting