public function index() { $queue = ContentNotifierQueue::get_unnotified(); if ($queue->exists()) { $count = $queue->count(); $e = Injector::inst()->create('ContentNotifierEmail')->setRecords($queue)->send(); echo "Sent {$count} notifications\n"; } else { echo "No queued notifications\n"; } }
public function send() { if (!$this->records) { $this->setRecords(ContentNotifierQueue::get_unnotified()); } ContentNotifierExtension::disable_filtering(); $total = $this->records->count(); $grouped = GroupedList::create($this->records->limit($this->config()->items_limit))->GroupedBy('Category'); $this->emailer->populateTemplate(array('Headline' => $this->config()->headline, 'GroupedItems' => $grouped, 'Total' => $total, 'Link' => Controller::join_links(Director::absoluteBaseURL(), 'admin', 'content-notifications'))); $this->emailer->send(); foreach ($this->records as $record) { $record->HasNotified = true; $record->write(); } ContentNotifierExtension::enable_filtering(true); }
public function onAfterWrite() { // Trigger events after approval state changes. if ($this->owner->isChanged('ContentNotifierApproved', 2)) { if ($this->owner->ContentNotifierApproved) { $this->owner->invokeWithExtensions('onAfterContentNotifierApprove'); } else { $this->owner->invokeWithExtensions('onAfterContentNotifierUnapprove'); } } // Note: this has an effect that privileged user's showcase submissions will not show up in the queue. if ($this->checkPermission()) { return; } if ($this->owner->isCreating) { $this->createQueue('CREATED'); } else { if ($this->owner->isChanged()) { // Clear any existing entry if ($queue = $this->getQueue('UPDATED')) { $queue->delete(); } $this->createQueue('UPDATED'); } } if (!$this->getSetting('batch_email')) { $email = ContentNotifierEmail::create(); $email->setRecords(ContentNotifierQueue::get_unnotified()); $email->send(); } }