Commit bd63c3b6 authored by Primoz Hmeljak's avatar Primoz Hmeljak Committed by Sascha Grossenbacher
Browse files

Issue #3312233 by Primsi: Support notification webhooks

parent 535b3db6
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -10,6 +10,6 @@
    "source": "https://www.drupal.org/project/tmgmt_xillio"
  },
  "require": {
    "drupal/tmgmt": "^1.5"
    "drupal/tmgmt": "^1.14"
  }
}
+11 −8
Original line number Diff line number Diff line
@@ -10,3 +10,6 @@ tmgmt.translator.settings.xillio:
    password:
      type: string
      label: The password for the xillio translation service.
    webhook_id:
      type: string
      label: The id for the notification webhook.
+86 −90
Original line number Diff line number Diff line
@@ -2,98 +2,94 @@
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
 "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
 width="2685.000000pt" height="1243.000000pt" viewBox="0 0 2685.000000 1243.000000"
 width="2708.000000pt" height="1374.000000pt" viewBox="0 0 2708.000000 1374.000000"
 preserveAspectRatio="xMidYMid meet">

<g transform="translate(0.000000,1243.000000) scale(0.100000,-0.100000)"
<g transform="translate(0.000000,1374.000000) scale(0.100000,-0.100000)"
fill="#000000" stroke="none">
<path d="M6835 12420 c-264 -40 -485 -200 -601 -435 -61 -125 -84 -221 -84
-360 0 -141 23 -236 87 -365 40 -80 63 -110 143 -191 161 -163 308 -228 535
-236 159 -7 252 13 390 81 206 102 356 286 416 512 30 111 30 287 0 399 -92
343 -383 580 -739 599 -48 3 -114 1 -147 -4z"/>
<path d="M15745 12406 c-157 -36 -272 -101 -390 -220 -174 -176 -243 -352
-232 -596 6 -136 23 -206 77 -315 101 -205 265 -345 485 -415 50 -16 106 -24
193 -27 160 -7 256 12 387 76 l95 46 722 -668 c1015 -940 994 -920 1049 -1013
92 -157 128 -299 108 -424 -13 -82 -22 -103 -114 -256 -191 -318 -291 -553
-360 -848 -52 -224 -60 -302 -60 -606 1 -249 3 -301 23 -414 83 -477 267 -889
559 -1251 154 -191 416 -427 618 -557 704 -453 1576 -550 2361 -262 251 92
531 251 744 421 110 88 318 295 404 403 93 116 210 295 274 416 64 122 95 161
167 208 88 59 153 77 290 82 l120 4 709 -242 709 -243 3 -105 c13 -496 358
-911 841 -1009 590 -121 1158 274 1253 872 19 117 8 319 -24 434 -99 359 -363
626 -732 740 -84 26 -100 27 -284 27 -183 0 -200 -2 -285 -27 -269 -81 -499
-260 -630 -492 -25 -44 -46 -84 -48 -89 -4 -13 -1267 425 -1385 480 -156 72
-271 168 -335 277 -45 77 -55 137 -61 372 -10 441 -82 736 -281 1155 -94 198
-105 233 -105 328 0 126 39 231 132 357 52 71 75 93 703 653 l480 429 25 -19
c257 -197 519 -289 825 -289 203 -1 339 25 510 96 407 168 699 529 787 970 26
130 28 344 4 467 -33 173 -46 200 -170 355 -130 164 -254 308 -408 475 -103
111 -112 118 -193 152 -180 75 -333 106 -525 106 -347 0 -653 -121 -901 -358
-211 -200 -345 -450 -393 -731 -20 -121 -21 -320 0 -442 27 -159 105 -365 184
-485 l20 -31 -548 -490 c-301 -269 -570 -507 -596 -527 -117 -89 -265 -141
-401 -139 -117 1 -149 14 -309 121 -354 238 -730 381 -1156 438 -151 21 -479
23 -625 5 -344 -42 -623 -129 -955 -297 -91 -46 -185 -88 -210 -93 -151 -35
-317 15 -476 144 -41 33 -465 424 -943 870 l-867 810 37 80 c56 122 73 211 66
369 -5 143 -18 199 -73 311 -96 197 -271 346 -489 415 -89 29 -307 37 -400 16z
m4865 -4045 c393 -89 697 -335 870 -703 83 -178 117 -357 107 -576 -9 -190
-42 -321 -124 -487 -163 -327 -455 -564 -811 -657 -108 -29 -130 -31 -292 -32
-188 -1 -268 11 -413 60 -424 143 -751 529 -828 974 -16 94 -17 303 -1 396 90
543 525 969 1067 1043 102 14 324 5 425 -18z"/>
<path d="M9595 12373 c-102 -9 -286 -35 -347 -49 l-68 -16 2 -3831 3 -3831 30
-8 c62 -17 275 -48 404 -58 324 -25 745 -2 991 53 l55 12 3 3833 c1 2107 1
3832 0 3832 -2 0 -48 9 -104 20 -188 36 -377 50 -661 48 -147 -1 -286 -3 -308
-5z"/>
<path d="M12595 12373 c-102 -9 -286 -35 -347 -49 l-68 -16 2 -3831 3 -3831
30 -8 c62 -17 275 -48 404 -58 324 -25 745 -2 991 53 l55 12 3 3833 c1 2107 1
3832 0 3832 -2 0 -48 9 -104 20 -188 36 -377 50 -661 48 -147 -1 -286 -3 -308
-5z"/>
<path d="M810 9674 c-172 -15 -487 -58 -498 -68 -2 -3 318 -549 712 -1215 394
-666 716 -1213 716 -1216 0 -3 -358 -570 -795 -1261 -437 -690 -795 -1258
-795 -1263 0 -9 199 -45 355 -63 146 -17 629 -17 765 0 148 18 332 51 345 62
6 5 231 363 501 794 269 432 492 786 495 786 3 0 222 -356 485 -790 458 -757
480 -791 514 -800 125 -33 384 -59 655 -67 265 -7 508 7 755 43 91 13 168 24
173 24 4 0 7 4 7 9 0 5 -356 587 -791 1293 -435 705 -796 1292 -801 1304 -8
17 100 194 716 1173 400 634 730 1161 736 1171 8 16 1 19 -78 33 -237 44 -340
51 -682 51 -296 0 -351 -2 -470 -22 -74 -12 -157 -27 -185 -34 l-50 -13 -416
-665 c-229 -366 -423 -673 -430 -683 -13 -16 -54 50 -419 666 l-405 685 -125
21 c-69 12 -163 26 -210 32 -84 10 -692 20 -780 13z"/>
<path d="M6615 9673 c-81 -6 -274 -33 -353 -50 l-72 -16 2 -2480 3 -2481 50
-13 c311 -79 962 -82 1345 -5 l85 17 3 2478 2 2477 -24 9 c-39 15 -263 50
-391 61 -110 9 -531 11 -650 3z"/>
<path d="M15550 9669 c-117 -11 -316 -44 -353 -58 l-27 -11 2 -2477 3 -2477
30 -8 c62 -17 275 -48 404 -58 324 -25 745 -2 991 53 l55 12 3 2481 2 2481
-85 17 c-198 39 -299 48 -615 51 -173 2 -358 -1 -410 -6z"/>
<path d="M17750 3091 c-326 -69 -528 -275 -610 -624 -67 -285 -47 -651 49
-892 93 -231 271 -386 519 -452 87 -24 115 -26 277 -26 162 0 190 2 277 26
122 32 206 72 291 137 209 162 317 449 317 845 0 366 -91 632 -273 801 -108
100 -229 158 -395 190 -106 20 -345 17 -452 -5z m327 -426 c50 -21 71 -41 100
-99 38 -74 53 -174 60 -387 12 -387 -33 -575 -150 -635 -42 -22 -153 -22 -201
1 -109 52 -148 203 -148 570 1 302 29 440 106 514 18 18 46 36 62 41 47 14
132 11 171 -5z"/>
<path d="M19876 3095 c-185 -38 -300 -98 -422 -220 -80 -79 -98 -104 -143
-196 -107 -220 -144 -499 -106 -796 51 -385 234 -632 550 -740 240 -82 644
-63 872 42 l55 25 -7 57 c-10 81 -40 168 -80 228 -49 73 -79 99 -107 91 -154
-44 -258 -57 -364 -45 -159 17 -246 111 -285 310 -19 96 -16 425 4 517 32 146
83 224 175 269 54 27 64 28 187 27 97 -1 149 -6 205 -21 87 -24 91 -23 150 56
45 59 78 152 87 237 l6 60 -62 28 c-34 15 -105 39 -159 53 -85 22 -121 26
-292 29 -141 2 -214 -1 -264 -11z"/>
<path d="M15700 3065 c-8 -2 -45 -7 -82 -10 l-68 -7 0 -959 0 -959 654 0 654
0 7 30 c22 102 22 305 0 393 l-7 27 -359 0 -359 0 -2 732 -3 733 -40 7 c-45 9
-372 19 -395 13z"/>
<path d="M21170 3065 c-8 -2 -45 -7 -82 -10 l-68 -7 0 -948 0 -948 68 -9 c86
-10 413 -8 472 4 l45 9 3 372 2 372 205 0 205 0 2 -372 3 -372 40 -9 c51 -12
389 -15 478 -4 l67 9 0 948 0 948 -67 9 c-87 10 -414 8 -473 -4 l-45 -9 -3
-347 -2 -347 -205 0 -205 0 -2 347 -3 348 -40 7 c-45 9 -372 19 -395 13z"/>
<path d="M23127 3060 c-38 -5 -75 -11 -83 -14 -13 -5 -15 -95 -12 -693 4 -681
4 -689 27 -763 57 -191 167 -324 333 -404 143 -70 240 -90 433 -90 122 -1 179
3 240 17 284 66 461 220 536 467 23 75 23 79 27 772 l3 696 -68 9 c-88 10
-358 10 -445 0 l-68 -9 0 -646 c0 -421 -4 -660 -11 -685 -14 -50 -61 -103
-107 -118 -46 -16 -148 -15 -195 0 -45 15 -92 68 -106 118 -7 25 -11 264 -11
684 l0 647 -37 6 c-70 10 -388 15 -456 6z"/>
<path d="M25070 2100 l0 -970 473 0 c268 0 509 5 556 10 179 23 325 93 397
192 62 84 86 164 92 304 5 134 -5 198 -43 278 -34 72 -85 128 -162 178 l-65
42 23 16 c94 60 166 166 190 278 16 81 6 241 -21 320 -60 174 -208 279 -435
312 -38 5 -280 10 -537 10 l-468 0 0 -970z m831 547 c53 -35 71 -79 66 -163
-3 -53 -10 -79 -26 -103 -36 -51 -67 -61 -186 -61 l-105 0 0 175 0 175 109 0
c96 0 112 -3 142 -23z m30 -763 c60 -36 74 -66 74 -162 0 -156 -45 -192 -238
-192 l-117 0 0 191 0 192 125 -5 c96 -5 132 -10 156 -24z"/>
<path d="M5890 12924 c-237 -21 -473 -71 -655 -139 -461 -172 -809 -515 -1004
-989 -144 -351 -208 -702 -218 -1191 -16 -797 134 -1395 460 -1827 360 -477
968 -721 1732 -695 761 27 1309 313 1637 857 234 388 358 928 358 1565 0 690
-137 1240 -411 1651 -93 138 -294 343 -424 431 -337 227 -705 330 -1205 337
-124 2 -245 2 -270 0z m346 -1045 c211 -39 339 -202 405 -516 49 -237 72 -666
58 -1108 -26 -845 -178 -1135 -594 -1135 -312 0 -472 180 -544 610 -39 233
-45 350 -45 785 0 525 23 766 95 985 69 214 195 347 359 379 65 13 197 13 266
0z"/>
<path d="M10850 12919 c-882 -77 -1476 -530 -1740 -1327 -174 -526 -209 -1236
-90 -1832 126 -630 418 -1090 870 -1371 430 -267 1045 -364 1740 -273 302 39
634 135 795 230 l45 26 0 61 c0 133 -46 329 -110 472 -55 122 -170 281 -253
349 l-44 36 -74 -25 c-226 -78 -411 -108 -654 -109 -226 -1 -302 13 -442 80
-233 112 -362 344 -419 751 -35 255 -35 776 0 1023 46 325 118 502 261 647 65
65 98 90 164 122 133 64 202 76 446 76 235 -1 341 -16 561 -79 l119 -34 68 69
c170 174 276 408 306 682 18 158 27 141 -102 202 -371 179 -945 268 -1447 224z"/>
<path d="M685 12829 c-118 -9 -339 -36 -367 -45 -17 -5 -18 -124 -18 -2305 l0
-2299 1549 0 1549 0 11 52 c40 184 46 245 45 498 0 251 -9 347 -45 483 l-10
37 -854 0 -855 0 0 1764 c0 1672 -1 1765 -17 1770 -32 10 -255 35 -398 46
-161 11 -430 11 -590 -1z"/>
<path d="M13645 12829 c-118 -9 -339 -36 -367 -45 -17 -5 -18 -122 -18 -2274
0 -2152 1 -2269 18 -2274 81 -24 458 -56 672 -56 204 0 606 33 683 56 16 5 17
57 17 900 l0 894 495 0 495 0 0 -894 c0 -843 1 -895 18 -900 81 -24 463 -56
677 -56 214 0 596 32 678 56 16 5 17 122 17 2274 0 2152 -1 2269 -17 2274 -75
23 -472 56 -678 56 -199 0 -602 -33 -677 -56 -17 -5 -18 -54 -18 -840 l0 -834
-495 0 -495 0 0 834 c0 786 -1 835 -17 840 -32 10 -255 35 -398 46 -161 11
-430 11 -590 -1z"/>
<path d="M18420 12829 c-115 -9 -319 -35 -352 -45 -17 -5 -18 -88 -18 -1567 1
-1634 1 -1665 44 -1864 44 -203 141 -429 253 -585 331 -462 943 -710 1688
-685 599 21 1061 202 1382 541 172 182 292 403 357 661 58 231 56 172 56 1903
0 1398 -2 1591 -15 1596 -62 23 -452 56 -675 56 -220 0 -603 -32 -665 -56 -13
-5 -15 -192 -15 -1538 -1 -1655 0 -1623 -54 -1742 -52 -114 -126 -178 -251
-217 -93 -29 -299 -31 -390 -3 -161 48 -249 139 -301 312 -17 55 -18 152 -21
1621 l-4 1563 -24 5 c-14 3 -36 7 -49 10 -159 33 -714 53 -946 34z"/>
<path d="M22860 10510 l0 -2331 1178 4 c1285 4 1259 3 1517 64 529 124 815
418 906 929 16 91 21 163 22 304 1 200 -11 289 -60 444 -83 263 -267 477 -526
612 l-79 41 73 49 c151 100 302 281 368 443 68 163 91 292 91 506 0 259 -38
444 -129 630 -155 315 -429 504 -855 590 -209 42 -307 45 -1433 45 l-1073 0 0
-2330z m1955 1338 c123 -65 185 -195 185 -387 -1 -201 -72 -342 -205 -403 -47
-22 -64 -23 -297 -26 l-248 -3 0 426 0 426 258 -3 c256 -3 257 -3 307 -30z
m20 -1831 c182 -51 265 -185 265 -427 0 -221 -76 -361 -229 -422 -53 -21 -73
-23 -338 -26 l-283 -3 0 452 0 452 268 -6 c184 -4 283 -10 317 -20z"/>
<path d="M16250 3874 c-110 -30 -199 -105 -253 -214 -29 -59 -32 -73 -32 -160
1 -120 25 -187 96 -265 190 -207 527 -154 647 102 24 51 27 70 27 158 0 91 -3
106 -32 167 -51 109 -139 182 -258 212 -72 19 -123 19 -195 0z"/>
<path d="M20680 3879 c-119 -20 -233 -109 -288 -226 -24 -51 -27 -70 -27 -158
0 -87 4 -107 27 -157 35 -76 109 -153 183 -191 57 -30 66 -32 170 -32 98 0
116 3 166 26 l56 26 414 -383 c228 -211 428 -404 445 -429 43 -62 68 -145 62
-204 -4 -35 -23 -79 -76 -172 -119 -206 -177 -397 -188 -619 -32 -635 406
-1198 1039 -1331 133 -29 360 -31 489 -6 350 69 658 272 846 559 31 47 69 109
84 137 33 60 89 96 171 112 70 12 55 16 461 -122 l323 -110 7 -72 c18 -196
120 -349 290 -432 292 -143 630 12 721 329 26 88 17 239 -19 327 -111 272
-438 395 -706 266 -75 -36 -185 -139 -219 -205 -12 -23 -26 -42 -32 -42 -19 0
-620 211 -675 236 -65 31 -139 96 -163 143 -14 27 -20 69 -24 171 -9 220 -42
354 -134 554 -47 101 -55 128 -55 177 0 118 36 161 419 502 l223 198 45 -31
c363 -250 838 -92 986 327 29 82 36 246 15 337 -14 60 -26 81 -90 160 -99 123
-222 258 -249 273 -86 48 -245 75 -360 63 -250 -28 -451 -192 -538 -437 -14
-39 -22 -94 -26 -168 -6 -132 10 -214 64 -324 36 -73 37 -74 17 -90 -11 -9
-136 -119 -277 -246 -142 -126 -279 -242 -306 -257 -58 -34 -132 -49 -188 -39
-25 5 -74 29 -115 57 -104 70 -207 119 -328 158 -159 51 -227 61 -405 61 -230
0 -374 -35 -593 -140 -96 -47 -121 -55 -170 -55 -103 0 -122 15 -612 471 -247
231 -450 421 -450 422 0 1 10 27 22 57 31 78 31 212 -1 292 -46 118 -171 216
-301 237 -36 6 -67 10 -70 10 -3 -1 -30 -5 -60 -10z m2378 -1984 c177 -42 329
-165 408 -330 84 -174 83 -361 -2 -535 -52 -106 -170 -223 -276 -274 -397
-190 -849 75 -875 514 -17 291 180 555 466 625 75 18 202 18 279 0z"/>
<path d="M17675 3864 c-74 -7 -197 -25 -211 -31 -12 -4 -14 -281 -14 -1879 l0
-1873 38 -10 c151 -40 530 -37 675 5 16 5 17 103 17 1879 0 1776 -1 1874 -17
1879 -72 22 -382 41 -488 30z"/>
<path d="M19145 3863 c-63 -5 -195 -24 -211 -30 -12 -4 -14 -281 -14 -1879 l0
-1873 38 -11 c142 -39 531 -36 675 6 16 5 17 103 17 1879 l0 1873 -52 12
c-114 24 -316 35 -453 23z"/>
<path d="M13275 2534 c-99 -14 -165 -26 -165 -31 0 -2 156 -268 347 -591 190
-322 346 -591 346 -596 0 -6 -174 -285 -386 -620 -213 -335 -385 -612 -382
-616 11 -17 190 -35 360 -35 167 0 306 14 344 35 8 4 121 178 251 387 130 208
240 377 245 375 6 -1 110 -167 233 -370 122 -202 228 -374 236 -383 21 -25
188 -44 396 -44 175 0 385 18 395 35 2 4 -171 292 -385 640 -215 348 -390 635
-390 639 0 3 162 262 359 576 353 561 359 570 333 577 -113 31 -540 36 -647 7
l-50 -14 -205 -327 c-113 -180 -208 -329 -211 -332 -3 -4 -95 144 -203 328
l-198 334 -61 12 c-60 12 -501 23 -562 14z"/>
<path d="M16125 2533 c-16 -2 -54 -8 -83 -14 l-52 -10 2 -1217 3 -1217 65 -13
c89 -19 480 -19 575 -1 l70 14 3 1217 2 1216 -27 6 c-98 20 -180 26 -343 24
-102 0 -198 -3 -215 -5z"/>
<path d="M20525 2533 c-16 -2 -54 -8 -83 -14 l-52 -10 2 -1217 3 -1217 65 -13
c88 -19 479 -19 575 0 l70 13 3 1217 2 1216 -27 6 c-88 19 -188 25 -348 24
-99 0 -193 -3 -210 -5z"/>
</g>
</svg>
+41 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\tmgmt_xillio\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\tmgmt\Entity\RemoteMapping;
use Drupal\tmgmt\JobItemInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

/**
 * Returns responses for Xillio routes.
 */
class XillioController extends ControllerBase {

  /**
   * Receives the task updated notification.
   */
  public function notifyTaskUpdate(Request $request) {
    $request_content = json_decode($request->getContent(), TRUE);
    if (isset($request_content['task']['status']) && $request_content['task']['status'] == 'completed') {
      $task = $request_content['task'];
      $mapping_candidates = RemoteMapping::loadByRemoteIdentifier(NULL, NULL, $task['id']);
      /** @var \Drupal\tmgmt\Entity\RemoteMapping $mapping */
      $mapping = array_shift($mapping_candidates);

      if (empty($mapping)) {
        return new Response('No job items found for this task.', 400);
      }

      $job_item = $mapping->getJobItem();
      if ($job_item->getState() == JobItemInterface::STATE_ACTIVE) {
        /** @var \Drupal\tmgmt_xillio\Plugin\tmgmt\Translator\XillioTranslator $plugin */
        $plugin = $job_item->getTranslatorPlugin();
        $plugin->addTranslation($mapping);
      }
    }
    return new Response(NULL, 202);
  }

}
+5 −15
Original line number Diff line number Diff line
@@ -3,28 +3,16 @@
namespace Drupal\tmgmt_xillio\Plugin\tmgmt\Translator;

use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Logger\LoggerChannelInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Url;
use Drupal\tmgmt\ContinuousTranslatorInterface;
use Drupal\tmgmt\Entity\Job;
use Drupal\tmgmt\Entity\RemoteMapping;
use Drupal\tmgmt\JobItemInterface;
use Drupal\tmgmt\RemoteMappingInterface;
use Drupal\tmgmt\SourcePreviewInterface;
use Drupal\tmgmt\TMGMTException;
use Drupal\tmgmt\TranslatorPluginBase;
use Drupal\tmgmt_xillio\TapiccConnector;
use Drupal\user\Entity\User;
use Drupal\user\UserInterface;
use GuzzleHttp\Exception\RequestException;
use Symfony\Component\DependencyInjection\ContainerInterface;
use GuzzleHttp\ClientInterface;
use Drupal\tmgmt\TranslatorInterface;
use Drupal\tmgmt\JobInterface;
use Drupal\tmgmt\Translator\AvailableResult;
@@ -34,8 +22,8 @@ use Drupal\tmgmt\Translator\AvailableResult;
 *
 * @TranslatorPlugin(
 *   id = "xillio",
 *   label = @Translation("xillio"),
 *   description = @Translation("Xillio translator service."),
 *   label = @Translation("LocHub"),
 *   description = @Translation("Connects Drupal to LocHub platform, a translation middleware provided by Xillio."),
 *   ui = "Drupal\tmgmt_xillio\XillioTranslatorUi",
 *   logo = "icons/xillio.svg",
 * )
@@ -120,6 +108,7 @@ class XillioTranslator extends TranslatorPluginBase implements ContainerFactoryP
      'username' => '',
      'password' => '',
      'project' => NULL,
      'webhook_id' => '',
    ];
  }

@@ -154,7 +143,8 @@ class XillioTranslator extends TranslatorPluginBase implements ContainerFactoryP
    $translator = $job->getTranslator();

    /** @var DrupalDateTime $due_at */
    $due_at = $job->getSetting('due_at');
    $due_at_values = $job->getSetting('due_at');
    $due_at = $due_at_values['object'];
    $due_at->setTimezone(new \DateTimeZone('UTC'));
    // @todo Is there a better way to get the 2021-09-27T12:07:48.575Z format?
    $due = $due_at->format('Y-m-d\TH:i:s\Z');
Loading