@@ -291,7 +291,7 @@ public function getStatsForSubmission(bool $updateQueried = false): array
291291 * Submit stats to Tenth.
292292 *
293293 * @param bool $blocking If true, will wait for the response from the server before returning and the method will
294- * print a status. If false, no status prints.
294+ * print a status. If false, nothing prints.
295295 *
296296 * @return void
297297 */
@@ -327,7 +327,7 @@ protected function submitStats(bool $blocking = false): void
327327 'blocking ' => $ blocking ,
328328 ]);
329329
330- if (! $ blocking ) {
330+ if ($ blocking ) {
331331 if (is_wp_error ($ r )) {
332332 echo "error " ;
333333 error_log ("TouchPoint-WP: Stats: Failed to submit telemetry to $ endpoint: " . $ r ->get_error_message ());
@@ -488,11 +488,17 @@ public static function handleSubmission(): bool
488488 $ data = array_intersect_key ($ data , $ s ->getStatsForSubmission ());
489489 $ data ['updatedDT ' ] = date ('Y-m-d H:i:s ' );
490490
491- // upsert the data into the database into the stats table without destructive replace function
491+ // Upsert the data into the stats table without treating a no-op update as a failed write.
492492 global $ wpdb ;
493- $ r = $ wpdb ->update ($ wpdb ->prefix . TouchPointWP::TABLE_STATS , $ data , ['installId ' => $ data ['installId ' ]]);
494- if ($ r < 1 ) {
495- $ r = $ wpdb ->insert ($ wpdb ->prefix . TouchPointWP::TABLE_STATS , $ data );
493+ $ table = $ wpdb ->prefix . TouchPointWP::TABLE_STATS ;
494+ $ existingInstallId = $ wpdb ->get_var ($ wpdb ->prepare (
495+ "SELECT installId FROM {$ table } WHERE installId = %s LIMIT 1 " ,
496+ $ data ['installId ' ]
497+ ));
498+ if ($ existingInstallId !== null ) {
499+ $ r = $ wpdb ->update ($ table , $ data , ['installId ' => $ data ['installId ' ]]);
500+ } else {
501+ $ r = $ wpdb ->insert ($ table , $ data );
496502 }
497503
498504 if ($ r === false ) {
0 commit comments