4
4
5
5
use Craft ;
6
6
use craft \db \Query ;
7
+ use craft \helpers \StringHelper ;
7
8
use yii \base \InvalidArgumentException ;
8
9
9
10
/**
@@ -31,8 +32,13 @@ public function getAllGroups(): array
31
32
->all ();
32
33
33
34
$ groups = [];
35
+ $ isMysql = Craft::$ app ->getDb ()->getIsMysql ();
34
36
35
37
foreach ($ results as $ result ) {
38
+ if ($ isMysql ) {
39
+ $ result ['name ' ] = html_entity_decode ($ result ['name ' ], ENT_QUOTES | ENT_HTML5 );
40
+ }
41
+
36
42
$ groups [] = new Group ($ result );
37
43
}
38
44
@@ -55,18 +61,24 @@ public function saveGroup(Group $group, bool $runValidation = true): bool
55
61
56
62
$ db = Craft::$ app ->getDb ();
57
63
64
+ if ($ db ->getIsMysql ()) {
65
+ $ name = StringHelper::encodeMb4 ($ group ->name );
66
+ } else {
67
+ $ name = $ group ->name ;
68
+ }
69
+
58
70
if ($ group ->id ) {
59
71
$ db ->createCommand ()
60
72
->update ('{{%webhookgroups}} ' , [
61
- 'name ' => $ group -> name ,
73
+ 'name ' => $ name ,
62
74
], [
63
75
'id ' => $ group ->id ,
64
76
])
65
77
->execute ();
66
78
} else {
67
79
$ db ->createCommand ()
68
80
->insert ('{{%webhookgroups}} ' , [
69
- 'name ' => $ group -> name ,
81
+ 'name ' => $ name ,
70
82
])
71
83
->execute ();
72
84
@@ -153,7 +165,7 @@ public function getWebhookById(int $id): Webhook
153
165
throw new InvalidArgumentException ('Invalid webhook ID: ' . $ id );
154
166
}
155
167
156
- return new Webhook ($ result );
168
+ return $ this -> _createWebhook ($ result );
157
169
}
158
170
159
171
/**
@@ -170,10 +182,18 @@ public function saveWebhook(Webhook $webhook, bool $runValidation = true): bool
170
182
return false ;
171
183
}
172
184
185
+ $ db = Craft::$ app ->getDb ();
186
+
187
+ if ($ db ->getIsMysql ()) {
188
+ $ name = StringHelper::encodeMb4 ($ webhook ->name );
189
+ } else {
190
+ $ name = $ webhook ->name ;
191
+ }
192
+
173
193
$ data = [
174
194
'groupId ' => $ webhook ->groupId ,
175
195
'enabled ' => (bool )$ webhook ->enabled ,
176
- 'name ' => $ webhook -> name ,
196
+ 'name ' => $ name ,
177
197
'class ' => $ webhook ->class ,
178
198
'event ' => $ webhook ->event ,
179
199
'type ' => $ webhook ->type ,
@@ -183,8 +203,6 @@ public function saveWebhook(Webhook $webhook, bool $runValidation = true): bool
183
203
'eventAttributes ' => $ webhook ->eventAttributes ,
184
204
];
185
205
186
- $ db = Craft::$ app ->getDb ();
187
-
188
206
if ($ webhook ->id ) {
189
207
$ db ->createCommand ()
190
208
->update ('{{%webhooks}} ' , $ data , ['id ' => $ webhook ->id ])
@@ -221,16 +239,31 @@ private function _createWebhookQuery(): Query
221
239
->from (['{{%webhooks}} ' ]);
222
240
}
223
241
242
+ /**
243
+ * @param array $result
244
+ * @param bool|null $isMysql
245
+ * @return Webhook
246
+ */
247
+ private function _createWebhook (array $ result , bool $ isMysql = null ): Webhook
248
+ {
249
+ if ($ isMysql ?? Craft::$ app ->getDb ()->getIsMysql ()) {
250
+ $ result ['name ' ] = html_entity_decode ($ result ['name ' ], ENT_QUOTES | ENT_HTML5 );
251
+ }
252
+
253
+ return new Webhook ($ result );
254
+ }
255
+
224
256
/**
225
257
* @param array
226
258
* @return Webhook[]
227
259
*/
228
260
private function _createWebhooks (array $ results ): array
229
261
{
230
262
$ webhooks = [];
263
+ $ isMysql = Craft::$ app ->getDb ()->getIsMysql ();
231
264
232
265
foreach ($ results as $ result ) {
233
- $ webhooks [] = new Webhook ($ result );
266
+ $ webhooks [] = $ this -> _createWebhook ($ result, $ isMysql );
234
267
}
235
268
236
269
return $ webhooks ;
0 commit comments