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

Type error with siteId in v3.3.1 #284

Closed
chrismlusk opened this issue Nov 14, 2023 · 3 comments
Closed

Type error with siteId in v3.3.1 #284

chrismlusk opened this issue Nov 14, 2023 · 3 comments

Comments

@chrismlusk
Copy link

After updating to v3.3.1, I get this error when attempting to access Utilities > Scout Indices:

foreach() argument must be of type array|object, int given

The stack trace refers to line 44 in ScoutUtility.php.

foreach ($engine->scoutIndex->criteria->siteId as $id) {
    $sites[] = Craft::$app->getSites()->getSiteById($id);
}

Here's my scout.php:

function createIndices(): array
{
    $sites = Craft::$app->getSites()->getSitesByGroupId(1);
    $baseLocationIndex = App::parseEnv('$ALGOLIA_LOCATION_INDEX_BASE');
    $baseProviderIndex = App::parseEnv('$ALGOLIA_PROVIDER_INDEX_BASE');

    $indices = [];

    foreach ($sites as $site) {
        $siteId = $site->id;
        $siteLanguage = $site->language;

        $indices[] = ScoutIndex::create($baseLocationIndex . '_' . $siteLanguage)
            ->criteria(function(EntryQuery $query) use ($siteId) {
                return $query
                    ->sectionId(8)
                    ->siteId($siteId);
            })
            ->transformer(new AlgoliaLocationTransformer([
                'siteId' => $siteId,
                'siteLanguage' => $siteLanguage,
            ]));

        $indices[] = ScoutIndex::create($baseProviderIndex . '_' . $siteLanguage)
            ->criteria(function(EntryQuery $query) use ($siteId) {
                return $query
                    ->sectionId(9)
                    ->siteId($siteId);
            })
            ->transformer(new AlgoliaProviderTransformer([
                'siteId' => $siteId,
                'siteLanguage' => $siteLanguage,
            ]));
    }

    return $indices;
}

return [
    'sync' => false,
    'queue' => true,
    'connect_timeout' => 1,
    'batch_size' => 1000,
    'indexRelations' => true,
    'application_id' => App::parseEnv('$ALGOLIA_APPLICATION_ID'),
    'admin_api_key' => App::parseEnv('$ALGOLIA_ADMIN_API_KEY'),
    'search_api_key' => App::parseEnv('$ALGOLIA_SEARCH_API_KEY'),
    'indices' => createIndices(),
];
janhenckens added a commit that referenced this issue Nov 15, 2023
@janhenckens
Copy link
Member

Thanks for catching that @chrismlusk, pushed a fixed and I'll have release out shortly!

@janhenckens
Copy link
Member

Released in 3.3.2, can you give that a go? Feel free to reopen this issue should you still have an issue!

@chrismlusk
Copy link
Author

Perfect! Thanks for the quick fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants