Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
How to delete millions of CommerceWishList entries?
When I tried to upgrade Liferay from 7.1ga4 to 7.3ga6 i recognized that i have got more then 2 millions default entries in my CommerceWishList tables. First I don't know from where they are coming? Is there a script running in the background or is my server hacked?
Now I would like to delete the entries. I know it is strongly forbidden to delete them directly in the database. So I tried to delete the entries with a Groovy script. I figured out that the following script is working when there are only a few entries in the Database.
import com.liferay.commerce.wish.list.model.CommerceWishList;
import com.liferay.commerce.wish.list.service.CommerceWishListLocalServiceUtil;
import java.util.List;
CommerceWishListLocalServiceUtil.deleteCommerceWishListsByUserId(20120);
But when I try this Groovy script to delete the more then 2 million entries it does not work.
Have someone any Idee how I can delete these CommereceWishList entires in my database?
Thank you
Dieter
I found a solution to delete the entries with a javascript portlet which is using the Liferay.service() method. I created a liferay module project in my eclipse IDE with the mvc-portlet template. Then I added the following code to the view.jsp and deployed the portlet. Now I can enter the start and the end commerceWishListId in a form.
<%@ include file="/init.jsp" %>
<input id="start" label="Start"></input>
<input id="end" label="End"></input>
<button value='send' id="submit" onclick="myFunction()">Delete</button>
<script type="text/javascript">
function myFunction() {
const start = document.getElementById("start").value;
const end = document.getElementById("end").value;
for (var i = start; i < end; i++) {
console.log(i);
object = deleteWishlist(i);
console.log(object);
}
}
async function deleteWishlist(wlId) {
const response = await Liferay.Service(
'/commerce.commercewishlist/delete-commerce-wish-list',
{
commerceWishListId: wlId
},
function(obj) {
console.log(wlId + "deleted");
}
);
return(obj);
}
</script>
The program is working but sometimes it stops deleting after a few thousand entries. I hope a javascript expert can help me to improve the script. I think it's an issue with the async request.
Powered by Liferay™