| @@ -74,8 +74,13 @@ | ||
| 74 | 74 | |
| 75 | 75 | foreach ($fieldsArray as $fieldKey => $field) { |
| 76 | 76 | // print_r(gettype($field)); |
| 77 | 77 | $convertFormate = $conversionFormate->getFormate($field->typ); |
| 78 | + // Unknown field type: keep the field as-is instead of fataling the migration | |
| 79 | + if (empty($convertFormate)) { | |
| 80 | + $newFieldsArray[$fieldKey] = $field; | |
| 81 | + continue; | |
| 82 | + } | |
| 78 | 83 | $newFieldProperty = []; |
| 79 | 84 | |
| 80 | 85 | // convert unchange property |
| 81 | 86 | foreach ($convertFormate['unchangeProperty'] as $property) { |
| @@ -195,12 +200,40 @@ | ||
| 195 | 200 | } |
| 196 | 201 | return $newSuccessMessageArr; |
| 197 | 202 | } |
| 198 | 203 | |
| 204 | + public static function convertWebHooksToIntegrations($formSettingsV1) | |
| 205 | + { | |
| 206 | + $webHooks = $formSettingsV1->confirmation->type->webHooks; | |
| 207 | + $integrations = $formSettingsV1->integrations; | |
| 208 | + foreach ($webHooks as $webHook) { | |
| 209 | + $webHook->type = 'Web Hooks'; | |
| 210 | + $webHook->name = $webHook->title; | |
| 211 | + $integrations[] = $webHook; | |
| 212 | + } | |
| 213 | + return $integrations; | |
| 214 | + } | |
| 215 | + | |
| 216 | + public static function duplicateV1StyleFiles() | |
| 217 | + { | |
| 218 | + $source = BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles'; | |
| 219 | + $destination = BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles-v1'; | |
| 220 | + if (!file_exists(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles-v1')) { | |
| 221 | + wp_mkdir_p(BITFORMS_CONTENT_DIR . DIRECTORY_SEPARATOR . 'form-styles-v1'); | |
| 222 | + } | |
| 223 | + self::recursiveCopyFiles($source, $destination); | |
| 224 | + self::recursiveDeleteFiles($source); | |
| 225 | + } | |
| 226 | + | |
| 227 | + public static function getBitformDefaultStyleClass() | |
| 228 | + { | |
| 229 | + return self::arrayToCssString(BitformDefaultStyle::commonStyleClasses()); | |
| 230 | + } | |
| 231 | + | |
| 199 | 232 | public static function recursiveDeleteFiles($src) |
| 200 | 233 | { |
| 201 | 234 | if (is_file($src)) { |
| 202 | - return unlink($src); | |
| 235 | + return wp_delete_file($src); | |
| 203 | 236 | } elseif (is_dir($src)) { |
| 204 | 237 | $scan = glob(rtrim($src, '/') . '/*'); |
| 205 | 238 | foreach ($scan as $path) { |
| 206 | 239 | self::recursiveDeleteFiles($path); |
| @@ -217,6 +250,43 @@ | ||
| 217 | 250 | foreach ($scan as $path) { |
| 218 | 251 | self::recursiveCopyFiles($path, $dst . '/' . basename($path)); |
| 219 | 252 | } |
| 220 | 253 | } |
| 254 | + } | |
| 255 | + | |
| 256 | + public static function arrayToCssString($array) | |
| 257 | + { | |
| 258 | + $cssString = ''; | |
| 259 | + | |
| 260 | + foreach ($array as $selector => $properties) { | |
| 261 | + $cssString .= $selector . ' {'; | |
| 262 | + | |
| 263 | + foreach ($properties as $property => $value) { | |
| 264 | + $cssString .= $property . ': ' . $value . '; '; | |
| 265 | + } | |
| 266 | + | |
| 267 | + // Remove the trailing space and add closing brace | |
| 268 | + $cssString = rtrim($cssString, ' ') . '}'; | |
| 269 | + } | |
| 270 | + | |
| 271 | + return $cssString; | |
| 272 | + } | |
| 273 | + | |
| 274 | + public static function formatFormData($formData) | |
| 275 | + { | |
| 276 | + $newFormData = json_decode(wp_json_encode($formData)); | |
| 277 | + | |
| 278 | + $formContent = json_decode(wp_json_encode($formData->form_content)); | |
| 279 | + | |
| 280 | + $newFormData->fields = $formContent->fields; | |
| 281 | + $newFormData->layout = $formContent->layout; | |
| 282 | + $newFormData->nestedLayouts = $formContent->nestedLayout; | |
| 283 | + $newFormData->formInfo = $formContent->formInfo; | |
| 284 | + | |
| 285 | + if (is_array($formData->reports) && count($formData->reports) > 0) { | |
| 286 | + $newFormData->currentReport = $formData->reports[0]; | |
| 287 | + $newFormData->report_id = $formData->reports[0]->id; | |
| 288 | + } | |
| 289 | + | |
| 290 | + return $newFormData; | |
| 221 | 291 | } |
| 222 | 292 | } |