Startseite
  • » Home
  • » Handbuch & FAQ
  • » Forum
  • » Übersetzungsserver
  • » Suche
Startseite › Forum › Drupalcenter.de › Anfängerfragen ›

Patch für Modul installieren?

Eingetragen von Tropse (111)
am 13.02.2022 - 01:22 Uhr in
  • Anfängerfragen
  • Drupal 9.x oder neuer

Hallo,

wie bekommt man am unkompliziertesten einen Patch in ein Modul?
Es geht um diesen Patch: https://www.drupal.org/project/bulk_user_registration/issues/3259418

diff --git a/src/Form/BulkUserImport.php b/src/Form/BulkUserImport.php
index 99c4c90..09116e5 100644
--- a/src/Form/BulkUserImport.php
+++ b/src/Form/BulkUserImport.php
@@ -190,8 +190,8 @@ class BulkUserImport extends FormBase {
       $operations[] = [
         '\Drupal\bulk_user_registration\Form\BulkUserImport::batchImport',
         [
-          'userData' => $data,
-          'defaultRole' => $defaultRole,
+          $data,
+          $defaultRole,
         ],
       ];
     }

Das Patch Modul ist installiert:
composer require cweagans/composer-patches

Wie hier beschrieben: https://github.com/cweagans/composer-patches
Habe ich versucht das in die composer.json einzubauen:

    "extra": {
        "merge-plugin": {
            "include": [
                "web/modules/contrib/webform/composer.libraries.json"
            ]
        },
        "patches": {
           "drupal/core": {
               "Add startup configuration for PHP server": "https://www.drupal.org/files/issues/2022-01-19/batch-error-with-php-version-8-3259418-2.patch"
                   }
                         
         },
        "drupal-scaffold": {
            "locations": {
                "web-root": "web/"
            }
        },

Es kommt diese Fehlermeldung:

Gathering patches for dependencies. This might take a minute.
  - Installing drupal/core (9.3.5): Extracting archive
  - Applying patches for drupal/core
    https://www.drupal.org/files/issues/2022-01-19/batch-error-with-php-vers... (Add startup configuration for PHP server)
   Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2022-01-19/batch-error-with-php-version-8-3259418-2.patch

Danke.

‹ Drupal update 8 auf 9 mit Composer update 1 auf 2 Präsentation eines Drupalprojektes ›
  • Anmelden oder Registrieren um Kommentare zu schreiben

wenn es nur so wenige

Eingetragen von montviso (2188)
am 15.02.2022 - 07:51 Uhr

wenn es nur so wenige Änderungen sind, mache ich das per Hand.
Also in Deinem Fall:
Datei suchen, die beiden Zeilen mit Minus entfernen, die beiden Zeilen mit Plus vorne das Plus entfernen.
Evt. einen Kommentar dazu und irgendwo in den Unterlagen dokumentieren.

Größere Patches habe ich auch schon auf der console eingespielt:
https://wiki.ubuntuusers.de/patch/

  • Anmelden oder Registrieren um Kommentare zu schreiben

Schade

Eingetragen von Tropse (111)
am 16.02.2022 - 22:23 Uhr

Danke für den Tipp!
Auch nach zwei Stolpersteinen funktioniert der Patch bei mir nicht.

      $operations[] = [
        '\Drupal\bulk_user_registration\Form\BulkUserImport::batchImport',
        [
          $data,
          $defaultRole,
        ],
      ];
    }

Schade.

  • Anmelden oder Registrieren um Kommentare zu schreiben

In deiner composer.json

Eingetragen von Sammelzwerg (377)
am 17.02.2022 - 18:53 Uhr

In deiner composer.json versuchst du anscheinend den Patch in den Core einzubauen, er gehört aber in die Datei BulkUserImport.php im Modul Bulk User Registration.
So sagt es auch die Fehlermeldung:
- Applying patches for drupal/core: Der patch wird versucht im Core unterzubringen, da passt er aber nicht dazu.

So sollte das in der composer.json aussehen:

    "extra": {
        "merge-plugin": {
            "include": [
                "web/modules/contrib/webform/composer.libraries.json"
            ]
        },
        "patches": {
           "drupal/bulk_user_registration": {
               "Add startup configuration for PHP server": "https://www.drupal.org/files/issues/2022-01-19/batch-error-with-php-version-8-3259418-2.patch"
                   }
                        
         },
        "drupal-scaffold": {
            "locations": {
                "web-root": "web/"
            }
        },

Alternativ hier der Inhalt der gepatchten Datei bulk_user_registration/src/Form/BulkUserImport.php:

<?php

namespace Drupal\bulk_user_registration\Form;

use Drupal\bulk_user_registration\BulkUserRegistration;
use Drupal\bulk_user_registration\BulkUserRegistrationInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\FileBag;

/**
* Bulk user import form.
*
* @package Drupal\bulk_user_registration
*/
class BulkUserImport extends FormBase {

  /**
   * Request stack.
   *
   * @var \Symfony\Component\HttpFoundation\RequestStack
   */
  protected $requestStack;

  /**
   * The bulk user registration service.
   *
   * @var \Drupal\bulk_user_registration\BulkUserRegistration
   */
  protected $bulkUserRegistration;

  /**
   * Constructor.
   *
   * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
   *   Request stack.
   * @param \Drupal\bulk_user_registration\BulkUserRegistration $bulkUserRegistration
   *   The bulk user registration service.
   */
  public function __construct(RequestStack $requestStack, BulkUserRegistration $bulkUserRegistration) {
    $this->requestStack = $requestStack;
    $this->bulkUserRegistration = $bulkUserRegistration;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('request_stack'),
      $container->get('bulk_user_registration')
    );
  }

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'bulk_user_registration_import';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {

    $form['file_upload'] = [
      '#type' => 'file',
      '#title' => $this->t('Import CSV file'),
      '#description' => $this->t('The CSV file to be imported. Check the CSV sample below if you are not sure about the format.'),
      '#autoupload' => TRUE,
      '#upload_validators' => ['file_validate_extensions' => ['csv']],
    ];

    $form['sample_csv'] = [
      '#type' => 'item',
      'link' => [
        '#type' => 'link',
        '#title' => $this->t('Download sample CSV'),
        '#url' => Url::fromRoute('bulk_user_registration.csv_sample'),
      ],
      '#description' => $this->t('This sample file contains all possible fields and various data samples to get you started.'),
    ];

    $form['default_role'] = [
      '#type' => 'select',
      '#title' => $this->t('Default role'),
      '#description' => $this->t('The default role for imported users. When no role data is provided in the CSV, this role will be assigned.'),
      '#options' => self::getAllowedRoles(),
      '#default_value' => '',
      '#required' => TRUE,
    ];

    $form['actions']['submit'] = [
      '#type' => 'submit',
      '#value' => $this->t('Import'),
      '#button_type' => 'primary',
    ];

    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function validateForm(array &$form, FormStateInterface $form_state) {
    // TODO Prevent form submit when file_upload is empty.
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $defaultRole = $form_state->getValue('default_role');
    $this->handleFileData($this->requestStack->getCurrentRequest()->files, $defaultRole);
  }

  /**
   * To import data as users.
   *
   * @param \Symfony\Component\HttpFoundation\FileBag $filedata
   *   Field data.
   * @param string $defaultRole
   *   The default role.
   */
  protected function handleFileData(FileBag $filedata, $defaultRole) {

    /** @var \Symfony\Component\HttpFoundation\File\UploadedFile $uploadedFile */
    $uploadedFiles = $filedata->get('files');
    $location = $uploadedFiles['file_upload']->getRealPath();
    if (($handle = fopen($location, 'r')) === FALSE) {
      return;
    }

    // Read the csv data.
    $headerData = [];
    $csvData = [];
    while (($data = fgetcsv($handle)) !== FALSE) {
      if (empty($headerData)) {
        $headerData = $data;
      }
      else {
        $csvData[] = $data;
      }
    }
    fclose($handle);

    // Only standard and extra fields are allowed as csv columns. Unknown
    // fields will be ignored.
    $fieldNames = $this->bulkUserRegistration->getFieldNames();
    $columnsToIgnore = [];
    foreach ($headerData as $column => $header) {
      if (!isset($fieldNames[$header])) {
        $columnsToIgnore[] = $column;
      }
    }

    // Collect the user data in a structured array. Where keys are the
    // names of the appropriate header column.
    $userData = [];
    foreach ($csvData as $csvRow) {
      $row_data = [];
      foreach ($csvRow as $column => $value) {
        if (in_array($column, $columnsToIgnore)) {
          continue;
        }
        $row_data[$headerData[$column]] = trim($value);
      }
      $userData[] = $row_data;
    }
    $userData = array_filter($userData);

    $this->batchProcessUserInfo($userData, $defaultRole);
  }

  /**
   * Process user information in a batch.
   *
   * @param array $userData
   *   Structured array of user data.
   * @param string $defaultRole
   *   Default user role.
   */
  public function batchProcessUserInfo(array $userData, $defaultRole) {
    $operations = [];
    foreach ($userData as $data) {
      $operations[] = [
        '\Drupal\bulk_user_registration\Form\BulkUserImport::batchImport',
        [
          $data,
          $defaultRole,
        ],
      ];
    }

    $batch = [
      'title' => $this->t('Importing users..'),
      'operations' => $operations,
      'finished' => '\Drupal\bulk_user_registration\Form\BulkUserImport::batchFinished',
    ];
    batch_set($batch);
  }

  /**
   * Batch callback: User import operation.
   *
   * @param array $userData
   *   Structured array of user data. The keys are user field names.
   * @param string $defaultRole
   *   The default role.
   * @param array $context
   *   Batch context data.
   */
  public static function batchImport(array $userData, $defaultRole, array &$context) {

    // Required user data is missing. Do not import.
    if (empty($userData[BulkUserRegistrationInterface::FIELD_EMAIL]) || empty($userData[BulkUserRegistrationInterface::FIELD_USER_NAME])) {
      return;
    }

    // This user already exists. Do not import.
    if (user_load_by_mail($userData[BulkUserRegistrationInterface::FIELD_EMAIL])) {
      return;
    }

    $user = \Drupal::service('bulk_user_registration')
      ->createUser($userData, $defaultRole);

    // Notify user via mail.
    if ($user->isActive()) {
      _user_mail_notify('register_no_approval_required', $user);
    }

    $context['results'][] = $user->id();
  }

  /**
   * Batch callback: Finish bulk user import process.
   *
   * @param bool $success
   *   Success or not.
   * @param array $results
   *   Results array.
   * @param mixed $operations
   *   Operations.
   */
  public static function batchFinished($success, array $results, $operations) {
    $messenger = \Drupal::messenger();
    if ($success) {
      $messenger->addStatus(\Drupal::translation()
        ->formatPlural(count($results), '1 user imported.', '@count users imported.'));
    }
    else {
      $messenger->addError(t('Finished with errors.'));
    }
  }

  /**
   * The roles allowed to import.
   *
   * @return array
   *   An associative array with the role id as the key and the role name as
   *   value.
   */
  protected function getAllowedRoles() {
    $allowedRoles = \Drupal::config('bulk_user_registration.settings')->get('allowed_roles');
    return array_intersect_key(user_role_names(TRUE), array_flip(array_filter($allowedRoles)));
  }

}

  • Anmelden oder Registrieren um Kommentare zu schreiben

Also wenn Composer dir sagt.

Eingetragen von dinmikkith (1573)
am 19.02.2022 - 11:34 Uhr

Also wenn Composer dir sagt. Hi ich kann den Patch nicht anwenden. Dann ist doch die Frage warum nicht. Ich mach das, da Ann immer mit git apply und lass mir, den output ausgeben, damit ich sehe, warum der Patch nicht angewendet werden kann.

Meistens ist er dann schon in Der aktuellen release verbaut.

Aber du musst halt erst mal rauskriegen ob du den Patch überhaupt noch applyen kannst. Wenn nicht schmeiß ihn aus, der Composer. Json. Wenn ja check deiner Composer.json noch mal.

  • Anmelden oder Registrieren um Kommentare zu schreiben

dinmikkith schrieb Also wenn

Eingetragen von Sammelzwerg (377)
am 19.02.2022 - 14:37 Uhr
dinmikkith schrieb

Also wenn Composer dir sagt. Hi ich kann den Patch nicht anwenden. Dann ist doch die Frage warum nicht. Ich mach das, da Ann immer mit git apply und lass mir, den output ausgeben, damit ich sehe, warum der Patch nicht angewendet werden kann.

Meistens ist er dann schon in Der aktuellen release verbaut.

Aber du musst halt erst mal rauskriegen ob du den Patch überhaupt noch applyen kannst. Wenn nicht schmeiß ihn aus, der Composer. Json. Wenn ja check deiner Composer.json noch mal.

Wie ich oben bereits geschrieben habe, ist in der composer.json fälschlicherweise drupal/core als Patch-Ziel angegeben anstatt von drupal/bulk_user_registration.

  • Anmelden oder Registrieren um Kommentare zu schreiben

https://duvien.com/blog/how-a

Eingetragen von dinmikkith (1573)
am 19.02.2022 - 18:54 Uhr

https://duvien.com/blog/how-apply-patch-file-composer-based-drupal-89

  • Anmelden oder Registrieren um Kommentare zu schreiben

Benutzeranmeldung

  • Registrieren
  • Neues Passwort anfordern

Aktive Forenthemen

  • für drupal11 ein Slider Modul
  • [gelöst] W3CSS Paragraphs Views
  • Drupal 11 neu aufsetzen und Bereiche aus 10 importieren
  • Wie erlaubt man neuen Benutzern auf die Resetseite zugreifen zu dürfen.
  • [gelöst] Anzeigeformat Text mit Bild in einem Artikel, Drupal 11
  • Social Media Buttons um Insteragram erweitern
  • Nach Installation der neuesten D10-Version kein Zugriff auf Website
  • Composer nach Umzug
  • [gelöst] Taxonomie Begriffe zeigt nicht alle Nodes an
  • Drupal 11 + Experience Builder (Canvas) + Layout Builder
  • Welche KI verwendet ihr?
  • Update Manger läst sich nicht Installieren
Weiter

Neue Kommentare

  • melde mich mal wieder, da ich
    vor 1 Woche 6 Tagen
  • Hey danke
    vor 2 Wochen 10 Stunden
  • Update: jetzt gibt's ein
    vor 2 Wochen 1 Tag
  • Hallo, im Prinzip habe ich
    vor 2 Wochen 5 Tagen
  • Da scheint die Terminologie
    vor 2 Wochen 5 Tagen
  • Kannst doch auch alles direkt
    vor 3 Wochen 2 Tagen
  • In der entsprechenden View
    vor 3 Wochen 2 Tagen
  • Dazu müsstest Du vermutlich
    vor 3 Wochen 2 Tagen
  • gelöst
    vor 5 Wochen 6 Tagen
  • Ja natürlich. Dass ist etwas,
    vor 6 Wochen 11 Stunden

Statistik

Beiträge im Forum: 250233
Registrierte User: 20451

Neue User:

  • ByteScrapers
  • Mroppoofpaync
  • 4aficiona2

» Alle User anzeigen

User nach Punkten sortiert:
wla9461
stBorchert6003
quiptime4972
Tobias Bähr4019
bv3924
ronald3857
md3717
Thoor3678
Alexander Langer3416
Exterior2903
» User nach Punkten
Zur Zeit sind 0 User und 21 Gäste online.

Hauptmenü

  • » Home
  • » Handbuch & FAQ
  • » Forum
  • » Übersetzungsserver
  • » Suche

Quicklinks I

  • Infos
  • Drupal Showcase
  • Installation
  • Update
  • Forum
  • Team
  • Verhaltensregeln

Quicklinks II

  • Drupal Jobs
  • FAQ
  • Drupal-Kochbuch
  • Best Practice - Drupal Sites - Guidelines
  • Drupal How To's

Quicklinks III

  • Tipps & Tricks
  • Drupal Theme System
  • Theme Handbuch
  • Leitfaden zur Entwicklung von Modulen

RSS & Twitter

  • Drupal Planet deutsch
  • RSS Feed News
  • RSS Feed Planet
  • Twitter Drupalcenter
Drupalcenter Team | Impressum & Datenschutz | Kontakt
Angetrieben von Drupal | Drupal is a registered trademark of Dries Buytaert.
Drupal Initiative - Drupal Association