Skip to content

Commit

Permalink
Fix a bunch of minor issues that sometime prevents sync // VNLA-5468 (#…
Browse files Browse the repository at this point in the history
…79)

* First wave of minor fixes

* Fixed status change via API
  • Loading branch information
vanilla-dbarbier authored Feb 8, 2024
1 parent 5c40c93 commit 549025b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
13 changes: 8 additions & 5 deletions src/Destinations/VanillaDestination.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ public function importKnowledgeBaseTranslations(iterable $rows)
$lookup = $row;
$lookup["recordIDs"] = [$row["recordID"]];
$existing = $this->vanillaApi->getKnowledgeBaseTranslation($lookup);

$patch = $this->updateFields(
$existing,
$row,
Expand Down Expand Up @@ -1014,11 +1015,13 @@ private function updateFields(
$res = $this->compareFields($existing, $new, $fieldsMap);
break;
case self::UPDATE_MODE_ON_DATE:
$existingDate = strtotime($existing[self::DATE_UPDATED]);
$newDate = strtotime($new[self::DATE_UPDATED]);
if (isset($existing[self::DATE_UPDATED])) {
$existingDate = strtotime($existing[self::DATE_UPDATED]);
$newDate = strtotime($new[self::DATE_UPDATED]);

if ($existingDate < $newDate) {
$res = $this->resolveUpdateFields($new, $fieldsMap);
if ($existingDate < $newDate) {
$res = $this->resolveUpdateFields($new, $fieldsMap);
}
}

break;
Expand Down Expand Up @@ -1320,7 +1323,7 @@ public function syncArticles(
);

$response = $this->vanillaApi->patch(
"/api/v2/articles/{$article["articleID"]}",
"/api/v2/articles/{$article["articleID"]}/status",
["status" => self::DELETED_STATUS]
);

Expand Down
5 changes: 3 additions & 2 deletions src/HttpClients/RequestThrottleMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class RequestThrottleMiddleware
{
protected $lastRequestTime = null;

private $lastRequestMicrotime = false;

/**
* Make sure at least one second has past between each call.
*
Expand All @@ -27,8 +29,7 @@ class RequestThrottleMiddleware
public function __invoke(HttpRequest $request, callable $next): HttpResponse
{
$minRequestMicroTime = 1000 * 1000;
$this->lastRequestMicrotime =
$this->lastRequestMicrotime ?? microtime(true);
$this->lastRequestMicrotime = $this->lastRequestMicrotime ?? microtime(true);
$diff = microtime(true) - $this->lastRequestMicrotime;
if ($diff < $minRequestMicroTime) {
usleep($minRequestMicroTime - (int) $diff);
Expand Down
3 changes: 1 addition & 2 deletions src/Sources/ZendeskSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class ZendeskSource extends AbstractSource
const LIMIT = 50;
const PAGE_START = 1;
const PAGE_END = 10;

const DEFAULT_SOURCE_LOCALE = "en-us";
const DEFAULT_LOCALE = "en";

Expand Down Expand Up @@ -286,7 +285,7 @@ public function processKnowledgeArticles(): array
$queryParams = ["page" => $page, "per_page" => $pageLimit];

$syncFrom = $this->config["syncFrom"] ?? null;
$syncFrom = strtotime($syncFrom);
$syncFrom = !is_null($syncFrom) ? strtotime($syncFrom) : null;
$currentTime = time();

$syncFrom = $syncFrom >= $currentTime ? false : $syncFrom;
Expand Down

0 comments on commit 549025b

Please sign in to comment.