From bdd4ee1333334128d7a7e64cbe50ffc69cb019a5 Mon Sep 17 00:00:00 2001 From: David Barbier Date: Mon, 15 Jan 2024 10:32:53 -0500 Subject: [PATCH 1/5] First wave of minor fixes --- src/Destinations/VanillaDestination.php | 11 +++++++---- src/HttpClients/RequestThrottleMiddleware.php | 5 +++-- src/Sources/ZendeskSource.php | 3 +-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Destinations/VanillaDestination.php b/src/Destinations/VanillaDestination.php index 2cf3437..db8504f 100644 --- a/src/Destinations/VanillaDestination.php +++ b/src/Destinations/VanillaDestination.php @@ -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, @@ -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; diff --git a/src/HttpClients/RequestThrottleMiddleware.php b/src/HttpClients/RequestThrottleMiddleware.php index e6a2cb5..c16be48 100644 --- a/src/HttpClients/RequestThrottleMiddleware.php +++ b/src/HttpClients/RequestThrottleMiddleware.php @@ -17,6 +17,8 @@ class RequestThrottleMiddleware { protected $lastRequestTime = null; + private $lastRequestMicrotime = false; + /** * Make sure at least one second has past between each call. * @@ -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); diff --git a/src/Sources/ZendeskSource.php b/src/Sources/ZendeskSource.php index 83630a3..1ed5dc7 100644 --- a/src/Sources/ZendeskSource.php +++ b/src/Sources/ZendeskSource.php @@ -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"; @@ -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; From a2a2880d2a19add5e7d0219f5b4a82d1810a0a69 Mon Sep 17 00:00:00 2001 From: David Barbier Date: Wed, 17 Jan 2024 11:03:03 -0500 Subject: [PATCH 2/5] Fixed status change via API --- src/Destinations/VanillaDestination.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Destinations/VanillaDestination.php b/src/Destinations/VanillaDestination.php index db8504f..3fff8b5 100644 --- a/src/Destinations/VanillaDestination.php +++ b/src/Destinations/VanillaDestination.php @@ -1323,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] ); From 6c886d3ac7e16ffb72a62fa322e5fa8c6bbba587 Mon Sep 17 00:00:00 2001 From: David Barbier Date: Mon, 12 Feb 2024 16:34:26 -0500 Subject: [PATCH 3/5] Added a minor check --- src/Destinations/VanillaDestination.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Destinations/VanillaDestination.php b/src/Destinations/VanillaDestination.php index 3fff8b5..a29bfe6 100644 --- a/src/Destinations/VanillaDestination.php +++ b/src/Destinations/VanillaDestination.php @@ -1322,9 +1322,12 @@ public function syncArticles( "Deleting article {$article["articleID"]} because it no longer exists on the source." ); + $this->logger->debug("HeyO-HeyO-HeyO-HeyO-HeyO-HeyO-HeyO-HeyO-HeyO-HeyO-HeyO-HeyO-HeyO-HeyO!"); + $response = $this->vanillaApi->patch( "/api/v2/articles/{$article["articleID"]}/status", - ["status" => self::DELETED_STATUS] + ["status" => self::DELETED_STATUS], + ["Cookie: vanilla_ratelimit_bypass=dev-cjhLJkudRmvKXvWH7qT4Kr8gksx3Qouf"] ); if (!$response->isSuccessful()) { From 13427b5826e4a0af03d8266254ae02f351fc5651 Mon Sep 17 00:00:00 2001 From: David Barbier Date: Mon, 12 Feb 2024 16:39:31 -0500 Subject: [PATCH 4/5] Removed sensitive data --- src/Destinations/VanillaDestination.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Destinations/VanillaDestination.php b/src/Destinations/VanillaDestination.php index a29bfe6..3fff8b5 100644 --- a/src/Destinations/VanillaDestination.php +++ b/src/Destinations/VanillaDestination.php @@ -1322,12 +1322,9 @@ public function syncArticles( "Deleting article {$article["articleID"]} because it no longer exists on the source." ); - $this->logger->debug("HeyO-HeyO-HeyO-HeyO-HeyO-HeyO-HeyO-HeyO-HeyO-HeyO-HeyO-HeyO-HeyO-HeyO!"); - $response = $this->vanillaApi->patch( "/api/v2/articles/{$article["articleID"]}/status", - ["status" => self::DELETED_STATUS], - ["Cookie: vanilla_ratelimit_bypass=dev-cjhLJkudRmvKXvWH7qT4Kr8gksx3Qouf"] + ["status" => self::DELETED_STATUS] ); if (!$response->isSuccessful()) { From 9d5cdd643a831d38e68e5bda1769bf0af1cbf8fb Mon Sep 17 00:00:00 2001 From: David Barbier Date: Mon, 12 Feb 2024 16:41:59 -0500 Subject: [PATCH 5/5] Cleanup --- src/Destinations/VanillaDestination.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Destinations/VanillaDestination.php b/src/Destinations/VanillaDestination.php index 3fff8b5..49bb7c6 100644 --- a/src/Destinations/VanillaDestination.php +++ b/src/Destinations/VanillaDestination.php @@ -219,7 +219,6 @@ public function importKnowledgeBaseTranslations(iterable $rows) $lookup = $row; $lookup["recordIDs"] = [$row["recordID"]]; $existing = $this->vanillaApi->getKnowledgeBaseTranslation($lookup); - $patch = $this->updateFields( $existing, $row,