matthiasblaesing commented on code in PR #53:
URL: https://github.com/apache/netbeans-tools/pull/53#discussion_r1004770741


##########
pp3/module/Application/src/Application/Controller/AdminController.php:
##########
@@ -326,6 +343,124 @@ public function nbVersionsAction() {
         ]);
     }
 
+    public function emailSendingAction() {
+        $this->_checkAdminUser();
+        $req = $this->request;
+        $successMessage = false;
+
+        $onlyVerified = false;
+        $nbVersionId = [];
+        $subject = '[NetBeans PluginPortal] <SUBJECT>';
+        $emailText = '
+<html>
+<head><title></title></head>
+<body>
+<p>Dear %1$s,</p>
+
+<p>we have some news for you.</p>
+
+<p>&lt;Your message&gt;</p>
+
+<p>
+Your plugins:<br />
+%3$s
+</p>
+
+<p>Direct link to the plugin portal:<br />
+<a href="%2$s">%2$s</a>
+</p>
+
+<p>
+Best wishes<br />
+NetBeans development team
+</p>
+
+<p>P.S.: Please contact [email protected] for questions.</p>
+</body>
+</html>';
+
+        if ($req->isPost() && ($this->params()->fromPost('sendEmail') || 
$this->params()->fromPost('sendPreview'))) {
+            $successMessage = '';
+            $onlyVerified = $this->params()->fromPost('onlyVerified');
+            $nbVersionId = $this->params()->fromPost('nbVersionId');
+            $subject = $this->params()->fromPost('subject');
+            $emailText = $this->params()->fromPost('emailText');
+
+            $users = [];
+
+            $plugins = $this->_pluginRepository
+                    ->getPluginsByNetBeansVersion($nbVersionId, $onlyVerified);
+
+            foreach ($plugins as $plugin) {
+                foreach ($plugin->getAuthors() as $author) {
+                    $email = $author->getEmail();
+                    if (!array_key_exists($email, $users)) {
+                        $users[$email] = [
+                            'email' => $email,
+                            'name' => $author->getName(),
+                            'plugins' => []
+                        ];
+                    }
+                    if (!in_array($plugin->getName(), 
$users[$email]['plugins'])) {
+                        $users[$email]['plugins'][] = $plugin->getName();
+                    }
+                }
+            }
+
+            $successMessage .= sprintf("Generating E-Mails for %d plugins and 
%d users<br>\n",
+                    count($plugins),
+                    count($users));
+
+            if ($this->params()->fromPost('sendPreview')) {
+                $successMessage .= "Only sending preview email!<br>\n";
+
+                /**
+                 * @var \Application\Entity\User
+                 */
+                $user = 
$this->_userRepository->find($this->getAuthenticatedUserId());
+                $users = [$user->getEmail() => [
+                    'email' => $user->getEmail(),
+                    'name' => $user->getName(),
+                    'plugins' => ['Demo plugin 1', 'Demo plugin 2']
+                ]];
+            }
+
+            $transport = new Mail\Transport\Sendmail();
+
+            $emailCount = 0;
+            foreach (array_values(($users)) as $entry) {
+                $emailCount++;
+                $list = "<ul>";
+                foreach($entry['plugins'] as $pluginName) {
+                    $list .= sprintf("<li>%s</li>", 
htmlspecialchars($pluginName));
+                }
+                $list .= "</ul>";
+
+                $mail = new Mail\Message();
+                $mail->setFrom('[email protected]', 'NetBeans 
webmaster');
+                $mail->setSubject($subject);
+                
$mail->getHeaders()->addHeader(ContentType::fromString('Content-Type: 
text/html; charset=utf-8'));
+                $mail->setBody(sprintf($emailText,
+                                htmlspecialchars($entry['name']),
+                                htmlspecialchars($this->getHomeUrl()),
+                                $list
+                ));
+                $mail->addTo($entry['email']);
+                $transport->send($mail);
+            }
+
+            $successMessage .= "E-Mails were successfully send: " . 
$emailCount;

Review Comment:
   Fixed - thankss



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to