Initial work on enabledByOwner - #18152
Conversation
|
A little stumped on the most efficient way to bulid out the I considered only calling
In this situation, the entry’s So either:
Option 2 would be more performant, but would also require a new |
…dbyowner-element-query-param # Conflicts: # src/services/Elements.php
|
This PR had conflicts with |
There was a problem hiding this comment.
Pull request overview
Adds initial support for an enabledByOwner element query parameter by introducing an elements_sites.enabledByOwner column and plumbing it into element queries and element saving/propagation.
Changes:
- Adds
enabledByOwnertoElementQueryInterface/ElementQuery, filtering results viaelements_sites.enabledByOwner. - Adds
enabledByOwnercolumn + index to installs and a new migration. - Starts tracking status changes during element saves to trigger recalculation of nested
enabledByOwnervalues.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/services/Elements.php | Tracks enabled-status changes and attempts to initialize/update enabledByOwner during element/site saves and propagation. |
| src/records/Element_SiteSettings.php | Updates record docblock to include the new enabledByOwner property. |
| src/migrations/m251208_193926_enabledByOwner.php | Adds the enabledByOwner column and index to elements_sites. |
| src/migrations/Install.php | Ensures new installs create the enabledByOwner column and index. |
| src/elements/db/ElementQueryInterface.php | Adds the enabledByOwner() query API contract. |
| src/elements/db/ElementQuery.php | Implements enabledByOwner() and applies the filter during query preparation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| private function updateNestedEnabledByOwnerValues(int $elementId, int $siteId, bool $enabledByOwner): void | ||
| { | ||
| // update nested elements' enabledByOwner values, | ||
| // but only if they are primarily owned by this element (recursively) | ||
| // ... |
| * @param bool $saveContent Whether the element’s content should be saved | ||
| * @param bool $statusChanged Whether the element’s `enabled` status just changed | ||
| * @param Element_SiteSettingsRecord|null $siteSettingsRecord | ||
| * @retrun bool |
| if ($this->enabledByOwner) { | ||
| $this->subQuery->andWhere(['elements_sites.enabledByOwner' => true]); | ||
| } |
| public function safeUp(): bool | ||
| { | ||
| $this->addColumn(Table::ELEMENTS_SITES, 'enabledByOwner', $this->boolean()->notNull()->defaultValue(true)->after('enabled')); | ||
| $this->createIndex(null, Table::ELEMENTS_SITES, ['enabledByOwner'], false); | ||
| return true; |
Description
Adds a new
enabledByOwnerelement query param, which maps to a newelements_sites.enabledByOwnercolumn. The column keeps track of whether the element/site’s owner element is enabled (recursively).Related issues