Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fillpdf
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
drupal.org
fillpdf
Commits
05178a08
Commit
05178a08
authored
2 years ago
by
jungle
Committed by
Liam Morland
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue #3276361: Increase maximum length for pdf_key if it has values before
parent
c10c7532
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fillpdf.install
+61
-21
61 additions, 21 deletions
fillpdf.install
with
61 additions
and
21 deletions
fillpdf.install
+
61
−
21
View file @
05178a08
...
@@ -283,27 +283,10 @@ function fillpdf_update_8111() {
...
@@ -283,27 +283,10 @@ function fillpdf_update_8111() {
* Increase maximum length for pdf_key.
* Increase maximum length for pdf_key.
*/
*/
function
fillpdf_update_9501
()
{
function
fillpdf_update_9501
()
{
$db
=
\Drupal
::
database
();
// The code of this hook_update_N() implementation is removed in favor of
// fillpdf_update_9503() as it does not cover the case that pdf_key has
$transaction
=
$db
->
startTransaction
();
// values.
// @see https://www.drupal.org/project/fillpdf/issues/3276361
// Update field storage definition.
$edum
=
\Drupal
::
entityDefinitionUpdateManager
();
$field_storage_definition
=
$edum
->
getFieldStorageDefinition
(
'pdf_key'
,
'fillpdf_form_field'
);
$field_storage_definition
->
setSetting
(
'type'
,
'string_long'
);
$edum
->
updateFieldStorageDefinition
(
$field_storage_definition
);
// Update database schema.
$spec
=
[
'type'
=>
'text'
,
'size'
=>
'big'
,
];
$db
->
schema
()
->
changeField
(
'fillpdf_fields'
,
'pdf_key'
,
'pdf_key'
,
$spec
);
// Commit transaction.
unset
(
$transaction
);
}
}
/**
/**
...
@@ -362,3 +345,60 @@ function fillpdf_update_9502() {
...
@@ -362,3 +345,60 @@ function fillpdf_update_9502() {
// Commit transaction.
// Commit transaction.
unset
(
$transaction
);
unset
(
$transaction
);
}
}
/**
* Increase maximum length for pdf_key.
*/
function
fillpdf_update_9503
()
{
$field_name
=
'pdf_key'
;
$entity_type
=
'fillpdf_form_field'
;
$new_field_type
=
'string_long'
;
$database
=
\Drupal
::
database
();
$transaction
=
$database
->
startTransaction
();
$entity_type_manager
=
\Drupal
::
entityTypeManager
();
$storage
=
$entity_type_manager
->
getStorage
(
$entity_type
);
$entity_definition
=
$entity_type_manager
->
getDefinition
(
$entity_type
);
$id_key
=
$entity_definition
->
getKey
(
'id'
);
$table_name
=
$storage
->
getBaseTable
();
$definition_manager
=
\Drupal
::
entityDefinitionUpdateManager
();
$field_storage_definition
=
$definition_manager
->
getFieldStorageDefinition
(
$field_name
,
$entity_type
);
// If the field type is string_long already, do nothing.
if
(
$field_storage_definition
->
getType
()
===
$new_field_type
)
{
return
;
}
// Store the existing values.
$migrated_values
=
$database
->
select
(
$table_name
)
->
fields
(
$table_name
,
[
$id_key
,
$field_name
])
->
execute
()
->
fetchAllKeyed
();
// Clear out the values.
$database
->
update
(
$table_name
)
->
fields
([
$field_name
=>
NULL
])
->
execute
();
// Uninstall the field.
$definition_manager
->
uninstallFieldStorageDefinition
(
$field_storage_definition
);
// Create the new field definition.
$new_field
=
BaseFieldDefinition
::
create
(
$new_field_type
)
->
setLabel
(
t
(
'PDF Key'
))
->
setDescription
(
t
(
'The name of the field in the PDF form.'
));
// Install the new definition.
$definition_manager
->
installFieldStorageDefinition
(
$field_name
,
$entity_type
,
$entity_type
,
$new_field
);
// Restore the values.
foreach
(
$migrated_values
as
$id
=>
$value
)
{
$database
->
update
(
$table_name
)
->
fields
([
$field_name
=>
$value
])
->
condition
(
$id_key
,
$id
)
->
execute
();
}
// Commit transaction.
unset
(
$transaction
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment