Commit b1824b81 authored by Thomas Nilsson's avatar Thomas Nilsson
Browse files

Issue #3200737 by sl27257, bachbach, TLWatson: make the related_flag id unique

parent f88c6c49
Loading
Loading
Loading
Loading
+14 −6
Original line number Diff line number Diff line
@@ -130,6 +130,7 @@ function flag_lists_update_8003() {
 */
function flag_lists_update_8004() {

  $missingRelated = FALSE;
  $flagService = \Drupal::service('flag');
  $flagListsService = \Drupal::service('flaglists');
  $database = \Drupal::database();
@@ -137,6 +138,13 @@ function flag_lists_update_8004() {
  foreach ($flagListsService->getAllFlaggingCollections() as $flagList) {
    $entity_id = $flagList->id();
    $userId = $flagList->getOwnerId();
    if (empty($flagList->getRelatedFlag())) {
      // The related Flag is broken, just bail out.
      // It must be fixed by the method recommended in the help.
      // Show a message that the related Flag is missing.
      $missingRelated = TRUE;
      continue;
    }
    $relatedFlag = $flagList->getRelatedFlag();
    $originalId = $relatedFlag->id();
    $newName = 'relflag_' . $entity_id . '_' . $userId;
@@ -144,27 +152,22 @@ function flag_lists_update_8004() {
      $database->update('flagging')
        ->fields(['flag_id' => $newName])
        ->condition('flag_id', $originalId)
        ->distinct()
        ->execute();
      $database->update('flag_counts')
        ->fields(['flag_id' => $newName])
        ->condition('flag_id', $originalId)
        ->distinct()
        ->execute();
      $database->update('flagging_collection_field_data')
        ->fields(['relatedflag' => $newName])
        ->condition('id', $entity_id)
        ->distinct()
        ->execute();
      $database->update('flagging_collection_field_revision')
        ->fields(['relatedflag' => $newName])
        ->condition('id', $entity_id)
        ->distinct()
        ->execute();
      $database->update('flag_list_item_field_data')
        ->fields(['baseflag' => $newName])
        ->condition('baseflag', $originalId)
        ->distinct()
        ->execute();
      // Update the name of the Related Flag by creating a new
      // and delete the old. The deletion must be done after all
@@ -175,7 +178,12 @@ function flag_lists_update_8004() {
      $newRelatedFlag->save();
    }
  }
  if ($missingRelated) {
    $message = 'Some of your Flag Lists where not updated due to incorrect Related Flags. Check your Flag Lists for errors and update them accordingly.';
  }
  else {
    $message = 'Updated the Flagging Collections Related flags to follow the new naming convention.';
  }
  return $message;
}

+4 −0
Original line number Diff line number Diff line
@@ -43,6 +43,10 @@ function flag_lists_help($route_name, RouteMatchInterface $route_match) {
      $output .= t('More detailed information on the usage of this module can be found on the Drupal documentation site under') . ' ';
      $output .= $link->toString();
      $output .= '</p>';
      $output .= '<h3>' . t('Missing / Deleted Related Flags') . '</h3>';
      $output .= '<p>';
      $output .= t('If you get the error message that you have a problem with related Flags, a solution is descibed on the this page <a href=":missingRelated"><em>Missing Related Flags</em></a>', [':missingRelated' => Url::fromRoute('flag_lists.missing_related')->toString()]);
      $output .= '</p>';
      return $output;

    case 'entity.flag_for_list.collection':