Skip to content

Commit

Permalink
fix(SFT-1621): fixed a couple of issues with the Freeform 4.x migrati…
Browse files Browse the repository at this point in the history
…on (#1661)

* fix(SFT-1621): form submission table names being incorrectly converted to camel case during migration
* fix(SFT-1540): removed  string helper function when cleaning handles
  • Loading branch information
seandelaney authored and kjmartens committed Nov 29, 2024
1 parent 2fdc0a8 commit eab5390
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ private function processForms(): bool
$attributes[$attr] = $value;
}

$formHandle = preg_replace('/\ /', '_', $form->handle);
$formHandle = StringHelper::toHandle($formHandle);
$formHandle = StringHelper::toAscii($form->handle);
$formHandle = StringHelper::truncate($formHandle, $maxHandleSize, '');
$formHandle = trim($formHandle, '-_');

$propertyProvider->setObjectProperties(
$general,
Expand Down Expand Up @@ -139,6 +139,8 @@ private function applyFormHandleChangesToMatchingSubmissionsTable(): void
;

$prefix = \Craft::$app->db->tablePrefix;
$prefixLength = \strlen($prefix);
$maxHandleSize = 36 - $prefixLength;

$tables = $this->db->schema->getTableSchemas();
foreach ($tables as $table) {
Expand All @@ -154,6 +156,10 @@ private function applyFormHandleChangesToMatchingSubmissionsTable(): void
continue;
}

$formHandle = StringHelper::toSnakeCase($formHandle);
$formHandle = StringHelper::truncate($formHandle, $maxHandleSize, '');
$formHandle = trim($formHandle, '-_');

$tempTableName = 'tmp_'.substr(sha1($tableName), 0, 5);

$this->renameTable('{{%'.$tableName.'}}', '{{%'.$tempTableName.'}}');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,7 @@ private function extractMetadata(string $fieldClass, \stdClass $data): array

$label = $data->label ?? '';
$handle = $data->handle ?? $data->type.'_'.HashHelper::sha1(random_bytes(10).microtime(), 5);
$handle = preg_replace('/\ /', '_', $handle);
$handle = StringHelper::toHandle($handle);
$handle = StringHelper::toAscii($handle);

if (!$label) {
$globalField = $this->globalFieldData[$data->id ?? 0] ?? null;
Expand Down

0 comments on commit eab5390

Please sign in to comment.