Commit 42984989 authored by Chris's avatar Chris

Adding initial support for Magento v1.10

parent 3e7a03a6
<?php
class FreeLunchLabs_MailGun_Model_Resource_Email extends Mage_Core_Model_Resource_Db_Abstract
{
protected function _construct()
{
$this->_init('freelunchlabs_mailgun/email', 'id');
}
public function deleteEmailTrackingLogs($days = false) {
if($days) {
$daysPrior = date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time() - (86400 * $days)));
$where = " WHERE date_sent < '{$daysPrior}'";
} else {
$where = "";
}
$query = "DELETE FROM {$this->getMainTable()}" . $where;
Mage::getSingleton('core/resource')
->getConnection('core_write')
->query($query);
}
if (version_compare(Mage::getVersion(), '1.10', '>=')) {
class FreeLunchLabs_MailGun_Model_Resource_Email extends FreeLunchLabs_MailGun_Model_Resource_Email_V2 {}
} else {
class FreeLunchLabs_MailGun_Model_Resource_Email extends FreeLunchLabs_MailGun_Model_Resource_Email_V1 {}
}
<?php
class FreeLunchLabs_MailGun_Model_Resource_Email_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
{
protected function _construct()
{
parent::_construct();
$this->_init('freelunchlabs_mailgun/email');
}
public function getGridCollection() {
//Fields
$this->addFieldToSelect('id');
$this->addFieldToSelect('subject');
$this->addFieldToSelect('email_address');
$this->addFieldToSelect('mailgun_id');
$this->addFieldToSelect('date_sent');
$this->addFieldToSelect('customer_id');
//Get latest status
$this->getSelect()->joinLeft(
array('me1' => Mage::getResourceModel('freelunchlabs_mailgun/event')->getMainTable()),
'main_table.id = me1.email_id',
'event_type as current_status'
);
$this->getSelect()->joinLeft(
array('me2' => Mage::getResourceModel('freelunchlabs_mailgun/event')->getMainTable()),
'(main_table.id = me2.email_id AND (me1.timestamp < me2.timestamp OR me1.timestamp = me2.timestamp AND me1.id < me2.id))',
false
);
$this->getSelect()->where('me2.id IS NULL');
return $this;
}
}
\ No newline at end of file
if (version_compare(Mage::getVersion(), '1.10', '>=')) {
class FreeLunchLabs_MailGun_Model_Resource_Email_Collection extends FreeLunchLabs_MailGun_Model_Resource_Email_Collection_V2 {}
} else {
class FreeLunchLabs_MailGun_Model_Resource_Email_Collection extends FreeLunchLabs_MailGun_Model_Resource_Email_Collection_V1 {}
}
<?php
class FreeLunchLabs_MailGun_Model_Resource_Email_Collection_V1 extends Mage_Core_Model_Resource_Db_Collection_Abstract
{
protected function _construct() {
parent::_construct();
$this->_init('freelunchlabs_mailgun/email');
}
public function getGridCollection() {
// Fields
$this->addFieldToSelect('id');
$this->addFieldToSelect('subject');
$this->addFieldToSelect('email_address');
$this->addFieldToSelect('mailgun_id');
$this->addFieldToSelect('date_sent');
$this->addFieldToSelect('customer_id');
// Get latest status
$this->getSelect()->joinLeft(
array('me1' => Mage::getResourceModel('freelunchlabs_mailgun/event')->getMainTable()),
'main_table.id = me1.email_id',
'event_type as current_status'
);
$this->getSelect()->joinLeft(
array('me2' => Mage::getResourceModel('freelunchlabs_mailgun/event')->getMainTable()),
'(main_table.id = me2.email_id AND (me1.timestamp < me2.timestamp OR me1.timestamp = me2.timestamp AND me1.id < me2.id))',
false
);
$this->getSelect()->where('me2.id IS NULL');
return $this;
}
}
<?php
class FreeLunchLabs_MailGun_Model_Resource_Email_Collection_V2 extends Mage_Core_Model_Mysql4_Collection_Abstract
{
protected function _construct() {
parent::_construct();
$this->_init('freelunchlabs_mailgun/email');
}
public function getGridCollection() {
// Fields
$this->addFieldToSelect('id');
$this->addFieldToSelect('subject');
$this->addFieldToSelect('email_address');
$this->addFieldToSelect('mailgun_id');
$this->addFieldToSelect('date_sent');
$this->addFieldToSelect('customer_id');
// Get latest status
$this->getSelect()->joinLeft(
array('me1' => Mage::getResourceModel('freelunchlabs_mailgun/event')->getMainTable()),
'main_table.id = me1.email_id',
'event_type as current_status'
);
$this->getSelect()->joinLeft(
array('me2' => Mage::getResourceModel('freelunchlabs_mailgun/event')->getMainTable()),
'(main_table.id = me2.email_id AND (me1.timestamp < me2.timestamp OR me1.timestamp = me2.timestamp AND me1.id < me2.id))',
false
);
$this->getSelect()->where('me2.id IS NULL');
return $this;
}
}
<?php
class FreeLunchLabs_MailGun_Model_Resource_Email_V1 extends Mage_Core_Model_Resource_Db_Abstract
{
protected function _construct() {
$this->_init('freelunchlabs_mailgun/email', 'id');
}
public function deleteEmailTrackingLogs($days = false) {
if ($days) {
$daysPrior = date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time() - (86400 * $days)));
$where = " WHERE date_sent < '{$daysPrior}'";
} else {
$where = "";
}
$query = "DELETE FROM {$this->getMainTable()}" . $where;
Mage::getSingleton('core/resource')
->getConnection('core_write')
->query($query);
}
}
<?php
class FreeLunchLabs_MailGun_Model_Resource_Email_V2 extends Mage_Core_Model_Mysql4_Abstract
{
protected function _construct() {
$this->_init('freelunchlabs_mailgun/email', 'id');
}
public function deleteEmailTrackingLogs($days = false) {
if ($days) {
$daysPrior = date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time() - (86400 * $days)));
$where = " WHERE date_sent < '{$daysPrior}'";
} else {
$where = "";
}
$query = "DELETE FROM {$this->getMainTable()}" . $where;
Mage::getSingleton('core/resource')
->getConnection('core_write')
->query($query);
}
}
<?php
class FreeLunchLabs_MailGun_Model_Resource_Event extends Mage_Core_Model_Resource_Db_Abstract
{
protected function _construct()
{
$this->_init('freelunchlabs_mailgun/event', 'id');
}
if (version_compare(Mage::getVersion(), '1.10', '>=')) {
class FreeLunchLabs_MailGun_Model_Resource_Event extends FreeLunchLabs_MailGun_Model_Resource_Event_V2 {}
} else {
class FreeLunchLabs_MailGun_Model_Resource_Event extends FreeLunchLabs_MailGun_Model_Resource_Event_V1 {}
}
<?php
class FreeLunchLabs_MailGun_Model_Resource_Event_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
{
protected function _construct()
{
parent::_construct();
$this->_init('freelunchlabs_mailgun/event');
}
}
\ No newline at end of file
if (version_compare(Mage::getVersion(), '1.10', '>=')) {
class FreeLunchLabs_MailGun_Model_Resource_Event_Collection extends FreeLunchLabs_MailGun_Model_Resource_Event_Collection_V2 {}
} else {
class FreeLunchLabs_MailGun_Model_Resource_Event_Collection extends FreeLunchLabs_MailGun_Model_Resource_Event_Collection_V1 {}
}
<?php
class FreeLunchLabs_MailGun_Model_Resource_Event_Collection_V1 extends Mage_Core_Model_Resource_Db_Collection_Abstract
{
protected function _construct() {
parent::_construct();
$this->_init('freelunchlabs_mailgun/event');
}
}
<?php
class FreeLunchLabs_MailGun_Model_Resource_Event_Collection_V2 extends Mage_Core_Model_Mysql4_Collection_Abstract
{
protected function _construct() {
parent::_construct();
$this->_init('freelunchlabs_mailgun/event');
}
}
<?php
class FreeLunchLabs_MailGun_Model_Resource_Event_V1 extends Mage_Core_Model_Resource_Db_Abstract
{
protected function _construct() {
$this->_init('freelunchlabs_mailgun/event', 'id');
}
}
<?php
class FreeLunchLabs_MailGun_Model_Resource_Event_V2 extends Mage_Core_Model_Mysql4_Abstract
{
protected function _construct() {
$this->_init('freelunchlabs_mailgun/event', 'id');
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment