Browse Source

Blog revision tags

master
Egorka 6 years ago
parent
commit
0d51b2e7a4
  1. 8
      common/modules/blog/helpers/BlogPostHelper.php
  2. 20
      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_at = $revision->updated_at;
$revision->revision_id = $model->id; $revision->revision_id = $model->id;
$revision->type = BlogPost::TYPE_REVISION; $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'); $path = Yii::getAlias('@staticRoot/origin/posts');
$parts = pathinfo($model->image); $parts = pathinfo($model->image);

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

@ -133,9 +133,7 @@ class BlogPostManageService
$this->transaction->wrap(function () use ($post, $form) { $this->transaction->wrap(function () use ($post, $form) {
$post->revokeTags(); $post->revokeTags();
//$post->doRevision();
$this->posts->save($post); $this->posts->save($post);
//$post->stopRevision();
if (is_array($form->tags->new_tags) && !empty($form->tags->new_tags)) { if (is_array($form->tags->new_tags) && !empty($form->tags->new_tags)) {
foreach ( $form->tags->new_tags as $tag_id => $tag_name ) { foreach ( $form->tags->new_tags as $tag_id => $tag_name ) {
@ -188,6 +186,16 @@ class BlogPostManageService
$post = $this->posts->get($id); $post = $this->posts->get($id);
$from = $this->posts->get($from_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 // remove current revision
$this->posts->remove($post); $this->posts->remove($post);
@ -201,7 +209,13 @@ class BlogPostManageService
$from->type = BlogPost::TYPE_PUBLIC; $from->type = BlogPost::TYPE_PUBLIC;
$from->revision_id = null; $from->revision_id = null;
// restore revision to current 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); $this->posts->save($from);
// delete never revisions // delete never revisions

Loading…
Cancel
Save