Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/AC-988' into GL_PR_21102021
Browse files Browse the repository at this point in the history
  • Loading branch information
glo71317 committed Oct 21, 2021
2 parents 5bf4ef4 + f8575b5 commit cb375e7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
15 changes: 8 additions & 7 deletions app/code/Magento/Cron/Model/Config/Backend/Product/Alert.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@
*/
namespace Magento\Cron\Model\Config\Backend\Product;

use Magento\Framework\Exception\LocalizedException;

/**
* Cron job Alert configuration
*/
class Alert extends \Magento\Framework\App\Config\Value
{
/**
* Cron expression config path
* Cron string path for product alerts
*/
const CRON_STRING_PATH = 'crontab/default/jobs/catalog_product_alert/schedule/cron_expr';

/**
* Cron model config path
* Cron model path for product alerts
*/
const CRON_MODEL_PATH = 'crontab/default/jobs/catalog_product_alert/run/model';

Expand Down Expand Up @@ -67,7 +69,7 @@ public function __construct(
* @inheritdoc
*
* @return $this
* @throws \Exception
* @throws LocalizedException
*/
public function afterSave()
{
Expand All @@ -83,8 +85,8 @@ public function afterSave()
$frequency = $this->getValue();

$cronExprArray = [
(int)$time[1], //Minute
(int)$time[0], //Hour
(int)($time[1] ?? 0), //Minute
(int)($time[0] ?? 0), //Hour
$frequency == \Magento\Cron\Model\Config\Source\Frequency::CRON_MONTHLY ? '1' : '*', //Day of the Month
'*', //Month of the Year
$frequency == \Magento\Cron\Model\Config\Source\Frequency::CRON_WEEKLY ? '1' : '*', //Day of the Week
Expand All @@ -110,8 +112,7 @@ public function afterSave()
self::CRON_MODEL_PATH
)->save();
} catch (\Exception $e) {
// phpcs:ignore Magento2.Exceptions.DirectThrow
throw new \Exception(__('We can\'t save the cron expression.'));
throw new LocalizedException(__('We can\'t save the cron expression.'));
}

return parent::afterSave();
Expand Down
12 changes: 7 additions & 5 deletions app/code/Magento/Cron/Model/Config/Backend/Sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
*/
namespace Magento\Cron\Model\Config\Backend;

use Magento\Framework\Exception\LocalizedException;

/**
* Sitemap configuration
*/
class Sitemap extends \Magento\Framework\App\Config\Value
{
/**
* Cron string path
* Cron string path for product alerts
*/
const CRON_STRING_PATH = 'crontab/default/jobs/sitemap_generate/schedule/cron_expr';

Expand Down Expand Up @@ -67,16 +69,16 @@ public function __construct(
* After save handler
*
* @return $this
* @throws \Exception
* @throws LocalizedException
*/
public function afterSave()
{
$time = $this->getData('groups/generate/fields/time/value');
$frequency = $this->getData('groups/generate/fields/frequency/value');

$cronExprArray = [
(int)$time[1], //Minute
(int)$time[0], //Hour
(int)($time[1] ?? 0), //Minute
(int)($time[0] ?? 0), //Hour
$frequency == \Magento\Cron\Model\Config\Source\Frequency::CRON_MONTHLY ? '1' : '*', //Day of the Month
'*', //Month of the Year
$frequency == \Magento\Cron\Model\Config\Source\Frequency::CRON_WEEKLY ? '1' : '*', //# Day of the Week
Expand All @@ -102,7 +104,7 @@ public function afterSave()
self::CRON_MODEL_PATH
)->save();
} catch (\Exception $e) {
throw new \Exception(__('We can\'t save the cron expression.'));
throw new LocalizedException(__('We can\'t save the cron expression.'));
}
return parent::afterSave();
}
Expand Down

0 comments on commit cb375e7

Please sign in to comment.