-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
99 additions
and
37 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
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,83 @@ | ||
<?php | ||
|
||
namespace Drupal\search_api_pantheon\Services; | ||
|
||
|
||
use Drupal\Core\Logger\LoggerChannelFactoryInterface; | ||
use Drupal\search_api_pantheon\Exceptions\PantheonSearchApiException; | ||
use GuzzleHttp\Psr7\Request; | ||
use GuzzleHttp\Psr7\Uri; | ||
use Psr\Log\LoggerAwareInterface; | ||
use Psr\Log\LoggerAwareTrait; | ||
use Drupal\search_api_pantheon\Services\PantheonGuzzle; | ||
|
||
class Reload implements LoggerAwareInterface { | ||
use LoggerAwareTrait; | ||
|
||
/** | ||
* @var \Drupal\search_api_pantheon\Services\Reload | ||
*/ | ||
protected $configuration; | ||
/** | ||
* @var \Drupal\search_api_pantheon\Services\Reload | ||
*/ | ||
protected $logger_factory; | ||
|
||
/** | ||
* @var \Drupal\search_api_pantheon\Services\PantheonGuzzle | ||
*/ | ||
protected PantheonGuzzle $client; | ||
|
||
/** | ||
* Class Constructor. | ||
*/ | ||
public function __construct( | ||
LoggerChannelFactoryInterface $logger_factory, | ||
PantheonGuzzle $client, | ||
) { | ||
$this->logger_factory = $logger_factory; | ||
$this->client = $client; | ||
} | ||
|
||
|
||
/** | ||
* Reload the server after schema upload. | ||
* | ||
* @throws \Drupal\search_api_pantheon\Exceptions\PantheonSearchApiException | ||
*/ | ||
public function reloadServer(): void { | ||
// Schema upload URL. | ||
$uri = new Uri( | ||
$this->getClient() | ||
->getEndpoint() | ||
->getReloadUri() | ||
); | ||
|
||
$this->logger->debug('Reload url: ' . (string) $uri); | ||
|
||
// Send the request. | ||
$request = new Request( | ||
'POST', | ||
$uri, | ||
[ | ||
'Accept' => 'application/json', | ||
'Content-Type' => 'application/json', | ||
] | ||
); | ||
$response = $this->getClient()->sendRequest($request); | ||
|
||
$status_code = $response->getStatusCode(); | ||
$reload_logger_content = [ | ||
'status_code' => $status_code, | ||
'reason' => $response->getReasonPhrase(), | ||
]; | ||
if ($status_code >= 200 && $status_code < 300) { | ||
$this->logger->info('Server reloaded: {status_code} {reason}', $reload_logger_content); | ||
return; | ||
} | ||
$this->logger->error('Server not reloaded: {status_code} {reason}', $reload_logger_content); | ||
throw new PantheonSearchApiException('Server not reloaded.'); | ||
} | ||
|
||
|
||
} |
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