Merge branch 'master' into develop

This commit is contained in:
Lucas Bartholemy 2023-04-24 17:18:08 +02:00
commit 4948b3f0c3
4 changed files with 25 additions and 2 deletions

View File

@ -1,6 +1,11 @@
HumHub Changelog 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) 1.14.0 (April 20, 2023)
----------------------- -----------------------
- Fix #6196: Use class names for default logging targets in default common config - Fix #6196: Use class names for default logging targets in default common config

View File

@ -113,7 +113,7 @@ class ActiveQueryContent extends ActiveQuery
$conditionUser = 'cuser.id IS NOT NULL and cuser.visibility=' . User::VISIBILITY_ALL . ' AND content.visibility=1'; $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'; $globalCondition .= 'content.contentcontainer_id IS NULL AND content.visibility=1';
} else { } else {
$this->emulateExecution(); return $this->emulateExecution();
} }
$this->andWhere("{$conditionSpace} OR {$conditionUser} OR {$globalCondition}"); $this->andWhere("{$conditionSpace} OR {$conditionUser} OR {$globalCondition}");

View File

@ -454,6 +454,16 @@ class ContentActiveRecord extends ActiveRecord implements ContentOwner, Movable,
parent::afterSave($insert, $changedAttributes); 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. * Returns the class used in the polymorphic content relation.
* By default this function will return the static class. * By default this function will return the static class.

View File

@ -244,12 +244,20 @@ class Content extends ActiveRecord implements Movable, ContentOwner, SoftDeletab
$changedAttributes['state'] == Content::STATE_DRAFT $changedAttributes['state'] == Content::STATE_DRAFT
)) { )) {
$this->processNewContent(); $this->processNewContent();
}
if ($insert || array_key_exists('state', $changedAttributes)) {
$previousState = $changedAttributes['state'] ?? null;
$this->trigger(self::EVENT_STATE_CHANGED, new ContentStateEvent([ $this->trigger(self::EVENT_STATE_CHANGED, new ContentStateEvent([
'content' => $this, 'content' => $this,
'newState' => $this->state, '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) { if ($this->state === static::STATE_PUBLISHED) {