Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uw_cfg_common
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
WCMS
uw_cfg_common
Commits
eaf156d5
Commit
eaf156d5
authored
2 years ago
by
Eric Bremner
Committed by
Kevin Paxman
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
ISTWCMS-5880: fixing update hook for existing sites and media
parent
38a5b6b9
No related branches found
No related tags found
3 merge requests
!284
Feature/istwcms 5880 ebremner banners above
,
!274
Draft: ISTWCMS-5551: fixing office hours display
,
!260
Feature/istwcms 5668 a5kulkar rename references to publications
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
uw_cfg_common.install
+65
-0
65 additions, 0 deletions
uw_cfg_common.install
with
65 additions
and
0 deletions
uw_cfg_common.install
+
65
−
0
View file @
eaf156d5
...
...
@@ -465,6 +465,46 @@ function uw_cfg_common_update_9105(&$sandbox) {
*/
function
uw_cfg_common_update_9106
(
&
$sandbox
)
{
// The database service.
$database
=
\Drupal
::
database
();
// The tables to be used for fields to get and remove.
$tables
=
[
'node__field_uw_type_of_media'
,
'node_revision__field_uw_type_of_media'
,
'node__field_uw_hero_image'
,
'node_revision__field_uw_hero_image'
,
];
// Step through each of the tables and get the data,
// then truncate them. We need to truncate the table
// so that we are able to modify the fields, if there
// is data in these tables, Drupal throws an error about
// data already existing in the fields. We will insert
// the data back into the tables after everything is
// completed.
foreach
(
$tables
as
$table
)
{
// Get the rows in the table.
$values
=
$database
->
select
(
$table
,
'n'
)
->
fields
(
'n'
)
->
execute
()
->
fetchAll
();
// Step through each of the rows and add to variable.
foreach
(
$values
as
$value
)
{
// Add to the variable and cast to an array so that
// we are not using an object, just makes it easier
// to work with when inserting these rows back
// into the database.
$node_data
[
$table
][]
=
(
array
)
$value
;
}
// Truncate the table.
$database
->
truncate
(
$table
)
->
execute
();
}
// The content types that are not getting any changes.
$cts_not_to_install
=
[
'uw_ct_sidebar'
,
...
...
@@ -630,4 +670,29 @@ function uw_cfg_common_update_9106(&$sandbox) {
$node
->
save
();
}
}
// Step through all the tables and insert back into
// the database.
foreach
(
$node_data
as
$table
=>
$data
)
{
// Get all the rows from the table.
foreach
(
$data
as
$field_data
)
{
// Reset the fields array, so we are working with
// a blank array to insert.
$fields
=
[];
// Step through all the entries in the row and add
// to the fields array, this makes it much easier to
// do one insert command.
foreach
(
$field_data
as
$key
=>
$value
)
{
$fields
[
$key
]
=
$value
;
}
// Insert the row into the database.
$result
=
$database
->
insert
(
$table
)
->
fields
(
$fields
)
->
execute
();
}
}
}
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