Felix Laate
|
Tuesday 15 March 2005 11:49:38 pm
Hi all! I'm currently working on an ImageMap extension. So far I'm through the selecting og image and the plotting of the mappoint. Now I need to put the info into the database. I've made a class (with the fields: text, x, y and link). I have a module-file updatedb.php, but I'm not sure what to påut into it. I tried using something I found in the forum (http://ez.no/community/forum/developer/inserting_article_through_code_problem), but it gives me this:
Cannot redeclare ezdbcleanup() (previously declared in /home/enternett/ezpublish/index.php:184
Would be be with any hints or ideas! Felix
Publlic Relations Manager
Greater Stavanger
www.greaterstavanger.com
|
Eirik Alfstad Johansen
|
Wednesday 16 March 2005 12:46:16 am
Hi Felix, First of all, due to the redeclare error, it seems that you are including one or more files several times (unless you have copied the declaration of the exdbcleanup function, of course). Try using include_once() instead of include().
Sincerely,
Eirik Alfstad Johansen
http://www.netmaking.no/
|
Felix Laate
|
Wednesday 16 March 2005 1:16:47 am
Hi Erik! There's only one file included (ezscript.php) and it's done with an include_once. Removing it gives an "Undefined class name 'ezscript'" error, so i suppose it should be included. I also tried to use the createFolderObject() function proposed in the above mentioned link, but that gives me an "Call to a member function on a non-object" error. Thank you for helping! Felix
Publlic Relations Manager
Greater Stavanger
www.greaterstavanger.com
|
Felix Laate
|
Wednesday 16 March 2005 2:00:08 am
Well, the code originates from the thread http://ez.no/community/forum/deve...erting_article_through_code_problem as mentioned:
include_once( 'kernel/classes/ezscript.php' );
$siteaccess = "pub";
$script =& eZScript::instance( array( 'debug-message' => '',
'use-session' => true,
'use-modules' => true,
'use-extensions' => true ) );
$script->startup();
$script->setUseSiteAccess( $siteaccess );
$script->initialize();
$currentUser=& eZUser::currentUser();
$user_id = $currentUser->attribute('contentobject_id');
$parentNodeID = 118; // testing folder
$parentContentObjectTreeNode = eZContentObjectTreeNode::fetch($parentNodeID);
$parentContentObject = $parentContentObjectTreeNode->attribute('object');
$sectionID=$parentContentObject->attribute('section_id');
$class =& eZContentClass::fetch( 30 ); //mappoint
$contentObject =& $class->instantiate( $userID, $sectionID );
$nodeAssignment =& eZNodeAssignment::create( array(
'contentobject_id' => $contentObject->attribute( 'id' ),
'contentobject_version' => $contentObject->attribute( 'current_version' ),'parent_node' => 118,'is_main' => 1)
);
// Set a status for the content object version
$version =& $contentObject->version($contentObject->attribute( 'current_version' ) );
$version->setAttribute( 'status', EZ_VERSION_STATUS_DRAFT);
$version->store();
$contentObjectAttributes =& $version->contentObjectAttributes();
$loopLength = count($contentObjectAttributes);
// Adding content to fields
for($i=0;$i<$loopLength;$i++)
{
srand(time()); //just a random number to add to fields
$random = (rand()%9);
$text = "sometext " . $random;
$datatype = $contentObjectAttributes[$i]->datatype();
if($datatype->attribute('data_type_string' ) == 'eztext' || $datatype->attribute('data_type_string' ) == 'ezstring'){
$contentObjectAttributes[$i]->setContent($text);
$contentObjectAttributes[$i]->store();
}
}
$nodeAssignment->store();
$contentObject->store();
$operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObject->attribute( 'id' ), 'version' => 1 ) );
Publlic Relations Manager
Greater Stavanger
www.greaterstavanger.com
|
Eirik Alfstad Johansen
|
Wednesday 16 March 2005 7:23:17 am
Hi Felix, As the error msg says, the function eZDBCleanup() is declared twice; once in index.php at around line 182 and then again in ezscript.php at around line 1096. I think this problem occurs because you are trying to run your script as a view to a module in addition to including the ezscript.php file. If I'm not mistaking, files that include the ezscript.php file are meant to be run separately, outside the ez interface.
Sincerely,
Eirik Alfstad Johansen
http://www.netmaking.no/
|