Skip to content

Commit

Permalink
fix: Null fields cause problems when used in string functions
Browse files Browse the repository at this point in the history
  • Loading branch information
live627 committed Apr 4, 2023
1 parent fcf9990 commit a464946
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/CustomForm/ManageCustomForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -714,8 +714,8 @@ public function AddForm(): void
$this->smcFunc['db_insert'](
'',
'{db_prefix}cf_forms',
['id_board' => 'int'],
['0'],
['id_board' => 'int', 'title' => 'string', 'icon' => 'string', 'output' => 'string', 'subject' => 'string', 'form_exit' => 'string', 'template_function' => 'string', 'output_type' => 'string'],
['0', '', '', '', '', '', '', ''],
['id_form']
);
$form_id = $this->smcFunc['db_insert_id']('{db_prefix}cf_forms', 'id_form');
Expand Down Expand Up @@ -924,8 +924,8 @@ public function AddField(int $form_id): void
$this->smcFunc['db_insert'](
'',
'{db_prefix}cf_fields',
['id_form' => 'int'],
[$form_id],
['id_form' => 'int', 'title' => 'string', 'type' => 'string', 'text' => 'string', 'type_vars' => 'string'],
[$form_id, '', '', '', ''],
['id_field']
);
$field_id = $this->smcFunc['db_insert_id']('{db_prefix}cf_fields', 'id_field');
Expand Down
10 changes: 0 additions & 10 deletions src/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,36 +34,30 @@
'name' => 'title',
'type' => 'varchar',
'size' => 150,
'null' => true,
],
[
'name' => 'subject',
'type' => 'varchar',
'size' => 150,
'null' => true,
],
[
'name' => 'icon',
'type' => 'varchar',
'size' => 150,
'null' => true,
],
[
'name' => 'form_exit',
'type' => 'varchar',
'size' => 150,
'null' => true,
],
[
'name' => 'template_function',
'type' => 'varchar',
'size' => 150,
'null' => true,
],
[
'name' => 'output',
'type' => 'text',
'null' => true,
],
];
$indexes = [
Expand All @@ -90,24 +84,20 @@
'name' => 'title',
'type' => 'varchar',
'size' => 150,
'null' => true,
],
[
'name' => 'text',
'type' => 'varchar',
'size' => 4096,
'null' => true,
],
[
'name' => 'type',
'type' => 'varchar',
'size' => 150,
'null' => true,
],
[
'name' => 'type_vars',
'type' => 'text',
'null' => true,
],
];
$indexes = [
Expand Down
14 changes: 14 additions & 0 deletions src/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,17 @@
);

$smcFunc['db_free_result']($request);

$smcFunc['db_query']('', '
UPDATE {db_prefix}cf_forms
SET icon = CASE WHEN icon IS NULL THEN \'\' ELSE icon END,
title = CASE WHEN title IS NULL THEN \'\' ELSE title END, output = CASE WHEN output IS NULL THEN \'\' ELSE output END,
subject = CASE WHEN subject IS NULL THEN \'\' ELSE subject END,
form_exit = CASE WHEN form_exit IS NULL THEN \'\' ELSE form_exit END,
template_function = CASE WHEN template_function IS NULL THEN \'\' ELSE template_function END,
output_type = CASE WHEN output_type IS NULL THEN \'\' ELSE output_type END');

$smcFunc['db_query']('', '
UPDATE {db_prefix}cf_fields
SET title = CASE WHEN title IS NULL THEN \'\' ELSE title END, text = CASE WHEN text IS NULL THEN \'\' ELSE text END,
type = CASE WHEN type IS NULL THEN \'\' ELSE type END, type_vars = CASE WHEN type_vars IS NULL THEN \'\' ELSE type_vars END');

0 comments on commit a464946

Please sign in to comment.