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

Check if Craft is installed before generating autocomplete classes #14

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file.

## 1.12.2 - 2024.09.23
### Fixed
* Fixed an exception that was getting thrown when Craft wasn't installed yet

## 1.12.1 - 2024.04.15
### Added
* Stable release for Craft CMS 5
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "nystudio107/craft-autocomplete",
"description": "Provides Twig template IDE autocomplete of Craft CMS & plugin variables",
"type": "yii2-extension",
"version": "1.12.1",
"version": "1.12.2",
"keywords": [
"craft",
"cms",
Expand Down
12 changes: 7 additions & 5 deletions src/Autocomplete.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,14 @@ public function registerEventHandlers()
*/
public function generateAutocompleteClasses()
{
$autocompleteGenerators = $this->getAllAutocompleteGenerators();
foreach ($autocompleteGenerators as $generatorClass) {
/* @var Generator $generatorClass */
$generatorClass::generate();
if (Craft::$app->getIsInstalled()) {
Copy link
Collaborator

@bencroker bencroker Sep 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like at this point, no primary site exists. Does this necessarily mean that the plugin Craft is not installed, or couldn’t the error also appear in an installed setup with no primary sites?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well the thing is, Craft Autocomplete is a self-bootstrapping module, so as long as it's required, it's installed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I meant Craft (not a plugin). What I’m getting at is, wouldn’t it be more correct to check whether a primary site exists rather than whether Craft is installed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't the installation process create the default site? Although I guess you're right, someone could potentially delete the one and only site somehow.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm gonna merge it anyway, because I think this is probably a good safety check to have in regardless. If we need to do more for further edge cases down the road, we can.

$autocompleteGenerators = $this->getAllAutocompleteGenerators();
foreach ($autocompleteGenerators as $generatorClass) {
/* @var Generator $generatorClass */
$generatorClass::generate();
}
Craft::info('Autocomplete classes generated', __METHOD__);
}
Craft::info('Autocomplete classes generated', __METHOD__);
}

/**
Expand Down