Wednesday 02 February 2011 11:25:32 am
Hello Jitesh,
you cannot launch a php script using eZ Publish API without eZ Publish context. If you make your own module and your own view, your script will run in the eZ Publish context. You can also use php in command line. If you want to use the command line, you need to initialize eZ Publish context. Here is a script you can launch in command line:
#!/usr/bin/env php
<?php
require 'autoload.php';
$cli = eZCLI::instance();
$scriptSettings = array();
$scriptSettings['description'] = 'Create a simple article in a simple folder';
$scriptSettings['use-session'] = false;
$scriptSettings['use-modules'] = true;
$scriptSettings['use-extensions'] = true;
$script = eZScript::instance( $scriptSettings );
$script->startup();
$config = '';
$argumentConfig = '';
$optionHelp = false;
$arguments = false;
$useStandardOptions = true;
$options = $script->getOptions( $config, $argumentConfig, $optionHelp, $arguments, $useStandardOptions );
$script->initialize();
createASimpleArticleForJitesh();
$script->shutdown( 0 );
function createASimpleArticleForJitesh()
{
$user = eZUser::fetchByName( 'admin' );
if (!$user)
{
//if no user exists let's pull out the current user:
$user = eZUser::currentUser();
}
$parent_node = eZContentObjectTreeNode::fetchByURLPath('my_folder');
$params= array();
$params['class_identifier'] = "article";
$params['creator_id'] = eZUser::currentUser()->ContentObjectID;
$params['parent_node_id'] = $parent_node->NodeID;
$params['section_id'] = $parent_node->ContentObject->SectionID;
$attributesData = array() ;
$attributesData['name'] = 'Title of Article' ;
$attributesData['short_description'] = 'This is an amazing article.' ;
$params['attributes'] = $attributesData;
$contentObject = eZContentFunctions::createAndPublishObject($params);
eZContentCacheManager::clearObjectViewCache( $parent_node->ContentObjectID, true );
}
?> You must save it as /var/www/html/OSCAR_UAT/script.php to execute it, open a terminal and type these commands:
$ cd /var/www/html/OSCAR_UAT
$ php script.php
--
Developer at Open Wide
|