diff --git a/components/BaseContentController.php b/components/BaseContentController.php index 23a8e06..e525917 100644 --- a/components/BaseContentController.php +++ b/components/BaseContentController.php @@ -386,6 +386,10 @@ protected function updateMetadata(ContentActiveRecord $activeRecord, array $data return false; } + if (!$this->updateVisibility($activeRecord, $data['metadata'])) { + return false; + } + if (!$this->updateArchived($activeRecord, $data['metadata'])) { return false; } @@ -402,6 +406,10 @@ protected function updateMetadata(ContentActiveRecord $activeRecord, array $data return false; } + if (Yii::$app->user->identity->isSystemAdmin() && !$this->updateCreatedAt($activeRecord, $data['metadata'])) { + return false; + } + return true; } @@ -511,4 +519,27 @@ protected function updateScheduledAt(ContentActiveRecord $activeRecord, array $d return $activeRecord->content->save(); } + + public function updateCreatedAt(ContentActiveRecord $activeRecord, array $data): bool + { + if (!isset($data['created_at'])) { + return true; + } + + $validator = DynamicModel::validateData([ + 'created_at' => $data['created_at'] + ], [ + ['created_at', 'datetime', 'format' => 'php:Y-m-d H:i:s'] + ]); + + if (!$validator->validate()) { + $activeRecord->addError('created_at', $validator->getFirstError('created_at')); + + return false; + } + + $activeRecord->content->created_at = $data['created_at']; + + return $activeRecord->content->save(); + } } diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 925c271..202b102 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,6 +1,10 @@ Changelog ========= +0.10.1 (Unreleased) +---------------------- +- Enh #173: Added possibility to change `created_at` of `content` + 0.10.0 (July 16, 2024) ---------------------- - Enh #155: Add `requirements.php` diff --git a/docs/html/content.html b/docs/html/content.html index 7345bd1..c39ccc4 100644 --- a/docs/html/content.html +++ b/docs/html/content.html @@ -410,7 +410,7 @@

Response samples

Content type
application/json
{
  • "total": 76,
  • "page": 1,
  • "pages": 8,
  • "links": {
    },
  • "results": [
    ]
}

Tags

Group API