Share » Forums » Developer » Inserting article through code problem

Inserting article through code problem

Inserting article through code problem

Wednesday 30 June 2004 10:55:06 am - 24 replies

Author Message

Paul Forsyth

Wednesday 30 June 2004 11:23:58 am

You might need to store the version, eg:

      // Set a status for the content object version
      $version =& $contentObject->version($contentObject->attribute( 'current_version' ) );
      $version->setAttribute( 'status', EZ_VERSION_STATUS_DRAFT);
      $version->store();

Plus at the end try this:

$operationResult = eZOperationHandler::execute( 'content', 
                                                'publish', 
                                                array( 'object_id' => $contentObject->attribute( 'id' ), 
                                                       'version' => $contentObject->attribute('current_version' ) ) );

for good measure.

paul

--
http://www.visionwt.com

Lior Solomon

Wednesday 30 June 2004 7:21:40 pm

thanks
i tried your suggestion
but still no change
on the admin panel i see a new article created called "New Article"
i click on the item to see the content and get an empty object.
if i press the update button i get the "Edit Article - New Article" page
but there are no fields to edit!!! :-(
this module is executed as an extention and the user that executes it has administrative permissions(just if you wondered about this option)

any ideas?

Paul Forsyth

Thursday 01 July 2004 12:47:50 am

Im not sure.

Here is the code I have for creating an folder Maybe you can adapt it instead of yours to see if it works?

    function createFolderObject($user, $sectionID, $userNodeID=2, $folderTitle="No title")
    {
      $folderClassID=1;
      
      $class =& eZContentClass::fetch( $folderClassID );
      $folderContentObject =& $class->instantiate( $user->id(), $sectionID );
      
      // Create a node for the object in the tree.
      $nodeAssignment =& eZNodeAssignment::create( array(
                             'contentobject_id' => $folderContentObject->attribute( 'id' ),
                             'contentobject_version' => 1,
                             'parent_node' => $userNodeID,
                             'sort_field' => 2, //Published
                             'sort_order' => 1, //Descending
                             'is_main' => 1));
      $nodeAssignment->store();
        
      // Set a status for the content object version
      $folderContentObjectVersion =& $folderContentObject->version($folderContentObject->attribute( 'current_version' ) );
      $folderContentObjectVersion->setAttribute( 'status', EZ_VERSION_STATUS_DRAFT);
      $folderContentObjectVersion->store();

      // Set the title of the folder.
      $folderContentObjectAttributes =& $folderContentObjectVersion->contentObjectAttributes();
      foreach ($folderContentObjectAttributes as $folderAttribute)
      {
        // Each attribute has an attribute called 'identifier' that identifies it.    

        if ($folderAttribute->attribute("contentclass_attribute_identifier") == "title")
        {
          $folderAttribute->setAttribute("data_text",$folderTitle);
          $folderAttribute->store();
        }
      }
          
      // Now publish the object.
      $operationResult = eZOperationHandler::execute( 'content', 'publish',
                              array( 'object_id' => $folderContentObject->attribute( 'id' ),
                                     'version' => $folderContentObject->attribute('current_version' ) ) );
      
      return;
    }

good luck!

paul

--
http://www.visionwt.com

Lior Solomon

Thursday 01 July 2004 2:23:47 am

well i added the function
and i see the same simptoms
the folder is created
but when i try to edit it
there are no fields to edit - the description field is missing on this case
but if i create a folder manualy on the admin pannel i can edit the field

Paul Forsyth

Thursday 01 July 2004 3:47:53 am

Are you getting any errors?

Clear cache and try to edit again.

paul

--
http://www.visionwt.com

Lior Solomon

Thursday 01 July 2004 4:50:59 am

well not helped at all
just to make the problem clear
the folowing image is a snapshot of a created manualy folder object - edit screen:
http://www.kabbalahmedia.info/~testworkarea/folder-by-manualy.jpg

and this one for created by module(code generated) - edit screen:
http://www.kabbalahmedia.info/~testworkarea/folder-by-code.jpg

somehow it doesn't alows me to view or edit fields on the created object

Paul Forsyth

Thursday 01 July 2004 5:02:06 am

Are you getting any errors?

paul

Lior Solomon

Thursday 01 July 2004 5:12:05 am

i just uploaded images that includes the debug info
go to the bottom of the image(it is scrolable now)

thanks for the support

Paul Forsyth

Thursday 01 July 2004 5:16:26 am

Ok, first try switching of the online editor to test whether that has anything to do with it.

Make sure your clear the cache before looking at the errors. Cached pages wont have errors.

Are you able to look at the database with a tool like phpmyadmin?

paul

Lior Solomon

Thursday 01 July 2004 5:36:26 am

i'm using postgre db
but i can try and scroll the db tables
do you know the ez db scheme?
or where can i find documantation for that?

Paul Forsyth

Thursday 01 July 2004 5:45:43 am

One thing you could try is to edit the file:

design/standard/templates/content/edit.tpl

and add in near the top:

{$object|attribute(show)}

Try this for a normal folder and your created folder. Are there differences?

Have you switched off the online editor? Switch it off in the site.ini.

paul

Lior Solomon

Thursday 01 July 2004 6:24:45 am

THE PLOT IS PLOTING

folder - code
>contentobject_attributes array Array(0)
>data_map array Array(0)

folder - manual
>contentobject_attributes array Array(2)
>data_map array Array(2)

that explains it
so probably there is something preventing from the code to be executed proparly but no propare exceptions are thrown
actualy the attributes are not being stored
:-(

Paul Forsyth

Thursday 01 July 2004 6:51:05 am

Hmm, look at your logs, var/log/error.log, var/log/warning.log, var/log/debug.log.

Try a 'tail -f' on these files and watch them when you run your script. Something is going wrong here...

paul

Lior Solomon

Thursday 01 July 2004 7:20:40 am

on the error messages i get the following:

Error: eZTemplate Jul 01 2004 07:09:51 
No such attribute for array(3): node_id
Choose one of following: content, path, uri
 
Error: eZTemplate Jul 01 2004 07:09:51 
No such attribute for array(3): node_id
Choose one of following: content, path, uri
 
Error: eZTemplate Jul 01 2004 07:09:51 
No such attribute for array(3): node_id
Choose one of following: content, path, uri
 
Error: eZTemplate Jul 01 2004 07:09:51 
No such attribute for array(3): node_id
Choose one of following: content, path, uri
 
Error: eZTemplate Jul 01 2004 07:09:51 
No such attribute for array(3): node_id
Choose one of following: content, path, uri
 
Error: eZTemplate Jul 01 2004 07:09:51 
No such attribute for array(3): node_id
Choose one of following: content, path, uri


but this are template error that shouldn't be related to the problem.

warnings:

Warning: eZCodePage Jul 01 2004 07:09:51 
Couldn't load codepage file share/codepages/utf-8
 
Warning: ezi18n Jul 01 2004 07:09:51 
No translation for file(translation.ts) in context(kernel/classes/datatypes): 'XML Text field' with comment(Datatype name)
 
Warning: ezi18n Jul 01 2004 07:09:51 
No translation for file(translation.ts) in context(kernel/classes/datatypes): 'XML Text field' with comment(Datatype name)
 
Warning: ezi18n Jul 01 2004 07:09:51 
No translation for file(translation.ts) in context(kernel/classes/datatypes): 'XML Text field' with comment(Datatype name)
 
Debug: changing value of attribute_original_id to default Jul 01 2004 07:09:51 

 
Warning: ezi18n Jul 01 2004 07:09:51 
No translation for file(translation.ts) in context(kernel/classes/datatypes): 'XML Text field' with comment(Datatype name)
 
Warning: ezi18n Jul 01 2004 07:09:51 
No translation for file(translation.ts) in context(kernel/classes/datatypes): 'XML Text field' with comment(Datatype name)
 
....(alot of those)

Warning: eZModuleOperationInfo::execute Jul 01 2004 07:09:51 
Missing main operation memento for key: 6f0d86830744444ae0968edcc19e1706
 
Warning: PHP Jul 01 2004 07:09:51 
Undefined index:  user_id in /var/www/html/eznew/kernel/classes/ezworkflowprocess.php on line 156

Warning: PHP Jul 01 2004 07:09:51 
fread(): Length parameter must be greater than 0. in /var/www/html/eznew/lib/eztemplate/classes/eztemplatecompiler.php on line 1632
 

this workflow warning looks suspisious
what do you think?
man i'm so happy to have you helping
realy this is outstanding help

Lior

Paul Forsyth

Thursday 01 July 2004 7:28:15 am

Are the logs correct? I see times of 07.09. Is that your local time?

Im a little stumped here. Attributes should be created when the object is created, so why yours are not create im not sure.

eZ crew, can you help here?

paul

Kåre Køhler Høvik

Monday 05 July 2004 2:12:52 am

Hi

Whats the default language ?
Which PHP version are you using ?

--
Kåre Høvik

Kåre Høvik

Lior Solomon

Monday 05 July 2004 3:26:15 am

Thanks mate
the php version is: PHP 4.3.6
the local of the user side is : rus_RU
and for admin : eng_GB

any ideas?
dont tell me its related to the default language!!!
:)

Kåre Køhler Høvik

Monday 05 July 2004 3:41:13 am

I thnk it might be language related. From where do you run this import script ?
What siteaccess do you use on the import ? Try to make sure to set it to the one you use for admin.

--
Kåre Høvik

Kåre Høvik

Lior Solomon

Monday 05 July 2004 3:44:45 am

hmm
i'm not using any siteaccess
just running the create.php example you gave with your new book
there is no mention there for siteaccess

how should i do it ?

Kåre Køhler Høvik

Monday 05 July 2004 3:55:23 am

Try adding this to the start of your script :

include_once( 'kernel/classes/ezscript.php' );
$script =& eZScript::instance( array( 'debug-message' => '',
                                      'use-session' => true,
                                      'use-modules' => true,
                                      'use-extensions' => true ) );
$script->startup();
$script->setUseSiteAccess( $siteaccess );
$script->initialize();

Replace $siteaccess with your admin siteaccess.

--
Kåre Høvik

Kåre Høvik

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu