insert into ANNOUNCEMENT_BOARD (CREATION_DATE,EXECUTION_COURSE_PERMITTED_WRITE_GROUP_TYPE, EXECUTION_COURSE_PERMITTED_READ_GROUP_TYPE, EXECUTION_COURSE_PERMITTED_MANAGEMENT_GROUP_TYPE, KEY_ROOT_DOMAIN_OBJECT, KEY_EXECUTION_COURSE, NAME, OJB_CONCRETE_CLASS) select date_sub(now(),interval 8 day), 'ECB_PUBLIC', 'ECB_PUBLIC', 'ECB_PUBLIC', 1, EXECUTION_COURSE.ID_INTERNAL, EXECUTION_COURSE.NOME, 'net.sourceforge.fenixedu.domain.messaging.ExecutionCourseAnnouncementBoard' from EXECUTION_COURSE;

update EXECUTION_COURSE, ANNOUNCEMENT_BOARD set EXECUTION_COURSE.KEY_BOARD = ANNOUNCEMENT_BOARD.ID_INTERNAL where EXECUTION_COURSE.ID_INTERNAL = ANNOUNCEMENT_BOARD.KEY_EXECUTION_COURSE;

insert into ANNOUNCEMENT 
(
KEY_ROOT_DOMAIN_OBJECT,
KEY_ANNOUNCEMENT_BOARD,
CREATION_DATE,
LAST_MODIFICATION,
SUBJECT,
BODY,
VISIBLE
) select 1, ANNOUNCEMENT_BOARD.ID_INTERNAL, OLD_ANNOUNCEMENT.CREATION_DATE_DATE_TIME,OLD_ANNOUNCEMENT.LAST_MODIFIED_DATE_DATE_TIME, concat("pt",length(OLD_ANNOUNCEMENT.TITLE),":",OLD_ANNOUNCEMENT.TITLE), concat("pt",length(OLD_ANNOUNCEMENT.INFORMATION),":",OLD_ANNOUNCEMENT.INFORMATION), 1
from OLD_ANNOUNCEMENT inner join SITE on SITE.ID_INTERNAL=OLD_ANNOUNCEMENT.KEY_SITE inner join EXECUTION_COURSE on EXECUTION_COURSE.ID_INTERNAL=SITE.KEY_EXECUTION_COURSE inner join ANNOUNCEMENT_BOARD on ANNOUNCEMENT_BOARD.ID_INTERNAL=EXECUTION_COURSE.KEY_BOARD;

UPDATE ANNOUNCEMENT set ANNOUNCEMENT.LAST_MODIFICATION=ANNOUNCEMENT.CREATION_DATE where ANNOUNCEMENT.LAST_MODIFICATION is null;
