8000 [Translation] [LocoProvider] Use rawurlencode and separate tag setting · symfony/symfony@b694858 · GitHub
[go: up one dir, main page]

Skip to content

Commit b694858

Browse files
danut007ronicolas-grekas
authored andcommitted
[Translation] [LocoProvider] Use rawurlencode and separate tag setting
1 parent f075ce8 commit b694858

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

src/Symfony/Component/Translation/Bridge/Loco/LocoProvider.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public function delete(TranslatorBagInterface $translatorBag): void
140140

141141
foreach (array_keys($catalogue->all()) as $domain) {
142142
foreach ($this->getAssetsIds($domain) as $id) {
143-
$responses[$id] = $this->client->request('DELETE', sprintf('assets/%s.json', $id));
143+
$responses[$id] = $this->client->request('DELETE', sprintf('assets/%s.json', rawurlencode($id)));
144144
}
145145
}
146146

@@ -202,7 +202,7 @@ private function translateAssets(array $translations, string $locale): void
202202
$responses = [];
203203

204204
foreach ($translations as $id => $message) {
205-
$responses[$id] = $this->client->request('POST', sprintf('translations/%s/%s', $id, $locale), [
205+
$responses[$id] = $this->client->request('POST', sprintf('translations/%s/%s', rawurlencode($id), rawurlencode($locale)), [
206206
'body' => $message,
207207
]);
208208
}
@@ -220,13 +220,35 @@ private function tagsAssets(array $ids, string $tag): void
220220
$this->createTag($tag);
221221
}
222222

223-
$response = $this->client->request('POST', sprintf('tags/%s.json', $tag), [
224-
'body' => implode(',', $ids),
223+
// Separate ids with and without comma.
224+
$idsWithComma = $idsWithoutComma = [];
225+
foreach ($ids as $id) {
226+
if (false !== strpos($id, ',')) {
227+
$idsWithComma[] = $id;
228+
} else {
229+
$idsWithoutComma[] = $id;
230+
}
231+
}
232+
233+
// Set tags for all ids without comma.
234+
$response = $this->client->request('POST', sprintf('tags/%s.json', rawurlencode($tag)), [
235+
'body' => implode(',', $idsWithoutComma),
225236
]);
226237

227238
if (200 !== $response->getStatusCode()) {
228239
$this->logger->error(sprintf('Unable to tag assets with "%s" on Loco: "%s".', $tag, $response->getContent(false)));
229240
}
241+
242+
// Set tags for each id with comma one by one.
243+
foreach ($idsWithComma as $id) {
244+
$response = $this->client->request('POST', sprintf('assets/%s/tags', rawurlencode($id)), [
245+
'body' => ['name' => $tag],
246+
]);
247+
248+
if (200 !== $response->getStatusCode()) {
249+
$this->logger->error(sprintf('Unable to tag asset "%s" with "%s" on Loco: "%s".', $id, $tag, $response->getContent(false)));
250+
}
251+
}
230252
}
231253

232254
private function createTag(string $tag): void

0 commit comments

Comments
 (0)
0