Pearl1594 commented on code in PR #12439:
URL: https://github.com/apache/cloudstack/pull/12439#discussion_r2695848867


##########
server/src/main/java/com/cloud/user/AccountManagerImpl.java:
##########
@@ -1221,6 +1221,30 @@ public int compare(NetworkVO network1, NetworkVO 
network2) {
         }
     }
 
+    private void cleanupAccountUserData(AccountVO account) {
+        long accountId = account.getId();
+        List<UserDataVO> userData = userDataDao.listByAccountId(accountId);
+        if (CollectionUtils.isEmpty(userData)) {
+            return;
+        }
+        logger.info("Deleting {} registered UserData for Account {}", 
userData.size(), account);
+        for (UserDataVO userdata : userData) {
+            List<VMTemplateVO> templatesLinkedToUserdata = 
_templateDao.findTemplatesLinkedToUserdata(userdata.getId());
+            if (CollectionUtils.isEmpty(templatesLinkedToUserdata)) {
+                continue;
+            }
+            for (VMTemplateVO template : templatesLinkedToUserdata) {
+                logger.debug("Unregistering UserData {} from Template {}", 
userdata, template);
+                template.setUserDataId(null);
+                template.setUserDataLinkPolicy(null);
+                _templateDao.update(template.getId(), template);
+            }
+            userDataDao.remove(userdata.getId());
+        }
+        int userDataRemoved = userDataDao.removeByAccountId(accountId);

Review Comment:
   Do you think that the userDataDao.remove(..) performed on L1242 will affect 
the result of userDataDao.removeByAccountId(..) in other words, do we need it 
being done twice?



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

Reply via email to