Skip to content

Commit

Permalink
[EPAD8-2237] Adding updated deploy hook that should ensure we don't r…
Browse files Browse the repository at this point in the history
…un into the duplicate key constraint violation as we're seeing on staging-www.
  • Loading branch information
carsoncho committed Jan 19, 2024
1 parent 4ba5290 commit b886a5e
Showing 1 changed file with 56 additions and 28 deletions.
84 changes: 56 additions & 28 deletions services/drupal/web/modules/custom/epa_core/epa_core.deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,47 +337,75 @@ function epa_core_deploy_0004_set_card_field_default_values(&$sandbox) {

// Update all card_group paragraph revision and non-revision items to set field_image_style if a value is not already set.
$field_table = $table_prefix . 'field_image_style';
$missing_image_styles_paragraphs = $database->query("SELECT p.id, p.revision_id FROM $item_table AS p LEFT JOIN $field_table AS i ON p.revision_id = i.revision_id WHERE p.type = 'card_group' AND i.field_image_style_value IS NULL")->fetchAll();
$missing_image_styles_paragraphs = $database->query("SELECT p.id, p.revision_id, i.revision_id AS field_revision_id FROM $item_table AS p LEFT JOIN $field_table AS i ON p.revision_id = i.revision_id WHERE p.type = 'card_group' AND i.field_image_style_value IS NULL")->fetchAll();
foreach ($missing_image_styles_paragraphs as $paragraph) {
$database->insert($field_table)->fields([
'bundle' => 'card_group',
'deleted' => 0,
'entity_id' => $paragraph->id,
'revision_id' => $paragraph->revision_id,
'langcode' => 'en',
'delta' => 0,
'field_image_style_value' => 'exdent'
])->execute();
if (empty($paragraph->field_revision_id)) {
// Record does not exist in field table.
$database->insert($field_table)->fields([
'bundle' => 'card_group',
'deleted' => 0,
'entity_id' => $paragraph->id,
'revision_id' => $paragraph->revision_id,
'langcode' => 'en',
'delta' => 0,
'field_image_style_value' => 'exdent'
])->execute();
}
else {
// Record does exist but is null, run update instead.
$database->update($field_table)->fields([
'field_image_style_value' => 'exdent'
])->execute();
}
}

// Update all card_group paragraph revision and non-revision items to set field_title_placement if a value is not already set.
$field_table = $table_prefix . 'field_title_placement';
$missing_title_placement_paragraphs = $database->query("SELECT p.id, p.revision_id FROM $item_table AS p LEFT JOIN $field_table AS i ON p.revision_id = i.revision_id WHERE p.type = 'card_group' AND i.field_title_placement_value IS NULL")->fetchAll();
$missing_title_placement_paragraphs = $database->query("SELECT p.id, p.revision_id, i.revision_id AS field_revision_id FROM $item_table AS p LEFT JOIN $field_table AS i ON p.revision_id = i.revision_id WHERE p.type = 'card_group' AND i.field_title_placement_value IS NULL")->fetchAll();
foreach ($missing_title_placement_paragraphs as $paragraph) {
$database->insert($field_table)->fields([
'bundle' => 'card_group',
'deleted' => 0,
'entity_id' => $paragraph->id,
'revision_id' => $paragraph->revision_id,
'langcode' => 'en',
'delta' => 0,
'field_title_placement_value' => 'media-first'
])->execute();
if (empty($paragraph->field_revision_id)) {
// Record does not exist in field table.
$database->insert($field_table)->fields([
'bundle' => 'card_group',
'deleted' => 0,
'entity_id' => $paragraph->id,
'revision_id' => $paragraph->revision_id,
'langcode' => 'en',
'delta' => 0,
'field_title_placement_value' => 'media-first'
])->execute();
}
else {
// Record does exist but is null, run update.
$database->update($field_table)->fields([
'field_title_placement_value' => 'media-first'
])->execute();
}

}

// Update all card paragraph revision and non-revision items to set field_flag_card_alignment if a value is not already set.
$field_table = $table_prefix . 'field_flag_card_alignment';
$missing_flag_alignment_paragraphs = $database->query("SELECT p.id, p.revision_id FROM $item_table AS p LEFT JOIN $field_table AS i ON p.revision_id = i.revision_id WHERE p.type = 'card' AND i.field_flag_card_alignment_value IS NULL")->fetchAll();
$missing_flag_alignment_paragraphs = $database->query("SELECT p.id, p.revision_id, i.revision_id as field_revision_id FROM $item_table AS p LEFT JOIN $field_table AS i ON p.revision_id = i.revision_id WHERE p.type = 'card' AND i.field_flag_card_alignment_value IS NULL")->fetchAll();
foreach ($missing_flag_alignment_paragraphs as $paragraph) {
$database->insert($field_table)->fields([
'bundle' => 'card',
'deleted' => 0,
'entity_id' => $paragraph->id,
'revision_id' => $paragraph->revision_id,
'langcode' => 'en',
'delta' => 0,
if (empty($paragraph->field_revision_id)) {
// Record does not exist in field table.
$database->insert($field_table)->fields([
'bundle' => 'card',
'deleted' => 0,
'entity_id' => $paragraph->id,
'revision_id' => $paragraph->revision_id,
'langcode' => 'en',
'delta' => 0,
'field_flag_card_alignment_value' => 'default'
])->execute();
}
else {
// Record does exist but is null, run update.
$database->update($field_table)->fields([
'field_flag_card_alignment_value' => 'default'
])->execute();
}
}
}
}

0 comments on commit b886a5e

Please sign in to comment.