Forums / Extensions / Updating the modified by field on a content object using eZ API / PHP

Updating the modified by field on a content object using eZ API / PHP

Author Message

Conrad Decker

Friday 08 October 2010 1:57:49 am

Does anyone have any pointers on how I can update the modified by field on a content object using PHP and the eZ API. I've got the update and publish functionality working, but I'm curious how I would go about setting the user who modified the object.

I thought it would be similar to the creation process:

$params = array();
$params['class_identifier'] = 'image';
$params['creator_id'] = $user->attribute( 'contentobject_id' ); //using the user extracted above
$params['parent_node_id'] = $parent_node->attribute( 'node_id' ); //pulling the node id out of the parent

but I thought I'd just have to update the modifier_id field, so I tried this:

<span class="Apple-style-span" style="font-size: 13px; " mce_style="font-size: 13px;" mce_fixed="1">$params = array();</span><span class="Apple-style-span" style="font-size: 13px; " mce_style="font-size: 13px;" mce_fixed="1">
</span><span class="Apple-style-span" style="font-size: 13px; " mce_style="font-size: 13px;" mce_fixed="1">$params['modifier_id'] = $user->attribute( 'contentobject_id' ); //using the user extracted above</span><font class="Apple-style-span" size="3"><span class="Apple-style-span" style="" mce_fixed="1">
</span></font>

Unfortunately...no such luck. Any pointers would be appreciated.

Thanks!

Jérôme Vieilledent

Moderated by: Jérôme Vieilledent

Friday 08 October 2010 4:23:56 am

Hi Conrad

If you're talking about the modified timestamp, here's the tip :

$myContentObject->setAttribute( 'modified', $myTimestamp );
$myContentObject->store( array( 'modified' ) ) ;

Quoc Huy Nguyen Dinh

Friday 08 October 2010 6:08:41 am

@Jerome, I think what Conrad want is to be able to set the modifier(person) id for the edit of an object.

@Conrad, if I'm not wrong there is no modifier_id as the modifier of an object is the creator of the new version of an object.

For example you create a complete new object and publish it:

version #1, creator id=45 => object_id=5454, current version = 1

Then you edit the object (means you should create a new version of the object):

version #2, creator id=46 => object_id=5454, current version = 2

So currently the object of id 5454 is at current version set to #2, the creator of version #2 is of id 46. So this means the current modifier of object id 5454 is of id 46. See what I mean?

If you are trying to edit an object in PHP by directly accessing the attributes then store it without creating a new version, you're doing it wrong, or would I say not in the recommended way.

You can have a look at the file:

kernel/content/edit.php

Conrad Decker

Wednesday 13 October 2010 10:12:08 am

(Sorry for the delayed response, didn't have the notifications enabled)

Ahhh...gotcha, that's perfect guys! Thank you so much.

@Jerome, I was in fact looking for a way to set the id of the user that modified the object, but I think what Quoc mentioned makes sense. I'm going to give that a shot...however, I just came across a need to update the modified timestamp, so thank you as well for your input.

@Quoc, I see what you're saying...that does indeed make sense. I'm going to try it that way and see how I make out.

Cheers!

eZ debug

Timing: Jan 18 2025 00:07:19
Script start
Timing: Jan 18 2025 00:07:19
Module start 'content'
Timing: Jan 18 2025 00:07:19
Module end 'content'
Timing: Jan 18 2025 00:07:20
Script end

Main resources:

Total runtime0.7578 sec
Peak memory usage4,096.0000 KB
Database Queries201

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0083 593.3203180.8047
Module start 'content' 0.00830.5837 774.1250591.6797
Module end 'content' 0.59200.1658 1,365.8047337.3672
Script end 0.7578  1,703.1719 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00400.5298210.0002
Check MTime0.00160.2051210.0001
Mysql Total
Database connection0.00190.246910.0019
Mysqli_queries0.677389.37142010.0034
Looping result0.00250.32521990.0000
Template Total0.727596.020.3638
Template load0.00200.262720.0010
Template processing0.725595.739720.3628
Template load and register function0.00010.014110.0001
states
state_id_array0.00090.115210.0009
state_identifier_array0.00120.160720.0006
Override
Cache load0.00170.2285350.0000
Sytem overhead
Fetch class attribute can translate value0.00160.213640.0004
Fetch class attribute name0.00190.248070.0003
XML
Image XML parsing0.00200.267940.0005
class_abstraction
Instantiating content class attribute0.00000.002280.0000
General
dbfile0.00260.3423420.0001
String conversion0.00000.000930.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
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
4content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
4content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
6content/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
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 19
 Number of unique templates used: 6

Time used to render debug report: 0.0002 secs