掲示板

How to delete an asset directly from database?

thumbnail
7年前 に Abhishek Jain によって更新されました。

How to delete an asset directly from database?

Regular Member 投稿: 226 参加年月日: 16/08/20 最新の投稿
I made some custom assets and deleted those assets from the entity(Slogan3) table as well as the assetentries table but the database has become inconsistent. When I make a search in the search portlet for the custom asset which are deleted then it gives me error as NoSuchSlogan3Exception where Slogan3 is the name of entity. Please tell me what can I do to make the database consistent. From which other tables I have to remove the asset entries manually? Please help...thanks in advance..
thumbnail
7年前 に David H Nebinger によって更新されました。

RE: How to delete an asset directly from database?

Liferay Legend 投稿: 14914 参加年月日: 06/09/02 最新の投稿
Abhishek Jain:
I deleted those assets from the entity(Slogan3) table as well as the assetentries table but the database has become inconsistent.


Please tell me what can I do to make the database consistent.


Rule #1 in Liferay - never touch the database directly. This is for a reason. You will never completely understand what a seemingly simple CRUD action actually does.

How to fix? Restore the DB back to a place before you deleted anything.
thumbnail
6年前 に Mahmoud Elsonbati によって更新されました。

RE: How to delete an asset directly from database?

New Member 投稿: 22 参加年月日: 14/12/10 最新の投稿
I am following role number 1 .. Now what is the best way to delete test cases custom assets?
thumbnail
6年前 に David H Nebinger によって更新されました。

RE: How to delete an asset directly from database?

Liferay Legend 投稿: 14914 参加年月日: 06/09/02 最新の投稿
You don't worry about it. A test database is not going to be your production database and therefore it opens the door to things such throwing it out and starting over or restoring from a saved version.
thumbnail
6年前 に Mahmoud Elsonbati によって更新されました。

RE: How to delete an asset directly from database?

New Member 投稿: 22 参加年月日: 14/12/10 最新の投稿
My client had the live testing and they want to delete it on production database
thumbnail
6年前 に Olaf Kock によって更新されました。

RE: How to delete an asset directly from database?

Liferay Legend 投稿: 6396 参加年月日: 08/09/23 最新の投稿
Mahmoud Elsonbati:
My client had the live testing and they want to delete it on production database


Implement the proper delete operation in your custom Asset-Entity. This should in turn use the API to delete all related entities that have been created during creation of this asset (look at the code used in creation, candidates are the asset-tables itself, tags and category mappings, permissions and full text indexes. Whatever related assets you created earlier need to be removed as well. And, of course, you'll do that through the API to still adhere to rule #1.
thumbnail
6年前 に Mahmoud Elsonbati によって更新されました。

RE: How to delete an asset directly from database?

New Member 投稿: 22 参加年月日: 14/12/10 最新の投稿
Is there any documentation or detailed example in this regard to follow?
thumbnail
6年前 に Olaf Kock によって更新されました。

RE: How to delete an asset directly from database?

Liferay Legend 投稿: 6396 参加年月日: 08/09/23 最新の投稿
Mahmoud Elsonbati:
Is there any documentation or detailed example in this regard to follow?


Let's start with the basics: You have followed up on a thread where OP has created a custom asset class and wants to delete this. Is this exactly your situation? If it is: Creating the Asset class is quite some work, which is well documented. Take a look at the samples where you learned how to implement the Asset Framework. And take a look at the add method(s) in your implementation.

If this isn't your situation: Describe it.
thumbnail
6年前 に Mahmoud Elsonbati によって更新されました。

RE: How to delete an asset directly from database?

New Member 投稿: 22 参加年月日: 14/12/10 最新の投稿
Thank you

i found it

let say my entity is Order..so i have to delete it from the database plus two other places 1- the asset entries 2- the workflow instance


Order order = OrderLocalServiceUtil.fetchOrder(orderId);
if (order != null) {
OrderLocalServiceUtil.deleteOrder(order);
}

AssetEntryLocalServiceUtil.deleteEntry(Order.class.getName(), order.getClassPK());

WorkflowInstanceLinkLocalServiceUtil.deleteWorkflowInstanceLinks(order.getCompanyId(), order.getGroupId(), Order.class.getName(), order.getClassPK());


below are the affected db tables along with the createdcustom table

for asset entry
assetentry

and for workflow
kaleoinstance
kaleoinstancetoken
kaleotaskinstancetoken
kaleotaskassignmentinstance
kaleolog
thumbnail
6年前 に Olaf Kock によって更新されました。

RE: How to delete an asset directly from database?

Liferay Legend 投稿: 6396 参加年月日: 08/09/23 最新の投稿
Mahmoud Elsonbati:
let say my entity is Order..so i have to delete it from the database plus two other places 1- the asset entries 2- the workflow instance


Wrong words, correct code: You will have to delete the AssetEntries and the WorkflowInstanceLinks (it might be that the later is included in the first ones - can't tell). But you won't have to delete anything from the database. I'm stating it this way because thinking in terms of "deleting columns in the database" is dangerous and prone to execute SQL on those columns - which you shouldn't do.

As of the tables that you list: I refuse to even look up if they are all or if you're missing any, because that level of detail is just one that you shouldn't look at ever. And I'm assuming that it's incorrect, just for that reason. Don't ask me for a correct number of tables because I don't know and refuse to find out. The basic assumption is: Whenever you think you've nailed anything in Liferay's database, someone would be able to prove that you were wrong, but as everybody refuses to do so, you'll only recognize it when your production system goes down a year later.

Yes, I'm drastic here. Because I've seen too many problems introduced by people who assumed they've understood Liferay's data storage. All of them failed sooner or later. Some knew it, some have left the project since and didn't get the feedback that they made a big mistake earlier.
thumbnail
6年前 に Mahmoud Elsonbati によって更新されました。

RE: How to delete an asset directly from database?

New Member 投稿: 22 参加年月日: 14/12/10 最新の投稿
Sorry for expressing it wrongly what i meant is deleting the entity from database using only the API as i mentioned in the code already and not going to the database tables directly
it is too risky to hit the database directly and even if it worked it might not work with the next update of the portal
thumbnail
6年前 に Olaf Kock によって更新されました。

RE: How to delete an asset directly from database?

Liferay Legend 投稿: 6396 参加年月日: 08/09/23 最新の投稿
Mahmoud Elsonbati:
Sorry for expressing it wrongly what i meant is deleting the entity from database using only the API as i mentioned in the code already and not going to the database tables directly
it is too risky to hit the database directly and even if it worked it might not work with the next update of the portal


Now it's all the right words emoticon

I didn't mean to criticize, just wanted to make 100% sure for others who are reading here in future, what is the actual method to manipulate Liferay data (again: yes, "Liferay's data", not "Liferay's database")
4年前 に Gabor Nagy によって更新されました。

RE: How to delete an asset directly from database?

New Member 投稿: 4 参加年月日: 17/05/31 最新の投稿
David H Nebinger::

Rule #1 in Liferay - never touch the database directly. This is for a reason. You will never completely understand what a seemingly simple CRUD action actually does.

I understand why you might say that to newcomers but this is no rule in real life since Liferay tend to fuck its own database up. I have some migration experience where database knowledge is crucial because it seems Liferay devs were reluctant to develop their own migration tool well. Honestly, without database manipulation we could not even complete our projects. And Migration is a regular job to do with Liferay ... so yeah, DB knowledge is pretty much crucial.
thumbnail
4年前 に David H Nebinger によって更新されました。

RE: How to delete an asset directly from database?

Liferay Legend 投稿: 14914 参加年月日: 06/09/02 最新の投稿
Migration is an edge case that may require database knowledge, but most of the time I think you can do a migration without direct DB knowledge. Tables need to migrate, column types need correct coercion, but it doesn't require a deep dive into the relationships, etc. when migrating, you're just (or should only be) moving all data as is, not making any changes in the process.

But it is a solid rule that any Liferay developer should not go mucking around in the database. It is way too easy to think you know something about the data, the structures, the relationships, etc. that is incorrect.

Plus there's the indexes to worry about since a direct database modification will not update. And since Liferay caches all data retrieved, running Liferay nodes will not be aware of any live database modifications which will lead to stale data issues.

I've heard this kind of thing before, "we need to know how the database works", "we need to change the db directly", "we shouldn't have to use the apis", etc. I get that as a developer it always seems easier to craft a quick SQL statement to change data directly rather than write code or scripts to invoke the Liferay APIs.

I push and stand behind this "no direct db modification" because, with my years of experience, I know and have seen people corrupt their database because they thought they knew what they were doing.

And honestly there is no support for CE admins or even EE/DXP admins when they have made direct DB modifications. The only option available is a database restore to fix the broken system.  This is often an issue because sometimes backups aren't taken, but other times the backup is too old and restoring the backup loses data that had been correctly added to the system.

So yes, there are going to be edge cases such as DB migration where you might argue that DB knowledge is necessary, but that doesn't invalidate the rule nor should the existence of a rule exception invalidate the rule completely.