diff --git a/code/editor/EditableFormField.php b/code/editor/EditableFormField.php
index 688e1ac..849930a 100755
--- a/code/editor/EditableFormField.php
+++ b/code/editor/EditableFormField.php
@@ -116,7 +116,7 @@ class EditableFormField extends DataObject {
*
* @return Array Return all the Settings
*/
- protected function getFieldSettings() {
+ public function getFieldSettings() {
return (!empty($this->CustomSettings)) ? unserialize($this->CustomSettings) : array();
}
@@ -126,7 +126,7 @@ class EditableFormField extends DataObject {
*
* @param Array the custom settings
*/
- protected function setFieldSettings($settings = array()) {
+ public function setFieldSettings($settings = array()) {
$this->CustomSettings = serialize($settings);
}
diff --git a/code/editor/EditableTextField.php b/code/editor/EditableTextField.php
index 7c9a838..a9b8358 100755
--- a/code/editor/EditableTextField.php
+++ b/code/editor/EditableTextField.php
@@ -37,11 +37,11 @@ class EditableTextField extends EditableFormField {
}
function getFormField() {
- if($this->getSetting('Rows') && $this->getSetting('Rows') <= 1) {
- return new TextField($this->Name, $this->Title, null, $this->getSetting('MaxLength'));
+ if($this->getSetting('Rows') && $this->getSetting('Rows') > 1) {
+ return new TextareaField($this->Name, $this->Title, $this->getSetting('Rows'));
}
else {
- return new TextareaField($this->Name, $this->Title, $this->getSetting('Rows'));
+ return new TextField($this->Name, $this->Title, null, $this->getSetting('MaxLength'));
}
}
diff --git a/code/migration/UserFormsMigrationTask.php b/code/migration/UserFormsMigrationTask.php
new file mode 100644
index 0000000..45858e2
--- /dev/null
+++ b/code/migration/UserFormsMigrationTask.php
@@ -0,0 +1,167 @@
+Count() . " Forms to ensure proper structure
";
+
+ foreach($forms as $form) {
+ echo " -- Updating $form->URLSegment
";
+ // easy step first port over email data from the structure
+ if($form->EmailOnSubmit && $form->EmailTo) {
+ $emailTo = new UserDefinedForm_EmailRecipient();
+ $emailTo->EmailAddress = $form->EmailTo;
+ $emailTo->EmailSubject = _t('UserFormsMigrationTask.DEFAULTSUBMISSIONTITLE',"Submission Data");
+ $emailTo->EmailFrom = Email::getAdminEmail();
+ $emailTo->EmailBody = $form->EmailMessageToSubmitter;
+ $emailTo->FormID = $form->ID;
+ $emailTo->write();
+ }
+
+ // now fix all the fields
+ if($form->Fields()) {
+ foreach($form->Fields() as $field) {
+ switch($field->ClassName) {
+ case 'EditableDropdown':
+ case 'EditableRadioField':
+ case 'EditableCheckboxGroupField':
+
+ $optionClass = "EditableDropdownOption";
+ if($field->ClassName = "EditableRadioField") {
+ $optionClass = "EditableRadioOption";
+ }
+ else if($field->ClassName = "EditableCheckboxGroupField") {
+ $optionClass = "EditableCheckboxOption";
+ }
+
+ $query = DB::query("SELECT * FROM $optionClass WHERE ParentID = '$field->ID'");
+ $result = $query->first();
+ if($result) {
+ do {
+ $this->createOption($result, $optionClass);
+ } while($result = $query->next());
+ }
+
+ break;
+ case 'EditableTextField':
+
+ // find what table to use
+ $database = $this->findDatabaseTableName('EditableTextField');
+
+ // get the data from the table
+ $result = DB::query("SELECT * FROM $database WHERE ID = $field->ID")->first();
+
+ if($result) {
+ $field->setFieldSettings(array(
+ 'Size' => $result['Size'],
+ 'MinLength' => $result['MinLength'],
+ 'MaxLength' => $result['MaxLength'],
+ 'Rows' => $result['Rows']
+ ));
+ }
+
+ break;
+ case 'EditableLiteralField':
+ if($field->Content) {
+ // find what table to use
+ $database = $this->findDatabaseTableName('EditableLiteralField');
+
+ // get the data from the table
+ $result = DB::query("SELECT * FROM $database WHERE ID = $field->ID")->first();
+
+ if($result) {
+ $field->setFieldSettings(array(
+ 'Content' => $result['Content']
+ ));
+ }
+ }
+ break;
+ case 'EditableMemberListField':
+ if($field->GroupID) {
+ // find what table to use
+ $database = $this->findDatabaseTableName('EditableMemberListField');
+
+ // get the data from the table
+ $result = DB::query("SELECT * FROM $database WHERE ID = $field->ID")->first();
+
+ if($result) {
+ $field->setFieldSettings(array(
+ 'GroupID' => $result['GroupID']
+ ));
+ }
+ }
+ break;
+ case 'EditableCheckbox':
+ if($field->Checked) {
+ // find what table to use
+ $database = $this->findDatabaseTableName('EditableCheckbox');
+
+ // get the data from the table
+ $result = DB::query("SELECT * FROM $database WHERE ID = $field->ID")->first();
+
+ if($result) {
+ $field->setFieldSettings(array(
+ 'Default' => $result['Checked']
+ ));
+ }
+ }
+ break;
+ }
+ $field->write();
+ }
+ }
+ }
+ }
+ /**
+ * Find if this table is obsolete or used
+ *
+ */
+ function findDatabaseTableName($tableName) {
+ $table = DB::query("SHOW TABLES LIKE '$tableName'")->value();
+ if(!$table) {
+ $table = DB::query("SHOW TABLES LIKE '_obsolete_EditableTextField'")->value();
+ }
+ return $table;
+ }
+ /**
+ * Create a EditableOption from a whatever type of multi
+ * form field it is coming from
+ */
+ function createOption($option, $class) {
+ $editableOption = new EditableOption();
+ $editableOption->ParentID = $option['ParentID'];
+ $editableOption->populateFromPostData($option);
+ // log
+ echo " -- -- Created new option '$editableOption->Title'
";
+ }
+}
+?>
\ No newline at end of file