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

return 500 status on unconfigured website, add nocache query argument to published page URL #62

Merged
merged 1 commit into from
Jul 31, 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
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 ?: [];
}
}
Loading