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 2021/03/08 12:52:00 UTC

[GitHub] [netbeans-tools] jkovalsky commented on a change in pull request #44: Improve PP3

jkovalsky commented on a change in pull request #44:
URL: https://github.com/apache/netbeans-tools/pull/44#discussion_r589388576



##########
File path: pp3/module/Application/src/Application/Entity/Plugin.php
##########
@@ -116,6 +116,19 @@ private function updateVersions($versioning) {
         }
     }
 
+    public function removeAuthor($user) {
+        $this->authors->removeElement($user);
+    }
+
+    public function addAuthor($user) {

Review comment:
       Could return true/false if user was actually added or not which could then be reflected in both **Plugin/AdminControllers** by displaying "_Cannot add the same user twice._" information message.

##########
File path: pp3/module/Application/src/Application/Controller/AdminController.php
##########
@@ -404,60 +407,96 @@ private function _checkAdminUser() {
     public function editAction() {
         $this->_checkAdminUser();
         $pId = $this->params()->fromQuery('id');
-        $plugin = $this->_pluginRepository->find($pId);        
+        $plugin = $this->_pluginRepository->find($pId);
         if (!$plugin || empty($pId)) {
             return $this->redirect()->toRoute('admin');
         }
         $req = $this->request;
         if ($req->isPost()) {
-            $validatedData = $this->_validateAndCleanPluginData(
-                $this->params()->fromPost('name'),
-                $this->params()->fromPost('license'),
-                $this->params()->fromPost('description'),
-                $this->params()->fromPost('short_description'),
-                $this->params()->fromPost('category')
-            );
-            if ($validatedData) {
-                $plugin->setName($validatedData['name']);
-                $plugin->setLicense($validatedData['license']);
-                $plugin->setDescription($validatedData['description']);
-                $plugin->setShortDescription($validatedData['short_description']);
-                $plugin->setLastUpdatedAt(new \DateTime('now'));                
-
-                // save image
-                $im = $this->handleImgUpload($this->_config['pp3']['catalogSavepath'].'/plugins/'.$plugin->getId());
-                if ($im) {                    
-                    $plugin->setImage($im);
+            $queryString = "";
+            if ($this->params()->fromPost('addUserByEMail')) {
+                $queryString = '&activeTab=authors';
+                $users = $this->_userRepository->findByEmail($this->params()->fromPost('addUserByEMail'));
+                if (count($users) > 0) {
+                    foreach ($users as $user) {
+                        $plugin->addAuthor($user);
+                    }
+                    $this->flashMessenger()->setNamespace('success')->addMessage('Authors updated.');
+                    $this->_pluginRepository->persist($plugin);
+                } else {
+                    $this->flashMessenger()->setNamespace('error')->addMessage('No user found with specified address.');
                 }
+            } else if ($this->params()->fromPost('removeAuthor')) {
+                $queryString = '&activeTab=authors';
+                $user = $this->_userRepository->find($this->params()->fromPost('removeAuthor'));
+                if (!$user) {
+                    $this->flashMessenger()->setNamespace('error')->addMessage('No user found with specified id.');
+                } else {
+                    $plugin->removeAuthor($user);
+                    if (count($plugin->getAuthors()) > 0) {
+                        $this->_pluginRepository->persist($plugin);
+                        $this->flashMessenger()->setNamespace('success')->addMessage('Author was removed.');
+                    } else {
+                        $this->flashMessenger()->setNamespace('error')->addMessage('Last author can not be removed.');
+                    }
+                }
+            } else {
+                $validatedData = $this->_validateAndCleanPluginData(
+                        $this->params()->fromPost('name'),
+                        $this->params()->fromPost('license'),
+                        $this->params()->fromPost('description'),
+                        $this->params()->fromPost('short_description'),
+                        $this->params()->fromPost('category')
+                );
+                if ($validatedData) {
+                    $plugin->setName($validatedData['name']);
+                    $plugin->setLicense($validatedData['license']);
+                    $plugin->setDescription($validatedData['description']);
+                    $plugin->setShortDescription($validatedData['short_description']);
+                    $plugin->setLastUpdatedAt(new \DateTime('now'));
 
+                    // save image
+                    $im = $this->handleImgUpload($this->_config['pp3']['catalogSavepath'] . '/plugins/' . $plugin->getId());
+                    if ($im) {
+                        $plugin->setImage($im);
+                    }
 
-                // categ
-                $plugin->removeCategories();
-                $this->_pluginRepository->persist($plugin);
-                $cat = $this->_categoryRepository->find($validatedData['category']);
-                if ($cat) {
-                    $plugin->addCategory($cat);
-                }
-                $cat2 = $this->params()->fromPost('category2');
-                if ($cat2 && (!$cat || ($cat2 != $cat->getId()))) {
-                    $cat2 = $this->_categoryRepository->find($this->params()->fromPost('category2'));
-                    if ($cat2) {
-                        //die(var_dump($cat2, $plugin->getCategories()[1], $validatedData['category']));
-                        $plugin->addCategory($cat2);
+
+                    // categ
+                    $plugin->removeCategories();
+                    $this->_pluginRepository->persist($plugin);
+                    $cat = $this->_categoryRepository->find($validatedData['category']);
+                    if ($cat) {
+                        $plugin->addCategory($cat);
+                    }
+                    $cat2 = $this->params()->fromPost('category2');
+                    if ($cat2 && (!$cat || ($cat2 != $cat->getId()))) {
+                        $cat2 = $this->_categoryRepository->find($this->params()->fromPost('category2'));
+                        if ($cat2) {
+                            //die(var_dump($cat2, $plugin->getCategories()[1], $validatedData['category']));

Review comment:
       Commented out code should not be committed.




----------------------------------------------------------------
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.

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