You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2022/10/25 16:51:14 UTC

[GitHub] [netbeans-tools] jkovalsky commented on a diff in pull request #53: Add E-Mail sending option for Pluginportal Admins

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


##########
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 dev@netbeans.apache.org 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('noreply@netbeans.apache.org', '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:
   Typo. Should read "_E-mails were successfully sent:_"



-- 
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: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

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