PluginProbe
The Innovative Form Builder – IvyForms / 1.5.1
The Innovative Form Builder – IvyForms v1.5.1
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
← All changes | backend/src/Repository/Notification/NotificationRepository.php +65 -26 1.1 → 1.5.1 View file →
@@ -29,24 +29,14 @@
29 29 */
30 30 public function add($entity): int
31 31 {
32 32 $data = $entity->toArray();
33 + $row = $this->buildPersistRow($data);
33 34
34 35 $result = $this->wpdb->insert(
35 36 $this->table,
36 - [
37 - 'formId' => (int) $data['formId'],
38 - 'name' => $data['name'],
39 - 'sender' => $data['sender'],
40 - 'replyTo' => $data['replyTo'],
41 - 'receiver' => $data['receiver'],
42 - 'enabled' => (int) $data['enabled'],
43 - 'subject' => $data['subject'],
44 - 'message' => $data['message'],
45 - 'showEmptyFields' => (int) $data['showEmptyFields'],
46 - 'smartLogic' => wp_json_encode($data['smartLogic']),
47 - ],
48 - ['%d', '%s', '%s', '%s', '%s', '%d', '%s', '%s', '%d', '%s']
37 + $row['values'],
38 + $row['formats']
49 39 );
50 40
51 41 if ($result === false) {
52 42 throw new QueryExecutionException(
@@ -69,25 +59,15 @@
69 59 */
70 60 public function update(int $id, $entity): bool
71 61 {
72 62 $data = $entity->toArray();
63 + $row = $this->buildPersistRow($data);
73 64
74 65 $result = $this->wpdb->update(
75 66 $this->table,
76 - [
77 - 'formId' => (int) $data['formId'],
78 - 'name' => $data['name'],
79 - 'sender' => $data['sender'],
80 - 'replyTo' => $data['replyTo'],
81 - 'receiver' => $data['receiver'],
82 - 'enabled' => (int) $data['enabled'],
83 - 'subject' => $data['subject'],
84 - 'message' => $data['message'],
85 - 'showEmptyFields' => (int) $data['showEmptyFields'],
86 - 'smartLogic' => wp_json_encode($data['smartLogic']),
87 - ],
67 + $row['values'],
88 68 ['id' => $id],
89 - ['%d', '%s', '%s', '%s', '%s', '%d', '%s', '%s', '%d', '%s'],
69 + $row['formats'],
90 70 ['%d']
91 71 );
92 72
93 73 if ($result === false) {
@@ -94,8 +74,67 @@
94 74 throw new QueryExecutionException(BackendStrings::getAllFormsStrings()['unable_to_save_data'] . __CLASS__);
95 75 }
96 76
97 77 return true;
78 + }
79 +
80 + /**
81 + * Build insert/update row values and formats, allowing Pro to append columns.
82 + *
83 + * @param array<string, mixed> $data
84 + * @return array{values: array<string, mixed>, formats: string[]}
85 + */
86 + private function buildPersistRow(array $data): array
87 + {
88 + $values = [
89 + 'formId' => (int) $data['formId'],
90 + 'name' => $data['name'],
91 + 'sender' => $data['sender'],
92 + 'replyTo' => $data['replyTo'],
93 + 'receiver' => $data['receiver'],
94 + 'cc' => $data['cc'],
95 + 'bcc' => $data['bcc'],
96 + 'enabled' => (int) $data['enabled'],
97 + 'subject' => $data['subject'],
98 + 'message' => $data['message'],
99 + 'showEmptyFields' => (int) $data['showEmptyFields'],
100 + 'smartLogic' => wp_json_encode($data['smartLogic']),
101 + ];
102 + $formats = ['%d', '%s', '%s', '%s', '%s', '%s', '%s', '%d', '%s', '%s', '%d', '%s'];
103 +
104 + /**
105 + * Extend notification DB persist row (values + formats) for Pro columns.
106 + *
107 + * @since 1.2.0
108 + *
109 + * @param array<string, mixed> $row
110 + * @param array<string, mixed> $data
111 + */
112 + $filtered = apply_filters(
113 + 'ivyforms/notification/repository_row',
114 + [
115 + 'values' => $values,
116 + 'formats' => $formats,
117 + ],
118 + $data
119 + );
120 +
121 + if (
122 + !is_array($filtered)
123 + || !isset($filtered['values'], $filtered['formats'])
124 + || !is_array($filtered['values'])
125 + || !is_array($filtered['formats'])
126 + ) {
127 + return [
128 + 'values' => $values,
129 + 'formats' => $formats,
130 + ];
131 + }
132 +
133 + return [
134 + 'values' => $filtered['values'],
135 + 'formats' => $filtered['formats'],
136 + ];
98 137 }
99 138
100 139 /**
101 140 * Get all notifications by form ID.