Empty an ezkeyword field in PHP ?

Author Message

Benoit Vodkaster

Wednesday 14 October 2009 1:28:32 pm

Hello,

In a content class, I have an ezkeyword field ('my_field') which Id like to update in PHP

I use the usual fromString() function

$contentObjectAttributes = $contentObject->fetchAttributesByIdentifier(array('my_field'), $new_version_id, $languageCode);

foreach($contentObjectAttributes as $key => $contentObjectAttribute)
{
  $contentObjectAttribute->fromString($my_new_value);
  $contentObjectAttribute->store();
}

... which works fine when <b>$my_new_value</b> is not set to ''
but it does not change anything when <b>$my_new_value</b> is empty

I've had a look in <b>classes/datatypes/ezkeyword/ezkeywordtype.php</b> and I've found this circa line 285

function fromString( $contentObjectAttribute, $string )
{
  if ( $string != '' )
  {
    $keyword = new eZKeyword();
    $keyword->initializeKeyword( $string );
    $contentObjectAttribute ->setContent( $keyword );
  }
  return true;
}

... which explains why nothing happens in my fromString when <b>$my_new_value</b> is empty

So my question is : <b>how do I empty in PHP an ezkeyword field ?</b>

Thanks a lot in advance
Benoit

Piotrek Karaƛ

Wednesday 14 October 2009 9:33:27 pm

Try investigating eZKeywordType::deleteStoredObjectAttribute() method.

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu

Benoit Vodkaster

Thursday 15 October 2009 7:14:11 am

Thanks Piotrek

I just did a

  $dataType = $newContentObjectAttribute->dataType();
  $dataType->deleteStoredObjectAttribute($newContentObjectAttribute);

and it works fine
Thanks

Hugues Charleux

Wednesday 29 September 2010 3:36:28 am

Sorry to up this one year old topic but I just ran into the same issue (except I did not notice this behavior before production stage x( )

I just filled up a ticket on issues.ez.no [1] as I think we should not have to make a workarround for this but fromString should empty attribute if an empty param is given (as it does for other datatypes).

[1] http://issues.ez.no/IssueView.php?Id=17352&activeItem=1

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 11:23:13
Script start
Timing: Jan 18 2025 11:23:13
Module start 'layout'
Timing: Jan 18 2025 11:23:13
Module start 'content'
Timing: Jan 18 2025 11:23:14
Module end 'content'
Timing: Jan 18 2025 11:23:14
Script end

Main resources:

Total runtime0.7734 sec
Peak memory usage4,096.0000 KB
Database Queries62

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0060 589.0313152.6250
Module start 'layout' 0.00600.0029 741.656339.4453
Module start 'content' 0.00890.7629 781.1016592.4453
Module end 'content' 0.77180.0016 1,373.546912.1563
Script end 0.7734  1,385.7031 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00360.4601160.0002
Check MTime0.00140.1816160.0001
Mysql Total
Database connection0.00080.100610.0008
Mysqli_queries0.713692.2596620.0115
Looping result0.00090.1173600.0000
Template Total0.742396.020.3712
Template load0.00210.272120.0011
Template processing0.740295.702620.3701
Template load and register function0.00030.034210.0003
states
state_id_array0.00240.312310.0024
state_identifier_array0.00100.125720.0005
Override
Cache load0.00180.2347290.0001
Sytem overhead
Fetch class attribute can translate value0.00090.112630.0003
Fetch class attribute name0.00210.265760.0003
XML
Image XML parsing0.00290.377530.0010
class_abstraction
Instantiating content class attribute0.00000.002060.0000
General
dbfile0.00270.3440230.0001
String conversion0.00000.000940.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
4content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
8content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
3content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 22
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs