Skip to content

Commit

Permalink
Merge pull request #61 from crowdfavorite/bugfix/handle-save-token-issue
Browse files Browse the repository at this point in the history
check valid configuration before execution content retrieval logic
  • Loading branch information
al-esc authored Jul 29, 2024
2 parents 440aff7 + 1ea9eec commit e53d5e6
Showing 1 changed file with 47 additions and 43 deletions.
90 changes: 47 additions & 43 deletions app/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,52 +137,56 @@ public function publishDocuments(): void
return;
}

$PCCManager = new PccSyncManager();
// Publish document
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
if (
isset($_GET['publishingLevel']) &&
PublishingLevel::PRODUCTION->value === $_GET['publishingLevel'] &&
$PCCManager->isPCCConfigured()
) {
$parts = explode('/', $wp->request);
$documentId = end($parts);
$pcc = new PccSyncManager();
$postId = $pcc->fetchAndStoreDocument($documentId, PublishingLevel::PRODUCTION);

wp_redirect(get_permalink($postId));
exit;
}

// Preview document
if (
try {
$PCCManager = new PccSyncManager();
// Publish document
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
isset($_GET['pccGrant']) && isset($_GET['publishingLevel']) &&
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
PublishingLevel::REALTIME->value === $_GET['publishingLevel'] &&
$PCCManager->isPCCConfigured()
) {
$parts = explode('/', $wp->request);
$documentId = end($parts);
$pcc = new PccSyncManager();

if (!$pcc->findExistingConnectedPost($documentId)) {
$pcc->fetchAndStoreDocument($documentId, PublishingLevel::REALTIME, true);
if (
isset($_GET['publishingLevel']) &&
PublishingLevel::PRODUCTION->value === $_GET['publishingLevel'] &&
$PCCManager->isPCCConfigured()
) {
$parts = explode('/', $wp->request);
$documentId = end($parts);
$pcc = new PccSyncManager();
$postId = $pcc->fetchAndStoreDocument($documentId, PublishingLevel::PRODUCTION);

wp_redirect(get_permalink($postId));
exit;
}

$query = get_posts([
'post_type' => get_option(PCC_INTEGRATION_POST_TYPE_OPTION_KEY, 'post'),
'post_status' => 'publish',
'posts_per_page' => 1,
'orderby' => 'date',
'order' => 'ASC',
'fields' => 'ids'
]);

$url = $pcc->preparePreviewingURL($documentId, $query[0] ?? 0);

wp_redirect($url);
exit;
// Preview document
if (
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
isset($_GET['pccGrant']) && isset($_GET['publishingLevel']) &&
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
PublishingLevel::REALTIME->value === $_GET['publishingLevel'] &&
$PCCManager->isPCCConfigured()
) {
$parts = explode('/', $wp->request);
$documentId = end($parts);
$pcc = new PccSyncManager();

if (!$pcc->findExistingConnectedPost($documentId)) {
$pcc->fetchAndStoreDocument($documentId, PublishingLevel::REALTIME, true);
}

$query = get_posts([
'post_type' => get_option(PCC_INTEGRATION_POST_TYPE_OPTION_KEY, 'post'),
'post_status' => 'publish',
'posts_per_page' => 1,
'orderby' => 'date',
'order' => 'ASC',
'fields' => 'ids'
]);

$url = $pcc->preparePreviewingURL($documentId, $query[0] ?? 0);

wp_redirect($url);
exit;
}
} catch (\Exception $ex) {
// No Action needed for safe exit
}
}

Expand Down

0 comments on commit e53d5e6

Please sign in to comment.