Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a few minor issues that sometime prevents sync // VNLA-5468 #80

Merged
merged 5 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/Destinations/VanillaDestination.php
Original file line number Diff line number Diff line change
Expand Up @@ -1014,11 +1014,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 +1322,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
Loading