@@ -386,6 +386,12 @@ private function updateCardFromCalendar(Card $sourceItem, string $data, bool $re
386386 }
387387 $ done = $ this ->mapDoneFromTodo ($ todo , $ card );
388388 $ incomingDue = isset ($ todo ->DUE ) ? $ todo ->DUE ->getDateTime () : null ;
389+ $ categories = $ this ->extractCategories ($ todo );
390+ if ($ categories !== null ) {
391+ $ categories = $ this ->normalizeCategoriesForLabelSync ($ boardId , $ categories , $ mode );
392+ }
393+ $ categoriesChanged = $ categories !== null
394+ && !$ this ->hasSameCategoryLabels ($ categories , $ card );
389395
390396 $ isNoopUpdate = $ title === $ card ->getTitle ()
391397 && $ stackId === $ card ->getStackId ()
@@ -394,7 +400,11 @@ private function updateCardFromCalendar(Card $sourceItem, string $data, bool $re
394400 && $ this ->isDateEqual ($ card ->getDone (), $ done ->getValue ())
395401 && (!$ restoreDeleted || $ card ->getDeletedAt () === 0 );
396402
397- if ($ isNoopUpdate ) {
403+ if ($ isNoopUpdate && !$ categoriesChanged ) {
404+ return $ card ;
405+ }
406+ if ($ isNoopUpdate && $ categories !== null ) {
407+ $ this ->syncCardCategories ($ card ->getId (), $ categories );
398408 return $ card ;
399409 }
400410
@@ -412,9 +422,7 @@ private function updateCardFromCalendar(Card $sourceItem, string $data, bool $re
412422 $ done ,
413423 $ boardId
414424 );
415- $ categories = $ this ->extractCategories ($ todo );
416425 if ($ categories !== null ) {
417- $ categories = $ this ->normalizeCategoriesForLabelSync ($ boardId , $ categories , $ mode );
418426 $ this ->syncCardCategories ($ updatedCard ->getId (), $ categories );
419427 }
420428
@@ -896,6 +904,29 @@ private function normalizeDescriptionForCompare(string $value): string {
896904 return str_replace (["\r\n" , "\r" ], "\n" , $ value );
897905 }
898906
907+ /**
908+ * @param list<string> $categories
909+ */
910+ private function hasSameCategoryLabels (array $ categories , Card $ card ): bool {
911+ $ incoming = [];
912+ foreach ($ categories as $ category ) {
913+ $ key = mb_strtolower (trim ($ category ));
914+ if ($ key !== '' ) {
915+ $ incoming [$ key ] = true ;
916+ }
917+ }
918+
919+ $ current = [];
920+ foreach ($ card ->getLabels () ?? [] as $ label ) {
921+ $ key = mb_strtolower (trim ($ label ->getTitle ()));
922+ if ($ key !== '' ) {
923+ $ current [$ key ] = true ;
924+ }
925+ }
926+
927+ return array_keys ($ incoming ) === array_keys ($ current );
928+ }
929+
899930 private function isDateEqual (?\DateTimeInterface $ left , ?\DateTimeInterface $ right ): bool {
900931 if ($ left === null && $ right === null ) {
901932 return true ;
0 commit comments