resourceGroupBatcher

Looking to verify if this is the current version of resourceGroupBatcher or if someone can point out what has changed with ModX that would help get this code from GitHub by @henk_heibel working on the most current version of ModX:

if ($collection = $modx->getCollection('modResource')){
    foreach ($collection as $resource){
        $resource->joinGroup('AllDocs');
		$resource->save();
		echo $resource->get('id').' updated<br/>';
    } 
}

When I attempted to run this code, I got a 500 error on the page I included the snippet on.

This snippet should still work on the current version of MODx. I did a quick test and had no errors.

You probably have to look at the PHP error log of your server (not the error log in MODx) to see what the cause of your 500 error is.

Thank you @halftrainedharry! I did not think to check the error log. It looks like the size of my collection is too large for the memory. Is there a way of calling smaller chunks of getCollection()?

I found a page about xPDO - is this the same? Can I create a filter using the second argument to limit the number of each query? For example, getCollection(‘modResource’, [‘id’ =< 150])

Yes this is xPDO!
Maybe you can use an iterator instead of getCollection

$modx->getIterator('modResource')

or using a query should also work.

1 Like

Thank you again @halftrainedharry!