Content state flag "was published" (#6626)

This commit is contained in:
Yuriy Bakhtin 2023-10-25 15:04:36 +02:00 committed by GitHub
parent 7d19bf7a45
commit 6376b93ace
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 14 deletions

View File

@ -7,6 +7,7 @@ HumHub Changelog
- Enh #6620: Marketplace: Add more module checks
- Enh #6621: Avoid PHP error when trying to download a file without guid in the URL params (return 404 exception instead)
- Enh #6623: Add a hint in the "Dropdown space order" settings to inform that a manual sort is always applied first
- Enh #6626: Content state flag "was published"
- Enh #6628: Add self test check: "Mobile App - Push Service"
1.15.0-beta.2 (October 5, 2023)

View File

@ -0,0 +1,28 @@
<?php
use humhub\components\Migration;
/**
* Class m231024_062218_content_was_published
*/
class m231024_062218_content_was_published extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->safeAddColumn('content', 'was_published',
$this->boolean()->defaultValue(false)->notNull()->after('state')
);
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->safeDropColumn('content', 'was_published');
}
}

View File

@ -71,6 +71,7 @@ use yii\helpers\Url;
* @property integer $archived
* @property integer $hidden
* @property integer $state
* @property integer $was_published
* @property string $scheduled_at
* @property integer $locked_comments
* @property string $created_at
@ -259,6 +260,10 @@ class Content extends ActiveRecord implements Movable, ContentOwner, SoftDeletab
if ($model instanceof ContentActiveRecord) {
$model->afterStateChange($this->state, $previousState);
}
if (!$this->getStateService()->wasPublished() && (int) $previousState === self::STATE_PUBLISHED) {
$this->updateAttributes(['was_published' => 1]);
}
}
if ($this->getStateService()->isPublished()) {

View File

@ -8,8 +8,6 @@
namespace humhub\modules\content\services;
use humhub\libs\DbDateValidator;
use humhub\modules\activity\helpers\ActivityHelper;
use humhub\modules\content\activities\ContentCreated;
use humhub\modules\content\models\Content;
use yii\base\Component;
@ -81,20 +79,13 @@ class ContentStateService extends Component
return $this->is(Content::STATE_PUBLISHED);
}
/**
* @since 1.14.3
* @return bool
*/
public function wasPublished(): bool
{
$activityQuery = ActivityHelper::getActivitiesQuery($this->content->getPolymorphicRelation());
if ($activityQuery === null) {
return false;
}
$contentCreatedActivity = new ContentCreated();
return $activityQuery
->andWhere(['class' => get_class($contentCreatedActivity)])
->andWhere(['module' => $contentCreatedActivity->moduleId])
->exists();
return (bool) $this->content->was_published;
}
public function isDraft(): bool