public function getPreviousMessage() { global $wpdb; $getAutoresponderMessageQuery = sprintf("SELECT id FROM %swpr_autoresponder_messages WHERE aid=%d AND sequence < %d ORDER BY sequence DESC LIMIT 1; ", $wpdb->prefix, $this->getAutoresponder()->getId(), $this->getDayNumber()); $emailResult = $wpdb->get_results($getAutoresponderMessageQuery); if (0 == count($emailResult)) { return false; } $id = $emailResult[0]->id; return AutoresponderMessage::getMessage((int) $id); }
public function testFetchingPagedListOfAutoresponders() { global $wpdb; $autoresponder1_id = $this->createAAutoresponderWithRandomName(); $numberOfMessagesInAutoresponderOne = 100; $autoresponderMessagesIds = $this->createMessagesForAutoresponder($numberOfMessagesInAutoresponderOne, $autoresponder1_id); $messages = AutoresponderMessage::getAllMessages(20, 30); $this->assertEquals(30, count($messages)); $received_ids = $this->getMessageIds($messages); $expected = array_slice($autoresponderMessagesIds, 20, 30); $intersect = array_intersect($received_ids, $expected); $this->assertEquals(count($intersect), count($expected)); }
public static function edit_message() { $message_id = intval($_GET['id']); try { $message = AutoresponderMessage::getMessage($message_id); } catch (NonExistentMessageException $ex) { wp_redirect("admin.php?page=_wpr/utoresponders"); //TODO:This shouldn't happen. This should instead be a error screen } catch (NonExistentAutoresponderException $Ex) { wp_redirect("admin.php?page=_wpr/utoresponders"); //TODO:This shouldn't happen. This should instead be a error screen } $autoresponder = $message->getAutoresponder(); $custom_fields = $autoresponder->getNewsletter()->getCustomFieldKeyLabelPair(); self::enqueue_wysiwyg(); //TODO: THIS METHOD DEF SHOULDN'T BE WHERE IT IS RIGHT NOW $form_data = array('subject' => $message->getSubject(), 'htmlbody' => $message->getHTMLBody(), 'textbody' => $message->getTextBody(), 'offset' => $message->getDayNumber()); if (!is_array(_wpr_get("form_values"))) { _wpr_set("form_values", $form_data); } _wpr_set("custom_fields", $custom_fields); _wpr_set("autoresponder", $autoresponder); _wpr_set("message", $message); _wpr_setview("autoresponder_edit_message"); }
public function deleteMessage(AutoresponderMessage $message) { global $wpdb; $deleteAutoresponderMessageQuery = sprintf("DELETE FROM %swpr_autoresponder_messages WHERE id=%d AND aid=%d", $wpdb->prefix, $message->getId(), $this->getId()); $wpdb->query($deleteAutoresponderMessageQuery); $deleteMessagesPendingDeliveryQuery = sprintf("DELETE FROM %swpr_queue WHERE `meta_key` LIKE 'AR-%%%%-%%%%-%d-%%' AND sent=0;", $wpdb->prefix, $message->getId()); $wpdb->query($deleteMessagesPendingDeliveryQuery); }
private function wasLastMessageDeliveredThePreviousMessageInTheSeries(AutoresponderMessage $message, $currentSubscriber) { $previousMessage = $message->getPreviousMessage(); return $previousMessage->getDayNumber() == $currentSubscriber->sequence; }
/** * @expectedException NonExistentMessageException */ public function testDeletingAutoresponderMessageDeletesTheMessage() { global $wpdb; $addAutoresponderQuery = sprintf("INSERT INTO %swpr_autoresponders (nid, name) VALUES (%d,'%s' )", $wpdb->prefix, $this->newsletterId, md5(microtime())); $results = $wpdb->query($addAutoresponderQuery); $autoresponder = Autoresponder::getAutoresponder($wpdb->insert_id); $autoresponder_message = array('textbody' => 'This is a test', 'htmlbody' => 'This is a <test>body</test>', 'subject' => 'Test Subject', 'offset' => 3); try { $message = $autoresponder->addMessage($autoresponder_message); } catch (Exception $exc) { throw new BadFunctionCallException(); } $autoresponder_message = array('subject' => md5(microtime() . "subject"), 'textbody' => md5(microtime() . "textbody"), 'htmlbody' => md5(microtime() . "htmlbody"), 'offset' => 'a'); $message_id = $message->getId(); $autoresponder->deleteMessage($message); AutoresponderMessage::getMessage($message_id); }
public function testWhetherAutoresponderFactoryFetchesTheAppropriateAutoresponderMessage() { global $wpdb; $autoresponder = AutoresponderTestHelper::addAutoresponderAndFetchRow($this->newsletter_id, "test"); $addAutoresponderMessageQuery = sprintf("INSERT INTO {$wpdb->prefix}wpr_autoresponder_messages (aid, subject, sequence) VALUES (%d, '%s', %d)", $autoresponder->id, 'Test Subject', 1); $wpdb->query($addAutoresponderMessageQuery); $autoresponder_message_id = $wpdb->insert_id; $message = AutoresponderMessage::getMessage($autoresponder_message_id); $this->assertEquals('Test Subject', $message->getSubject()); $this->assertEquals($autoresponder_message_id, $message->getId()); $this->assertEquals(1, $message->getDayNumber()); }