-
-
Notifications
You must be signed in to change notification settings - Fork 128
Added a new method miniShop2::shootEmail
#933
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -905,27 +905,6 @@ public function changeOrderStatus($order_id, $status_id) | |
| } | ||
| } | ||
|
|
||
| $useScheduler = $this->modx->getOption('ms2_use_scheduler', null, false); | ||
| $task = null; | ||
| if ($useScheduler) { | ||
| /** @var Scheduler $scheduler */ | ||
| $path = $this->modx->getOption( | ||
| 'scheduler.core_path', | ||
| null, | ||
| $this->modx->getOption('core_path') . 'components/scheduler/' | ||
| ); | ||
| $scheduler = $this->modx->getService('scheduler', 'Scheduler', $path . 'model/scheduler/'); | ||
| if ($scheduler) { | ||
| $task = $scheduler->getTask('minishop2', 'ms2_send_email'); | ||
| if (!$task) { | ||
| $task = $this->createEmailTask(); | ||
| } | ||
| } else { | ||
| $useScheduler = false; | ||
| $this->modx->log(1, 'not found Scheduler extra'); | ||
| } | ||
| } | ||
|
|
||
| if ($status->get('email_manager')) { | ||
| $subject = $this->pdoTools->getChunk('@INLINE ' . $status->get('subject_manager'), $pls); | ||
| $tpl = ''; | ||
|
|
@@ -940,21 +919,7 @@ public function changeOrderStatus($order_id, $status_id) | |
| $this->modx->getOption('ms2_email_manager', null, $this->modx->getOption('emailsender')) | ||
| ) | ||
| ); | ||
| if (!empty($subject)) { | ||
| foreach ($emails as $email) { | ||
| if (preg_match('#.*?@#', $email)) { | ||
| if ($useScheduler && $task instanceof sTask) { | ||
| $task->schedule('+1 second', [ | ||
| 'email' => $email, | ||
| 'subject' => $subject, | ||
| 'body' => $body | ||
| ]); | ||
| } else { | ||
| $this->sendEmail($email, $subject, $body); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| $this->shootEmail($emails, $subject, $body); | ||
| } | ||
|
|
||
| if ($status->get('email_user')) { | ||
|
|
@@ -966,24 +931,78 @@ public function changeOrderStatus($order_id, $status_id) | |
| } | ||
| $body = $this->modx->runSnippet('msGetOrder', array_merge($pls, ['tpl' => $tpl])); | ||
| $email = $profile->get('email'); | ||
| if (!empty($subject) && preg_match('#.*?@#', $email)) { | ||
| if ($useScheduler && $task instanceof sTask) { | ||
| $task->schedule('+1 second', [ | ||
| 'email' => $email, | ||
| 'subject' => $subject, | ||
| 'body' => $body | ||
| ]); | ||
| } else { | ||
| $this->sendEmail($email, $subject, $body); | ||
| } | ||
| } | ||
| $this->shootEmail($email, $subject, $body); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Method of sending email depends on the settings | ||
| * | ||
| * @param array|string $emails | ||
| * @param string $subject | ||
| * @param string $body | ||
| * @param bool $force | ||
| * | ||
| * @return bool | ||
| */ | ||
| public function shootEmail($emails, $subject, $body = '', $force = false) | ||
| { | ||
| if (empty($subject) || empty($emails)) { | ||
| return false; | ||
| } | ||
| if (is_string($emails)) { | ||
| $emails = [$emails]; | ||
| } | ||
|
|
||
| $sTask = null; | ||
| if ($force === false && $this->modx->getOption('ms2_use_scheduler', null, false)) { | ||
| /** @var Scheduler $scheduler */ | ||
| $scheduler = $this->modx->getService('scheduler', 'Scheduler', | ||
| $this->modx->getOption('scheduler.core_path', null, MODX_CORE_PATH . 'components/scheduler/') . 'model/scheduler/' | ||
| ); | ||
| if ($scheduler) { | ||
| $sTask = $scheduler->getTask('minishop2', 'ms2_send_email'); | ||
| if (empty($sTask)) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Три вложенных друг в друга if выглядят не очень хорошо.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Чиво?) |
||
| $sTask = $this->modx->newObject('sFileTask'); | ||
| $sTask->fromArray([ | ||
| 'class_key' => 'sFileTask', | ||
| 'content' => '/tasks/sendEmail.php', | ||
| 'namespace' => 'minishop2', | ||
| 'reference' => 'ms2_send_email', | ||
| 'description' => 'MiniShop2 Email' | ||
| ]); | ||
| if (!$sTask->save()) { | ||
| $sTask = null; | ||
| } | ||
| } | ||
| } else { | ||
| $this->modx->log(1, 'Not found Scheduler extra'); | ||
| } | ||
| } | ||
|
|
||
| $result = false; | ||
| foreach ($emails as $email) { | ||
| if (preg_match('#.*?@#', $email)) { | ||
| if ($sTask instanceof sTask) { | ||
| $sTask->schedule('+1 second', [ | ||
| 'email' => $email, | ||
| 'subject' => $subject, | ||
| 'body' => $body | ||
| ]); | ||
| $result = true; | ||
| } else { | ||
| $result = $this->sendEmail($email, $subject, $body); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return $result; | ||
| } | ||
|
|
||
| /** | ||
| * Function for sending email | ||
| * | ||
|
|
@@ -1307,24 +1326,4 @@ protected function updateSetting($key, $value) | |
| $setting->set('value', json_encode($value)); | ||
| $setting->save(); | ||
| } | ||
|
|
||
| /** | ||
| * Creating Sheduler's task for sending email | ||
| * @return false|object|null | ||
| */ | ||
| private function createEmailTask() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Не очень понял, почему тут удален метод? Как будет исполняется его функционал?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Может стоить весь код правок посмотреть, прежде чем задавать такие вопросы? |
||
| { | ||
| $task = $this->modx->newObject('sFileTask'); | ||
| $task->fromArray([ | ||
| 'class_key' => 'sFileTask', | ||
| 'content' => '/tasks/sendEmail.php', | ||
| 'namespace' => 'minishop2', | ||
| 'reference' => 'ms2_send_email', | ||
| 'description' => 'MiniShop2 Email' | ||
| ]); | ||
| if (!$task->save()) { | ||
| return false; | ||
| } | ||
| return $task; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
тут было бы эффективнее написать if (!$force
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Эффективнее?) Про типы данных не слышал, видимо?