You are on page 1of 3

/* * This script inserts site config attributes and values in the * site attribute tables.

* More specifically, it inserts into the SIT_ATTRIBUTE table. * * The task of inserting into this table is simplified to calls to * the InsertSiteConfigAttribute() method. * * The method InsertSiteConfigAttribute() is used to create the config * attribute and takes the following parameters: * * attribute definition id (name) * category id (category number: 'default' or '12' = GeneralConfigAttribute Category) * description of the attribute * displayType (e.g. TextBox or DropDown or null) * */ set DEFINE OFF; declare function FindNextSitAttributeDataId return NUMBER as ret NUMBER; rowCount NUMBER; begin LOOP select SIT_ATTRIBUTE_DATA_SEQ.NEXTVAL into ret from DUAL; select count(*) into rowCount from SIT_ATTRIBUTE_DATA where ATTRIBUT E_DATA_ID=ret; exit when rowCount = 0; end LOOP; return ret; end; procedure InsertSiteConfigAttribute(defnId in VARCHAR2, classType in VARCHAR2, categoryId in VARCHAR2, description in VARCHAR2, displayType in VARCHAR2) as attrDataId VARCHAR2(64); rowCount NUMBER; begin select count(*) into rowCount from SIT_ATTRIBUTE where ATTRIBUTE_DEFN_ID = defnId; if rowCount = 0 then insert into SIT_ATTRIBUTE(ATTRIBUTE_DEFN_ID, CLASS_TYPE, IS_MULTIVAL UE, DEFAULT_LOCALE, ATTRIBUTE_TYPE, CATEGORY_I D) values (defnId, classType, '0', 'en_US', 'ConfigAttribute', category Id); end if; /* Optionally insert into SIT_ATTRIBUTE_DATA; only needed if site config needs localized values. */

select count(*) into rowCount from SIT_ATTRIBUTE_DATA where ATTRIBUTE_DE FN_ID = defnId; if rowCount = 0 then attrDataId := FindNextSitAttributeDataId(); insert into SIT_ATTRIBUTE_DATA(ATTRIBUTE_DATA_ID, LOCALE, DESCRIPTIO N, DISPLAY_NAME, DISPLAY_TYPE, ATTRIBUTE _TYPE, ATTRIBUTE_DEFN_ID) values (attrDataId, 'en_US', description, defnId, displayType, 'ConfigAttribute', defnId); end if; end; function FindNextSitSiteConfigValueId return NUMBER as ret VARCHAR(64); rowCount NUMBER; begin LOOP select SIT_CONFIG_VALUE_SEQ.NEXTVAL into ret from DUAL; select count(*) into rowCount from SIT_SITE_CONFIG_VALUE where CONFI G_VALUE_ID=ret; exit when rowCount = 0; end LOOP; return ret; end; procedure InsertSiteConfigAttributeValue(defnId in VARCHAR2, configValue in VARCHAR2, siteId in VARCHAR2) as configValueId VARCHAR2(64); rowCount NUMBER; begin select count(*) into rowCount from sit_site_site_config sc, sit_site_con fig_value cv where sc.CONFIG_VALUE_ID = cv.CONFIG_VALUE_ID and cv.attribute_defn_id = defnId and sc.site_id = siteId; /* Since these are site config attributes, we must add a sit_site_config _value AND a sit_site_site_config * row for each site, not just a sit_site_site_config row. Otherwise, if a change to the value is required, * we would be changing it for all sites. */ if rowCount = 0 then configValueId := FindNextSitSiteConfigValueId(); insert into SIT_SITE_CONFIG_VALUE (CONFIG_VALUE_ID, VALUE, ATTRIBUTE _DEFN_ID) values (configValueId, configValue, defnId); insert into SIT_SITE_SITE_CONFIG(CONFIG_VALUE_ID, SITE_ID) values (configValueId, siteId); end if;

end; procedure InsertConfigValueForAllSites(defnId in VARCHAR2, configValue in VARCHAR2) as configValueId VARCHAR2(64); rowCount NUMBER; begin /* go over all sites, not just active ones (in case a deactive one gets activated later on */ declare cursor cursI is select site_id from sit_site; cursI_rec cursI%ROWTYPE; begin open cursI; LOOP fetch cursI into cursI_rec; EXIT WHEN cursI%NOTFOUND; InsertSiteConfigAttributeValue(defnId, configValue, cursI_rec.si te_id); end LOOP; end; end; begin InsertSiteConfigAttribute('PRODUCT_REVIEW_ENABLED','java.lang.Boolean','12','Ena ble product review, blab, blah', null); end; / set DEFINE ON;

You might also like