Skip to content

Commit

Permalink
Merge pull request #173 from humhub/enh/allow-change-content-created-at
Browse files Browse the repository at this point in the history
Add possibility to change created_at of content
  • Loading branch information
luke- committed Jul 30, 2024
2 parents 05bd040 + de9e432 commit 0f8f768
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 7 deletions.
31 changes: 31 additions & 0 deletions components/BaseContentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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();
}
}
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
2 changes: 1 addition & 1 deletion docs/html/content.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/html/notification.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/html/post.html

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion docs/swagger/content.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ definitions:
- $ref: "user.yaml#/definitions/UserShort"
created_at:
type: string
readOnly: true
example: "2022-04-13 05:15:43"
updated_by:
readOnly: true
Expand Down
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"keywords": [
"api", "rest"
],
"version": "0.10.0",
"version": "0.10.1",
"homepage": "https://github.com/humhub/rest",
"humhub": {
"minVersion": "1.16"
Expand Down

0 comments on commit 0f8f768

Please sign in to comment.