This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Forums » Developer » Creating an archival batch script for...
expandshrink

Creating an archival batch script for eZP 5.3

Creating an archival batch script for eZP 5.3

Thursday 04 September 2014 9:50:24 pm - 6 replies

Hi,

We're using eZP for publishing information about events. Editor users create events in a particular folder where they're visible until the event has taken place.

Eventually a large number of events is expected to accumulate in the folder making event management difficult for editors as well as degrading performance.

To solve these issues I'd like to create a batch script that would move event objects whose time has passed to an archive folder.

Can anyone give pointers on creating eZP batch scripts and moving content objects to a eZP newbie?

marko

Friday 05 September 2014 9:21:17 am

Probably this example can help you: https://github.com/ezsystems/Cook...ob/master/Command/SubtreeCommand.php

You need to move your event location to a new parent location:

$locationService = $repository->getLocationService();
$location = $locationService->loadLocation( $oldEventLocationId );
$newParentLocation = $locationService->loadLocation( $newEventLocationId );
$locationService->moveSubtree( $locationId, $newParentLocation );

Further information

Modified on Friday 05 September 2014 10:37:43 am by Andrey Astakhov

Friday 05 September 2014 2:46:37 pm

Thanks!

I was able to get to a point where content items are successfully moved to target folders, but for some reason move operation aborts with the following error:

PHP Fatal error:  Call to a member function attribute() on a non-object in /opt/ez/ezpublish_legacy/kernel/classes/ezcontentobjecttreenode.php on line 6134</span>

Any suggestions?

Here's the code from the file:

...
6127     static function clearViewCacheForSubtree( eZContentObjectTreeNode $node, $clearForRootNode = true )
6128     {
6129         // Max nodes to fetch at a time
6130         static $limit = 200;
6131
6132         if ( $clearForRootNode )
6133         {
6134             $objectID = $node->attribute( 'contentobject_id' );
…

I'm creating new folders in the way described here:

https://github.com/ezsystems/CookbookBundle/blob/master/Command/CreateContentCommand.php

Modified on Friday 05 September 2014 3:01:38 pm by marko asplund

Friday 05 September 2014 3:14:16 pm

Looks like a bug in 5.3. Legacy view cache is being purged but $node is null.

Can you show how are you running your script? My idea is somehow avoid to purge view cache (if it is possible).

Friday 05 September 2014 3:32:37 pm

I'm running it as a console command from the command line like this:

 php ezpublish/console my:events:archive foo bar

Sunday 07 September 2014 7:29:38 pm

Hello Marko!

Would you consider sharing your script php code as a github.com gist here in the forums so that other users with a similar need can more quickly learn how to code such a script for themselves?

Also by posting your code as a gist here in the forums a code review of your script can be done that might help solve the errors your getting.

Please consider sharing your script here in the forums as a gist. Thank you.

Respectfully,
Heath 

Monday 22 September 2014 2:27:18 pm

Hi,

I tested the script in another eZP 5.3 installation and didn't get any errors there. In my development environment I originally had 5.3.0, but later updated to 5.3.2. The error occurred with both versions. The environment where the script works runs 5.3.0. So, I guess the data could be corrupt somehow or this is a bug related to esoteric data.

We're developing an application for a client who owns the IPR for our code, so unfortunately I can't post the code here.

But, basically the script consists of the following subtasks (I've included references to relevant Cookbook examples):

  • find items to archive (e.g. FindContent2Command.php et al.)
  • create target archive folder (CreateContentCommand.php)
  • move items (SubtreeCommand.php)

marko

expandshrink

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

36 542 Users on board!

Forums menu

Proudly Developed with from