This repository has been archived by the owner on Jun 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12611 from Wikia/IRIS-3983
IRIS-3983 Redirect all Forum URLs to Discussions on migrated site
- Loading branch information
Showing
7 changed files
with
865 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
use Swagger\Client\ApiException; | ||
use Swagger\Client\Discussion\Api\LegacyRedirectsApi; | ||
use Wikia\DependencyInjection\Injector; | ||
use Wikia\Service\Swagger\ApiProvider; | ||
|
||
class LegacyRedirect { | ||
|
||
const SERVICE_NAME = 'discussion'; | ||
const TIMEOUT = 5; | ||
const SITE_NAME_MAX_LENGTH = 256; | ||
|
||
private $siteId; | ||
|
||
private $legacyRedirectApi; | ||
private $logger; | ||
|
||
public function __construct( int $siteId ) { | ||
$this->siteId = $siteId; | ||
|
||
$this->legacyRedirectApi = $this->getLegacyRedirectApi(); | ||
$this->logger = Wikia\Logger\WikiaLogger::instance(); | ||
} | ||
|
||
/** | ||
* Return a path to redirect the client to based on a board ID | ||
* | ||
* @param int $boardId | ||
* @return string | ||
*/ | ||
public function getBoardRedirect( $boardId ) { | ||
try { | ||
$response = $this->legacyRedirectApi->getForumRedirect( $this->siteId, $boardId ); | ||
return $response->getPath(); | ||
} catch ( ApiException $e ) { | ||
$this->logAndThrowError( $e ); | ||
} | ||
|
||
return ''; | ||
} | ||
|
||
/** | ||
* Return a path to redirect the client to based on a thread ID | ||
* | ||
* @param int $threadId | ||
* @return string | ||
*/ | ||
public function getThreadRedirect( $threadId ) { | ||
try { | ||
$response = $this->legacyRedirectApi->getThreadRedirect( $this->siteId, $threadId ); | ||
return $response->getPath(); | ||
} catch ( ApiException $e ) { | ||
$this->logAndThrowError( $e ); | ||
} | ||
|
||
return ''; | ||
} | ||
|
||
private function getLegacyRedirectApi() { | ||
/** @var ApiProvider $apiProvider */ | ||
$apiProvider = Injector::getInjector()->get( ApiProvider::class ); | ||
/** @var LegacyRedirectsApi $api */ | ||
$api = $apiProvider->getApi( self::SERVICE_NAME, LegacyRedirectsApi::class ); | ||
$api->getApiClient()->getConfig()->setCurlTimeout( self::TIMEOUT ); | ||
|
||
return $api; | ||
} | ||
|
||
private function logAndThrowError( Exception $e ) { | ||
$this->logger->error( | ||
'DISCUSSIONS Retrieving legacy Forum redirect caused an error', | ||
[ | ||
'siteId' => $this->siteId, | ||
'error' => $e->getMessage() | ||
] | ||
); | ||
throw new ErrorPageError( 'unknown-error', 'discussions-activate-error' ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.