Forums / General / Cannot change object states with php scripts running from shell?

Cannot change object states with php scripts running from shell?

Author Message

Denitsa M.

Tuesday 27 April 2010 8:06:07 am

Hi,

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.

Deni

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).

Iguana IT - http://www.iguanait.com

Denitsa M.

Thursday 13 May 2010 7:52:40 am

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.

Deni 

Iguana IT - http://www.iguanait.com

Damien Pobel

Thursday 13 May 2010 1: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 );
$user->loginCurrent();

I hope that helps.

Cheers

Damien
Planet eZ Publish.fr : http://www.planet-ezpublish.fr
Certification : http://auth.ez.no/certification/verify/372448
Publications about eZ Publish : http://pwet.fr/tags/keywords/weblog/ez_publish