Skip to content

Commit

Permalink
(index): change records for indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
rvgool-oym committed Sep 27, 2024
1 parent 9826ba7 commit 2b0d498
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/controllers/CpController.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ protected function reindexElement(): ?string
$request = Craft::$app->getRequest();

$model = new IndexableElementModel();
$model->elementId = $request->getRequiredBodyParam('params.elementId');
$model->siteId = $request->getRequiredBodyParam('params.siteId');
$model->elementId = (int) $request->getRequiredBodyParam('params.elementId');
$model->siteId = (int) $request->getRequiredBodyParam('params.siteId');
$model->type = $request->getRequiredBodyParam('params.type');
$element = $model->getElement();

Expand Down
20 changes: 10 additions & 10 deletions src/records/ElasticsearchRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class ElasticsearchRecord extends ActiveRecord
private mixed $_schema;
private array $_attributes = ['title', 'url', 'elementHandle', 'content', 'postDate', 'expiryDate', 'noPostDate', 'noExpiryDate'];
private Element $_element;
private mixed $_queryParams;
private mixed $_highlightParams;
private array $_queryParams = [];
private array $_highlightParams = [];
private array $_searchFields = ['attachment.content', 'title'];

public static function type(): string
Expand Down Expand Up @@ -427,7 +427,7 @@ public function setElement(Element $element): void
*/
public function getQueryParams(string $query): mixed
{
if ($this->_queryParams === null) {
if (empty($this->_queryParams)) {
$currentTimeDb = Db::prepareDateForDb(new \DateTime());
$this->_queryParams = [
'bool' => [
Expand Down Expand Up @@ -480,19 +480,19 @@ public function getQueryParams(string $query): mixed
}

/**
* @param mixed $queryParams
* @param array $queryParams
*/
public function setQueryParams(mixed $queryParams): void
public function setQueryParams(array $queryParams): void
{
$this->_queryParams = $queryParams;
}

/**
* @return mixed
* @return array
*/
public function getHighlightParams(): mixed
public function getHighlightParams(): array
{
if (is_null($this->_highlightParams)) {
if (empty($this->_highlightParams)) {
$this->_highlightParams = ArrayHelper::merge(
ElasticsearchPlugin::getInstance()->settings->highlight,
[
Expand All @@ -506,9 +506,9 @@ public function getHighlightParams(): mixed
}

/**
* @param mixed $highlightParams
* @param array $highlightParams
*/
public function setHighlightParams(mixed $highlightParams): void
public function setHighlightParams(array $highlightParams): void
{
$this->_highlightParams = $highlightParams;
}
Expand Down
11 changes: 5 additions & 6 deletions src/services/ElementIndexerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,6 @@ protected function getReasonForNotReindexing(Element $element): ?string
}
}

if (!$element->hasContent()) {
$message = "Not indexing entry #{$element->id} since it has no content.";
Craft::debug($message, __METHOD__);
return $message;
}

if (!$element->getUrl()) {
$message = "Not indexing entry #{$element->id} since it has no URL.";
Craft::debug($message, __METHOD__);
Expand Down Expand Up @@ -239,6 +233,11 @@ protected function getElementIndexableContent(Element $element): bool|string
// Generate the sharable url based on the previously generated token
$url = UrlHelper::urlWithToken($element->getUrl(), $token);

// [OYM] Add fix to prevent cURL error, caused by the SSL certificate in our Docker environment is "invalid"
if (getenv('CRAFT_ENVIRONMENT') === 'dev') {
$url = str_replace('https://', 'http://', $url);
}

// Request the page content with GuzzleHttp\Client
$client = new \GuzzleHttp\Client(['connect_timeout' => 10]);
try {
Expand Down

0 comments on commit 2b0d498

Please sign in to comment.