Skip to content

Commit

Permalink
Merge pull request #62 from pantheon-systems/fix/improve-stability
Browse files Browse the repository at this point in the history
return 500 status on unconfigured website, add nocache query argument to published page URL
  • Loading branch information
kevinstubbs authored Jul 31, 2024
2 parents c963746 + e78b215 commit 9e2dec9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 36 deletions.
4 changes: 2 additions & 2 deletions app/RestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function pantheonCloudStatusCheck()

/**
* Handle incoming webhook requests.
* @return void
* @return void|WP_REST_Response
*/
public function handleWebhook(WP_REST_Request $request)
{
Expand All @@ -122,7 +122,7 @@ public function handleWebhook(WP_REST_Request $request)
if (!$isPCCConfiguredCorrectly) {
return new WP_REST_Response(
esc_html__('Website is not correctly configured', PCC_HANDLE),
200
500
);
}

Expand Down
69 changes: 35 additions & 34 deletions app/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace PCC;

use Exception;
use PccPhpSdk\api\Query\Enums\PublishingLevel;

use function add_action;
Expand Down Expand Up @@ -112,6 +113,38 @@ public function verifyCollectionUrl()
}
}

/**
* Get access token from the database.
*
* @return array|mixed
*/
private function getAccessToken(): mixed
{
$pccToken = get_option(PCC_ACCESS_TOKEN_OPTION_KEY);

return $pccToken ?: [];
}

/**
* @return false|mixed|null
*/
private function getSiteId(): mixed
{
return get_option(PCC_SITE_ID_OPTION_KEY);
}

/**
* Get access token from the database.
*
* @return array|mixed
*/
private function getAPIAccessKey(): mixed
{
$apiKey = get_option(PCC_API_KEY_OPTION_KEY);

return $apiKey ?: [];
}

/**
* Allow style tags in the content.
*
Expand Down Expand Up @@ -151,7 +184,7 @@ public function publishDocuments(): void
$pcc = new PccSyncManager();
$postId = $pcc->fetchAndStoreDocument($documentId, PublishingLevel::PRODUCTION);

wp_redirect(get_permalink($postId));
wp_redirect(add_query_arg('nocache', 'true', get_permalink($postId)));
exit;
}

Expand Down Expand Up @@ -185,7 +218,7 @@ public function publishDocuments(): void
wp_redirect($url);
exit;
}
} catch (\Exception $ex) {
} catch (Exception $ex) {
// No Action needed for safe exit
}
}
Expand Down Expand Up @@ -362,26 +395,6 @@ public function renderSettingsPage(): void
require $this->pages['setup'];
}

/**
* @return false|mixed|null
*/
private function getSiteId(): mixed
{
return get_option(PCC_SITE_ID_OPTION_KEY);
}

/**
* Get access token from the database.
*
* @return array|mixed
*/
private function getAccessToken(): mixed
{
$pccToken = get_option(PCC_ACCESS_TOKEN_OPTION_KEY);

return $pccToken ?: [];
}

/**
* Enqueue plugin assets on the WP Admin Dashboard.
*
Expand Down Expand Up @@ -498,16 +511,4 @@ private function getEncodedSiteURL(): mixed
{
return get_option(PCC_ENCODED_SITE_URL_OPTION_KEY);
}

/**
* Get access token from the database.
*
* @return array|mixed
*/
private function getAPIAccessKey(): mixed
{
$apiKey = get_option(PCC_API_KEY_OPTION_KEY);

return $apiKey ?: [];
}
}

0 comments on commit 9e2dec9

Please sign in to comment.