diff --git a/CHANGELOG.md b/CHANGELOG.md index f0407652ee..b21d8dfc40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ HumHub Changelog ================ +1.14.1 (Unreleased) +------------------- +- Fix #6251: Emulate execution on `readable()` content +- Enh #6252: Implement new method to handle changing of content active record state + 1.14.0 (April 20, 2023) ----------------------- - Fix #6196: Use class names for default logging targets in default common config diff --git a/protected/humhub/modules/content/components/ActiveQueryContent.php b/protected/humhub/modules/content/components/ActiveQueryContent.php index 1d5c2c4b30..757b60eeae 100644 --- a/protected/humhub/modules/content/components/ActiveQueryContent.php +++ b/protected/humhub/modules/content/components/ActiveQueryContent.php @@ -113,7 +113,7 @@ class ActiveQueryContent extends ActiveQuery $conditionUser = 'cuser.id IS NOT NULL and cuser.visibility=' . User::VISIBILITY_ALL . ' AND content.visibility=1'; $globalCondition .= 'content.contentcontainer_id IS NULL AND content.visibility=1'; } else { - $this->emulateExecution(); + return $this->emulateExecution(); } $this->andWhere("{$conditionSpace} OR {$conditionUser} OR {$globalCondition}"); diff --git a/protected/humhub/modules/content/components/ContentActiveRecord.php b/protected/humhub/modules/content/components/ContentActiveRecord.php index 62da713f99..da1c942700 100644 --- a/protected/humhub/modules/content/components/ContentActiveRecord.php +++ b/protected/humhub/modules/content/components/ContentActiveRecord.php @@ -454,6 +454,16 @@ class ContentActiveRecord extends ActiveRecord implements ContentOwner, Movable, parent::afterSave($insert, $changedAttributes); } + /** + * This method is called after state of the Content of this Active Record has been changed + * + * @param int|null $newState + * @param int|null $previousState + */ + public function afterStateChange(?int $newState, ?int $previousState): void + { + } + /** * Returns the class used in the polymorphic content relation. * By default this function will return the static class. diff --git a/protected/humhub/modules/content/models/Content.php b/protected/humhub/modules/content/models/Content.php index 9c0bbd7d7e..5096843c6a 100644 --- a/protected/humhub/modules/content/models/Content.php +++ b/protected/humhub/modules/content/models/Content.php @@ -244,12 +244,20 @@ class Content extends ActiveRecord implements Movable, ContentOwner, SoftDeletab $changedAttributes['state'] == Content::STATE_DRAFT )) { $this->processNewContent(); + } + if ($insert || array_key_exists('state', $changedAttributes)) { + $previousState = $changedAttributes['state'] ?? null; $this->trigger(self::EVENT_STATE_CHANGED, new ContentStateEvent([ 'content' => $this, 'newState' => $this->state, - 'previousState' => (isset($changedAttributes['state'])) ? $changedAttributes['state'] : null, + 'previousState' => $previousState ])); + + $model = $this->getPolymorphicRelation(); + if ($model instanceof ContentActiveRecord) { + $model->afterStateChange($this->state, $previousState); + } } if ($this->state === static::STATE_PUBLISHED) {