function fetchNewsletterCount($type = false)
 {
     $condArray = array('status' => eZNewsletter::StatusPublished);
     if ($type !== false) {
         $condArray['newslettertype_id'] = $type;
     }
     $customOperation = array(array('operation' => 'count( * )', 'name' => 'count'));
     $rows = eZPersistentObject::fetchObjectList(eZNewsletter::definition(), array(), $condArray, null, null, false, false, $customOperation);
     return array('result' => $rows[0]['count']);
 }
 function fetchNewsletterList($offset = 0, $limit = 10, $sendStatus = false, $status = eZNewsletter::StatusPublished, $asObject = true, $grouped = false, $recurring = false)
 {
     $condArray = array('newslettertype_id' => $this->attribute('id'), 'status' => $status);
     if ($sendStatus !== false) {
         $condArray['send_status'] = $sendStatus;
     }
     $grouping = $grouped ? array('contentobject_id') : null;
     if ($recurring == true) {
         $condArray['recurrence_type'] = array(array('d', 'w', 'm'));
     }
     if ($offset === -1 && $limit === -1) {
         return eZPersistentObject::fetchObjectList(eZNewsletter::definition(), null, $condArray, null, $asObject, $grouping);
     } else {
         return eZPersistentObject::fetchObjectList(eZNewsletter::definition(), null, $condArray, null, array('length' => $limit, 'offset' => $offset), $asObject, $grouping);
         // gouping
     }
 }
//   Public License along with this program; if not, write to the Free
//   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//   MA 02110-1301, USA.
//
//
// ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
//
/*! \file send_newsletter.php
*/
set_time_limit(0);
//1. get list of all finnished recurring newsletter
$condArray['send_status'] = array(array(eZNewsletter::SendStatusFinished));
$condArray['status'] = array(array(eZNewsletter::StatusPublished));
$condArray['recurrence_type'] = array(array('d', 'w', 'm'));
$cli->output('Fetching list of recurring newsletters...');
$newsletterArray = eZPersistentObject::fetchObjectList(eZNewsletter::definition(), null, $condArray, null, null, true);
// checks if the recurrence condition is fullfilled
$recurrence = new eZRecurrence();
$cli->output('Found ' . count($newsletterArray) . ' recurring newsletter.');
foreach ($newsletterArray as $newsletter) {
    // 1.0 check if constraint is fullfilled, skip if not
    if (false === $recurrence->checkRecurrenceCondition($newsletter) || in_array('--force-condition', $_SERVER['argv'])) {
        $cli->output('Condition "' . $newsletter->attribute('recurrence_condition') . '" for newsletter "' . $newsletter->attribute('name') . '" [id:' . $newsletter->attribute('id') . '] was not fulfilled. Skipping.');
        continue;
    }
    $cli->output('');
    $cli->output('Archiving newsletter: ' . $newsletter->attribute('id') . ' ' . $newsletter->attribute('name'));
    //1.1 copy newsletter and contentobject
    $newObject = $newsletter->copy();
    $oldObject = eZContentObject::fetch($newsletter->attribute('contentobject_id'));
    $cli->output('Publishing new object...');
 static function removeAll($id)
 {
     eZPersistentObject::removeObject(eZNewsletter::definition(), array('id' => $id));
 }