Forums / Developer / Empty an ezkeyword field in PHP ?

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

eZ debug

Timing: Jan 30 2025 16:38:16
Script start
Timing: Jan 30 2025 16:38:16
Module start 'content'
Timing: Jan 30 2025 16:38:16
Module end 'content'
Timing: Jan 30 2025 16:38:16
Script end

Main resources:

Total runtime0.1775 sec
Peak memory usage8,192.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0063 587.9297370.2969
Module start 'content' 0.00630.0128 958.22661,005.6563
Module end 'content' 0.01910.1583 1,963.88283,895.4609
Script end 0.1774  5,859.3438 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00432.4400200.0002
Check MTime0.00130.7502200.0001
Mysql Total
Database connection0.00060.347710.0006
Mysqli_queries0.088349.76871410.0006
Looping result0.00120.67801390.0000
Template Total0.157989.010.1579
Template load0.00080.432710.0008
Template processing0.157188.528110.1571
Override
Cache load0.00060.316810.0006
Sytem overhead
Fetch class attribute can translate value0.00221.213710.0022
XML
Image XML parsing0.00020.122310.0002
General
dbfile0.00935.2492200.0005
String conversion0.00000.002130.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs