createandpublishobject : links in ezxmltext

Author Message

Benjamin Plaquevent

Thursday 20 August 2009 1:37:24 am

Hi,

I wrote a script to import data in a eZ Publish site.

I encounter issues when I want to store a link in a ezxmltext attribute :

At first, all links are OK but after edition of any object, all imported links desappear. I found that it was because urls are stored in ezurl table but nothing in ezurl_object_link.

Why doesn't eZContentFunctions::createAndPublishObject method store anything into ezurl_object_link in this case?

Is there something to do after eZContentFunctions::createAndPublishObject to create the correct record into ezurl_object_link table?

My code:

$text = '<a href="' . $href . '" target="_blank">' . $link_text . '</a>';
$attributes["body"] = $this->getXML($texte); // a method returning valid eZPublish XML
$param_creation = array(
    'parent_node_id' => $parent_node_id,
    'class_identifier' => 'breve',
    'creator_id' => $creator_id,
    'attributes' => $attributes);
$object = eZContentFunctions::createAndPublishObject($param_creation);

Friendly,

Ben.

Benjamin Plaquevent
Project Manager
Smile

Benjamin Plaquevent

Thursday 20 August 2009 2:00:09 am

I solved this issue :

$url_id = eZURL::registerURL($href);

$text = '<a href="' . $href . '" target="_blank">' . $link_text . '</a>';

$attributes["body"] = $this->getXML($texte); // a method returning valid eZPublish XML

$param_creation = array(
   'parent_node_id' => $parent_node_id,
   'class_identifier' => 'breve',
   'creator_id' => $creator_id,
   'attributes' => $attributes);

$object = eZContentFunctions::createAndPublishObject($param_creation);

$data_map = $object->dataMap();
$object_attribute_id = $data_map['body']->attribute('id');
$object_attribute_version = $data_map['body']->attribute('version');

if (!eZURLObjectLink::fetch($url_id, $object_attribute_id, $object_attribute_version, false))
{
    $link_object_link = eZURLObjectLink::create( $url_id, $object_attribute_id, $object_attribute_version);
    $link_object_link->store();
}

I'm not sure this is the right way to do things so feel free to give me a better solution.

I steel don't understand why eZContentFunctions::createAndPublishObject method didn't create a record in ezurl_object_link table...

Friendly,

Ben.

Benjamin Plaquevent
Project Manager
Smile

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 16:50:06
Script start
Timing: Jan 18 2025 16:50:06
Module start 'layout'
Timing: Jan 18 2025 16:50:06
Module start 'content'
Timing: Jan 18 2025 16:50:07
Module end 'content'
Timing: Jan 18 2025 16:50:07
Script end

Main resources:

Total runtime1.1323 sec
Peak memory usage4,096.0000 KB
Database Queries52

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0070 588.0469152.6406
Module start 'layout' 0.00700.0056 740.687539.4766
Module start 'content' 0.01261.1181 780.1641491.3984
Module end 'content' 1.13080.0015 1,271.562512.1250
Script end 1.1323  1,283.6875 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00360.3176160.0002
Check MTime0.00130.1179160.0001
Mysql Total
Database connection0.00130.117310.0013
Mysqli_queries1.081095.4710520.0208
Looping result0.00050.0406500.0000
Template Total1.095596.720.5477
Template load0.00220.195220.0011
Template processing1.093296.547720.5466
Template load and register function0.00010.008210.0001
states
state_id_array0.00100.090010.0010
state_identifier_array0.00070.062020.0004
Override
Cache load0.00180.1629220.0001
Sytem overhead
Fetch class attribute can translate value0.00060.053910.0006
Fetch class attribute name0.00090.078730.0003
XML
Image XML parsing0.00190.165610.0019
class_abstraction
Instantiating content class attribute0.00000.000940.0000
General
dbfile0.00220.1967160.0001
String conversion0.00000.001240.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
2content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
4content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 12
 Number of unique templates used: 6

Time used to render debug report: 0.0002 secs