Whenever a Site is linked to a Site Template, Liferay does not immediately add the Pages of the Site Template to that Site. Instead, Liferay waits until someone first tries to visit the Site, and then it adds the Pages.
Normally, this is not an issue, because when using the UI to link a Site Template to a Site, the user is automatically redirected to that Site's Control Panel, thus triggering the Pages of the Site Template being added to that Site. However, if the Site is linked to the Site Template via the API, rather than the UI, then this redirect does not occur, so the Pages do not get added. This has a negative effect on the My Sites portlet - the My Sites portlet will link to that Site's Control Panel instead of one of its Pages, until the Pages get added.
This may seem like a trivial bug in most cases; however, this can be a huge nuisance if an administrator is using the API to add many Sites that are based on Site Templates. This bug will cause the My Sites portlet to link regular Users to the Control Panel the first time anyone tries to access the Site, which will result in a confusing and poor user experience.
We should add the pages immediately after linking the Site to a Site Template, rather than waiting until someone tries to visit the Site do so.
Steps to Reproduce
1. Start up Liferay and log in as the admin user.
2. Navigate to Control Panel > Sites > Site Templates.
3. Add a Site Template and make sure it has at least one public page (it should have one by default).
4. Navigate to Control Panel > Server Administration > Script, and run the attached
AddSiteFromLastCreatedSiteTemplate.groovy groovy script. The script will create a Site named "Test Site" using the Site Template you added in Step 3.
5. Click on the My Sites portlet (The "Go to Other Site" compass button next to the name of the current Site).
6. Select the My Sites tab.
7. Click on Test Site (the site added by the groovy script in Step 4).
Expected Result: You are taken to one of the Site's Public Pages.
* Actual Result:* You are taken to the Site's Control Panel. Subsequent visits to the My Sites portlet will take you to one of the Site's Public Pages, as expected.