Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix vulnerability issues #439

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions Cron/Ecommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ public function __construct(

public function execute()
{

$connection = $this->_chimpSyncEcommerce->getResource()->getConnection();
$tableName = $this->_chimpSyncEcommerce->getResource()->getMainTable();
$connection->delete($tableName, 'batch_id is null and mailchimp_sync_modified != 1');
Expand All @@ -128,8 +127,23 @@ public function execute()
$this->_apiResult->processResponses($storeId, true, $mailchimpStoreId);
$batchId = $this->_processStore($storeId, $mailchimpStoreId, $listId);
if ($batchId) {
$connection->update($tableName, ['batch_id' => $batchId, 'mailchimp_sync_modified' => 0, 'mailchimp_sync_delta' => $this->_helper->getGmtDate()], "batch_id is null and mailchimp_store_id = '$mailchimpStoreId'");
$connection->update($tableName, ['batch_id' => $batchId, 'mailchimp_sync_modified' => 0, 'mailchimp_sync_delta' => $this->_helper->getGmtDate()], "batch_id is null and mailchimp_store_id = '$listId'");
$connection->update($tableName,
[
'batch_id' => $batchId,
'mailchimp_sync_modified' => 0,
'mailchimp_sync_delta' => $this->_helper->getGmtDate()
],
$connection->quoteInto('batch_id is null and mailchimp_store_id = ?', $mailchimpStoreId)
);
$connection->update(
$tableName,
[
'batch_id' => $batchId,
'mailchimp_sync_modified' => 0,
'mailchimp_sync_delta' => $this->_helper->getGmtDate()
],
$connection->quoteInto('batch_id is null and mailchimp_store_id = ?', $listId)
);
}
}
}
Expand Down
24 changes: 19 additions & 5 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,13 +509,21 @@ public function markAllBatchesAs($mailchimpStore, $status)
{
$connection = $this->_syncBatches->getResource()->getConnection();
$tableName = $this->_syncBatches->getResource()->getMainTable();
$connection->update($tableName, ['status' => $status], "mailchimp_store_id = '".$mailchimpStore."'");
$connection->update(
$tableName,
['status' => $status],
$connection->quoteInto('mailchimp_store_id = ?', $mailchimpStore)
);
}
public function markRegisterAsModified($registerId, $type)
{
$connection = $this->_mailChimpSyncE->getResource()->getConnection();
$tableName = $this->_mailChimpSyncE->getResource()->getMainTable();
$connection->update($tableName,['mailchimp_sync_modified' => 1,'batch_id' => null],"type = '".$type."' and related_id = $registerId");
$connection->update(
$tableName,
['mailchimp_sync_modified' => 1, 'batch_id' => null],
$connection->quoteInto('type = ?', $type) . ' AND ' . $connection->quoteInto('related_id = ?', $registerId)
);
}
public function getMCStoreName($storeId)
{
Expand Down Expand Up @@ -695,11 +703,17 @@ public function resetErrors($mailchimpStore)
// clean the errors table
$connection = $this->_mailChimpErrors->getResource()->getConnection();
$tableName = $this->_mailChimpErrors->getResource()->getMainTable();
$connection->delete($tableName, "mailchimp_store_id = '".$mailchimpStore."'");
$connection->delete(
$tableName,
$connection->quoteInto('mailchimp_store_id = ?', $mailchimpStore)
);
// clean the syncecommerce table with errors
$connection = $this->_mailChimpSyncE->getResource()->getConnection();
$tableName = $this->_mailChimpSyncE->getResource()->getMainTable();
$connection->delete($tableName, "mailchimp_store_id = '".$mailchimpStore."' and mailchimp_sync_error is not null");
$connection->delete(
$tableName,
$connection->quoteInto('mailchimp_store_id = ? and mailchimp_sync_error is not null', $mailchimpStore)
);
// $connection->commit();
// $connection->truncateTable($tableName);
} catch (\Zend_Db_Exception $e) {
Expand Down Expand Up @@ -763,7 +777,7 @@ public function getScope()
}
public function loadStores()
{

$mcUserName = [];
$connection = $this->_mailChimpStores->getResource()->getConnection();
$tableName = $this->_mailChimpStores->getResource()->getMainTable();
Expand Down
28 changes: 20 additions & 8 deletions Model/Api/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,17 @@ protected function _getConvertedQuotes($mailchimpStoreId, $magentoStoreId)
{
$allCarts = [];
$convertedCarts = $this->_getQuoteCollection();
$connection = $convertedCarts->getConnection();
// get only the converted quotes
$convertedCarts->addFieldToFilter('store_id', ['eq' => $magentoStoreId]);
$convertedCarts->addFieldToFilter('is_active', ['eq' => 0]);
//join with mailchimp_ecommerce_sync_data table to filter by sync data.
$convertedCarts->getSelect()->joinLeft(
['m4m' => $this->_helper->getTableName('mailchimp_sync_ecommerce')],
"m4m.related_id = main_table.entity_id and m4m.type = '".\Ebizmarts\MailChimp\Helper\Data::IS_QUOTE."'
AND m4m.mailchimp_store_id = '" . $mailchimpStoreId . "'",
$connection->quoteInto(
'm4m.related_id = main_table.entity_id and m4m.type = ?',
\Ebizmarts\MailChimp\Helper\Data::IS_QUOTE
) . ' AND ' . $connection->quoteInto('m4m.mailchimp_store_id = ?', $mailchimpStoreId),
['m4m.*']
);
// be sure that the quotes are already in mailchimp and not deleted
Expand Down Expand Up @@ -186,15 +189,18 @@ protected function _getModifiedQuotes($mailchimpStoreId, $magentoStoreId)
{
$allCarts = [];
$modifiedCarts = $this->_getQuoteCollection();
$connection = $modifiedCarts->getConnection();
// select carts with no orders
$modifiedCarts->addFieldToFilter('is_active', ['eq'=>1]);
// select carts for the current Magento store id
$modifiedCarts->addFieldToFilter('store_id', ['eq' => $magentoStoreId]);
//join with mailchimp_ecommerce_sync_data table to filter by sync data.
$modifiedCarts->getSelect()->joinLeft(
['m4m' => $this->_helper->getTableName('mailchimp_sync_ecommerce')],
"m4m.related_id = main_table.entity_id and m4m.type = '".\Ebizmarts\MailChimp\Helper\Data::IS_QUOTE."'
AND m4m.mailchimp_store_id = '" . $mailchimpStoreId . "'",
$connection->quoteInto(
'm4m.related_id = main_table.entity_id and m4m.type = ?',
\Ebizmarts\MailChimp\Helper\Data::IS_QUOTE
) . ' AND ' . $connection->quoteInto('m4m.mailchimp_store_id = ?', $mailchimpStoreId),
['m4m.*']
);
// be sure that the quotes are already in mailchimp and not deleted
Expand Down Expand Up @@ -287,6 +293,7 @@ protected function _getNewQuotes($mailchimpStoreId, $magentoStoreId)
{
$allCarts = [];
$newCarts = $this->_getQuoteCollection();
$connection = $newCarts->getConnection();
$newCarts->addFieldToFilter('is_active', ['eq'=>1]);
$newCarts->addFieldToFilter('customer_email', ['notnull'=>true]);
$newCarts->addFieldToFilter('items_count', ['gt'=>0]);
Expand All @@ -299,8 +306,10 @@ protected function _getNewQuotes($mailchimpStoreId, $magentoStoreId)
//join with mailchimp_ecommerce_sync_data table to filter by sync data.
$newCarts->getSelect()->joinLeft(
['m4m' => $this->_helper->getTableName('mailchimp_sync_ecommerce')],
"m4m.related_id = main_table.entity_id and m4m.type = '" . \Ebizmarts\MailChimp\Helper\Data::IS_QUOTE . "'
AND m4m.mailchimp_store_id = '" . $mailchimpStoreId . "'",
$connection->quoteInto(
'm4m.related_id = main_table.entity_id and m4m.type = ?',
\Ebizmarts\MailChimp\Helper\Data::IS_QUOTE
) . ' AND ' . $connection->quoteInto('m4m.mailchimp_store_id = ?', $mailchimpStoreId),
['m4m.*']
);
// be sure that the quotes are already in mailchimp and not deleted
Expand Down Expand Up @@ -389,13 +398,16 @@ protected function _getNewQuotes($mailchimpStoreId, $magentoStoreId)
protected function _getAllCartsByEmail($email, $mailchimpStoreId, $magentoStoreId)
{
$allCartsForEmail = $this->_getQuoteCollection();
$connection = $allCartsForEmail->getConnection();
$allCartsForEmail->addFieldToFilter('is_active', ['eq' => 1]);
$allCartsForEmail->addFieldToFilter('store_id', ['eq' => $magentoStoreId]);
$allCartsForEmail->addFieldToFilter('customer_email', ['eq' => $email]);
$allCartsForEmail->getSelect()->joinLeft(
['m4m' => $this->_helper->getTableName('mailchimp_sync_ecommerce')],
"m4m.related_id = main_table.entity_id and m4m.type = '".\Ebizmarts\MailChimp\Helper\Data::IS_QUOTE."'
AND m4m.mailchimp_store_id = '" . $mailchimpStoreId . "'",
$connection->quoteInto(
'm4m.related_id = main_table.entity_id and m4m.type = ?',
\Ebizmarts\MailChimp\Helper\Data::IS_QUOTE
) . ' AND ' . $connection->quoteInto('m4m.mailchimp_store_id = ?', $mailchimpStoreId),
['m4m.*']
);
// be sure that the quotes are already in mailchimp and not deleted
Expand Down
16 changes: 11 additions & 5 deletions Model/Api/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,22 @@ public function sendCustomers($storeId)
{
$mailchimpStoreId = $this->_helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_MAILCHIMP_STORE, $storeId);
$collection = $this->_collection->create();
$connection = $collection->getConnection();
$collection->addFieldToFilter('store_id', ['eq'=>$storeId]);
$collection->getSelect()->joinLeft(
['m4m' => $this->_helper->getTableName('mailchimp_sync_ecommerce')],
"m4m.related_id = e.entity_id and m4m.type = '".\Ebizmarts\MailChimp\Helper\Data::IS_CUSTOMER.
"' and m4m.mailchimp_store_id = '".$mailchimpStoreId."'",
$connection->quoteInto(
'm4m.related_id = e.entity_id and m4m.type = ? ',
\Ebizmarts\MailChimp\Helper\Data::IS_CUSTOMER
) . ' AND ' . $connection->quoteInto('m4m.mailchimp_store_id = ?', $mailchimpStoreId),
['m4m.*']
);
$collection->getSelect()->where("m4m.mailchimp_sync_delta IS null ".
"OR (m4m.mailchimp_sync_delta > '".$this->_helper->getMCMinSyncDateFlag().
"' and m4m.mailchimp_sync_modified = 1)");
$collection->getSelect()->where(
'm4m.mailchimp_sync_delta IS null OR (' . $connection->quoteInto(
'm4m.mailchimp_sync_delta > ?',
$this->_helper->getMCMinSyncDateFlag()
) . ' and m4m.mailchimp_sync_modified = 1)'
);
$collection->getSelect()->limit(self::MAX);
$counter = 0;
$customerArray = [];
Expand Down
21 changes: 16 additions & 5 deletions Model/Api/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,25 @@ protected function _getModifiedOrders($magentoStoreId)
$batchArray = [];
$mailchimpStoreId = $this->_helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_MAILCHIMP_STORE, $magentoStoreId);
$modifiedOrders = $this->_getCollection();
$connection = $modifiedOrders->getConnection();
// select orders for the current Magento store id
$modifiedOrders->addFieldToFilter('store_id', ['eq' => $magentoStoreId]);
//join with mailchimp_ecommerce_sync_data table to filter by sync data.
$modifiedOrders->getSelect()->joinLeft(
['m4m' => $this->_helper->getTableName('mailchimp_sync_ecommerce')],
"m4m.related_id = main_table.entity_id and m4m.type = '".\Ebizmarts\MailChimp\Helper\Data::IS_ORDER.
"' and m4m.mailchimp_store_id = '".$mailchimpStoreId."'",
$connection->quoteInto(
'm4m.related_id = main_table.entity_id and m4m.type = ?',
\Ebizmarts\MailChimp\Helper\Data::IS_ORDER
) . ' AND ' . $connection->quoteInto('m4m.mailchimp_store_id = ?', $mailchimpStoreId),
['m4m.*']
);
// be sure that the order are already in mailchimp and not deleted
$modifiedOrders->getSelect()->where("m4m.mailchimp_sync_modified = 1 AND m4m.mailchimp_store_id = '".$mailchimpStoreId."'");
$modifiedOrders->getSelect()->where(
'm4m.mailchimp_sync_modified = 1 AND ' . $connection->quoteInto(
'm4m.mailchimp_store_id = ?',
$mailchimpStoreId
)
);
// limit the collection
$modifiedOrders->getSelect()->limit(self::BATCH_LIMIT);
/**
Expand Down Expand Up @@ -205,6 +213,7 @@ protected function _getNewOrders($magentoStoreId)
$batchArray = [];
$mailchimpStoreId = $this->_helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_MAILCHIMP_STORE, $magentoStoreId);
$newOrders = $this->_getCollection();
$connection = $newOrders->getConnection();
// select carts for the current Magento store id
$newOrders->addFieldToFilter('store_id', ['eq' => $magentoStoreId]);
// filter by first date if exists.
Expand All @@ -213,8 +222,10 @@ protected function _getNewOrders($magentoStoreId)
}
$newOrders->getSelect()->joinLeft(
['m4m' => $this->_helper->getTableName('mailchimp_sync_ecommerce')],
"m4m.related_id = main_table.entity_id and m4m.type = '".\Ebizmarts\MailChimp\Helper\Data::IS_ORDER.
"' and m4m.mailchimp_store_id = '".$mailchimpStoreId."'",
$connection->quoteInto(
'm4m.related_id = main_table.entity_id and m4m.type = ?',
\Ebizmarts\MailChimp\Helper\Data::IS_ORDER
) . ' AND ' . $connection->quoteInto('m4m.mailchimp_store_id = ?', $mailchimpStoreId),
['m4m.*']
);
// be sure that the quote are not in mailchimp
Expand Down
15 changes: 11 additions & 4 deletions Model/Api/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,22 @@ public function _sendProducts($magentoStoreId)
$mailchimpStoreId = $this->_helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_MAILCHIMP_STORE, $magentoStoreId);
$this->_markSpecialPrices($magentoStoreId,$mailchimpStoreId);
$collection = $this->_getCollection();
$connection = $collection->getConnection();
$collection->addStoreFilter($magentoStoreId);
$collection->getSelect()->joinLeft(
['m4m' => $this->_helper->getTableName('mailchimp_sync_ecommerce')],
"m4m.related_id = e.entity_id and m4m.type = '".\Ebizmarts\MailChimp\Helper\Data::IS_PRODUCT.
"' and m4m.mailchimp_store_id = '".$mailchimpStoreId."'",
$connection->quoteInto(
'm4m.related_id = e.entity_id and m4m.type = ?',
\Ebizmarts\MailChimp\Helper\Data::IS_PRODUCT
) . ' AND ' . $connection->quoteInto('m4m.mailchimp_store_id = ?', $mailchimpStoreId),
['m4m.*']
);
$collection->getSelect()->where("m4m.mailchimp_sync_delta IS null OR (m4m.mailchimp_sync_delta > '".$this->_helper->getMCMinSyncDateFlag().
"' and m4m.mailchimp_sync_modified = 1)");
$collection->getSelect()->where(
'm4m.mailchimp_sync_delta IS null OR (' . $connection->quoteInto(
'm4m.mailchimp_sync_delta > ?',
$this->_helper->getMCMinSyncDateFlag()
) . ' and m4m.mailchimp_sync_modified = 1)'
);
$collection->getSelect()->limit(self::MAX);
foreach ($collection as $item) {
/**
Expand Down
12 changes: 7 additions & 5 deletions Model/Api/PromoCodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,25 +114,27 @@ protected function _sendNewCoupons($mailchimpStoreId, $magentoStoreId)
* @var $ruleCollection \Magento\SalesRule\Model\ResourceModel\Rule\Collection
*/
$ruleCollection = $this->_ruleCollection->create();
$connection = $ruleCollection->getConnection();
$ruleCollection->addWebsiteFilter($websiteId);
$rulesId = [];
foreach($ruleCollection as $rule) {
$rulesId[] = $rule->getRuleId();
}
if(count($rulesId)) {
$inRoules = implode(',',$rulesId);
$collection = $this->_couponCollection->create();
$collection->getSelect()->joinLeft(
['m4m' => $this->_helper->getTableName('mailchimp_sync_ecommerce')],
"m4m.related_id = main_table.coupon_id and m4m.type = '" . \Ebizmarts\MailChimp\Helper\Data::IS_PROMO_CODE .
"' and m4m.mailchimp_store_id = '" . $mailchimpStoreId . "'",
$connection->quoteInto(
'm4m.related_id = main_table.coupon_id and m4m.type = ?',
\Ebizmarts\MailChimp\Helper\Data::IS_PROMO_CODE
) . ' AND ' . $connection->quoteInto('m4m.mailchimp_store_id = ?', $mailchimpStoreId),
['m4m.*']
);
$collection->getSelect()->joinLeft(
['rules' => $this->_helper->getTableName('salesrule')],
'main_table.rule_id = rules.rule_id'
);
$collection->getSelect()->where("m4m.mailchimp_sync_delta IS null and (rules.use_auto_generation = 1 and main_table.is_primary is null or rules.use_auto_generation = 0 and main_table.is_primary = 1) and main_table.rule_id in ($inRoules)");
$collection->getSelect()->where('m4m.mailchimp_sync_delta IS null and (rules.use_auto_generation = 1 and main_table.is_primary is null or rules.use_auto_generation = 0 and main_table.is_primary = 1) and '. $connection->quoteInto('main_table.rule_id in (?)', $rulesId));
$collection->getSelect()->limit(self::MAX);
$counter = 0;
/**
Expand Down Expand Up @@ -213,4 +215,4 @@ protected function _updateSyncData($storeId, $entityId, $sync_delta=null, $sync_
$this->_token
);
}
}
}
9 changes: 6 additions & 3 deletions Model/Api/PromoRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,14 @@ protected function _getModifiedPromoRules($mailchimpStoreId, $magentoStoreId)
* @var $collection \Magento\SalesRule\Model\ResourceModel\Rule\Collection
*/
$collection = $this->_collection->create();
$connection = $collection->getConnection();
$collection->addWebsiteFilter($websiteId);
$collection->getSelect()->joinLeft(
['m4m' => $this->_helper->getTableName('mailchimp_sync_ecommerce')],
"m4m.related_id = main_table.rule_id and m4m.type = '".\Ebizmarts\MailChimp\Helper\Data::IS_PROMO_RULE.
"' and m4m.mailchimp_store_id = '".$mailchimpStoreId."'",
$connection->quoteInto(
'm4m.related_id = main_table.rule_id and m4m.type = ?',
\Ebizmarts\MailChimp\Helper\Data::IS_PROMO_RULE
) . ' AND ' . $connection->quoteInto('m4m.mailchimp_store_id = ?', $mailchimpStoreId),
['m4m.*']
);
$collection->getSelect()->where("m4m.mailchimp_sync_modified = 1");
Expand Down Expand Up @@ -288,4 +291,4 @@ protected function _updateSyncData($storeId, $entityId, $sync_delta = null, $syn
);
}

}
}
Loading