function execute($process, $event)
 {
     $parameters = $process->attribute('parameter_list');
     $co = eZContentObject::fetch($parameters['object_id']);
     $parent = eZContentObjectTreeNode::fetch($co->attribute('main_parent_node_id'));
     $parentco = $parent->attribute('object');
     $newslettertype = eZPersistentObject::fetchObject(eZNewsletterType::definition(), null, array('article_pool_object_id' => $parentco->attribute('id'), 'status' => eZNewsletterType_StatusPublished));
     $list = eZNewsletter::fetchByContentObject($parameters['object_id']);
     if (empty($list) and is_object($newslettertype)) {
         $newsletter = eZNewsletter::create($co->attribute('name'), $co->attribute('owner_id'), $newslettertype->attribute('id'));
         $newsletter->setAttribute('contentobject_id', $parameters['object_id']);
         $newsletter->setAttribute('template_to_use', 'mobotixnewsletter');
         $newsletter->setAttribute('contentobject_version', $parameters['version']);
         $newsletter->store();
         $newsletter->publish();
     }
     return eZWorkflowType::STATUS_ACCEPTED;
 }
 function fetchObjectStat($contentObjectID)
 {
     $db = eZDB::instance();
     // Get total send
     $totalCountSQL = 'SELECT count(*) AS count
                       FROM ezsendnewsletteritem item, eznewsletter newsletter
                       WHERE newsletter.object_relations like \'%/' . $db->escapeString($contentObjectID) . '/%\' AND
                             item.send_status = \'' . eZSendNewsletterItem::SendStatusSent . '\' AND
                             newsletter.status = \'' . eZNewsletter::StatusPublished . '\' AND
                             item.newsletter_id = newsletter.id';
     $totalCountResult = $db->arrayQuery($totalCountSQL);
     $totalSend = $totalCountResult[0]['count'];
     // Get total read
     /* With relation check
        $totalReadSQL = 'SELECT count(*) AS count
                         FROM ezsendnewsletteritem item, eznewsletter newsletter
                         WHERE newsletter.object_relations like \'%/' . $db->escapeString( $contentObjectID ) . '/%\' AND
                               newsletter.status = \'' . eZNewsletter::StatusPublished . '\' AND
                               item.send_status = \'' . eZSendNewsletterItem::SendStatusSent . '\' AND
                               item.object_read_ids like \'%/' . $db->escapeString( $contentObjectID ) . '/%\' AND
                               item.newsletter_id = newsletter.id';
        */
     /* We ignore the relation */
     $totalReadSQL = 'SELECT count(*) AS count
                      FROM ezsendnewsletteritem item, eznewsletter newsletter
                      WHERE item.send_status = \'' . eZSendNewsletterItem::SendStatusSent . '\' AND
                            item.object_read_ids like \'%/' . $db->escapeString($contentObjectID) . '/%\' AND
                            item.newsletter_id = newsletter.id';
     $totalReadResult = $db->arrayQuery($totalReadSQL);
     $totalRead = $totalReadResult[0]['count'];
     return array('result' => array('num_sent' => $totalSend, 'num_read' => $totalRead, 'newsletter_list' => eZNewsletter::fetchListByRelatedContentObject($contentObjectID)));
 }
$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...');
    // publish the newly created object
    eZOperationHandler::execute('content', 'publish', array('object_id' => $newObject->attribute('id'), 'version' => $newObject->attribute('current_version')));
    $newNewsletter = eZNewsletter::fetchByContentObject($newObject->attribute('id'), $newObject->attribute('current_version'), eZNewsletter::StatusPublished, true);
    if ($newNewsletter) {
        $cli->output('Copied newsletter: ' . $newsletter->attribute('id') . ' to ' . $newNewsletter->attribute('id') . ' ' . $newsletter->attribute('name'));
        //1.2 remove recurrency of old one
        $newsletter->setAttribute('recurrence_type', '');
        $newsletter->setAttribute('recurrence_value', '');
        //1.3 set status of new to None for sending
        $newNewsletter->setAttribute('send_status', eZNewsletter::SendStatusNone);
        //1.4 set send date for new recurrence
        $oldDate = $newNewsletter->attribute('send_date');
        //echo date("YmdGHjs", $olddate);
        $date = mktime($newNewsletter->attribute('send_hour'), $newNewsletter->attribute('send_minute'), $newNewsletter->attribute('send_second'), $newNewsletter->attribute('send_month'), $newNewsletter->attribute('send_day'), $newNewsletter->attribute('send_year'));
        if ($newNewsletter->attribute('recurrence_type') == 'd') {
            echo "daily value: " . $newNewsletter->attribute('recurrence_value') . "\n";
            //get next senddate
            $date = getNextSendDateDaily($newNewsletter);
// The "eZ publish professional licence" version 2 is available at
// http://ez.no/ez_publish/licences/professional/ and in the file
// PROFESSIONAL_LICENCE included in the packaging of this file.
// For pricing of this licence please contact us via e-mail to licence@ez.no.
// Further contact information is available at http://ez.no/company/contact/.
//
// The "GNU General Public License" (GPL) is available at
// http://www.gnu.org/copyleft/gpl.html.
//
// Contact licence@ez.no if any conditions of this licencing isn't clear to
// you.
//
$ObjectID = $Params['ObjectID'];
$ObjectVersion = $Params['ObjectVersion'];
$object = eZContentObjectVersion::fetchVersion($ObjectVersion, $ObjectID);
$newsletter = eZNewsletter::fetchByContentObject($ObjectID, $ObjectVersion, false, true);
$tpl = eZNewsletterTemplateWrapper::templateInit();
$tpl->setVariable('object', $object);
$tpl->setVariable('contentobject', $object);
$tpl->setVariable('newsletter', $newsletter);
if (!$newsletter) {
    return false;
}
//skin selection
$skin_prefix = 'eznewsletter';
$custom_skin = $newsletter->attribute('design_to_use');
$Result = array();
if ($custom_skin) {
    $skin_prefix = $custom_skin;
}
$template = 'design:' . $skin_prefix . '/sendout/html.tpl';
                    } catch (Exception $e) {
                        eZDebug::writeError("Invalid XML input data.", 'view_newslettertype');
                        $input = "";
                    }
                } else {
                    $input = $newsletterType->attribute($typeSource);
                }
                $attribute->setAttribute('data_text', $input);
                $attribute->store();
            }
        }
        $contentObject->store();
    }
    $nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $contentObject->attribute('id'), 'contentobject_version' => $contentObject->attribute('current_version'), 'parent_node' => $parentNode->attribute('node_id'), 'is_main' => 1));
    $nodeAssignment->store();
    $newsletter = eZNewsletter::create('New "' . $class->attribute('name') . '" newsletter.', $userID, $newsletterType->attribute('id'));
    $newsletter->setAttribute('contentobject_id', $contentObject->attribute('id'));
    $newsletter->setAttribute('contentobject_version', $contentObject->attribute('current_version'));
    $newsletter->setAttribute('design_to_use', strtok($newsletterType->attribute('allowed_designs'), ','));
    $newsletter->store();
    $db->commit();
    return $Module->redirectTo('content/edit/' . $contentObject->attribute('id') . '/' . $contentObject->attribute('current_version'));
}
$userParameters = $Params['UserParameters'];
$offset = isset($userParameters['offset']) ? $userParameters['offset'] : 0;
$limitKey = isset($userParameters['limit']) ? $userParameters['limit'] : '1';
$limitList = array('1' => 10, '2' => 25, '3' => 50);
$limit = $limitList[(string) $limitKey];
$viewParameters = array('offset' => $offset, 'limitkey' => isset($userParameters['limitkey']) ? $userParameters['limitkey'] : 1);
$tpl = eZNewsletterTemplateWrapper::templateInit();
$tpl->setVariable('limit', $limit);
}
$conditions = array_merge($conditions, array('send_date' => array('<=', $timestamp)));
//newslettertype parameter
if (in_array('-newslettertype', $_SERVER['argv'])) {
    $key = array_search('-newslettertype', $_SERVER['argv']);
    $newslettertype_id = $_SERVER['argv'][$key + 1];
    if (is_numeric($newslettertype_id) && eZNewsletterType::fetch($newslettertype_id)) {
        $conditions = array_merge($conditions, array('newslettertype_id' => array('=', $newslettertype_id)));
        $cli->output('Filter for newslettertype <' . $newslettertype_id . '> enabled.');
    } else {
        $cli->output('Invalid id of newslettertype <' . $newslettertype_id . '>!');
        eZExecution::cleanup();
        eZExecution::setCleanExit();
        exit(1);
    }
}
$newsletterList = eZNewsletter::fetchListBySendStatus(eZNewsletter::SendStatusNone, eZNewsletter::StatusPublished, true, $conditions);
$cli->output('Found ' . count($newsletterList) . ' newsletter.');
foreach ($newsletterList as $newsletter) {
    $cli->output('Fetching subscriber for newsletter ' . $newsletter->attribute('name'));
    $newsletter->setAttribute('send_status', eZNewsletter::SendStatusBuldingList);
    $newsletter->sync();
    $newsletter->buildSendList();
    $newsletter->setAttribute('send_status', eZNewsletter::SendStatusSending);
    $newsletter->sync();
}
$cli->output('Build finished.');
// remove pid file to unlock cronjob
if (file_exists($pidfilename)) {
    unlink($pidfilename);
}
                            $newsletters[] = $newsletter;
                        }
                        $tpl->setVariable('delete_result', $newsletters);
                        $Result = array();
                        $Result['newsletter_menu'] = 'design:parts/content/newsletter_menu.tpl';
                        $Result['left_menu'] = 'design:parts/content/eznewsletter_menu.tpl';
                        $Result['content'] = $tpl->fetch("design:{$extension}/confirmremove_newsletter.tpl");
                        $Result['path'] = array(array('url' => false, 'text' => ezpI18n::tr('eznewsletter/list_newslettertype', 'Newsletter types')));
                        return;
                    } else {
                        if ($http->hasPostVariable('ConfirmRemoveNewsletterButton')) {
                            $newsletterIDArray = $http->sessionVariable('NewsletterList');
                            $db = eZDB::instance();
                            $db->begin();
                            foreach ($newsletterIDArray as $id) {
                                eZNewsletter::removeAll($id);
                            }
                            $db->commit();
                            return $Module->redirectToView('list_type');
                        }
                    }
                }
            }
        }
    }
}
$viewParameters = array('offset' => $offset, 'limitkey' => isset($userParameters['limitkey']) ? $userParameters['limitkey'] : 1);
$newsletterTypeArray = eZNewsletterType::fetchByOffset($offset, $limit, eZNewsletterType::StatusPublished, true, true);
$tpl->setVariable('view_parameters', $viewParameters);
$tpl->setVariable('limit', $limit);
$tpl->setVariable('newsletter_type_array', $newsletterTypeArray);
    $key = array_search('-newslettertype', $_SERVER['argv']);
    $newslettertype_id = $_SERVER['argv'][$key + 1];
    if (is_numeric($newslettertype_id) && eZNewsletterType::fetch($newslettertype_id)) {
        $conditions = array_merge($conditions, array('newslettertype_id' => array('=', $newslettertype_id)));
        $cli->output('Filter for newslettertype <' . $newslettertype_id . '> enabled.');
    } else {
        $cli->output('Invalid id of newslettertype <' . $newslettertype_id . '>!');
        eZExecution::cleanup();
        eZExecution::setCleanExit();
    }
}
// 2. Fetch all newsletters with status : eZNewsletter::SendStatusSending, and send date less than current TS.
$cli->output('Fetching prepared newsletter...');
$newsletterArray = eZNewsletter::fetchListBySendStatus(eZNewsletter::SendStatusSending, eZNewsletter::StatusPublished, true, $conditions);
$cli->output('Found ' . count($newsletterArray) . ' newsletter.');
if (0 === count($newsletterArray)) {
    $cli->output('Nothing to send.');
} else {
    $cli->output('Sending newsletter...');
}
foreach ($newsletterArray as $newsletter) {
    $cli->output('Sending messages for ' . $newsletter->attribute('name'));
    $statistics = eZNewsletter::sendNewsletterMail($newsletter);
    $newsletter->setAttribute('send_status', eZNewsletter::SendStatusFinished);
    $newsletter->sync();
    $cli->output('Sent ' . $statistics['sendCount'] . ' ( skipped:' . $statistics['skipCount'] . ' )' . ' messages for newsletter : ' . $newsletter->attribute('name'));
}
// remove pid file to unlock cronjob
if (file_exists($pidfilename)) {
    unlink($pidfilename);
}
Example #9
0
// For pricing of this licence please contact us via e-mail to licence@ez.no.
// Further contact information is available at http://ez.no/company/contact/.
//
// The "GNU General Public License" (GPL) is available at
// http://www.gnu.org/copyleft/gpl.html.
//
// Contact licence@ez.no if any conditions of this licencing isn't clear to
// you.
//
$Module = $Params['Module'];
$http = eZHTTPTool::instance();
$ObjectID = $Params['ObjectID'];
$ObjectVersion = $Params['ObjectVersion'];
$contentObject = eZContentObjectVersion::fetchVersion($ObjectVersion, $ObjectID);
if (is_object($contentObject)) {
    $newsletter = eZNewsletter::fetchByContentObject($contentObject->attribute('id'), $contentObject->attribute('version'), false);
    if ($http->hasPostVariable('BackButton')) {
        $http->setSessionVariable('RedirectIfDiscarded', $http->postVariable('RedirectAfterDiscard'));
        //return $Module->redirectTo( 'content/edit/' . $contentObject->attribute( 'id' ) . '/' . $contentObject->attribute( 'current_version' ) );
        return $Module->redirectTo('content/edit/' . $contentObject->attribute('id') . '/' . $contentObject->attribute('current_version') . '/' . $contentObject->attribute('current_language'));
    }
    $tpl = eZNewsletterTemplateWrapper::templateInit();
    $tpl->setVariable('object', $contentObject);
    $tpl->setVariable('newsletter', $newsletter);
    $Result = array();
    $Result['content'] = $tpl->fetch('design:eznewsletter/newsletter_preview.tpl');
    $Result['pagelayout'] = true;
} else {
    $tpl = eZNewsletterTemplateWrapper::templateInit();
    $Result = array();
    $Result['content'] = $tpl->fetch('design:eznewsletter/newsletter_preview.tpl');
Example #10
0
// 2. Fetch all newsletters with status : eZNewsletter::SendStatusSending, and send date less than current TS.
$cli->output('Fetching prepared newsletter...');
$newsletterArray = eZNewsletter::fetchListBySendStatus(eZNewsletter::SendStatusSending, eZNewsletter::StatusPublished, true, $conditions);
$cli->output('Found ' . count($newsletterArray) . ' newsletter.');
if (0 === count($newsletterArray)) {
    $cli->output('Nothing to send.');
} else {
    $cli->output('Sending newsletter...');
}
// stevo
$totallimit = 200;
$limit = $totallimit / count($newsletterArray);
foreach ($newsletterArray as $newsletter) {
    $cli->output('Sending messages for ' . $newsletter->attribute('name'));
    // stevo
    $statistics = eZNewsletter::sendNewsletterMail($newsletter, false, false, $limit);
    //$newsletter->setAttribute( 'send_status', eZNewsletter::SendStatusFinished );
    //$newsletter->sync();
    $cli->output('Sent ' . $statistics['sendCount'] . ' ( skipped:' . $statistics['skipCount'] . ' )' . ' messages for newsletter : ' . $newsletter->attribute('name'));
    // stevo
    $count = eZSendNewsletterItem::count(eZSendNewsletterItem::SendStatusNone, $newsletter->attribute('id'));
    $cli->output("{$count} users left");
    if ($count <= 0) {
        $newsletter->setAttribute('send_status', eZNewsletter::SendStatusFinished);
        $newsletter->sync();
        $cli->output('Finished sending newsletter : ' . $newsletter->attribute('name'));
    }
}
// remove pid file to unlock cronjob
if (file_exists($pidfilename)) {
    unlink($pidfilename);
 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
     }
 }
 function attribute($attr, $noFunction = false)
 {
     $retVal = false;
     switch ($attr) {
         case 'newsletter_related_object_list':
             $newsletter = $this->attribute('newsletter');
             if ($newsletter) {
                 $retVal = $newsletter->attribute('object_relation_id_list');
             }
             break;
         case 'newsletter':
             $retVal = eZNewsletter::fetch($this->attribute('newsletter_id'));
             break;
         default:
             $retVal = eZPersistentObject::attribute($attr);
             break;
     }
     return $retVal;
 }
 function copy($frontendcopy = false)
 {
     $userID = eZUser::currentUserID();
     if (!$userID) {
         $userID = $this->attribute('creator_id');
     }
     $newNewsletter = eZNewsletter::create($this->attribute('name'), $userID, $this->attribute('newslettertype_id'));
     $newNewsletter->setAttribute('output_format', $this->attribute('output_format'));
     $newNewsletter->setAttribute('design_to_use', $this->attribute('design_to_use'));
     $newNewsletter->setAttribute('send_date', $this->attribute('send_date'));
     $newNewsletter->setAttribute('newslettertype_id', $this->attribute('newslettertype_id'));
     $newNewsletter->setAttribute('category', $this->attribute('category'));
     $newNewsletter->setAttribute('pretext', $this->attribute('pretext'));
     $newNewsletter->setAttribute('posttext', $this->attribute('posttext'));
     $newNewsletter->setAttribute('object_relations', $this->attribute('object_relations'));
     $newNewsletter->setAttribute('preview_email', $this->attribute('preview_email'));
     $newNewsletter->setAttribute('recurrence_type', $this->attribute('recurrence_type'));
     $newNewsletter->setAttribute('recurrence_value', $this->attribute('recurrence_value'));
     $newNewsletter->setAttribute('creator_id', $this->attribute('creator_id'));
     $newNewsletter->setAttribute('status', eZNewsletter::StatusPublished);
     if ($frontendcopy == true) {
         $newNewsletter->setAttribute('send_status', eZNewsletter::SendStatusNone);
         $newNewsletter->setAttribute('status', eZNewsletter::StatusDraft);
     } else {
         $newNewsletter->setAttribute('send_status', $this->attribute('send_status'));
     }
     $objectID = $this->attribute('contentobject_id');
     $objectVersion = $this->attribute('contentobject_version');
     $object = eZContentObject::fetch($objectID);
     if (is_object($object)) {
         $newObject = $object->copy($objectVersion);
         $newNewsletter->setAttribute('contentobject_id', $newObject->attribute('id'));
         $newNewsletter->setAttribute('contentobject_version', $newObject->attribute('current_version'));
         $newNewsletter->store();
         return $newObject;
     }
 }
 function publish($contentObjectID, $contentObjectVersion)
 {
     $newsletter = eZNewsletter::fetchByContentObject($contentObjectID, $contentObjectVersion, eZNewsletter::StatusDraft);
     if ($newsletter) {
         $newsletter->publish();
     }
 }
// PROFESSIONAL_LICENCE included in the packaging of this file.
// For pricing of this licence please contact us via e-mail to licence@ez.no.
// Further contact information is available at http://ez.no/company/contact/.
//
// The "GNU General Public License" (GPL) is available at
// http://www.gnu.org/copyleft/gpl.html.
//
// Contact licence@ez.no if any conditions of this licencing isn't clear to
// you.
//
$Module = $Params['Module'];
$http = eZHTTPTool::instance();
if ($http->hasPostVariable('RecurrenceButton')) {
    $newsletterID = $http->postVariable('NewsletterID');
    if ($newsletterID) {
        $newsletter = eZNewsletter::fetch($newsletterID);
        if ($newsletter === null) {
            return $Module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel');
        }
        if ($http->hasPostVariable('Action')) {
            if ($http->postVariable('Action') === 'activate') {
                $newsletter->setAttribute('send_status', eZNewsletter::SendStatusNone);
            } else {
                if ($http->postVariable('Action') === 'stop') {
                    $newsletter->setAttribute('send_status', eZNewsletter::SendStatusStopped);
                }
            }
            $newsletter->sync();
            eZContentCacheManager::clearContentCacheIfNeeded($newsletter->attribute('contentobject_id'));
        }
    } else {