--
-- Remove Announcements and Events functionality sections from SiteTemplate
--

--
-- Department
--

DELETE FROM A USING ACCESSIBLE_ITEM AS A, ACCESSIBLE_ITEM F
WHERE F.ID_INTERNAL = A.KEY_FUNCTIONALITY
  AND F.UUID = 'c113952d-6c49-44c0-b30b-d56ab1d2d047'; -- announcements

DELETE FROM A USING ACCESSIBLE_ITEM AS A, ACCESSIBLE_ITEM F
WHERE F.ID_INTERNAL = A.KEY_FUNCTIONALITY
  AND F.UUID = '931438dc-b0e2-4d2a-b017-1a449adf59e3'; -- events

-- Increase order of current sections

UPDATE ACCESSIBLE_ITEM A, ACCESSIBLE_ITEM A2, SITE S
SET A.SECTION_ORDER = A.SECTION_ORDER + (
	SELECT S2.SHOW_SECTION_TEACHERS + S2.SHOW_SECTION_EMPLOYEES + S2.SHOW_SECTION_COURSES + S2.SHOW_SECTION_DEGREES 
	FROM SITE S2
	WHERE S2.ID_INTERNAL = S.ID_INTERNAL
)
WHERE A.KEY_SITE = S.ID_INTERNAL
  AND A.KEY_SUPERIOR_SECTION = A2.ID_INTERNAL
  AND A2.NAME LIKE '%pt7:Lateral%'
  AND S.OJB_CONCRETE_CLASS = 'net.sourceforge.fenixedu.domain.DepartmentSite';

-- connect template site with module

UPDATE SITE TS, ACCESSIBLE_ITEM F
SET TS.KEY_MODULE = F.ID_INTERNAL
WHERE TS.SITE_TYPE = 'net.sourceforge.fenixedu.domain.DepartmentSite'
  AND F.UUID = '3adea1cf-e612-456f-b8be-c24882b77c3e'; -- public/site/department

--
-- ResearchUnit
--

DELETE FROM A USING ACCESSIBLE_ITEM AS A, ACCESSIBLE_ITEM F
WHERE F.ID_INTERNAL = A.KEY_FUNCTIONALITY
  AND F.UUID = '8481d1a7-1b95-43f6-b091-e0d582aa86e5'; -- announcements

DELETE FROM A USING ACCESSIBLE_ITEM AS A, ACCESSIBLE_ITEM F
WHERE F.ID_INTERNAL = A.KEY_FUNCTIONALITY
  AND F.UUID = 'e9ab1a2b-cfd2-4c6d-9476-27c7c3caf4c6'; -- events

-- Increase order of current sections

UPDATE ACCESSIBLE_ITEM A, ACCESSIBLE_ITEM A2, SITE S
SET A.SECTION_ORDER = A.SECTION_ORDER + (
	SELECT S2.SHOW_PUBLICATIONS + S2.SHOW_RESEARCH_MEMBERS
	FROM SITE S2
	WHERE S2.ID_INTERNAL = S.ID_INTERNAL
)
WHERE A.KEY_SITE = S.ID_INTERNAL
  AND A.KEY_SUPERIOR_SECTION = A2.ID_INTERNAL
  AND A2.NAME LIKE '%pt7:Lateral%'
  AND S.OJB_CONCRETE_CLASS = 'net.sourceforge.fenixedu.domain.ResearchUnitSite';

  -- connect template site with module

UPDATE SITE TS, ACCESSIBLE_ITEM F
SET TS.KEY_MODULE = F.ID_INTERNAL
WHERE TS.SITE_TYPE = 'net.sourceforge.fenixedu.domain.ResearchUnitSite'
  AND F.UUID = 'aade3f06-9faf-49cc-a28b-d2cf136f8469'; -- public/site/research site
