Skip to content

Commit fb719ff

Browse files
committed
code review
1 parent 912d135 commit fb719ff

4 files changed

Lines changed: 19 additions & 9 deletions

File tree

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ echo "Update version in various json and js files..."
2525
node ./buildPipeline/versionUpdate.js
2626

2727
echo "Cleaning up old build directory..."
28-
rm -r build
28+
rm -rf build
2929
if [ -f touchpoint-wp.zip ]; then
3030
rm touchpoint-wp.zip
3131
fi

src/TouchPoint-WP/Auth.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,8 @@ public static function getProfileUrl(?int $peopleId = null): ?string
340340
$userId = get_current_user_id();
341341
$peopleId = (int)(get_user_meta($userId, Person::META_PEOPLEID, true));
342342
}
343-
if ($peopleId >= 0) {
343+
$peopleId = intval($peopleId);
344+
if ($peopleId >= 0) { // 0 is a valid peopleId for the purpose of this URL, but not elsewhere.
344345
return $tpwp->host() . '/Person2/' . $peopleId . "#tab-personal";
345346
}
346347

src/TouchPoint-WP/Report.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ public static function api(array $uri): bool
312312
break;
313313

314314
default:
315-
header("Content-Type: text/plain");
315+
header("Content-Type: text/html");
316316
break;
317317
}
318318

@@ -339,6 +339,7 @@ public static function api(array $uri): bool
339339
exit;
340340
}
341341

342+
header("Content-Type: text/html");
342343
echo $content;
343344
exit;
344345
}
@@ -411,6 +412,8 @@ public static function reportShortcode(mixed $params = [], string $content = "")
411412
}
412413

413414
if (self::$_indexingMode) {
415+
// TODO issue #247 Interrogate if parent post has limited access permissions and follow that through with report to be applied in API versions.
416+
414417
// It has been added to the index already, so our work here is done.
415418
return $content;
416419
}

src/TouchPoint-WP/Stats.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)