Foros de discusión

RE: How to get Liferay to pickup mysql database changes

Nick Lindberg, modificado hace 11 años.

How to get Liferay to pickup mysql database changes

Junior Member Mensajes: 28 Fecha de incorporación: 5/01/12 Mensajes recientes
Hello,

I was able to get into the mysql lportal database and change the createDate on a bunch of web content I'd created, within the JournalArticle table. I verified that the new date was correct and did a

flush tables;

but I cannot seem to get Liferay to pick up to the changes, and if I modify the web content, the new article version object it creates in the database still copies the old createDate value from before me changing it.

Is it a no no to manually udpate database entries? I didn't know how else to do it, and I haven't been able to figure out how to get Liferay to pick up my changes.

Thanks--
Nick
thumbnail
David H Nebinger, modificado hace 11 años.

RE: How to get Liferay to pickup mysql database changes

Liferay Legend Mensajes: 14916 Fecha de incorporación: 2/09/06 Mensajes recientes
You should never update the database directly.

Try reindexing all search indices to see if that fixes your problem.
Nick Lindberg, modificado hace 11 años.

RE: How to get Liferay to pickup mysql database changes

Junior Member Mensajes: 28 Fecha de incorporación: 5/01/12 Mensajes recientes
David H Nebinger:
You should never update the database directly.

Try reindexing all search indices to see if that fixes your problem.


Is there a reason I should never update the database directly? I'm not sure how else to change the create date.

I'll try that and see if it works.
Nick Lindberg, modificado hace 11 años.

RE: How to get Liferay to pickup mysql database changes

Junior Member Mensajes: 28 Fecha de incorporación: 5/01/12 Mensajes recientes
Nick Lindberg:
David H Nebinger:
You should never update the database directly.

Try reindexing all search indices to see if that fixes your problem.


Is there a reason I should never update the database directly? I'm not sure how else to change the create date.

I'll try that and see if it works.


OK-- I reindexed the search indices and even cleared the database cache, all under the Server Administration tab of the control panel. No dice.

I guess I don't understand the relationship between the database and how Liferay stores objects in it. Once an object is created, does it rely on a local cache not within the database to get metadata?
thumbnail
David H Nebinger, modificado hace 11 años.

RE: How to get Liferay to pickup mysql database changes

Liferay Legend Mensajes: 14916 Fecha de incorporación: 2/09/06 Mensajes recientes
Nick Lindberg:
Nick Lindberg:
David H Nebinger:
You should never update the database directly.

Try reindexing all search indices to see if that fixes your problem.


Is there a reason I should never update the database directly? I'm not sure how else to change the create date.

I'll try that and see if it works.


OK-- I reindexed the search indices and even cleared the database cache, all under the Server Administration tab of the control panel. No dice.

I guess I don't understand the relationship between the database and how Liferay stores objects in it. Once an object is created, does it rely on a local cache not within the database to get metadata?


And that's the whole reason not to modify the database directly.

The Liferay database is not published for a reason. The reason is the API does significantly more stuff than just simple SQL insert statements. There are internally managed foreign keys, there are things which are updated not just in the database but also in the indices, in jackrabbit, etc.

Since all of this is managed by the code and not by the database, any updates to the code will change how and when the database is updated. Even if it did work for you in a 6.1 GA1 version, GA2 is coming out in a couple of weeks and the database/code may change again.

Sticking with the API is the only way to insure the changes are done correctly.
thumbnail
Amos Fong, modificado hace 11 años.

RE: How to get Liferay to pickup mysql database changes

Liferay Legend Mensajes: 2047 Fecha de incorporación: 7/10/08 Mensajes recientes
Agree with David, always use APIs when possible.

Also, you'll need to reindex AFTER you clear the database cache, either through server admin or restarting like Hitoshi says. Clearing from server admin should work, but restarting will for sure clear all caches.
thumbnail
Hitoshi Ozawa, modificado hace 11 años.

RE: How to get Liferay to pickup mysql database changes

Liferay Legend Mensajes: 7942 Fecha de incorporación: 24/03/10 Mensajes recientes
The "right" way is to create a portlet to modify the "createDate" using setCreateDate(Date createDate) method in JournalArticleModel. Liferay API actually updates the memory entity instead of directly updating the database. Database is updated in the background.

using http://docs.liferay.com/portal/6.1/javadocs/com/liferay/portlet/journal/model/JournalArticleModel.html
thumbnail
David H Nebinger, modificado hace 11 años.

RE: How to get Liferay to pickup mysql database changes

Liferay Legend Mensajes: 14916 Fecha de incorporación: 2/09/06 Mensajes recientes
Well, if all you're doing is bulk-changing some records, I see no harm in starting a portlet plugin to leverage the service builder interface and just process them all in bulk, w/o implementing the full blown interface... Web service client might be an option, but I don't know if the fields are visible through the web service api or not...
thumbnail
Hitoshi Ozawa, modificado hace 11 años.

RE: How to get Liferay to pickup mysql database changes

Liferay Legend Mensajes: 7942 Fecha de incorporación: 24/03/10 Mensajes recientes
"createDate" is an internal field and it's not visible by default to web service nor LocalServiceUtil's update.
Nick Lindberg, modificado hace 11 años.

RE: How to get Liferay to pickup mysql database changes

Junior Member Mensajes: 28 Fecha de incorporación: 5/01/12 Mensajes recientes
Hitoshi Ozawa:
The "right" way is to create a portlet to modify the "createDate" using setCreateDate(Date createDate) method in JournalArticleModel. Liferay API actually updates the memory entity instead of directly updating the database. Database is updated in the background.

using http://docs.liferay.com/portal/6.1/javadocs/com/liferay/portlet/journal/model/JournalArticleModel.html


I've found the setCreateDate() method and have been trying to figure out how to use it. The problem is that I only really need to do this for like 15 pieces of web content and I don't want to create a portlet just for that purpose, which is why I went with the direct database method.

Can I just create a run a .java file directly on the server, if I import the right libraries, or do I need to do it all through Liferay?
Nick Lindberg, modificado hace 11 años.

RE: How to get Liferay to pickup mysql database changes

Junior Member Mensajes: 28 Fecha de incorporación: 5/01/12 Mensajes recientes
Amos Fong:
Agree with David, always use APIs when possible.

Also, you'll need to reindex AFTER you clear the database cache, either through server admin or restarting like Hitoshi says. Clearing from server admin should work, but restarting will for sure clear all caches.


I've tried all of these-- clearing the cache then reindexing, restarting Liferay, etc-- none of it is picking up the new createDate I modified in the database.
thumbnail
Hitoshi Ozawa, modificado hace 11 años.

RE: How to get Liferay to pickup mysql database changes

Liferay Legend Mensajes: 7942 Fecha de incorporación: 24/03/10 Mensajes recientes
This probably means you've modified the wrong "createDate". Have to check the code to see which createDate is being used to display.
Nick Lindberg, modificado hace 11 años.

RE: How to get Liferay to pickup mysql database changes

Junior Member Mensajes: 28 Fecha de incorporación: 5/01/12 Mensajes recientes
Hitoshi Ozawa:
This probably means you've modified the wrong "createDate". Have to check the code to see which createDate is being used to display.


I dunno. It's the only one I found. The piece of web content has an article ID of 16332... and there are two revisions, which is why it's showing two objects in the following query. That looks right doesn't it?

mysql> SELECT createDate,modifiedDate,statusDate,displayDate,expirationDate,reviewDate FROM JournalArticle WHERE ArticleID = 16332;
+---------------------+---------------------+---------------------+---------------------+----------------+------------+
| createDate | modifiedDate | statusDate | displayDate | expirationDate | reviewDate |
+---------------------+---------------------+---------------------+---------------------+----------------+------------+
| 2012-03-08 15:17:12 | 2012-05-08 15:17:12 | 2012-05-08 15:17:12 | 2011-02-08 15:15:00 | NULL | NULL |
| 2012-03-08 15:17:12 | 2012-05-08 16:47:46 | 2012-05-08 16:47:46 | 2011-02-08 15:15:00 | NULL | NULL |
+---------------------+---------------------+---------------------+---------------------+----------------+------------+
2 rows in set (0.00 sec)


I changed the createDate to 2012-03-08 from 2012-05-08, but it still shows May 8th in my Asset Publisher after trying all of the refresh mechanisms.

Is it alot of work to create a new portlet that I can use to modify createDate?
Nick Lindberg, modificado hace 11 años.

RE: How to get Liferay to pickup mysql database changes

Junior Member Mensajes: 28 Fecha de incorporación: 5/01/12 Mensajes recientes
Figured it out. I also had to change the entry for the article in the table "AssetEntry" within the database. The way to find it is to do a lookup on the articleId within the JournalArticle table, and then to use the layoutUuid to search for the same entry in the AssetEntry table and change the createDate there as well.

Then clearing the cache and reindexing solves the problem.

Thanks for everybody's help. I'm going to add a wiki on how to do this. It's a quick and dirty hack to but gets the job done.

Here it is:

http://www.liferay.com/community/wiki/-/wiki/Main/Changing+the+metadata+%28like+createDate%29%20fields+on+Asset+Publisher+Web+Content
thumbnail
Hitoshi Ozawa, modificado hace 11 años.

RE: How to get Liferay to pickup mysql database changes

Liferay Legend Mensajes: 7942 Fecha de incorporación: 24/03/10 Mensajes recientes
Nice to hear that you got it working. Thanks for the wiki page! emoticon
thumbnail
Hitoshi Ozawa, modificado hace 11 años.

RE: How to get Liferay to pickup mysql database changes

Liferay Legend Mensajes: 7942 Fecha de incorporación: 24/03/10 Mensajes recientes
Have you tried restarting your server? This forces liferay to get data from the database.