Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Mattia Possenti
Page connected to page template lost their web content after template is ed
March 21, 2013 2:54 AM
Answer

Mattia Possenti

Rank: Junior Member

Posts: 35

Join Date: April 19, 2011

Recent Posts

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
Diego Pietralunga
RE: Page connected to page template lost their web content after template i
March 25, 2013 10:33 AM
Answer

Diego Pietralunga

Rank: New Member

Posts: 17

Join Date: August 4, 2009

Recent Posts

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
RE: Page connected to page template lost their web content after template i
March 26, 2013 2:10 AM
Answer

Mattia Possenti

Rank: Junior Member

Posts: 35

Join Date: April 19, 2011

Recent Posts

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
Diego Pietralunga
RE: Page connected to page template lost their web content after template i
April 2, 2013 4:14 AM
Answer

Diego Pietralunga

Rank: New Member

Posts: 17

Join Date: August 4, 2009

Recent Posts

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
RE: Page connected to page template lost their web content after template i
April 2, 2013 5:22 AM
Answer

Mattia Possenti

Rank: Junior Member

Posts: 35

Join Date: April 19, 2011

Recent Posts

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
Diego Pietralunga
RE: Page connected to page template lost their web content after template i
April 2, 2013 10:40 AM
Answer

Diego Pietralunga

Rank: New Member

Posts: 17

Join Date: August 4, 2009

Recent Posts

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
RE: Page connected to page template lost their web content after template i
April 3, 2013 5:55 AM
Answer

Mattia Possenti

Rank: Junior Member

Posts: 35

Join Date: April 19, 2011

Recent Posts

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
Diego Pietralunga
RE: Page connected to page template lost their web content after template i
April 3, 2013 3:25 PM
Answer

Diego Pietralunga

Rank: New Member

Posts: 17

Join Date: August 4, 2009

Recent Posts

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)

  1
  2
  3//Replaced method
  4    public static void copyPortletSetups(
  5            Layout sourceLayout, Layout targetLayout)
  6        throws Exception {
  7
  8        LayoutTypePortlet sourceLayoutTypePortlet =
  9            (LayoutTypePortlet)sourceLayout.getLayoutType();
 10
 11        List<String> sourcePortletIds = sourceLayoutTypePortlet.getPortletIds();
 12
 13       
 14        System.out.println("Page Template:Checking portlet IDs:"+ sourcePortletIds);
 15       
 16        for (String sourcePortletId : sourcePortletIds) {
 17            
 18            PortletPreferences sourcePreferences =
 19                PortletPreferencesFactoryUtil.getPortletSetup(
 20                    sourceLayout, sourcePortletId, null);
 21
 22               
 23            //This piece of code tries to avoid issue http://issues.liferay.com/browse/LPS-32850
 24            //Originally posted on http://www.liferay.com/community/forums/-/message_boards/view_message/23294618
 25            
 26            //Direct patch applied to portal code on SitesUtil.java. Need to recompile e redeploy portal. Backup!
 27            //Compiled and run on JDK 1.6.0_23
 28            //ToDo: Check if EXT deploy is possible/advisable...
 29            
 30            //Applied only on LR 6.1 GA1 CE; WORKS4ME, untested on other platforms, might have unwanted side effects.
 31            
 32            //Issue:
 33            //Web Content Displays (Journals) on a Page Template that have a specific instance setup (i.e. linked to an article by an editor)
 34            //should not be blindly overridden by page prototype changes.
 35            
 36            //In plain words:
 37            //If this (prototyped) page has had a layout prototype change, apply a "soft" propagation
 38            //for WCD-only setups and preserve article and template unless specifically specified in WCD custom attribute PAGE_TEMPLATE_PROPAGATION_ALLOWED (to be added manually)
 39            
 40            //ToDo:Might check to propagate selected properties...
 41            
 42            //ToDo: Remove DEBUG statements in production
 43            ////**************************************************
 44            
 45            //Get TARGET portlet preferences.
 46            PortletPreferences targetPreferences =
 47                PortletPreferencesFactoryUtil.getPortletSetup(
 48                    targetLayout, sourcePortletId, null);
 49               
 50            System.out.println("DEBUG: Page Template: Checking Page Template propagation for:"+ sourcePortletId );
 51            
 52            String currentWCDArticleId = "";   
 53            //Are we talking about a WCD?
 54            if (sourcePortletId.startsWith("56_") ) { //"manual" check of portlet type; "56_" is in the beginning of WCD instances. ToDo: Check for API replacement
 55               
 56                currentWCDArticleId = targetPreferences.getValue("articleId", "");  //Check for article ID in this WCD setup
 57                System.out.println("DEBUG: Page Template: Article ID:'"+ currentWCDArticleId +"'");
 58               
 59                if (Validator.isNotNull(currentWCDArticleId) ) { //Is this WCD already linked to an article?
 60                   
 61                    long groupId = targetLayout.getGroupId();
 62                    System.out.println("Page Template: Group:"+ groupId);
 63                   
 64                    //Note: Used full package names to be cut-n-paste-ready. Use imports in production   
 65                    //import com.liferay.portlet.journal.model.JournalArticle;
 66                    //import com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil;
 67                     com.liferay.portlet.journal.model.JournalArticle journalArticle =
 68                        com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil.getArticle(groupId, currentWCDArticleId);
 69                        
 70                    //JournalArticle journalArticle = JournalArticleLocalServiceUtil.getArticle(groupId, currentWCDArticleId);
 71                        
 72                    //Search for a custom attribute (Boolean) added to WCDs that allows propagation from original Page Template.
 73                    //Should default to false when added in Control Panel for WCDs.
 74                    Object wcdPropagationBool = journalArticle.getExpandoBridge().getAttribute("PAGE_TEMPLATE_PROPAGATION_ALLOWED");
 75                   
 76                    //WARNING: This INVERTS default behavior!
 77                    //Has this WCD/Portal a custom attribute that might prevent page template "hard" propagation?
 78                    //If NOT, _preserve_ current WCD setup
 79                    if (wcdPropagationBool  == null ) {
 80                        System.out.println("DEBUG: Page Template: Missing PAGE_TEMPLATE_PROPAGATION_ALLOWED attribute for:"+ sourcePortletId + "\nSkipping propagation ANYWAY...");
 81                        continue; //skip this portlet, get to next
 82                    }
 83                    //Has the editor/designer decided to purposefully override this specific WCD setup during page template modification via WCD _custom_ attribute?
 84                     boolean isPageTemplatePropagationAllowed =(Boolean) wcdPropagationBool ; //Boolean.parseBoolean( ( wcdPropagationBool );
 85                     
 86                     if (!isPageTemplatePropagationAllowed){
 87                        System.out.println("DEBUG: Page Template: Propagation NOT allowed for WCD ID :"+ sourcePortletId + "\nSkipping propagation...");
 88                        continue;  //skip this portlet, get to next
 89                     }else{
 90                        System.out.println("DEBUG: Page Template: Propagation IS allowed for WCD ID :"+ sourcePortletId + "\nPrototype setup will overwrite this WCD setup.");
 91                     }
 92                }
 93            }//End if check WCD propagation            
 94            else{
 95                System.out.println("DEBUG: Page Template: Default Propagation for :"+ sourcePortletId + "\nPrototype setup will overwrite this PORTLET setup.");
 96            }
 97            PortletPreferencesImpl sourcePreferencesImpl =
 98                (PortletPreferencesImpl)sourcePreferences;
 99
100       
101
102            PortletPreferencesImpl targetPreferencesImpl =
103                (PortletPreferencesImpl)targetPreferences;
104
105                java.util.Enumeration<String> targetPrefNames1 = targetPreferencesImpl.getNames();
106            /*
107                while (targetPrefNames1.hasMoreElements()) {
108                    String prefName = (String) targetPrefNames1.nextElement();
109                    System.out.println("Page Template 1: sourcePortletId:"+sourcePortletId + "has preference:"+ prefName+ " => VALUE="+targetPreferencesImpl.getValue(prefName, "NONE"));
110                }   
111            */
112
113               
114                           
115               
116            PortletPreferencesLocalServiceUtil.updatePreferences(
117                targetPreferencesImpl.getOwnerId(),
118                targetPreferencesImpl.getOwnerType(),
119                targetPreferencesImpl.getPlid(), sourcePortletId,
120                sourcePreferences);
121
122            if ((sourcePreferencesImpl.getOwnerId() !=
123                    PortletKeys.PREFS_OWNER_ID_DEFAULT) &&
124                (sourcePreferencesImpl.getOwnerType() !=
125                    PortletKeys.PREFS_OWNER_TYPE_LAYOUT)) {
126
127                   
128                    System.out.println("DEBUG: Page Template: Checking Page Template propagation (Owner) for:"+ sourcePortletId );
129                sourcePreferences =
130                    PortletPreferencesFactoryUtil.getLayoutPortletSetup(
131                        sourceLayout, sourcePortletId);
132
133                sourcePreferencesImpl =
134                    (PortletPreferencesImpl)sourcePreferences;
135
136                targetPreferences =
137                    PortletPreferencesFactoryUtil.getLayoutPortletSetup(
138                        targetLayout, sourcePortletId);
139
140                targetPreferencesImpl =
141                    (PortletPreferencesImpl)targetPreferences;
142
143            /*       
144                java.util.Enumeration<String> targetPrefNames = targetPreferencesImpl.getNames();
145            
146                while (targetPrefNames.hasMoreElements()) {
147                    String prefName = (String) targetPrefNames.nextElement();
148                    System.out.println("Page Template: sourcePortletId:"+sourcePortletId + "has preference:"+ prefName);
149                }
150            */
151                   
152                PortletPreferencesLocalServiceUtil.updatePreferences(
153                    targetPreferencesImpl.getOwnerId(),
154                    targetPreferencesImpl.getOwnerType(),
155                    targetPreferencesImpl.getPlid(), sourcePortletId,
156                    sourcePreferences);
157            }
158       
159        }//End main for
160    }



Bye.

Diego
Mattia Possenti
RE: Page connected to page template lost their web content after template i
April 4, 2013 1:26 AM
Answer

Mattia Possenti

Rank: Junior Member

Posts: 35

Join Date: April 19, 2011

Recent Posts

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
RE: Page connected to page template lost their web content after template i
April 4, 2013 2:02 AM
Answer

Mattia Possenti

Rank: Junior Member

Posts: 35

Join Date: April 19, 2011

Recent Posts

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
Diego Pietralunga
RE: Page connected to page template lost their web content after template i
April 4, 2013 4:39 AM
Answer

Diego Pietralunga

Rank: New Member

Posts: 17

Join Date: August 4, 2009

Recent Posts

That's great Mattia emoticon

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

Diego
Diego Pietralunga
RE: Page connected to page template lost their web content after template i
April 4, 2013 4:43 AM
Answer

Diego Pietralunga

Rank: New Member

Posts: 17

Join Date: August 4, 2009

Recent Posts

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
RE: Page connected to page template lost their web content after template i
April 4, 2013 8:41 AM
Answer

Mattia Possenti

Rank: Junior Member

Posts: 35

Join Date: April 19, 2011

Recent Posts

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