// Status for users we should send newsletter to $valid_status = array(JAJ_USER_STATUS_PENDING, JAJ_USER_STATUS_CONFIRMED, JAJ_USER_STATUS_APPROVED); $limit = 50; $offset = 0; // Loop through users, 50 at a time to avoid excessive memory usage $recipient_count = 0; while (true) { //$users =& eZContentObjectTreeNode::subTreeByNodeID( $users =& eZContentObjectTreeNode::subTree(array('ClassFilterType' => 'include', 'ClassFilterArray' => array('subscription_user'), 'AttributeFilter' => array(array('subscription_user/status', 'in', $valid_status)), 'ExtendedAttributeFilter' => array(id => 'eorfilter', params => array(array('subscription_user/subscriptions', $distributionLists, 'or'))), 'Limit' => $limit, 'Offset' => $offset, 'LoadDataMap' => false), $subscriptionUsersNode); foreach ($users as $user) { if (in_array($user->ContentObjectID, $delivered)) { continue; } $row = array('newsletter_issue_id' => $object->ID, 'subscription_user_id' => $user->ContentObjectID); $delivery = new JAJDelivery($row); $delivery->store(); $recipient_count++; } eZContentObject::clearCache(); if (count($users) < $limit) { break; } else { $offset += $limit; } } // Update Newsletter issue status if we found new recipients if ($recipient_count > 0) { $status = $dataMap["status"]; $status->setAttribute('data_text', "1"); $status->sync(); }