Fórumok

Page connected to page template lost their web content after template is ed

Mattia Possenti, módosítva 11 év-val korábban

Page connected to page template lost their web content after template is ed

Junior Member Bejegyzések: 35 Csatlakozás dátuma: 2011.04.19. Legújabb bejegyzések
Hello,
I'm facing the issue in the object that is a known bug LPS-32850 on Liferay 6.1.1 GA2
I have enabled the property hibernate.show_sql=true to see which queries are called. I have seen this query:

update PortletPreferences set ownerId=?, ownerType=?, plid=?, portletId=?, preferences=? where portletPreferencesId=?

After this query is executed the record that contains the mapping between the articleId and the layout in the preferences column of the portletPreferences table is erased.
The strange thing is that this query is called when it is executed this line requestDispatcher.forward(request, response); in the FriendlyURLServlet.java class

How can be possible that a forward made an update?
Someone of you know something more about this issue? When it will be fixed?

Thanks

Mattia
thumbnail
Diego Pietralunga, módosítva 11 év-val korábban

RE: Page connected to page template lost their web content after template i

New Member Bejegyzések: 17 Csatlakozás dátuma: 2009.08.04. Legújabb bejegyzések
Hi Mattia,

I confirm this issue on 6.1 GA1 too. (see this thread http://www.liferay.com/community/forums/-/message_boards/message/21852764)
Nice analisys of the problem, but I didn't go as deep as you into searching.
I'll try to have a look at the code, if possible to at least find a workaround; meanwhile, please log in and _vote_ for the resolution of issue

http://issues.liferay.com/browse/LPS-32850

Thanks emoticon

Diego
Mattia Possenti, módosítva 11 év-val korábban

RE: Page connected to page template lost their web content after template i

Junior Member Bejegyzések: 35 Csatlakozás dátuma: 2011.04.19. Legújabb bejegyzések
Hi Diego,
I've voted for the resolution of this issue.
I hope it will be fixed soon because this is really a big bug!
I'm working in ext environment and I've try a couple of workaround, but no one of them worked because every time I refresh the page that is linked to the template, the link to the content is erased.

Mattia
thumbnail
Diego Pietralunga, módosítva 10 év-val korábban

RE: Page connected to page template lost their web content after template i

New Member Bejegyzések: 17 Csatlakozás dátuma: 2009.08.04. Legújabb bejegyzések
Hi Mattia,

are you still struggling with this bug?
Did you discover anything useful?

I hunted down this little monster during Easter vacation... it was quite frustrating...
BUT

i think I'm on the right track for a possible solution.
Well, now it's more like a hack, and in the process of trasforming it into a workaround.

Let me know if I can give you some help if still worthy; you told that you were on ext environment.
I was thinking of going that way but never done before. Can you help explaining a little bit, perhaps?

Keep in mind that I'm using 6.1 GA1 at the moment.

Diego
Mattia Possenti, módosítva 10 év-val korábban

RE: Page connected to page template lost their web content after template i

Junior Member Bejegyzések: 35 Csatlakozás dátuma: 2011.04.19. Legújabb bejegyzések
Hi Diego,
thank you for your help.
I am using Liferay 6.1.1 GA2

I absolutely need that this issue will be fixed. I am developing some extra SEO features for Liferay and I'm working mainly on ext environment.
I would try to use the template feature to quickly develop websites. I've discovered this bug while I was developing a portlet to manage menu in a different way.
I've try to bypass this bug in different ways, for example rewriting the column preference in PortetPreferences table whenever I edit the template, but unfortunately when you refresh the page that has the template associated, the update query is executed and it delete my modifications.

I've seen that the template deletes content when you change the configuration of any portlet in the template too, not only when you add/delete/move a portlet in the template.

I still haven't found a workaround to this issue. If you have something in mind that can be useful, let me know.
If my explanation wasn't too clear and you want some more informations about I would like to use the template feature, just let me know emoticon

Thanks again

Mattia
thumbnail
Diego Pietralunga, módosítva 10 év-val korábban

RE: Page connected to page template lost their web content after template i

New Member Bejegyzések: 17 Csatlakozás dátuma: 2009.08.04. Legújabb bejegyzések
Mattia,

sorry for being late, today I had some other work to do...

I _guess_ i DID IT!.

TOMORROW, I'll try to post a detailed log of what I achieved and how (not perfect but we can work together if you like)

Basically the page propagation mechanism in Liferay (6.1) is based on a check on every site page reload of the modification date of the applied
Page template, BUT via a method interceptor ( :-O ), namely an 'advice' to that call that checks for propagation to happen.

The culprit is in SitesUtil.java, called by that 'advice'.

The method copyPreferences copyPortletSetups applies a HARD propagation of many configs, including portle setups.
My solution differentiates this in case it encounters a WCD making propagation SOFT.

Hope is enough for now, see you tomorrow for sharing the implementation details emoticon

Bye!

Diego

P.S.= In my previous post I was asking if you can help me adopt the EXT plugins practice since I've never done it before (using Eclipse Juno and Liferay DE 1.6.0 btw)
What I plan to do, if possible and advisable, is to use an ext deploy to subsitute/override the 'offending' code, since thet code is not hookable/extensible the LR-way
Mattia Possenti, módosítva 10 év-val korábban

RE: Page connected to page template lost their web content after template i

Junior Member Bejegyzések: 35 Csatlakozás dátuma: 2011.04.19. Legújabb bejegyzések
Hi Diego,
I had some work to do till now. I'm going to take a look at your suggestions.
I'll be available for some help in the ext development emoticon

I'll be back with some feedback asap.

Mattia
thumbnail
Diego Pietralunga, módosítva 10 év-val korábban

RE: Page connected to page template lost their web content after template i

New Member Bejegyzések: 17 Csatlakozás dátuma: 2009.08.04. Legújabb bejegyzések
Hey Mattia!

I finally had some time to assemble something workable.
I only hope I didn't make some late night errors... emoticon

I coded a replacement of copyPortletSetups in SiteUtils.java against LR 6.1 GA1 CE, then compiled and redeployed portal.
I also added a control to actually allow propagation, if editor wants.
It's not perfect and it's not fully tested but...WORKS4ME for now emoticon
If you decide to use it, check against your actual codebase, should be very similar.

See comments inside code and let me know what you think.
EDIT: This code preserves/propagates ALL setup properties (does not filter)



//Replaced method
	public static void copyPortletSetups(
			Layout sourceLayout, Layout targetLayout)
		throws Exception {

		LayoutTypePortlet sourceLayoutTypePortlet =
			(LayoutTypePortlet)sourceLayout.getLayoutType();

		List<string> sourcePortletIds = sourceLayoutTypePortlet.getPortletIds();

		
		System.out.println("Page Template:Checking portlet IDs:"+ sourcePortletIds);
		
		for (String sourcePortletId : sourcePortletIds) {
			
			PortletPreferences sourcePreferences =
				PortletPreferencesFactoryUtil.getPortletSetup(
					sourceLayout, sourcePortletId, null);

				
			//This piece of code tries to avoid issue http://issues.liferay.com/browse/LPS-32850
			//Originally posted on http://www.liferay.com/community/forums/-/message_boards/view_message/23294618
			
			//Direct patch applied to portal code on SitesUtil.java. Need to recompile e redeploy portal. Backup!
			//Compiled and run on JDK 1.6.0_23
			//ToDo: Check if EXT deploy is possible/advisable...
			
			//Applied only on LR 6.1 GA1 CE; WORKS4ME, untested on other platforms, might have unwanted side effects.
			
			//Issue:
			//Web Content Displays (Journals) on a Page Template that have a specific instance setup (i.e. linked to an article by an editor) 
			//should not be blindly overridden by page prototype changes.
			
			//In plain words: 
			//If this (prototyped) page has had a layout prototype change, apply a "soft" propagation 
			//for WCD-only setups and preserve article and template unless specifically specified in WCD custom attribute PAGE_TEMPLATE_PROPAGATION_ALLOWED (to be added manually)
			
			//ToDo:Might check to propagate selected properties...
			
			//ToDo: Remove DEBUG statements in production
			////**************************************************
			
			//Get TARGET portlet preferences.
			PortletPreferences targetPreferences =
				PortletPreferencesFactoryUtil.getPortletSetup(
					targetLayout, sourcePortletId, null);
				
			System.out.println("DEBUG: Page Template: Checking Page Template propagation for:"+ sourcePortletId );
			
			String currentWCDArticleId = "";	
			//Are we talking about a WCD?
			if (sourcePortletId.startsWith("56_") ) { //"manual" check of portlet type; "56_" is in the beginning of WCD instances. ToDo: Check for API replacement
				
				currentWCDArticleId = targetPreferences.getValue("articleId", "");  //Check for article ID in this WCD setup
				System.out.println("DEBUG: Page Template: Article ID:'"+ currentWCDArticleId +"'");
				
				if (Validator.isNotNull(currentWCDArticleId) ) { //Is this WCD already linked to an article?
					
					long groupId = targetLayout.getGroupId();
					System.out.println("Page Template: Group:"+ groupId);
					
					//Note: Used full package names to be cut-n-paste-ready. Use imports in production	
					//import com.liferay.portlet.journal.model.JournalArticle;
					//import com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil;
					 com.liferay.portlet.journal.model.JournalArticle journalArticle = 
						com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil.getArticle(groupId, currentWCDArticleId);
						
					//JournalArticle journalArticle = JournalArticleLocalServiceUtil.getArticle(groupId, currentWCDArticleId);
						
					//Search for a custom attribute (Boolean) added to WCDs that allows propagation from original Page Template. 
					//Should default to false when added in Control Panel for WCDs.
					Object wcdPropagationBool = journalArticle.getExpandoBridge().getAttribute("PAGE_TEMPLATE_PROPAGATION_ALLOWED");
					
					//WARNING: This INVERTS default behavior!
					//Has this WCD/Portal a custom attribute that might prevent page template "hard" propagation? 
					//If NOT, _preserve_ current WCD setup
					if (wcdPropagationBool  == null ) { 
						System.out.println("DEBUG: Page Template: Missing PAGE_TEMPLATE_PROPAGATION_ALLOWED attribute for:"+ sourcePortletId + "\nSkipping propagation ANYWAY...");
						continue; //skip this portlet, get to next
					}
					//Has the editor/designer decided to purposefully override this specific WCD setup during page template modification via WCD _custom_ attribute?
					 boolean isPageTemplatePropagationAllowed =(Boolean) wcdPropagationBool ; //Boolean.parseBoolean( ( wcdPropagationBool );
					 
					 if (!isPageTemplatePropagationAllowed){
						System.out.println("DEBUG: Page Template: Propagation NOT allowed for WCD ID :"+ sourcePortletId + "\nSkipping propagation...");
						continue;  //skip this portlet, get to next
					 }else{
						System.out.println("DEBUG: Page Template: Propagation IS allowed for WCD ID :"+ sourcePortletId + "\nPrototype setup will overwrite this WCD setup.");
					 }
				}
			}//End if check WCD propagation			
			else{
				System.out.println("DEBUG: Page Template: Default Propagation for :"+ sourcePortletId + "\nPrototype setup will overwrite this PORTLET setup.");
			}
			PortletPreferencesImpl sourcePreferencesImpl =
				(PortletPreferencesImpl)sourcePreferences;

		

			PortletPreferencesImpl targetPreferencesImpl =
				(PortletPreferencesImpl)targetPreferences;

				java.util.Enumeration<string> targetPrefNames1 = targetPreferencesImpl.getNames();
			/*
				while (targetPrefNames1.hasMoreElements()) {
					String prefName = (String) targetPrefNames1.nextElement();
					System.out.println("Page Template 1: sourcePortletId:"+sourcePortletId + "has preference:"+ prefName+ " =&gt; VALUE="+targetPreferencesImpl.getValue(prefName, "NONE"));
				}	
			*/

				
							
				
			PortletPreferencesLocalServiceUtil.updatePreferences(
				targetPreferencesImpl.getOwnerId(),
				targetPreferencesImpl.getOwnerType(),
				targetPreferencesImpl.getPlid(), sourcePortletId,
				sourcePreferences);

			if ((sourcePreferencesImpl.getOwnerId() !=
					PortletKeys.PREFS_OWNER_ID_DEFAULT) &amp;&amp;
				(sourcePreferencesImpl.getOwnerType() !=
					PortletKeys.PREFS_OWNER_TYPE_LAYOUT)) {

					
					System.out.println("DEBUG: Page Template: Checking Page Template propagation (Owner) for:"+ sourcePortletId );
				sourcePreferences =
					PortletPreferencesFactoryUtil.getLayoutPortletSetup(
						sourceLayout, sourcePortletId);

				sourcePreferencesImpl =
					(PortletPreferencesImpl)sourcePreferences;

				targetPreferences =
					PortletPreferencesFactoryUtil.getLayoutPortletSetup(
						targetLayout, sourcePortletId);

				targetPreferencesImpl =
					(PortletPreferencesImpl)targetPreferences;

			/*		
				java.util.Enumeration<string> targetPrefNames = targetPreferencesImpl.getNames();
			
				while (targetPrefNames.hasMoreElements()) {
					String prefName = (String) targetPrefNames.nextElement();
					System.out.println("Page Template: sourcePortletId:"+sourcePortletId + "has preference:"+ prefName);
				}
			*/
					
				PortletPreferencesLocalServiceUtil.updatePreferences(
					targetPreferencesImpl.getOwnerId(),
					targetPreferencesImpl.getOwnerType(),
					targetPreferencesImpl.getPlid(), sourcePortletId,
					sourcePreferences);
			}
		
		}//End main for
	}
</string></string></string>



Bye.

Diego
Mattia Possenti, módosítva 10 év-val korábban

RE: Page connected to page template lost their web content after template i

Junior Member Bejegyzések: 35 Csatlakozás dátuma: 2011.04.19. Legújabb bejegyzések
Hi Diego,
I don't know how to thank you!!! emoticon
Your patch seems working great.

I've put the patch in ext environment on my Liferay 6.1.1 CE GA2 and it works!
I will make some other tests to check if it works always, because I've tested it only on staging environment.

If I will find some other issues I will report here.

Thanks a lot again!

Mattia
Mattia Possenti, módosítva 10 év-val korábban

RE: Page connected to page template lost their web content after template i

Junior Member Bejegyzések: 35 Csatlakozás dátuma: 2011.04.19. Legújabb bejegyzések
Ok, I've found an issue with this patch.
I've tested it with staging environment activated and everything works fine till I don't publish the page to live.
When I publish the page to live and I change the template, the modifications are not propagated in the staging environment.

I try to improve your patch to fix this too emoticon

Mattia
thumbnail
Diego Pietralunga, módosítva 10 év-val korábban

RE: Page connected to page template lost their web content after template i

New Member Bejegyzések: 17 Csatlakozás dátuma: 2009.08.04. Legújabb bejegyzések
Mattia Possenti:

When I publish the page to live and I change the template, the modifications are not propagated in the staging environment.



Yeah, that's for sure.
I don't work in Staging (for now) and didn't take care of that aspect at all.

Let me know your updates on this

Then maybe, we can share some Liferay knowledge,maybe in our main language emoticon

P.S.=I'm from Parma.

Diego
Mattia Possenti, módosítva 10 év-val korábban

RE: Page connected to page template lost their web content after template i

Junior Member Bejegyzések: 35 Csatlakozás dátuma: 2011.04.19. Legújabb bejegyzések
Diego Pietralunga:

Then maybe, we can share some Liferay knowledge,maybe in our main language emoticon


Yes, for sure! emoticon

Diego Pietralunga:

P.S.=I'm from Parma.


I'm from Milano

Mattia
thumbnail
Diego Pietralunga, módosítva 10 év-val korábban

RE: Page connected to page template lost their web content after template i

New Member Bejegyzések: 17 Csatlakozás dátuma: 2009.08.04. Legújabb bejegyzések
That's great Mattia emoticon

Let's try to make something useful together with this thing. emoticon

Diego