cftFieldUpdaterVersion = "1.2"; // process config defaults cfparam(name="adfApp", default="", type="string"); cfparam(name="adfAppName", default="", type="string"); cfparam(name="adfAppDir", default="", type="string"); cfparam(name="adfAppVersion", default="", type="string"); cfparam(name="runUpdateFieldTypes", default="false", type="boolean"); cfparam(name="runUpdatePropValues", default="false", type="boolean"); cfparam(name="verbose", default="false", type="boolean"); cfparam(name="packetFileSuffix", default="-cft-props-defaultvalues", type="string"); cfparam(name="packetFileExt", default=".wddx", type="string"); cfparam(name="updaterLogfile", default="_cft-props-defaults-updater.log", type="string"); // Log the cfUpdater component object cftUpdaterObj = createObject('component','cft-updater').init(packetFileSuffix,packetFileExt,updaterLogfile); if ( TRIM(adfApp) EQ '' OR TRIM(adfAppName) EQ '' OR TRIM(adfAppName) EQ '' ) { WriteOutput('
App Updater Config NOT Set!'); exit; }

cft-props-defaults-updater-for-#adfAppVersion#

This CFT Field Updater script for version #adfAppVersion# of the #adfAppName# App updates the fields and properties for the #adfApp# Elements.
Run this script to restore the required values.

/***************** START - ELEMENT AND CFT VALUES *****************/ /* Setup fields to update in an Array */ fldArray = ArrayNew(1); packetDirectoryPath = ExpandPath("/ADF/apps/#adfAppDir#/install/cftUpdaterData/v#adfAppVersion#/"); packetFileName = cftUpdaterObj.buildSafeFileName(filePrefix=adfApp); // Temp Dev packet file names //packetFileName = "ce-field-props-defaults.wddx"; //packetFileName = "department.wddx"; //dev only!! packetFilePath = packetDirectoryPath & packetFileName; // Get the update packet packetArray = cftUpdaterObj.readWDDXData(filePath=packetFilePath); /***************** END - Config *****************/ // After Process Runs... need to clear Custom Field Type Cache //Cache.clearElementTypeCache(elementTypeIDList)
This update script CAN NOT be run directly. Please run from the App Updater script installed at the site.
runUpdate = false; if ( NOT StructKeyExists(request.params,"action") ) request.params.action = "stop"; else if ( request.params.action EQ "RUN" ) runUpdate = true; if ( StructKeyExists(request.params,"verbose") ) verbose = request.params.verbose; c = 1; ceNameList = ""; // Get the list of Custom Elements that will be updated from this packet for ( c=1; c LTE ArrayLen(packetArray); c=c+1 ) { ceNameList = ListAppend(ceNameList, packetArray[c].FORMNAME); }
#updateInfoText#

Custom Elements to be Updated:

  • #ceName#

Running Update...

Building preview of proposed updates...


#RepeatString(" ",250)#
---> if ( verbose ) { application.ADF.utils.doDUMP(packetFilePath,"packetFilePath",1); application.ADF.utils.doDUMP(packetArray,"packetArray",0); } // init fldMap variables fldMap = StructNew(); fldMapArray = ArrayNew(1); fldUpdater = StructNew(); fldUpdaterArray = ArrayNew(1); fldTypeUpdaterArray = ArrayNew(1); fldPropsUpdaterArray = ArrayNew(1); updatedFieldIDlist = ""; p=1; f=1; t=1; z=1; u=1; // Begin to process by getting the current sites data from the selected fields // - Also flatten out the data as much as possible for ( p=1; p LTE ArrayLen(packetArray); p=p+1 ) { for ( f=1; f LTE ArrayLen(packetArray[p].Fields); f=f+1 ) { fldMap = StructNew(); fldMap.FormName = packetArray[p].FORMNAME; // Get the FORMID from current server fldMap.formid = application.ADF.ceData.getFormIDByCEName(fldMap.FORMNAME); //fldMap.wrong-formid = packetArray[p].FORMID; // wrong server fldMap.fieldName = packetArray[p].Fields[f].FIELDNAME; fldMap.ficFieldName = "FIC_" & packetArray[p].Fields[f].FieldName; // Get the FIELDID from current server fldMap.FIELDID = application.ADF.ceData.getElementFieldID(CEFormID=fldMap.formid,CEFieldName=fldMap.fieldName); //fldMap.wrong-FIELDID = packetArray[p].Fields[f].FIELDID; // wrong server fldMap.fieldType = packetArray[p].Fields[f].FieldType; //fldMap.standardProps = packetArray[p].Fields[f].props.Standard; //fldMap.otherProps = packetArray[p].Fields[f].props.Other; fldMap.props = StructNew(); StructAppend(fldMap.props, packetArray[p].Fields[f].props.Standard, false); StructAppend(fldMap.props, packetArray[p].Fields[f].props.Other, false); fldMap.params = packetArray[p].Fields[f].params; arrayAppend(fldMapArray,fldMap); } } if ( verbose ) application.ADF.utils.doDUMP(fldMapArray,"Field Map Array",0); // --- FIX THE FIELD TYPES --- WriteOutput("
"); // Step through the update process // 1) First Check the Field Type and get that straight for ( t=1; t LTE ArrayLen(fldMapArray); t=t+1 ) { currentProps = application.ADF.ceData.getFieldParamsByID(fieldID=fldMapArray[t].FIELDID); //application.ADF.utils.doDUMP(currentProps,"currentProps",1); if ( StructKeyExists(fldMapArray[t],"fieldType") AND StructKeyExists(currentProps,"Type") AND fldMapArray[t].fieldType NEQ currentProps.Type ) { fldTypeUpdater = StructNew(); fldTypeUpdater.FormID = fldMapArray[t].formid; fldTypeUpdater.FieldID = fldMapArray[t].FIELDID; fldTypeUpdater.FormName = fldMapArray[t].FormName; fldTypeUpdater.ficFieldName = fldMapArray[t].ficFieldName; fldTypeUpdater.currentType = currentProps.Type; fldTypeUpdater.defaultType = fldMapArray[t].fieldType; fldTypeUpdater.defaultParams = fldMapArray[t].params; fldTypeUpdater.defaultProps = fldMapArray[t].props; // Add the struct to the Updater Array arrayAppend(fldTypeUpdaterArray,fldTypeUpdater); } WriteOutput(CHR(42)); flush; //getPageContext().getOut().flush(); } WriteOutput("
"); if ( verbose ) application.ADF.utils.doDUMP(fldTypeUpdaterArray,"Field Type Updater Array",0); // 2) Update the fields found to have the wrong types if ( ArrayLen(fldTypeUpdaterArray) ) { WriteOutput("

"); if ( runUpdate AND runUpdateFieldTypes ) WriteOutput("Updating "); WriteOutput(ArrayLen(fldTypeUpdaterArray) & " "); WriteOutput("Fields with mismatched 'Types':"); WriteOutput("

"); for ( x=1; x LTE ArrayLen(fldTypeUpdaterArray); x=x+1 ) { typeUpdate = false; WriteOutput("
"); WriteOutput("#x#) "); if ( runUpdate AND runUpdateFieldTypes ) WriteOutput("Update: "); WriteOutput("Form: #fldTypeUpdaterArray[x].formName# - "); WriteOutput("Field: #fldTypeUpdaterArray[x].ficFieldName# "); WriteOutput("
-->> Current Type: [[#fldTypeUpdaterArray[x].currentType#]]"); WriteOutput("
-->> Default Type: [[#fldTypeUpdaterArray[x].defaultType#]]"); for ( yKey IN fldTypeUpdaterArray[x].defaultProps ) { WriteOutput("
"); WriteOutput(" --- [ prop: #yKey# == "); WriteOutput("default: #fldTypeUpdaterArray[x].defaultProps[yKey]# ]"); WriteOutput("
"); } if ( runUpdate AND runUpdateFieldTypes ) { WriteOutput("
"); WriteOutput(""); WriteOutput("Updating the #fldTypeUpdaterArray[x].ficFieldName# field's Type....
"); typeUpdate = cftUpdaterObj.updateCFTtype(formID=fldTypeUpdaterArray[x].FormID,fieldID=fldTypeUpdaterArray[x].FieldID,type=fldTypeUpdaterArray[x].DEFAULTTYPE,defaultParams=fldTypeUpdaterArray[x].DEFAULTPARAMS,clearCache=true); iF ( typeUpdate ) WriteOutput("Update: Success!"); else WriteOutput("Update: Failed!"); WriteOutput("
"); WriteOutput("
"); } WriteOutput("
"); // Output to the page what we have so far WriteOutput(RepeatString(" ",250)); flush; //getPageContext().getOut().flush(); } } else { WriteOutput("
"); WriteOutput(""); WriteOutput("No Fields with mismatched 'Types' found!
"); WriteOutput("
"); WriteOutput("
"); // Output to the page what we have so far WriteOutput(RepeatString(" ",250)); flush; //getPageContext().getOut().flush(); } WriteOutput("
"); // --- FIX THE PROPS AND DEFAULTS WriteOutput("
"); //application.ADF.utils.doDUMP(fldMapArray,"fldMapArray",0); // 3) After the FieldTypes are correct... fix the field props values for ( u=1; u LTE ArrayLen(fldMapArray); u=u+1 ) { for ( key IN fldMapArray[u].props ) { // use the formid and the fieldID to check to see if we have updates to do // build a array of proposed updates fldUpdater = StructNew(); // Look up the current field data based on FormID and FieldID fldUpdater.FormName = fldMapArray[u].FormName; fldUpdater.FormID = fldMapArray[u].formid; fldUpdater.FieldID = fldMapArray[u].FIELDID; fldUpdater.ficFieldName = fldMapArray[u].ficFieldName; currentProps = application.ADF.ceData.getFieldParamsByID(fieldID=fldMapArray[u].FIELDID); //application.ADF.utils.doDUMP(currentProps,"currentProps",1); currentDefaults = application.ADF.ceData.getFieldDefaultValueFromID(fieldID=fldMapArray[u].FIELDID); //application.ADF.utils.doDUMP(currentDefaults,"currentDefaults",1); //if ( StructKeyExists(currentProps,key) ) //application.ADF.utils.doDUMP(currentProps[key],"currentProps[#key#]",1); //else if ( StructKeyExists(currentDefaults,key) ) //application.ADF.utils.doDUMP(currentDefaults[key],"currentDefaults[#key#]",1); //if ( StructKeyExists(fldMapArray[u].props ,key) ) //application.ADF.utils.doDUMP(fldMapArray[u].props[key],"fldMapArray[#u#].prop[#key#]",1); if ( key NEQ "FIELDNAME" ) { if ( StructKeyExists(currentProps,key) AND TRIM(currentProps[key]) NEQ TRIM(fldMapArray[u].props[key]) ) { fldUpdater.PropField = key; fldUpdater.PropCurrentValue = TRIM(currentProps[key]); fldUpdater.PropDefaultValue = TRIM(fldMapArray[u].props[key]); fldUpdater.PropsUpdateDataFldVal = false; //fldUpdater[key] = fldMapArray[u].props[key]; arrayAppend(fldUpdaterArray,fldUpdater); } else if ( StructKeyExists(currentDefaults,key) AND TRIM(currentDefaults[key]) NEQ TRIM(fldMapArray[u].props[key]) ) { fldUpdater.PropField = key; fldUpdater.PropCurrentValue = TRIM(currentDefaults[key]); fldUpdater.PropDefaultValue = TRIM(fldMapArray[u].props[key]); fldUpdater.PropsUpdateDataFldVal = true; //fldUpdater[key] = fldMapArray[u].props[key]; arrayAppend(fldUpdaterArray,fldUpdater); } } } WriteOutput(CHR(42)); flush; //getPageContext().getOut().flush(); } WriteOutput("
"); if ( verbose ) application.ADF.utils.doDUMP(fldUpdaterArray,"Field Updater Array",0); // 4) Update the fields props if ( ArrayLen(fldUpdaterArray) ) { WriteOutput("

"); if ( runUpdate AND runUpdatePropValues ) WriteOutput("Updating "); WriteOutput(ArrayLen(fldUpdaterArray) & " "); WriteOutput("Fields with mismatched Properties:"); WriteOutput("

"); for ( z=1; z LTE ArrayLen(fldUpdaterArray); z=z+1 ) { propsUpdate = false; WriteOutput("
"); WriteOutput("#z#) "); if ( runUpdate AND runUpdatePropValues ) WriteOutput("Update: "); WriteOutput("Form: #fldUpdaterArray[z].formName# - "); WriteOutput("Field: #fldUpdaterArray[z].ficFieldName# - "); WriteOutput("Prop Field: #fldUpdaterArray[z].PropField#"); WriteOutput("
-->> Current Value: [[#fldUpdaterArray[z].PropCurrentValue#]]"); WriteOutput("
-->> Default Value: [[#fldUpdaterArray[z].PropDefaultValue#]]"); if ( runUpdate AND runUpdatePropValues ) { WriteOutput("
"); WriteOutput(""); WriteOutput("Updating the #fldUpdaterArray[z].ficFieldName# field...
"); propsUpdate = cftUpdaterObj.updateCFTprops(formID=fldUpdaterArray[z].FormID,fieldID=fldUpdaterArray[z].FieldID,PropField=fldUpdaterArray[z].PropField,DefaultValue=fldUpdaterArray[z].PropDefaultValue,useDFV=fldUpdaterArray[z].PropsUpdateDataFldVal,clearCache=true); iF ( propsUpdate ) WriteOutput("Update: Success!"); else WriteOutput("Update: Failed!"); WriteOutput("
"); WriteOutput("
"); } WriteOutput("
"); // Output to the page what we have so far WriteOutput(RepeatString(" ",250)); flush; //getPageContext().getOut().flush(); } } else { WriteOutput("
"); WriteOutput(""); WriteOutput("No Fields with mismatched 'Properties' found!
"); WriteOutput("
"); WriteOutput("
"); // Output to the page what we have so far WriteOutput(RepeatString(" ",250)); flush; //getPageContext().getOut().flush(); }



All processing is complete!!