@@ -1155,10 +1155,9 @@ public function createDailyRecordEvent(Integration $integration, string $kind, a
11551155 $ contributors = $ contributorsField ? Arr::get ($ item , $ contributorsField , []) : [];
11561156 foreach ($ contributors as $ name => $ value ) {
11571157 [$ encodedContrib , $ contribMultiplier ] = $ this ->encodeNumericValue (is_numeric ($ value ) ? (float ) $ value : null );
1158- $ event ->blocks ()-> create ([
1158+ $ event ->createBlock ([
11591159 'block_type ' => 'contributors ' ,
11601160 'time ' => $ event ->time ,
1161- 'integration_id ' => $ integration ->id ,
11621161 'title ' => Str::title (str_replace ('_ ' , ' ' , (string ) $ name )),
11631162 'metadata ' => ['type ' => 'contributor ' , 'field ' => $ name ],
11641163 'value ' => $ encodedContrib ,
@@ -1183,10 +1182,9 @@ public function createDailyRecordEvent(Integration $integration, string $kind, a
11831182 $ label = Str::title (str_replace ('_ ' , ' ' , $ field ));
11841183 $ value = $ item [$ field ];
11851184 [$ encodedDetail , $ detailMultiplier ] = $ this ->encodeNumericValue (is_numeric ($ value ) ? (float ) $ value : null );
1186- $ event ->blocks ()-> create ([
1185+ $ event ->createBlock ([
11871186 'block_type ' => 'activity_metrics ' ,
11881187 'time ' => $ event ->time ,
1189- 'integration_id ' => $ integration ->id ,
11901188 'title ' => $ label ,
11911189 'metadata ' => ['type ' => 'detail ' , 'field ' => $ field ],
11921190 'value ' => $ encodedDetail ,
@@ -1241,10 +1239,9 @@ public function createWorkoutEvent(Integration $integration, array $item): void
12411239 ]);
12421240
12431241 [$ encodedCalories , $ calMultiplier ] = $ this ->encodeNumericValue ($ calories );
1244- $ event ->blocks ()-> create ([
1242+ $ event ->createBlock ([
12451243 'block_type ' => 'workout_metrics ' ,
12461244 'time ' => $ event ->time ,
1247- 'integration_id ' => $ integration ->id ,
12481245 'title ' => 'Calories ' ,
12491246 'metadata ' => ['type ' => 'calorie_burn ' , 'estimated ' => true ],
12501247 'value ' => $ encodedCalories ,
@@ -1255,10 +1252,9 @@ public function createWorkoutEvent(Integration $integration, array $item): void
12551252 $ avgHr = Arr::get ($ item , 'average_heart_rate ' );
12561253 if ($ avgHr !== null ) {
12571254 [$ encodedAvgHr , $ avgHrMultiplier ] = $ this ->encodeNumericValue ($ avgHr );
1258- $ event ->blocks ()-> create ([
1255+ $ event ->createBlock ([
12591256 'block_type ' => 'heart_rate ' ,
12601257 'time ' => $ event ->time ,
1261- 'integration_id ' => $ integration ->id ,
12621258 'title ' => 'Average Heart Rate ' ,
12631259 'metadata ' => ['type ' => 'average ' , 'context ' => 'workout ' ],
12641260 'value ' => $ encodedAvgHr ,
@@ -1341,10 +1337,10 @@ public function createEventsSafely(Integration $integration, array $eventData):
13411337 ]
13421338 );
13431339
1344- // Create blocks if any
1340+ // Create blocks if any using the new unique creation method
13451341 if (isset ($ data ['blocks ' ])) {
13461342 foreach ($ data ['blocks ' ] as $ blockData ) {
1347- $ event ->blocks ()-> create ([
1343+ $ event ->createBlock ([
13481344 'time ' => $ blockData ['time ' ] ?? $ event ->time ,
13491345 'block_type ' => $ blockData ['block_type ' ] ?? '' ,
13501346 'title ' => $ blockData ['title ' ],
@@ -2062,7 +2058,7 @@ protected function fetchSleepRecords(Integration $integration, string $startDate
20622058 if ($ seconds === null ) {
20632059 continue ;
20642060 }
2065- $ event ->blocks ()-> create ([
2061+ $ event ->createBlock ([
20662062 'block_type ' => 'sleep_stages ' ,
20672063 'time ' => $ event ->time ,
20682064 'integration_id ' => $ integration ->id ,
@@ -2077,7 +2073,7 @@ protected function fetchSleepRecords(Integration $integration, string $startDate
20772073 $ hrAvg = Arr::get ($ item , 'average_heart_rate ' );
20782074 if ($ hrAvg !== null ) {
20792075 [$ encodedHrAvg , $ hrAvgMultiplier ] = $ this ->encodeNumericValue ($ hrAvg );
2080- $ event ->blocks ()-> create ([
2076+ $ event ->createBlock ([
20812077 'block_type ' => 'heart_rate ' ,
20822078 'time ' => $ event ->time ,
20832079 'integration_id ' => $ integration ->id ,
@@ -2314,10 +2310,9 @@ protected function fetchHeartRateSeries(Integration $integration, string $startI
23142310
23152311 // Replace summary with separate min/max blocks
23162312 [$ encMin , $ minMult ] = $ this ->encodeNumericValue ($ min );
2317- $ event ->blocks ()-> create ([
2313+ $ event ->createBlock ([
23182314 'block_type ' => 'heart_rate ' ,
23192315 'time ' => $ event ->time ,
2320- 'integration_id ' => $ integration ->id ,
23212316 'title ' => 'Min Heart Rate ' ,
23222317 'metadata ' => ['type ' => 'minimum ' , 'context ' => 'daily_series ' ],
23232318 'value ' => $ encMin ,
@@ -2326,21 +2321,19 @@ protected function fetchHeartRateSeries(Integration $integration, string $startI
23262321 ]);
23272322
23282323 [$ encMax , $ maxMult ] = $ this ->encodeNumericValue ($ max );
2329- $ event ->blocks ()-> create ([
2324+ $ event ->createBlock ([
23302325 'block_type ' => 'heart_rate ' ,
23312326 'time ' => $ event ->time ,
2332- 'integration_id ' => $ integration ->id ,
23332327 'title ' => 'Max Heart Rate ' ,
23342328 'metadata ' => ['type ' => 'maximum ' , 'context ' => 'daily_series ' ],
23352329 'value ' => $ encMax ,
23362330 'value_multiplier ' => $ maxMult ,
23372331 'value_unit ' => 'bpm ' ,
23382332 ]);
23392333
2340- $ event ->blocks ()-> create ([
2334+ $ event ->createBlock ([
23412335 'block_type ' => 'heart_rate ' ,
23422336 'time ' => $ event ->time ,
2343- 'integration_id ' => $ integration ->id ,
23442337 'title ' => 'Data Points ' ,
23452338 'metadata ' => ['type ' => 'count ' , 'context ' => 'daily_series ' ],
23462339 'value ' => (int ) $ points ->count (),
@@ -2389,10 +2382,9 @@ protected function createSessionEvent(Integration $integration, array $item): vo
23892382
23902383 $ state = Arr::get ($ item , 'mood ' , Arr::get ($ item , 'state ' ));
23912384 if ($ state ) {
2392- $ event ->blocks ()-> create ([
2385+ $ event ->createBlock ([
23932386 'block_type ' => 'biometrics ' ,
23942387 'time ' => $ event ->time ,
2395- 'integration_id ' => $ integration ->id ,
23962388 'title ' => 'State ' ,
23972389 'metadata ' => ['type ' => 'mood_state ' , 'value ' => (string ) $ state ],
23982390 'content ' => (string ) $ state ,
@@ -2445,10 +2437,9 @@ protected function createTagEvent(Integration $integration, array $item): void
24452437 'target_id ' => $ tagTarget ->id ,
24462438 ]);
24472439
2448- $ event ->blocks ()-> create ([
2440+ $ event ->createBlock ([
24492441 'block_type ' => 'tag_info ' ,
24502442 'time ' => $ event ->time ,
2451- 'integration_id ' => $ integration ->id ,
24522443 'title ' => 'Tag ' ,
24532444 'metadata ' => ['type ' => 'user_tag ' , 'label ' => (string ) $ label ],
24542445 'content ' => (string ) $ label ,
@@ -2750,7 +2741,7 @@ protected function createEnhancedTagEvent(Integration $integration, array $item)
27502741
27512742 // Add tag details as blocks
27522743 if ($ tagType ) {
2753- $ event ->blocks ()-> create ([
2744+ $ event ->createBlock ([
27542745 'block_type ' => 'tag_info ' ,
27552746 'time ' => $ event ->time ,
27562747 'integration_id ' => $ integration ->id ,
@@ -2761,7 +2752,7 @@ protected function createEnhancedTagEvent(Integration $integration, array $item)
27612752 }
27622753
27632754 if ($ item ['comment ' ] ?? null ) {
2764- $ event ->blocks ()-> create ([
2755+ $ event ->createBlock ([
27652756 'block_type ' => 'tag_info ' ,
27662757 'time ' => $ event ->time ,
27672758 'integration_id ' => $ integration ->id ,
@@ -2822,7 +2813,7 @@ protected function createSleepTimeEvent(Integration $integration, array $item):
28222813
28232814 // Add recommendation blocks
28242815 if ($ recommendation ) {
2825- $ event ->blocks ()-> create ([
2816+ $ event ->createBlock ([
28262817 'block_type ' => 'recommendation ' ,
28272818 'time ' => $ event ->time ,
28282819 'integration_id ' => $ integration ->id ,
@@ -2887,7 +2878,7 @@ protected function createRestModePeriodEvent(Integration $integration, array $it
28872878
28882879 // Add episode blocks
28892880 if (is_array ($ episodes ) && count ($ episodes ) > 0 ) {
2890- $ event ->blocks ()-> create ([
2881+ $ event ->createBlock ([
28912882 'block_type ' => 'biometrics ' ,
28922883 'time ' => $ event ->time ,
28932884 'integration_id ' => $ integration ->id ,
@@ -3019,7 +3010,7 @@ private function createSleepRecordFromItem(Integration $integration, array $item
30193010 if ($ seconds === null ) {
30203011 continue ;
30213012 }
3022- $ event ->blocks ()-> create ([
3013+ $ event ->createBlock ([
30233014 'block_type ' => 'sleep_stages ' ,
30243015 'time ' => $ event ->time ,
30253016 'integration_id ' => $ integration ->id ,
@@ -3034,7 +3025,7 @@ private function createSleepRecordFromItem(Integration $integration, array $item
30343025 $ hrAvg = Arr::get ($ item , 'average_heart_rate ' );
30353026 if ($ hrAvg !== null ) {
30363027 [$ encodedHrAvg , $ hrAvgMultiplier ] = $ this ->encodeNumericValue ($ hrAvg );
3037- $ event ->blocks ()-> create ([
3028+ $ event ->createBlock ([
30383029 'block_type ' => 'heart_rate ' ,
30393030 'time ' => $ event ->time ,
30403031 'integration_id ' => $ integration ->id ,
0 commit comments