Skip to content

Commit

Permalink
Merge pull request #8183 from magento-gl/comm_voted
Browse files Browse the repository at this point in the history
[Bluetooth] Community Pull Requests delivery - 2.4-develop
  • Loading branch information
sidolov authored Mar 2, 2023
2 parents cd41bc2 + d9b9726 commit aab3ee6
Show file tree
Hide file tree
Showing 25 changed files with 367 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class Upload extends \Magento\Backend\App\Action implements HttpPostActionInterf
private $allowedMimeTypes = [
'jpg' => 'image/jpg',
'jpeg' => 'image/jpeg',
'gif' => 'image/png',
'png' => 'image/gif'
'gif' => 'image/gif',
'png' => 'image/png'
];

/**
Expand Down
12 changes: 6 additions & 6 deletions app/code/Magento/Customer/Model/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,7 @@ public function setStore(\Magento\Store\Model\Store $store)
* Validate customer attribute values.
*
* @deprecated 100.1.0
* @see \Magento\Customer\Model\AccountManagement::validate()
* @return bool
*/
public function validate()
Expand Down Expand Up @@ -1286,6 +1287,8 @@ public function changeResetPasswordLinkToken($passwordLinkToken)
* Check if current reset password link token is expired
*
* @return boolean
* @deprecated
* @see \Magento\Customer\Model\AccountManagement::isResetPasswordLinkTokenExpired
*/
public function isResetPasswordLinkTokenExpired()
{
Expand All @@ -1304,12 +1307,9 @@ public function isResetPasswordLinkTokenExpired()
return true;
}

$dayDifference = floor(($currentTimestamp - $tokenTimestamp) / (24 * 60 * 60));
if ($dayDifference >= $expirationPeriod) {
return true;
}

return false;
$hourDifference = floor(($currentTimestamp - $tokenTimestamp) / (60 * 60));

return $hourDifference >= $expirationPeriod;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,16 @@ public function getAllOptions($withEmpty = true, $defaultValues = false)
$allowedCountries = array_unique(array_merge([], ...$allowedCountries));
} else {
// Address can be added only for the allowed country list.
$storeId = null;
$websiteId = null;
$customerId = $this->request->getParam('parent_id') ?? null;
if ($customerId) {
$customer = $this->customerRepository->getById($customerId);
$storeId = $customer->getStoreId();
$websiteId = $customer->getWebsiteId();
}

$allowedCountries = $this->allowedCountriesReader->getAllowedCountries(
ScopeInterface::SCOPE_WEBSITE,
$storeId
$websiteId
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="AdminEditCustomerWithAssociatedNewsletterQueueNewTest">
<annotations>
<stories value="Edit customer if there is associated newsletter queue new"/>
<title value="Edit customer if there is associated newsletter queue new"/>
<description value="Edit customer if there is associated newsletter queue new"/>
<severity value="BLOCKER"/>
<group value="customer"/>
</annotations>
<before>
<actionGroup ref="EnabledWYSIWYGActionGroup" stepKey="enableWYSIWYG"/>
<createData entity="Simple_US_Customer_Multiple_Addresses_No_Default_Address" stepKey="customer"/>
<magentoCron groups="index" stepKey="reindex"/>
<actionGroup ref="AdminLoginActionGroup" stepKey="login"/>
</before>
<after>
<deleteData createDataKey="customer" stepKey="deleteCustomer"/>

<actionGroup ref="AdminNavigateMenuActionGroup" stepKey="navigateToNewsletterGridPage">
<argument name="menuUiId" value="{{AdminMenuMarketing.dataUiId}}"/>
<argument name="submenuUiId" value="{{AdminMenuMarketingCommunicationsNewsletterTemplate.dataUiId}}"/>
</actionGroup>
<actionGroup ref="AdminSearchNewsletterTemplateOnGridActionGroup" stepKey="findCreatedNewsletterTemplateInGrid">
<argument name="name" value="{{_defaultNewsletter.name}}"/>
<argument name="subject" value="{{_defaultNewsletter.subject}}"/>
</actionGroup>
<actionGroup ref="AdminMarketingOpenNewsletterTemplateFromGridActionGroup" stepKey="openTemplate"/>
<actionGroup ref="AdminMarketingDeleteNewsletterTemplateActionGroup" stepKey="deleteTemplate"/>

<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
</after>

<actionGroup ref="AdminOpenCustomersGridActionGroup" stepKey="openCustomersGridPage"/>
<actionGroup ref="OpenEditCustomerFromAdminActionGroup" stepKey="openEditCustomerPage">
<argument name="customer" value="Simple_US_Customer_Multiple_Addresses_No_Default_Address"/>
</actionGroup>
<actionGroup ref="AdminSubscribeCustomerToNewsletters" stepKey="subscribeToNewsletter"/>

<actionGroup ref="AdminNavigateMenuActionGroup" stepKey="navigateToNewsletterTemplatePage">
<argument name="menuUiId" value="{{AdminMenuMarketing.dataUiId}}"/>
<argument name="submenuUiId" value="{{AdminMenuMarketingCommunicationsNewsletterTemplate.dataUiId}}"/>
</actionGroup>
<actionGroup ref="AdminNavigateToCreateNewsletterTemplatePageActionGroup" stepKey="navigateToCreateNewsletterTemplatePage"/>
<actionGroup ref="AdminCreateNewsletterTemplateActionGroup" stepKey="createNewsletterTemplate">
<argument name="name" value="{{_defaultNewsletter.name}}"/>
<argument name="subject" value="{{_defaultNewsletter.subject}}"/>
<argument name="senderName" value="{{_defaultNewsletter.senderName}}"/>
<argument name="senderEmail" value="{{_defaultNewsletter.senderEmail}}"/>
<argument name="templateContent" value="{{_defaultNewsletter.textAreaContent}}"/>
</actionGroup>
<actionGroup ref="AdminSearchNewsletterTemplateOnGridActionGroup" stepKey="findCreatedNewsletterTemplate">
<argument name="name" value="{{_defaultNewsletter.name}}"/>
<argument name="subject" value="{{_defaultNewsletter.subject}}"/>
</actionGroup>
<actionGroup ref="AdminCreateQueueNewsletterActionGroup" stepKey="addNewsletterToQueue">
<argument name="startAt" value="Dec 21, 2022 11:04:20 AM"/>
</actionGroup>

<actionGroup ref="OpenEditCustomerFromAdminActionGroup" stepKey="editCustomerForm">
<argument name="customer" value="Simple_US_Customer_Multiple_Addresses_No_Default_Address"/>
</actionGroup>
<actionGroup stepKey="editCustomerAddress" ref="AdminEditCustomerAddressesFromActionGroup">
<argument name="customerAddress" value="CustomerAddressSimple"/>
</actionGroup>
<actionGroup ref="AdminSaveCustomerAndAssertSuccessMessage" stepKey="saveCustomer"/>

</test>
</tests>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
<description value="Edit customer if there is associated newsletter queue"/>
<severity value="BLOCKER"/>
<group value="customer"/>
<skip>
<issueId value="DEPRECATED">Use AdminEditCustomerWithAssociatedNewsletterQueueNewTest instead</issueId>
</skip>
</annotations>
<before>
<actionGroup ref="EnabledWYSIWYGActionGroup" stepKey="enableWYSIWYG"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,9 @@ define([

// process sections that can expire due to storage information inconsistency
_.each(cookieSectionTimestamps, function (cookieSectionTimestamp, sectionName) {
sectionData = storage.get(sectionName);
if (storage !== undefined) {
sectionData = storage.get(sectionName);
}

if (typeof sectionData === 'undefined' ||
typeof sectionData === 'object' &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,28 @@ public function execute()
if (!is_array($indexerIds)) {
$this->messageManager->addErrorMessage(__('Please select indexers.'));
} else {
$updatedIndexersCount = 0;

try {
foreach ($indexerIds as $indexerId) {
/** @var \Magento\Framework\Indexer\IndexerInterface $model */
$model = $this->_objectManager->get(
\Magento\Framework\Indexer\IndexerRegistry::class
)->get($indexerId);
$model->setScheduled(true);

if (!$model->isScheduled()) {
$model->setScheduled(true);
$updatedIndexersCount++;
}
}
$this->messageManager->addSuccess(
__('%1 indexer(s) are in "Update by Schedule" mode.', count($indexerIds))

$this->messageManager->addSuccessMessage(
__(
'%1 indexer(s) have been updated to "Update by Schedule" mode.
%2 skipped because there was nothing to change.',
$updatedIndexersCount,
count($indexerIds) - $updatedIndexersCount
)
);
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addErrorMessage($e->getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,28 @@ public function execute()
if (!is_array($indexerIds)) {
$this->messageManager->addErrorMessage(__('Please select indexers.'));
} else {
$updatedIndexersCount = 0;

try {
foreach ($indexerIds as $indexerId) {
/** @var \Magento\Framework\Indexer\IndexerInterface $model */
$model = $this->_objectManager->get(
\Magento\Framework\Indexer\IndexerRegistry::class
)->get($indexerId);
$model->setScheduled(false);

if ($model->isScheduled()) {
$model->setScheduled(false);
$updatedIndexersCount++;
}
}
$this->messageManager->addSuccess(
__('%1 indexer(s) are in "Update on Save" mode.', count($indexerIds))

$this->messageManager->addSuccessMessage(
__(
'%1 indexer(s) have been updated to "Update on Save" mode.
%2 skipped because there was nothing to change.',
$updatedIndexersCount,
count($indexerIds) - $updatedIndexersCount
)
);
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addErrorMessage($e->getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
<actionGroup name="AdminSwitchAllIndexerToActionModeActionGroup">
<arguments>
<argument name="action" type="string" defaultValue="Update by Schedule"/>
<!-- <argument name="count" type="string" defaultValue="10"/> -->
</arguments>
<amOnPage url="{{AdminIndexManagementPage.url}}" stepKey="onIndexManagement"/>
<waitForPageLoad stepKey="waitForManagementPage"/>
<selectOption userInput="selectAll" selector="{{AdminIndexManagementSection.selectMassAction}}" stepKey="checkIndexer"/>
<selectOption userInput="{{action}}" selector="{{AdminIndexManagementSection.massActionSelect}}" stepKey="selectAction"/>
<grabValueFrom selector="{{AdminIndexManagementSection.massIndexSelectionCount}}" stepKey="selectCount"/>
<click selector="{{AdminIndexManagementSection.massActionSubmit}}" stepKey="clickSubmit"/>
<waitForPageLoad stepKey="waitForSubmit"/>
<see userInput="indexer(s) are in &quot;{{action}}&quot; mode." stepKey="seeMessage"/>
<see userInput="{$selectCount} indexer(s) have been updated to &quot;{{action}}&quot; mode. 0 skipped because there was nothing to change." stepKey="seeMessage"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
<selectOption userInput="{{action}}" selector="{{AdminIndexManagementSection.massActionSelect}}" stepKey="selectAction"/>
<click selector="{{AdminIndexManagementSection.massActionSubmit}}" stepKey="clickSubmit"/>
<waitForPageLoad stepKey="waitForSubmit"/>
<see selector="{{AdminIndexManagementSection.successMessage}}" userInput="1 indexer(s) are in &quot;{{action}}&quot; mode." stepKey="seeMessage"/>
<see selector="{{AdminIndexManagementSection.successMessage}}" userInput="1 indexer(s) have been updated to &quot;{{action}}&quot; mode. 0 skipped because there was nothing to change." stepKey="seeMessage"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
<element name="selectMassAction" type="select" selector="#gridIndexer_massaction-mass-select"/>
<element name="columnScheduleStatus" type="text" selector="//th[contains(@class, 'col-indexer_schedule_status')]"/>
<element name="indexerScheduleStatus" type="text" selector="//tr[contains(.,'{{var1}}')]//td[contains(@class,'col-indexer_schedule_status')]" parameterized="true"/>
<element name="massIndexSelectionCount" type="text" selector="#gridIndexer-total-count"/>
</section>
</sections>
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class MassOnTheFlyTest extends TestCase
protected $indexReg;

/**
* @return ResponseInterface
* @var ResponseInterface
*/
protected $response;

Expand Down Expand Up @@ -223,6 +223,8 @@ public function testExecute($indexerIds, $exception, $expectsExceptionValues)
->willReturn($indexerInterface);

if ($exception !== null) {
$indexerInterface->expects($this->any())
->method('isScheduled')->willReturn(true);
$indexerInterface->expects($this->any())
->method('setScheduled')->with(false)->willThrowException($exception);
} else {
Expand Down
37 changes: 20 additions & 17 deletions app/code/Magento/Newsletter/Block/Adminhtml/Queue/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Edit extends \Magento\Backend\Block\Template
protected $_template = 'Magento_Newsletter::queue/edit.phtml';

/**
* Core registry
* Magento Framework Core Registry
*
* @var \Magento\Framework\Registry
*/
Expand All @@ -43,6 +43,8 @@ public function __construct(
}

/**
* Queue Edit constructor
*
* @return void
*/
protected function _construct()
Expand Down Expand Up @@ -135,24 +137,25 @@ protected function _prepareLayout()
]
]
);

$this->getToolbar()->addChild(
'save_and_resume',
\Magento\Backend\Block\Widget\Button::class,
[
'label' => __('Save and Resume'),
'class' => 'save',
'data_attribute' => [
'mage-init' => [
'button' => [
'event' => 'save',
'target' => '#queue_edit_form',
'eventData' => ['action' => ['args' => ['_resume' => 1]]],
if ($this->getCanResume()) {
$this->getToolbar()->addChild(
'save_and_resume',
\Magento\Backend\Block\Widget\Button::class,
[
'label' => __('Save and Resume'),
'class' => 'save',
'data_attribute' => [
'mage-init' => [
'button' => [
'event' => 'save',
'target' => '#queue_edit_form',
'eventData' => ['action' => ['args' => ['_resume' => 1]]],
],
],
],
]
]
]
);
);
}

return parent::_prepareLayout();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace Magento\Newsletter\Block\Adminhtml\Queue\Edit;

use Magento\Newsletter\Model\Queue;

/**
* Newsletter queue edit form
*
Expand Down Expand Up @@ -227,7 +229,7 @@ protected function _prepareForm()
'value' => $queue->getTemplate()->getTemplateStyles()
]
);
} elseif (\Magento\Newsletter\Model\Queue::STATUS_NEVER != $queue->getQueueStatus()) {
} elseif (Queue::STATUS_NEVER != $queue->getQueueStatus() && $queue->getQueueStatus() != Queue::STATUS_PAUSE) {
$fieldset->addField(
'text',
'textarea',
Expand Down
20 changes: 19 additions & 1 deletion app/code/Magento/Newsletter/Model/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ public function setQueueStartAtByString($startAt)
* @param int $count
* @return $this
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function sendPerSubscriber($count = 20)
{
Expand Down Expand Up @@ -254,7 +255,11 @@ public function sendPerSubscriber($count = 20)
]
);

/** @var \Magento\Newsletter\Model\Subscriber $item */
if ($this->getQueueStatus() != self::STATUS_SENDING && count($collection->getItems()) > 0) {
$this->startQueue();
}

/** @var Subscriber $item */
foreach ($collection->getItems() as $item) {
$transport = $this->_transportBuilder->setTemplateOptions(
['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $item->getStoreId()]
Expand Down Expand Up @@ -291,6 +296,19 @@ public function sendPerSubscriber($count = 20)
return $this;
}

/**
* Start queue: set status SENDING for queue
*
* @return $this
*/
private function startQueue()
{
$this->setQueueStatus(self::STATUS_SENDING);
$this->save();

return $this;
}

/**
* Finish queue: set status SENT and update finish date
*
Expand Down
Loading

0 comments on commit aab3ee6

Please sign in to comment.