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

add a button in the admin to no retry when truncate the errors table … #1499

Merged
merged 1 commit into from
Aug 10, 2022
Merged
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
80 changes: 80 additions & 0 deletions Block/Adminhtml/System/Config/ResetErrorsNoRetry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/**
* mc-magento2 Magento Component
*
* @category Ebizmarts
* @package mc-magento2
* @author Ebizmarts Team <info@ebizmarts.com>
* @copyright Ebizmarts (http://ebizmarts.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @date: 2/20/17 3:25 PM
* @file: ResetErrors.php
*/

namespace Ebizmarts\MailChimp\Block\Adminhtml\System\Config;

class ResetErrorsNoRetry extends \Magento\Config\Block\System\Config\Form\Field
{
/**
* @var \Ebizmarts\MailChimp\Helper\Data
*/
private $_helper;

/**
* ResetErrors constructor.
* @param \Magento\Backend\Block\Template\Context $context
* @param \Ebizmarts\MailChimp\Helper\Data $helper
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Ebizmarts\MailChimp\Helper\Data $helper,
array $data = []
) {

$this->_helper = $helper;
parent::__construct($context, $data);
}

protected function _construct()
{
parent::_construct();
$this->setTemplate('system/config/reseterrorsnoretry.phtml');
}

protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
$originalData = $element->getOriginalData();
$this->addData(
[
'button_label' => __($originalData['button_label']),
'button_url' => $this->getAjaxCheckUrl(),
'html_id' => $element->getHtmlId(),
]
);
return $this->_toHtml();
}

public function getButtonHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
$originalData = $element->getOriginalData();
$label = $originalData['button_label'];
$this->addData([
'button_label' => __($label),
'button_url' => $this->getAjaxCheckUrl(),
'html_id' => $element->getHtmlId(),
]);
return $this->_toHtml();
}
public function getAjaxCheckUrl()
{
$params = $this->getRequest()->getParams();
$scope = [];
if (isset($params['website'])) {
$scope = ['website'=>$params['website']];
} elseif (isset($params['store'])) {
$scope = ['store'=>$params['store']];
}
return $this->_urlBuilder->getUrl('mailchimp/ecommerce/ResetLocalErrorsNoRetry', $scope);
}
}
2 changes: 1 addition & 1 deletion Controller/Adminhtml/Ecommerce/ResetLocalErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function execute()

$resultJson = $this->resultJsonFactory->create();
try {
$this->helper->resetErrors($mailchimpStore);
$this->helper->resetErrors($mailchimpStore, true);
} catch (ValidatorException $e) {
$valid = 0;
$message = $e->getMessage();
Expand Down
95 changes: 95 additions & 0 deletions Controller/Adminhtml/Ecommerce/ResetLocalErrorsNoRetry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php
/**
* mc-magento2 Magento Component
*
* @category Ebizmarts
* @package mc-magento2
* @author Ebizmarts Team <info@ebizmarts.com>
* @copyright Ebizmarts (http://ebizmarts.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @date: 2/21/17 5:07 PM
* @file: ResetLocalErrors.php
*/

namespace Ebizmarts\MailChimp\Controller\Adminhtml\Ecommerce;

use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\Exception\ValidatorException;
use Symfony\Component\Config\Definition\Exception\Exception;

class ResetLocalErrorsNoRetry extends \Magento\Backend\App\Action
{
/**
* @var JsonFactory
*/
protected $resultJsonFactory;
/**
* @var \Ebizmarts\MailChimp\Helper\Data
*/
protected $helper;
/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $storeManager;

/**
* ResetLocalErrors constructor.
* @param \Magento\Backend\App\Action\Context $context
* @param JsonFactory $resultJsonFactory
* @param \Magento\Store\Model\StoreManagerInterface $storeManagerInterface
* @param \Ebizmarts\MailChimp\Helper\Data $helper
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
JsonFactory $resultJsonFactory,
\Magento\Store\Model\StoreManagerInterface $storeManagerInterface,
\Ebizmarts\MailChimp\Helper\Data $helper
) {

parent::__construct($context);
$this->resultJsonFactory = $resultJsonFactory;
$this->helper = $helper;
$this->storeManager = $storeManagerInterface;
}

public function execute()
{
$valid = 1;
$message = '';
$params = $this->getRequest()->getParams();
if (isset($params['website'])) {
$mailchimpStore = $this->helper->getConfigValue(
\Ebizmarts\MailChimp\Helper\Data::XML_MAILCHIMP_STORE,
$params['website'],
'website'
);
} elseif (isset($params['store'])) {
$mailchimpStore = $this->helper->getConfigValue(
\Ebizmarts\MailChimp\Helper\Data::XML_MAILCHIMP_STORE,
$params['store'],
'store'
);
} else {
$mailchimpStore = $this->helper->getConfigValue(
\Ebizmarts\MailChimp\Helper\Data::XML_MAILCHIMP_STORE,
$this->storeManager->getStore()
);
}

$resultJson = $this->resultJsonFactory->create();
try {
$this->helper->resetErrors($mailchimpStore, false);
} catch (ValidatorException $e) {
$valid = 0;
$message = $e->getMessage();
}
return $resultJson->setData([
'valid' => (int)$valid,
'message' => $message,
]);
}
protected function _isAllowed()
{
return $this->_authorization->isAllowed('Ebizmarts_MailChimp::config_mailchimp');
}
}
16 changes: 9 additions & 7 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -831,20 +831,22 @@ public function getDateMicrotime()
$date = date('Y-m-d-H-i-s') . '-' . $msecArray[1];
return $date;
}
public function resetErrors($mailchimpStore)
public function resetErrors($mailchimpStore, $retry)
{
try {
// clean the errors table
$connection = $this->_mailChimpErrors->getResource()->getConnection();
$tableName = $this->_mailChimpErrors->getResource()->getMainTable();
$connection->delete($tableName, "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"
);
if ($retry) {
$connection = $this->_mailChimpSyncE->getResource()->getConnection();
$tableName = $this->_mailChimpSyncE->getResource()->getMainTable();
$connection->delete(
$tableName,
"mailchimp_store_id = '" . $mailchimpStore . "' and mailchimp_sync_error is not null"
);
}
} catch (\Zend_Db_Exception $e) {
throw new ValidatorException(__($e->getMessage()));
}
Expand Down
27 changes: 18 additions & 9 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -182,32 +182,32 @@
</group>
<group id="ecommerce" translate="label" type="text" sortOrder="110" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Ecommerce Configuration</label>
<field id="active" translate="label" type="select" sortOrder="112" showInDefault="1" showInWebsite="1" showInStore="1">
<field id="active" translate="label" type="select" sortOrder="110" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="customer_optin" translate="label" type="select" sortOrder="114" showInDefault="1" showInWebsite="1" showInStore="1">
<field id="customer_optin" translate="label" type="select" sortOrder="120" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Subscribe all customers to the newsletter</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<depends>
<field id="*/*/active">1</field>
</depends>
</field>
<field id="firstdate" translate="label" type="date" showInDefault="1" sortOrder="116" showInWebsite="1" showInStore="1">
<field id="firstdate" translate="label" type="date" showInDefault="1" sortOrder="130" showInWebsite="1" showInStore="1">
<label>First Date</label>
<frontend_model>Ebizmarts\MailChimp\Block\Adminhtml\System\Config\Date</frontend_model>
<depends>
<field id="*/*/active">1</field>
</depends>
</field>
<field id="send_promo" translate="label" type="select" sortOrder="118" showInDefault="1" showInWebsite="1" showInStore="1">
<field id="send_promo" translate="label" type="select" sortOrder="140" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Send Promo Rules and Promo Codes</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<depends>
<field id="*/*/active">1</field>
</depends>
</field>
<field id="including_taxes" translate="label" type="select" sortOrder="120" showInDefault="1" showInWebsite="1" showInStore="1">
<field id="including_taxes" translate="label" type="select" sortOrder="150" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Prices including taxes</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment><![CDATA[You must configure Price Display Settings in Sales/Tax to "including taxes"]]></comment>
Expand All @@ -216,22 +216,31 @@
<field id="*/*/active">1</field>
</depends>
</field>
<field id="reset_errors" translate="button_label" type="button" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
<button_label>Reset Errors</button_label>
<field id="reset_errors_retry" translate="button_label" type="button" sortOrder="160" showInDefault="1" showInWebsite="1" showInStore="1">
<button_label>Reset Errors and retry</button_label>
<frontend_model>Ebizmarts\MailChimp\Block\Adminhtml\System\Config\ResetErrors</frontend_model>
<comment>Truncate the errors table and retry all the registers with error</comment>
<depends>
<field id="*/*/active">1</field>
</depends>
</field>
<field id="delete_store" translate="button_label" type="button" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
<field id="reset_errors_noretry" translate="button_label" type="button" sortOrder="170" showInDefault="1" showInWebsite="1" showInStore="1">
<button_label>Reset Errors and no retry</button_label>
<frontend_model>Ebizmarts\MailChimp\Block\Adminhtml\System\Config\ResetErrorsNoRetry</frontend_model>
<comment>Truncate the errors table and retry all the registers with error</comment>
<depends>
<field id="*/*/active">1</field>
</depends>
</field>
<field id="delete_store" translate="button_label" type="button" sortOrder="180" showInDefault="1" showInWebsite="1" showInStore="1">
<button_label>Delete Store</button_label>
<comment>Proceed with caution, this delete the mailchimp store for all the connected magento stores</comment>
<frontend_model>Ebizmarts\MailChimp\Block\Adminhtml\System\Config\DeleteStore</frontend_model>
<depends>
<field id="*/*/active">1</field>
</depends>
</field>
<field id="resync_products" translate="button_label" type="button" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
<field id="resync_products" translate="button_label" type="button" sortOrder="190" showInDefault="1" showInWebsite="1" showInStore="1">
<button_label>Resync all products</button_label>
<frontend_model>Ebizmarts\MailChimp\Block\Adminhtml\System\Config\ResyncProducts</frontend_model>
<depends>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div id="monkey_errorconfirmation" style="display:none;" data-mage-init='{"mailchimpconfirmation":{}}'>
</div>
<div class="actions actions-reset-errors">
<div id="validation_result" class="message-validation hidden"></div>
<button onclick="mailchimpdeleteconfirmation('<?php echo $this->getAjaxCheckUrl() ?>')" class="action-reset-errors" type="button" id="<?php echo $block->getHtmlId() ?>">
<span><?php echo $block->escapeHtml($block->getButtonLabel()) ?></span>
</button>
</div>