Skip to content

Commit

Permalink
Merge pull request #25 from luyadev/use-behaviors
Browse files Browse the repository at this point in the history
use behaviors to ensure cli usage
  • Loading branch information
nadar authored Aug 3, 2021
2 parents 7fe969d + 0eaf84e commit 3b35c61
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).
In order to read more about upgrading and BC breaks have a look at the [UPGRADE Document](UPGRADE.md).

## 4.0.1 (3. August 2021)

+ [#25](https://github.com/luyadev/luya-module-news/pull/25) Fixed issue when using the Article Model in Queue Context.

## 4.0.0 (2. August 2021)

+ [#24](https://github.com/luyadev/luya-module-news/pull/24) New field to archive certain News Articles. A new archive action is available where developers can list the archived entries.
Expand Down
37 changes: 16 additions & 21 deletions src/models/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
use luya\admin\traits\SoftDeleteTrait;
use luya\admin\traits\TaggableTrait;
use luya\admin\aws\TaggableActiveWindow;
use luya\admin\behaviors\BlameableBehavior;
use luya\admin\buttons\DuplicateActiveButton;
use luya\admin\models\User;
use luya\news\admin\aws\PreviewActiveWindow;
use luya\web\LinkInterface;
use yii\behaviors\TimestampBehavior;

/**
* News Article
Expand Down Expand Up @@ -61,29 +63,22 @@ public static function tableName()
}

/**
* @inheritdoc
* {@inheritDoc}
*/
public function init()
{
parent::init();
$this->on(self::EVENT_BEFORE_INSERT, [$this, 'eventBeforeInsert']);
$this->on(self::EVENT_BEFORE_UPDATE, [$this, 'eventBeforeUpdate']);
}

public function eventBeforeUpdate()
{
$this->update_user_id = Yii::$app->adminuser->getId();
$this->timestamp_update = time();
}

public function eventBeforeInsert()
public function behaviors()
{
$this->create_user_id = Yii::$app->adminuser->getId();
$this->update_user_id = Yii::$app->adminuser->getId();
$this->timestamp_update = time();
if (empty($this->timestamp_create)) {
$this->timestamp_create = time();
}
return [
[
'class' => BlameableBehavior::class,
'createdByAttribute' => 'create_user_id',
'updatedByAttribute' => 'update_user_id',
],
[
'class' => TimestampBehavior::class,
'createdAtAttribute' => 'timestamp_create',
'updatedAtAttribute' => 'timestamp_update'
]
];
}

/**
Expand Down

0 comments on commit 3b35c61

Please sign in to comment.