function testDuplicateFiltering()
 {
     $newsletter = $this->objFromFixture('Newsletter', 'all');
     $nsc = NewsletterSendController::inst();
     $added = $nsc->enqueue($newsletter);
     $this->assertGreaterThanOrEqual($added, 4, "4 recipients added");
     //add the same newsletter again
     $added = $nsc->enqueue($newsletter);
     $this->assertEquals($added, 0, "0 recipients added. Because newsletter is a duplicate");
     $newsletter = $this->objFromFixture('Newsletter', 'daily');
     $this->assertEquals($nsc->enqueue($newsletter), 2, "2 recipients added first time");
     $this->assertEquals($nsc->enqueue($newsletter), 0, "0 recipients added. Because newsletter is a duplicate");
     $newsletter = $this->objFromFixture('Newsletter', 'monthly');
     $this->assertEquals($nsc->enqueue($newsletter), 2, "2 recipients added first time");
     $this->assertEquals($nsc->enqueue($newsletter), 0, "0 recipients added. Because newsletter is a duplicate");
 }
 public static function process_queue_invoke($newsletterID)
 {
     $lockFile = Director::getAbsFile(Requirements::backend()->getCombinedFilesFolder() . '/_newsletter_send_cache.lock');
     if (!file_exists($lockFile) || (int) file_get_contents($lockFile) < time() - 180) {
         file_put_contents($lockFile, time());
         $nsc = NewsletterSendController::inst();
         $nsc->processQueue($newsletterID, $lockFile);
     }
 }
 public function doSend($data, $form)
 {
     //copied from parent
     $new_record = $this->record->ID == 0;
     $controller = Controller::curr();
     try {
         $form->saveInto($this->record);
         $this->record->Status = 'Sending';
         //custom: changing the status of to indicate we are sending
         $this->record->write();
         $this->gridField->getList()->add($this->record);
     } catch (ValidationException $e) {
         $form->sessionMessage($e->getResult()->message(), 'bad');
         $responseNegotiator = new PjaxResponseNegotiator(array('CurrentForm' => function () use(&$form) {
             return $form->forTemplate();
         }, 'default' => function () use(&$controller) {
             return $controller->redirectBack();
         }));
         if ($controller->getRequest()->isAjax()) {
             $controller->getRequest()->addHeader('X-Pjax', 'CurrentForm');
         }
         return $responseNegotiator->respond($controller->getRequest());
     }
     //custom code
     $nsc = NewsletterSendController::inst();
     $nsc->enqueue($this->record);
     $nsc->processQueueOnShutdown($this->record->ID);
     //javascript hides the success message appropriately
     Requirements::javascript(NEWSLETTER_DIR . '/javascript/NewsletterSendConfirmation.js');
     $message = _t('NewsletterAdmin.SendMessage', 'Send-out process started successfully. Check the progress in the "Sent To" tab');
     //end custom code
     $form->sessionMessage($message, 'good');
     if ($new_record) {
         return Controller::curr()->redirect($this->Link());
     } elseif ($this->gridField->getList()->byId($this->record->ID)) {
         // Return new view, as we can't do a "virtual redirect" via the CMS Ajax
         // to the same URL (it assumes that its content is already current, and doesn't reload)
         return $this->edit(Controller::curr()->getRequest());
     } else {
         // Changes to the record properties might've excluded the record from
         // a filtered list, so return back to the main view if it can't be found
         $noActionURL = $controller->removeAction($data['url']);
         $controller->getRequest()->addHeader('X-Pjax', 'Content');
         return $controller->redirect($noActionURL, 302);
     }
 }
 static function process_queue_invoke($newsletterID)
 {
     $nsc = NewsletterSendController::inst();
     $nsc->processQueue($newsletterID);
 }