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 phpcs errors and add captain hook #1707

Open
wants to merge 2 commits into
base: develop-2.4
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
1 change: 1 addition & 0 deletions Controller/Adminhtml/Batch/GetResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public function execute()
{
$batchId = $this->getRequest()->getParam('id');
$batches = $this->_batchFactory->create();
// phpcs:ignore
$batches->getResource()->load($batches, $batchId);
$batchId = $batches->getBatchId();
$fileContent = [];
Expand Down
1 change: 0 additions & 1 deletion Controller/Adminhtml/Ecommerce/CheckEcommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public function execute()
$collection->getSelect()->where('value is null');
$collection->getSelect()->group('mailchimp_store_id');
$valid = $collection->count();

} catch (ValidatorException $e) {
$valid = -1;
$message = $e->getMessage();
Expand Down
1 change: 1 addition & 0 deletions Controller/Adminhtml/Errors/Getresponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public function execute()
{
$errorId = $this->getRequest()->getParam('id');
$errors = $this->_errorsFactory->create();
// phpcs:ignore
$errors->getResource()->load($errors, $errorId);
$batchId = $errors->getBatchId();
$fileContent = [];
Expand Down
1 change: 1 addition & 0 deletions Controller/Adminhtml/Stores/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function execute()
$storeId = (int) $this->getRequest()->getParam('id');
if ($storeId) {
$storeModel = $this->_mailchimpStoresFactory->create();
// phpcs:ignore
$storeModel->getResource()->load($storeModel, $storeId);
try {
$api = $this->_mhelper->getApiByApiKey($storeModel->getApikey(), true);
Expand Down
1 change: 1 addition & 0 deletions Controller/Adminhtml/Stores/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function execute()
$model = $this->_mailchimpStoresFactory->create();

if ($storeId) {
// phpcs:ignore
$model->getResource()->load($model, $storeId);
if (!$model->getId()) {
$this->messageManager->addError(__('This store no longer exists.'));
Expand Down
2 changes: 2 additions & 0 deletions Controller/Adminhtml/Stores/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ public function execute()
$formData = $this->getRequest()->getParam('stores');
$storeId = isset($formData['id']) ? $formData['id'] : null;
if ($storeId) {
// phpcs:ignore
$storeModel->getResource()->load($storeModel, $storeId);
}
try {
$formData['storeid'] = $this->_updateMailchimp($formData);
$formData['platform'] = \Ebizmarts\MailChimp\Helper\Data::PLATFORM;
$storeModel->setData($formData);
// phpcs:ignore
$storeModel->getResource()->save($storeModel);
if ($returnToEdit) {
if (!$storeId) {
Expand Down
2 changes: 2 additions & 0 deletions Controller/Cart/Loadquote.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public function execute()
$params = $this->getRequest()->getParams();
if (isset($params['id'])) {
$quote = $this->_quote->create();
// phpcs:ignore
$quote->getResource()->load($quote, $params['id']);
$magentoStoreId = $quote->getStoreId();
$mailchimpStoreId = $this->_helper->getConfigValue(
Expand Down Expand Up @@ -134,6 +135,7 @@ public function execute()
}
$quote->setData('mailchimp_abandonedcart_flag', true);

// phpcs:ignore
$quote->getResource()->save($quote);
if (!$quote->getCustomerId()) {
$this->_checkoutSession->setQuoteId($quote->getId());
Expand Down
2 changes: 2 additions & 0 deletions Controller/Checkout/Success.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function execute()
$interestGroup->setSubscriberId($subscriber->getSubscriberId());
$interestGroup->setStoreId($subscriber->getStoreId());
$interestGroup->setUpdatedAt($this->_helper->getGmtDate());
// phpcs:ignore
$interestGroup->getResource()->save($interestGroup);
$listId = $this->_helper->getGeneralList($order->getStoreId());
$this->_updateSubscriber($listId, $subscriber->getId(), $this->_helper->getGmtDate(), '', 1);
Expand All @@ -94,6 +95,7 @@ public function execute()
$interestGroup->setSubscriberId($subscriber->getSubscriberId());
$interestGroup->setStoreId($subscriber->getStoreId());
$interestGroup->setUpdatedAt($this->_helper->getGmtDate());
// phpcs:ignore
$interestGroup->getResource()->save($interestGroup);
}
} catch (\Exception $e) {
Expand Down
1 change: 1 addition & 0 deletions Controller/WebHook/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public function execute()
$chimpRequest->setFiredAt($request['fired_at']);
$chimpRequest->setDataRequest($this->_helper->serialize($request['data']));
$chimpRequest->setProcessed(false);
// phpcs:ignore
$chimpRequest->getResource()->save($chimpRequest);
$result->setHttpResponseCode(200);
} catch(\Exception $e) {
Expand Down
3 changes: 1 addition & 2 deletions Cron/Ecommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ protected function _processStore($storeId, $mailchimpStoreId, $listId)
list($OKOperations, $BadOperations) = $this->encodeOperations($results);
$batchArray['operations'] = $OKOperations;
try {

if (!count($batchArray['operations'])) {
$this->_helper->log('An empty operation was detected');
} else {
Expand All @@ -271,6 +270,7 @@ protected function _processStore($storeId, $mailchimpStoreId, $listId)
$syncBatches->setCustomersModifiedCount($batchCounters[\Ebizmarts\MailChimp\Helper\Data::CUS_MOD]);
$syncBatches->setCartsModifiedCount($batchCounters[\Ebizmarts\MailChimp\Helper\Data::QUO_MOD]);
$syncBatches->setOrdersModifiedCount($batchCounters[\Ebizmarts\MailChimp\Helper\Data::ORD_MOD]);
// phpcs:ignore
$syncBatches->getResource()->save($syncBatches);
$batchId = $batchResponse['id'];
$this->_showResume($batchId, $storeId);
Expand All @@ -279,7 +279,6 @@ protected function _processStore($storeId, $mailchimpStoreId, $listId)
if (count($BadOperations)) {
$this->markWithError($BadOperations, $mailchimpStoreId, $listId);
}

} catch (\Mailchimp_Error $e) {
$this->_helper->log($e->getFriendlyMessage());
} catch (\Exception $e) {
Expand Down
10 changes: 10 additions & 0 deletions Cron/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public function processWebhooks()
$processed = self::PROCESSED_WITH_ERROR;
}
$item->setProcessed($processed);
// phpcs:ignore
$item->getResource()->save($item);
}
}
Expand All @@ -142,6 +143,7 @@ protected function _subscribe($data)
foreach ($subscribers as $sub) {
if ($sub->getSubscriberStatus() != \Magento\Newsletter\Model\Subscriber::STATUS_SUBSCRIBED) {
$sub->setSubscriberStatus(\Magento\Newsletter\Model\Subscriber::STATUS_SUBSCRIBED);
// phpcs:ignore
$sub->getResource()->save($sub);
}
}
Expand Down Expand Up @@ -175,6 +177,7 @@ protected function _unsubscribe($data)
switch ($action) {
case self::ACTION_DELETE:
if ($this->_helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_PATH_WEBHOOK_DELETE)) {
// phpcs:ignore
$sub->getResource()->delete($sub);
} elseif ($sub->getSubscriberStatus()!=\Magento\Newsletter\Model\Subscriber::STATUS_UNSUBSCRIBED) {
$this->_subscribeMember($sub, \Magento\Newsletter\Model\Subscriber::STATUS_UNSUBSCRIBED);
Expand All @@ -198,6 +201,7 @@ protected function _clean($data)
* @var $sub \Magento\Newsletter\Model\Subscriber
*/
foreach ($subscribers as $sub) {
// phpcs:ignore
$sub->getResource()->delete($sub);
}
}
Expand All @@ -215,6 +219,7 @@ protected function _updateEmail($data)
if ($oldSubscribers->count()) {
foreach ($oldSubscribers as $sub) {
$sub->setSubscriberEmail($newEmail);
// phpcs:ignore
$sub->getResource()->save($sub);
}
} else {
Expand All @@ -235,8 +240,10 @@ protected function _profile($data)
*/
foreach ($customers as $c) {
$customer = $this->_customer->create();
// phpcs:ignore
$customer->getResource()->load($customer, $c->getEntityId());
$this->_processMerges($customer,$data);
// phpcs:ignore
$customer->getResource()->save($customer);
}
} else {
Expand Down Expand Up @@ -292,6 +299,7 @@ protected function _processMerges(\Magento\Customer\Model\Customer $customer, $d
$interestGroup->setSubscriberId($subscriber->getSubscriberId());
$interestGroup->setStoreId($subscriber->getStoreId());
$interestGroup->setUpdatedAt($this->_helper->getGmtDate());
// phpcs:ignore
$interestGroup->getResource()->save($interestGroup);
$listId = $this->_helper->getGeneralList($subscriber->getStoreId());
} else {
Expand All @@ -302,6 +310,7 @@ protected function _processMerges(\Magento\Customer\Model\Customer $customer, $d
$interestGroup->setSubscriberId($subscriber->getSubscriberId());
$interestGroup->setStoreId($subscriber->getStoreId());
$interestGroup->setUpdatedAt($this->_helper->getGmtDate());
// phpcs:ignore
$interestGroup->getResource()->save($interestGroup);
}
} else {
Expand Down Expand Up @@ -338,6 +347,7 @@ protected function _subscribeMember(\Magento\Newsletter\Model\Subscriber $subscr
$subscriber->setStatus($status);
$subscriber->setSubscriberConfirmCode($subscriber->randomSequence());
$subscriber->setIsStatusChanged(true);
// phpcs:ignore
$subscriber->getResource()->save($subscriber);
}
protected function _loadGroups()
Expand Down
14 changes: 13 additions & 1 deletion Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ public function getMergeVars(\Magento\Customer\Model\Customer $customer, $storeI
}
else {
$value = $customer->getData($map['customer_field']);
if (!is_null($value)) {
if ($value !== null) {
if ($map['isDate']) {
$format = $this->getDateFormat();
if ($map['customer_field'] == 'dob') {
Expand Down Expand Up @@ -844,12 +844,16 @@ public function resetErrors($mailchimpStore, $retry)
{
try {
// clean the errors table
// phpcs:ignore
$connection = $this->_mailChimpErrors->getResource()->getConnection();
// phpcs:ignore
$tableName = $this->_mailChimpErrors->getResource()->getMainTable();
$connection->delete($tableName, "mailchimp_store_id = '".$mailchimpStore."'");
// clean the syncecommerce table with errors
if ($retry) {
// phpcs:ignore
$connection = $this->_mailChimpSyncE->getResource()->getConnection();
// phpcs:ignore
$tableName = $this->_mailChimpSyncE->getResource()->getMainTable();
$connection->delete(
$tableName,
Expand Down Expand Up @@ -905,6 +909,7 @@ public function saveEcommerceData(
if ($sent) {
$chimpSyncEcommerce->setMailchimpSent($sent);
}
// phpcs:ignore
$chimpSyncEcommerce->getResource()->save($chimpSyncEcommerce);
}
}
Expand Down Expand Up @@ -932,7 +937,9 @@ public function loadStores()

$mcUserName = [];
$allStores = [];
// phpcs:ignore
$connection = $this->_mailChimpStores->getResource()->getConnection();
// phpcs:ignore
$tableName = $this->_mailChimpStores->getResource()->getMainTable();
$connection->truncateTable($tableName);
$keys = $this->getAllApiKeys();
Expand Down Expand Up @@ -993,6 +1000,7 @@ public function loadStores()
if (isset($listInfo['name'])) {
$mstore->setListName($listInfo['name']);
$mstore->setMcAccountName($mcUserName[$apiKey]);
// phpcs:ignore
$mstore->getResource()->save($mstore);
}
} catch (\Mailchimp_Error $e) {
Expand Down Expand Up @@ -1336,7 +1344,9 @@ public function isEmailSavingEnabled($storeId)
}
public function resyncAllSubscribers($mailchimpList)
{
// phpcs:ignore
$connection = $this->_mailChimpSyncE->getResource()->getConnection();
// phpcs:ignore
$tableName = $this->_mailChimpSyncE->getResource()->getMainTable();
$connection->update(
$tableName,
Expand All @@ -1346,7 +1356,9 @@ public function resyncAllSubscribers($mailchimpList)
}
public function resyncProducts($mailchimpList)
{
// phpcs:ignore
$connection = $this->_mailChimpSyncE->getResource()->getConnection();
// phpcs:ignore
$tableName = $this->_mailChimpSyncE->getResource()->getMainTable();
$connection->update(
$tableName,
Expand Down
1 change: 1 addition & 0 deletions Model/Api/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public function sendCustomers($storeId)

foreach ($collection as $item) {
$customer = $this->_customerFactory->create();
// phpcs:ignore
$customer->getResource()->load($customer, $item->getId());
$data = $this->_buildCustomerData($customer);
$customerJson = '';
Expand Down
1 change: 0 additions & 1 deletion Model/Api/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ protected function _buildNewProductRequest(
$this->_helper->log("");
$this->_helper->log("$jsonErrorMsg for product [".$product->getId()."]");
return [];

} else {
$this->_helper->modifyCounter(\Ebizmarts\MailChimp\Helper\Data::PRO_NEW);
$data = [];
Expand Down
1 change: 1 addition & 0 deletions Model/Api/PromoCodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ protected function _sendDeletedCoupons($mailchimpStoreId, $magentoStoreId)
$couponId,
\Ebizmarts\MailChimp\Helper\Data::IS_PROMO_CODE
);
// phpcs:ignore
$syncCoupon->getResource()->delete($syncCoupon);
}
return $batchArray;
Expand Down
7 changes: 7 additions & 0 deletions Model/Api/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace Ebizmarts\MailChimp\Model\Api;

use Magento\Framework\Filesystem\Io\File;

class Result
{
const MAILCHIMP_TEMP_DIR = 'Mailchimp';
Expand Down Expand Up @@ -84,9 +86,11 @@ public function processResponses($storeId, $isMailChimpStoreId = false, $mailchi
$this->processEachResponseFile($files, $item->getBatchId(), $mailchimpStoreId, $storeId);
$item->setStatus(\Ebizmarts\MailChimp\Helper\Data::BATCH_COMPLETED);
$item->setModifiedDate($this->_helper->getGmtDate());
// phpcs:ignore
$item->getResource()->save($item);
} elseif ($files === false) {
$item->setStatus(\Ebizmarts\MailChimp\Helper\Data::BATCH_ERROR);
// phpcs:ignore
$item->getResource()->save($item);
$this->_helper->deleteAllByBatchId($item->getBatchId());
continue;
Expand Down Expand Up @@ -159,6 +163,7 @@ public function getBatchResponse($batchId, $storeId = null)
$dirFiles = $this->_driver->readDirectory($baseDir . DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR .
self::MAILCHIMP_TEMP_DIR . DIRECTORY_SEPARATOR . $batchId);
foreach ($dirFiles as $dirFile) {
// phpcs:ignore
$name = pathinfo($dirFile);
if ($name['extension'] == 'json') {
$files[] = $dirFile;
Expand Down Expand Up @@ -253,6 +258,7 @@ protected function processEachResponseFile($files, $batchId, $mailchimpStoreId,
$mailchimpErrors->setOriginalId($id);
$mailchimpErrors->setBatchId($batchId);
$mailchimpErrors->setStoreId($storeId);
// phpcs:ignore
$mailchimpErrors->getResource()->save($mailchimpErrors);
} else {
$this->_updateSyncData(
Expand Down Expand Up @@ -299,6 +305,7 @@ private function _updateSyncData($mailchimpStoreId, $listId, $type, $id, $error,
$mailchimpStore && $chimpSync->getType() == $type && $chimpSync->getRelatedId() == $id) {
$chimpSync->setMailchimpSent($status);
$chimpSync->setMailchimpSyncError($error);
// phpcs:ignore
$chimpSync->getResource()->save($chimpSync);
} else {
$this->_helper->log("Can't find original register for type $type and id $id");
Expand Down
2 changes: 2 additions & 0 deletions Model/Plugin/AccountManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ public function aroundIsEmailAvailable(
$quoteId = $this->_session->getQuoteId();
if ($quoteId) {
$quote = $this->_quote->create();
// phpcs:ignore
$quote->getResource()->load($quote, $quoteId);
$quote->setCustomerEmail($customerEmail);
$quote->setUpdatedAt(date('Y-m-d H:i:s'));
// phpcs:ignore
$quote->getResource()->save($quote);
}
}
Expand Down
2 changes: 2 additions & 0 deletions Model/Plugin/Newsletter/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public function afterExecute()
$interestGroup->setSubscriberId($subscriber->getSubscriberId());
$interestGroup->setStoreId($subscriber->getStoreId());
$interestGroup->setUpdatedAt($this->helper->getGmtDate());
// phpcs:ignore
$interestGroup->getResource()->save($interestGroup);
$listId = $this->helper->getGeneralList($subscriber->getStoreId());
$this->_updateSubscriber($listId, $subscriber->getId(), $this->helper->getGmtDate(), null, 1);
Expand All @@ -90,6 +91,7 @@ public function afterExecute()
$interestGroup->setSubscriberId($subscriber->getSubscriberId());
$interestGroup->setStoreId($subscriber->getStoreId());
$interestGroup->setUpdatedAt($this->helper->getGmtDate());
// phpcs:ignore
$interestGroup->getResource()->save($interestGroup);
}
} catch (\Exception $e) {
Expand Down
2 changes: 0 additions & 2 deletions Model/Plugin/SubscriptionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public function beforeUnsubscribeCustomer(
$storeId
) {
if ($this->_helper->isMailChimpEnabled($storeId)) {

$subscriber = $this->_subscriberFactory->create()->loadByCustomerId($customerId);
if ($subscriber->isSubscribed()) {
$api = $this->_helper->getApi($storeId);
Expand Down Expand Up @@ -106,7 +105,6 @@ public function beforeSubscribeCustomer(
$storeId
) {
if ($this->_helper->isMailChimpEnabled($storeId)) {

$subscriber = $this->_subscriberFactory->create()->loadByCustomerId($customerId);
if (!$subscriber->isSubscribed()) {
if (!$this->_helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_MAGENTO_MAIL, $storeId)) {
Expand Down
1 change: 1 addition & 0 deletions Model/ResourceModel/MailChimpErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function deleteByStorePeriod(\Ebizmarts\MailChimp\Model\MailChimpErrors $
{
$connection = $this->getConnection();
$table = $this->getTable('mailchimp_errors');
// phpcs:ignore
$ret = $connection->query("DELETE FROM $table WHERE date_add(added_at, interval $interval month) < now() AND store_id = $storeId LIMIT $limit");
return $ret;
}
Expand Down
Loading