Browse Source

Blog revision tags

master
Egorka 7 years ago
parent
commit
0d51b2e7a4
  1. 8
      common/modules/blog/helpers/BlogPostHelper.php
  2. 22
      common/modules/blog/services/BlogPostManageService.php

8
common/modules/blog/helpers/BlogPostHelper.php

@ -77,7 +77,13 @@ class BlogPostHelper
$revision->revision_at = $revision->updated_at;
$revision->revision_id = $model->id;
$revision->type = BlogPost::TYPE_REVISION;
$revision->save( $revision );
$revision->save();
// tags
foreach ($model->tags as $tag) {
$revision->assignTag($tag->id);
}
$revision->save();
$path = Yii::getAlias('@staticRoot/origin/posts');
$parts = pathinfo($model->image);

22
common/modules/blog/services/BlogPostManageService.php

@ -133,9 +133,7 @@ class BlogPostManageService
$this->transaction->wrap(function () use ($post, $form) {
$post->revokeTags();
//$post->doRevision();
$this->posts->save($post);
//$post->stopRevision();
if (is_array($form->tags->new_tags) && !empty($form->tags->new_tags)) {
foreach ( $form->tags->new_tags as $tag_id => $tag_name ) {
@ -188,6 +186,16 @@ class BlogPostManageService
$post = $this->posts->get($id);
$from = $this->posts->get($from_id);
// get from tags
$from_tags = $from->tags;
$new_tags_names = array_map(function ($item){
return $item->name;
}, $from_tags);
// clear from tags
$from->revokeTags();
$this->posts->save($from);
// remove current revision
$this->posts->remove($post);
@ -201,8 +209,14 @@ class BlogPostManageService
$from->type = BlogPost::TYPE_PUBLIC;
$from->revision_id = null;
// restore revision to current
$this->posts->save($from);
foreach ($new_tags_names as $tag_name) {
if ( ! $tag = $this->tags->findByName( $tag_name ) ) {
$tag = BlogTag::create( $tag_name, Inflector::slug( $tag_name, '_' ) );
$this->tags->save( $tag );
}
$from->assignTag( $tag->id );
}
$this->posts->save($from);
// delete never revisions
BlogPost::deleteAll(['AND', ['revision_id' => $from->id], ['>', 'revision_at', $from->revision_at]]);

Loading…
Cancel
Save