@@ -18,6 +18,9 @@ function hoeringsportal_public_meeting_update_dependencies() {
1818 10002 => [
1919 'itk_pretix' => 10101,
2020 ],
21+ 10003 => [
22+ 'itk_pretix' => 10102,
23+ ],
2124 ],
2225 ];
2326}
@@ -79,3 +82,53 @@ function hoeringsportal_public_meeting_update_10002() {
7982 }
8083 }
8184}
85+
86+ /**
87+ * Copy contact mail to pretix event settings.
88+ *
89+ * Note: For performance reasons (mainly due to request to pretix), rather than
90+ * saving nodes we update values directly in the database.
91+ */
92+ function hoeringsportal_public_meeting_update_10003() {
93+ /** @var \Drupal\hoeringsportal_public_meeting\Helper\PublicMeetingHelper $helper */
94+ $helper = \Drupal::service('hoeringsportal_public_meeting.public_meeting_helper');
95+ $publicMeetings = $helper->loadPublicMeetings();
96+
97+ $values = [];
98+ foreach ($publicMeetings as $publicMeeting) {
99+ if ($helper->hasPretixSignUp($publicMeeting)) {
100+ $contactMail = $publicMeeting->field_email_address->getString() ?: NULL;
101+ foreach ($publicMeeting->field_pretix_event_settings as $delta => $_) {
102+ $values[] = [
103+ 'conditions' => [
104+ 'bundle' => $publicMeeting->bundle(),
105+ 'entity_id' => $publicMeeting->id(),
106+ 'delta' => $delta,
107+ ],
108+ 'fields' => [
109+ 'field_pretix_event_settings_contact_mail' => $contactMail,
110+ ],
111+ ];
112+ }
113+ }
114+ }
115+
116+ if (!empty($values)) {
117+ $tableNames = \Drupal::entityTypeManager()
118+ ->getStorage('node')
119+ ->getTableMapping()
120+ ->getAllFieldTableNames('field_pretix_event_settings');
121+ $database = \Drupal::database();
122+
123+ foreach ($tableNames as $tableName) {
124+ foreach ($values as $value) {
125+ $query = $database->update($tableName)
126+ ->fields($value['fields']);
127+ foreach ($value['conditions'] as $field => $val) {
128+ $query->condition($field, $val);
129+ }
130+ $query->execute();
131+ }
132+ }
133+ }
134+ }
0 commit comments