eZ Community » Forums » General » Cannot change object states with php...

Cannot change object states with php scripts running from shell?

Cannot change object states with php scripts running from shell?

Tuesday 27 April 2010 5:06:07 pm - 2 replies


while writing a cronjob script for changing objects's state from "ready to go online" into "published", I ran into this problem and as much as I tried, I couldn't find the solution to it.

It is basically the following situation: I want to be able to execute a conjob script, which will change certain objects state from one to another (regardless of the state, this is up to settings). My script is working correctly only if I add a new rule into anonymous role, giving permission for state/assign - which, need I say, I don't want to do, and is not correct for me. So without it, I am unable to change object state since into the updateObjectState() method there is a check for current user permissions to change the states, and after the array_intersect() for this check is passed, I am left with empty array for new object state variable, and thus the following eZSearch::updateObjectState($objectID, $selectedStateIDList); does not do anything.

The siteaccess defining option for cron script does not help in any way unfortunatelly.

Is there any way the cronjobs to be able to change states, and if yes - what is it? My search did not gave any result.

Appreciating all help and thanks is advance.


P.S.: Sorry, forgot to mention, eZp is at stable 4.3, used with ezwebin, ezflow, ezjscore, etc, but not installed as commonly done (automatic install).

Modified on Tuesday 27 April 2010 5:40:34 pm by Denitsa M

Thursday 13 May 2010 4:52:40 pm

Well, for whatever reason this may be organized the way it is, and no help there, I concluded that currently the way to go around this strange limitation is to use direct query as in standard cronjob unlock.php. I still hope this is fixed in later updates, because it is kind of useless to have working standard methods for change of state and do not use them in cronjobs, and instead use direct queries.


Thursday 13 May 2010 10:42:22 pm

Hi Denitsa,

it's probably because by default your code runs with the anonymous account. But with the following lines you can gain admin privileges in your script :

$adminUserID = 14;
$user = eZUser::fetch( $adminUserID );

I hope that helps.


Modified on Thursday 13 May 2010 10:43:35 pm by Damien Pobel


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

36 542 Users on board!

Forums menu

Proudly Developed with from