diff --git a/common/modules/blog/controllers/PostController.php b/common/modules/blog/controllers/PostController.php index e5775db..05ec42a 100644 --- a/common/modules/blog/controllers/PostController.php +++ b/common/modules/blog/controllers/PostController.php @@ -53,11 +53,16 @@ class PostController extends FrontendController 'class' => AccessControl::class, 'rules' => [ [ - 'actions' => ['index', 'category', 'tag', 'post', 'preview'], + 'actions' => ['index', 'category', 'tag', 'post'], 'allow' => true, //'roles' => ['Blog'], ], [ + 'actions' => ['preview'], + 'allow' => true, + 'roles' => ['BlogManagement'], + ], + [ 'actions' => ['comment'], 'allow' => true, 'roles' => ['Comments'], @@ -178,53 +183,71 @@ class PostController extends FrontendController return parent::beforeAction($action); } - public function actionPreview() + /*public function actionPreview($id = null) { Yii::$app->controller->enableCsrfValidation = false; $form = new BlogPostForm(); - if ($form->load(Yii::$app->request->post()) && $form->validate()) { - $post = new BlogPost(); - $post->id = -1; - $post->title = $form->title; - $post->description = $form->description; - $post->content = $form->content; - $post->category_id = $form->category_id; - $post->created_at = time(); - $post->updated_at = time(); - $post->published_at = time(); - - $meta = new Meta($form->meta->title, $form->meta->description, $form->meta->keywords); - $post->meta = $meta; - $post->meta_json = Json::encode([ - 'title' => $form->meta->title, - 'description' => $form->meta->description, - 'keywords' => $form->meta->keywords, - ]); - $post->video = $form->video; - $post->slug = $form->slug; - - if ($form->image) { - $post->setImage($form->image); - } - else if ($form->video) { - $src = 'https://i.ytimg.com/vi/' . BlogPostHelper::parseYoutubeUrl($post->video) . '/maxresdefault.jpg'; - $filename = (new Security())->generateRandomString(15) . '.jpg'; - copy($src, \Yii::getAlias(BlogPost::FILE_ORIGINAL_PATH . '/' . $post->id . '.jpg')); - //copy($src, \Yii::getAlias(BlogPost::FILE_ORIGINAL_PATH . '/' . $filename)); - $post->image = $filename; + $parent = $id ? BlogPost::findOne($id) : null; + + if ($form->load(Yii::$app->request->post())) { + $form->slug = md5(time()); + if ($form->validate()) { + $post = new BlogPost(); + $post->id = - 1; + $post->title = $form->title; + $post->description = $form->description; + $post->content = $form->content; + $post->category_id = $form->category_id; + $post->created_at = time(); + $post->updated_at = time(); + $post->published_at = time(); + + $meta = new Meta( $form->meta->title, $form->meta->description, $form->meta->keywords ); + $post->meta = $meta; + $post->meta_json = Json::encode( [ + 'title' => $form->meta->title, + 'description' => $form->meta->description, + 'keywords' => $form->meta->keywords, + ] ); + $post->video = $form->video; + $post->slug = $form->slug; + + if ( $form->image ) { + $post->setImage( $form->image ); + } else if ( $form->video ) { + $src = 'https://i.ytimg.com/vi/' . BlogPostHelper::parseYoutubeUrl( $post->video ) . '/maxresdefault.jpg'; + $filename = ( new Security() )->generateRandomString( 15 ) . '.jpg'; + copy( $src, \Yii::getAlias( BlogPost::FILE_ORIGINAL_PATH . '/' . $post->id . '.jpg' ) ); + //copy($src, \Yii::getAlias(BlogPost::FILE_ORIGINAL_PATH . '/' . $filename)); + $post->image = $filename; + } + + if ( $post->image ) { + $path = $post->getUploadedFilePath( 'image' ); + FileHelper::createDirectory( pathinfo( $path, PATHINFO_DIRNAME ), 0775, true ); + $post->image->saveAs( $path ); + $post->image = $post->getImageFileUrl( 'image' ); + } else { + $post->image = $parent->image; + //$post->image = $post->getImageFileUrl( 'image' ); + } + + return $this->render( 'post', [ + 'post' => $post, + ] ); } + } else {print_r($form->errors);} + return ''; + }*/ - if ($post->image && !is_string($post->image)) { - $path = $post->getUploadedFilePath( 'image' ); - FileHelper::createDirectory( pathinfo( $path, PATHINFO_DIRNAME ), 0775, true ); - $post->image->saveAs( $path ); - $post->image = $post->getImageFileUrl( 'image' ); - } + public function actionPreview($id) + { + if (!$post = $this->posts->findPreview($id)) { + throw new NotFoundHttpException('The requested page does not exist.'); + } - return $this->render('post', [ - 'post' => $post, - ]); - } - return ''; - } + return $this->render('post', [ + 'post' => $post, + ]); + } } \ No newline at end of file diff --git a/common/modules/blog/controllers/manage/PostController.php b/common/modules/blog/controllers/manage/PostController.php index 0a6fc2f..91b073c 100644 --- a/common/modules/blog/controllers/manage/PostController.php +++ b/common/modules/blog/controllers/manage/PostController.php @@ -8,6 +8,7 @@ use common\modules\blog\forms\BlogPostForm; use common\modules\blog\forms\search\BlogPostSearch; use common\modules\blog\services\BlogPostManageService; use Yii; +use yii\helpers\Url; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; @@ -49,6 +50,8 @@ class PostController extends Controller 'delete-photo' => ['POST'], 'move-photo-up' => ['POST'], 'move-photo-down' => ['POST'], + 'restore-history' => ['POST'], + 'clear-history' => ['POST'], ], ], ]; @@ -76,28 +79,63 @@ class PostController extends Controller public function actionView($id) { $post = $this->findModel($id); + + $history = BlogPost::find() + ->andWhere(['OR', ['revision_id' => $id], ['id' => $id]]) + ->orderBy(['revision_at' => SORT_DESC]) + ->limit(20) + ->all(); + return $this->render('view', [ 'post' => $post, + 'history' => $history, ]); } - /** - * @return string|Response - */ - public function actionCreate() + public function actionCreatePreview($id = null) { - $form = new BlogPostForm(); - $form->action = 'create'; + $this->service->removePreviews(); + + $form = new BlogPostForm(); + $form->type = BlogPost::TYPE_PREVIEW; + if ($form->load(Yii::$app->request->post()) && $form->validate()) { + try { + $post = $this->service->create( $form, BlogPost::TYPE_PREVIEW ); + if ($id && !$post->image) { + $real_post = BlogPost::findOne($id); + if ($real_post->image) { + $post->image = $real_post->image; + $post->save(); + $path = Yii::getAlias('@staticRoot/origin/posts'); + $parts = pathinfo($real_post->image); + copy($path . '/' . $real_post->id . '.' . $parts['extension'], $path . '/' . $post->id . '.' . $parts['extension']); + } + } + return $this->redirect(Url::to(Yii::$app->get('frontendUrlManager')->createAbsoluteUrl(['/blog/post/preview', 'id' => $post->id]))); + } catch (\DomainException $e) { + Yii::$app->errorHandler->logException($e); + Yii::$app->session->setFlash('error', $e->getMessage()); + } + } $form->published_at = date('d.m.Y H:i:s'); + return $this->render('create', [ + 'model' => $form, + ]); + } + + public function actionCreate() + { + $form = new BlogPostForm(); if ($form->load(Yii::$app->request->post()) && $form->validate()) { try { - $post = $this->service->create($form); - return $this->redirect(['view', 'id' => $post->id]); + $post = $this->service->create( $form ); + return $this->redirect( [ 'view', 'id' => $post->id ] ); } catch (\DomainException $e) { Yii::$app->errorHandler->logException($e); Yii::$app->session->setFlash('error', $e->getMessage()); } } + $form->published_at = date('d.m.Y H:i:s'); return $this->render('create', [ 'model' => $form, ]); @@ -113,7 +151,6 @@ class PostController extends Controller { $post = $this->findModel($id); $form = new BlogPostForm($post); - $form->action = 'update'; $form->published_at = date('d.m.Y H:i:s', $form->published_at); if ($form->load(Yii::$app->request->post()) && $form->validate()) { try { @@ -207,6 +244,23 @@ class PostController extends Controller return $out; } + public function actionRestoreHistory($id) + { + $post = $this->findModel($id); + if ($post_id = $post->revision_id) { + $this->service->restoreHistory($id, $post->revision_id); + return $this->redirect(['/blog/manage/post/view', 'id' => $post_id]); + } + return $this->redirect(['/blog/manage/post/index']); + } + + public function actionClearHistory($id) + { + $post = $this->findModel($id); + $this->service->clearHistory($post); + return $this->redirect(['/blog/manage/post/view', 'id' => $post->id]); + } + /** * @param $id * diff --git a/common/modules/blog/entities/BlogPost.php b/common/modules/blog/entities/BlogPost.php index e957a7d..d622613 100644 --- a/common/modules/blog/entities/BlogPost.php +++ b/common/modules/blog/entities/BlogPost.php @@ -4,6 +4,7 @@ namespace common\modules\blog\entities; use common\modules\blog\entities\queries\BlogPostQuery; use core\behaviors\MetaBehavior; +use core\behaviors\RevisionBehavior; use core\entities\Meta; use lhs\Yii2SaveRelationsBehavior\SaveRelationsBehavior; use yii\behaviors\TimestampBehavior; @@ -32,6 +33,9 @@ use Yii; * @property int $comments_count * @property int $views * @property string $slug + * @property int $type + * @property int $revision_at + * @property int $revision_id * * @property BlogComment[] $blogComments * @property BlogTagAssignment[] $blogTagAssignments @@ -45,11 +49,15 @@ class BlogPost extends ActiveRecord const STATUS_DRAFT = 0; const STATUS_ACTIVE = 1; + const TYPE_PUBLIC = 0; + const TYPE_REVISION = 1; + const TYPE_PREVIEW = 2; + const FILE_ORIGINAL_PATH = '@staticRoot/origin/posts'; public $meta; - public static function create($categoryId, $title, $slug, $description, $content, $published_at, $video, Meta $meta): self + public static function create($categoryId, $title, $slug, $description, $content, $published_at, $video, $type = 0, Meta $meta): self { $post = new static(); $post->category_id = $categoryId; @@ -63,6 +71,8 @@ class BlogPost extends ActiveRecord $post->comments_count = 0; $post->published_at = $published_at; $post->video = $video; + $post->type = $type; + $post->revision_at = time(); return $post; } @@ -72,7 +82,7 @@ class BlogPost extends ActiveRecord } - public function edit($categoryId, $title, $slug, $description, $content, $published_at, $video, Meta $meta): void + public function edit($categoryId, $title, $slug, $description, $content, $published_at, $video, $type = 0, Meta $meta): void { $this->category_id = $categoryId; $this->title = $title; @@ -82,6 +92,8 @@ class BlogPost extends ActiveRecord $this->meta = $meta; $this->published_at = $published_at; $this->video = $video; + $this->type = $type; + $this->revision_at = time(); } /** @@ -108,6 +120,8 @@ class BlogPost extends ActiveRecord 'content' => Yii::t('blog', 'Content'), 'image' => Yii::t('blog', 'Image'), 'video' => Yii::t('blog', 'Video'), + 'type' => Yii::t('blog', 'Type'), + 'revision_at' => Yii::t('blog', 'Revision At'), 'status' => Yii::t('blog', 'Status'), 'meta_json' => Yii::t('blog', 'Meta Json'), 'comments_count' => Yii::t('blog', 'Comments Count'), diff --git a/common/modules/blog/entities/queries/BlogPostQuery.php b/common/modules/blog/entities/queries/BlogPostQuery.php index 2876180..28dacb2 100644 --- a/common/modules/blog/entities/queries/BlogPostQuery.php +++ b/common/modules/blog/entities/queries/BlogPostQuery.php @@ -23,11 +23,18 @@ class BlogPostQuery extends ActiveQuery return $this->andWhere(['<', 'published_at', time()]); } - public function byType($type) + public function typePublic($alias = null) { - return $this->andWhere(['type_id' => $type]); + return $this->andWhere([ + ($alias ? $alias . '.' : '') . 'type' => BlogPost::TYPE_PUBLIC, + ]); } + /*public function byType($type) + { + return $this->andWhere(['type_id' => $type]); + }*/ + public function last() { return $this->orderBy(['published_at' => SORT_DESC]); diff --git a/common/modules/blog/forms/BlogPostForm.php b/common/modules/blog/forms/BlogPostForm.php index 19a5349..ae209d8 100644 --- a/common/modules/blog/forms/BlogPostForm.php +++ b/common/modules/blog/forms/BlogPostForm.php @@ -7,6 +7,7 @@ use common\modules\blog\entities\BlogPost; use core\forms\CompositeForm; use core\forms\MetaForm; use core\validators\SlugValidator; +use yii\db\ActiveQuery; use yii\helpers\ArrayHelper; use yii\web\UploadedFile; use Yii; @@ -17,7 +18,7 @@ use Yii; */ class BlogPostForm extends CompositeForm { - public $action; + public $type; public $category_id; public $title; @@ -65,7 +66,21 @@ class BlogPostForm extends CompositeForm ['reset_image', 'boolean'], ['published_at', 'safe'], ['slug', SlugValidator::class], - [['slug'], 'unique', 'targetClass' => BlogPost::class, 'filter' => $this->_post ? ['<>', 'id', $this->_post->id] : null], + //[['slug'], 'unique', 'targetClass' => BlogPost::class, 'filter' => $this->_post ? ['<>', 'id', $this->_post->id] : null], + //[['slug'], 'unique', 'targetClass' => BlogPost::class, 'filter' => $this->_post ? ['<>', 'id', $this->_post->id] : ['type' => BlogPost::TYPE_PUBLIC]], + //[['slug'], 'unique', 'targetClass' => BlogPost::class, 'filter' => $this->_post ? ['AND', ['<>', 'id', $this->_post->id], ['type' => BlogPost::TYPE_PUBLIC]] : ['type' => BlogPost::TYPE_PUBLIC]], + [['slug'], 'unique', 'targetClass' => BlogPost::class, 'filter' => function (ActiveQuery $query) { + + if ($this->type != BlogPost::TYPE_PUBLIC) { + $query->andWhere($this->type . '=' . BlogPost::TYPE_PUBLIC); + } + + $query->andWhere(['type' => BlogPost::TYPE_PUBLIC]); + if ($this->_post) { + $query->andWhere(['<>', 'id', $this->_post->id]); + } + return $query; + }], ]; } diff --git a/common/modules/blog/forms/search/BlogPostSearch.php b/common/modules/blog/forms/search/BlogPostSearch.php index 40138a2..da9c59b 100644 --- a/common/modules/blog/forms/search/BlogPostSearch.php +++ b/common/modules/blog/forms/search/BlogPostSearch.php @@ -30,7 +30,7 @@ class BlogPostSearch extends Model */ public function search(array $params): ActiveDataProvider { - $query = BlogPost::find(); + $query = BlogPost::find()->typePublic(); $dataProvider = new ActiveDataProvider([ 'query' => $query, diff --git a/common/modules/blog/helpers/BlogPostHelper.php b/common/modules/blog/helpers/BlogPostHelper.php index c1a00cd..3dd14de 100644 --- a/common/modules/blog/helpers/BlogPostHelper.php +++ b/common/modules/blog/helpers/BlogPostHelper.php @@ -2,6 +2,7 @@ namespace common\modules\blog\helpers; +use common\modules\blog\entities\BlogPost; use core\entities\post\Post; use yii\helpers\ArrayHelper; use yii\helpers\Html; @@ -67,4 +68,20 @@ class BlogPostHelper } return $id; } + + public static function saveRevision(BlogPost $model) { + if (!$model->revision_id) { + $revision = clone $model; + $revision->id = null; + $revision->isNewRecord = true; + $revision->revision_at = $revision->updated_at; + $revision->revision_id = $model->id; + $revision->type = BlogPost::TYPE_REVISION; + $revision->save( $revision ); + + $path = Yii::getAlias('@staticRoot/origin/posts'); + $parts = pathinfo($model->image); + copy($path . '/' . $model->id . '.' . $parts['extension'], $path . '/' . $revision->id . '.' . $parts['extension']); + } + } } \ No newline at end of file diff --git a/common/modules/blog/messages/ru/blog.php b/common/modules/blog/messages/ru/blog.php index 0f402f5..2631584 100644 --- a/common/modules/blog/messages/ru/blog.php +++ b/common/modules/blog/messages/ru/blog.php @@ -67,4 +67,14 @@ return [ 'Blog Post' => 'Статья', 'Blog Home' => 'Блог', 'Select post...' => 'Укажите статью...', + 'Type' => 'Тип', + 'Revision At' => 'Версия', + 'History' => 'История изменений', + 'Clear History' => 'Очистить историю', + 'History is empty' => 'Нет изменений', + 'Current Edition' => 'Текущая редакция', + 'Restore' => 'Восстановить', + 'Are you sure you want to restore this history item?' => 'Вы уверены, что хотите восстановить эту запись?', + 'Are you sure you want to remove this history?' => 'Вы уверены, что хотите удалить всю историю?', + 'View' => 'Просмотр', ]; \ No newline at end of file diff --git a/common/modules/blog/migrations/m180725_091725_add_blog_posts_type_field.php b/common/modules/blog/migrations/m180725_091725_add_blog_posts_type_field.php new file mode 100644 index 0000000..1ff062b --- /dev/null +++ b/common/modules/blog/migrations/m180725_091725_add_blog_posts_type_field.php @@ -0,0 +1,34 @@ +addColumn('{{%blog_posts}}', 'type', $this->integer(2)->defaultValue(0)); // 0 - public, 1 - revision, 2 - preview + $this->addColumn('{{%blog_posts}}', 'revision_at', $this->integer()->unsigned()); + $this->addColumn('{{%blog_posts}}', 'revision_id', $this->integer()); + + $this->createIndex('idx_blog_posts_revision_id', '{{%blog_posts}}', 'revision_id'); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropIndex('idx_blog_posts_revision_id', '{{%blog_posts}}'); + + $this->dropColumn('{{%blog_posts}}', 'type'); + $this->dropColumn('{{%blog_posts}}', 'revision_at'); + $this->dropColumn('{{%blog_posts}}', 'revision_id'); + return false; + } +} diff --git a/common/modules/blog/migrations/m180725_113503_remove_blog_posts_slug_unique_index.php b/common/modules/blog/migrations/m180725_113503_remove_blog_posts_slug_unique_index.php new file mode 100644 index 0000000..9c0b82f --- /dev/null +++ b/common/modules/blog/migrations/m180725_113503_remove_blog_posts_slug_unique_index.php @@ -0,0 +1,28 @@ +dropIndex('{{%idx-blog_posts-slug}}', '{{%blog_posts}}'); + $this->createIndex('{{%idx-blog_posts-slug}}', '{{%blog_posts}}', 'slug'); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + return false; + $this->dropIndex('{{%idx-blog_posts-slug}}', '{{%blog_posts}}'); + $this->createIndex('{{%idx-blog_posts-slug}}', '{{%blog_posts}}', 'slug'); + } +} diff --git a/common/modules/blog/repositories/read/BlogPostReadRepository.php b/common/modules/blog/repositories/read/BlogPostReadRepository.php index 7a8bc40..c589105 100644 --- a/common/modules/blog/repositories/read/BlogPostReadRepository.php +++ b/common/modules/blog/repositories/read/BlogPostReadRepository.php @@ -13,40 +13,40 @@ class BlogPostReadRepository { public function count(): int { - return BlogPost::find()->active()->pubDate()->count(); + return BlogPost::find()->active()->pubDate()->typePublic()->count(); } public function getAllByRange($offset, $limit): array { - return BlogPost::find()->active()->pubDate()->orderBy(['id' => SORT_ASC])->limit($limit)->offset($offset)->all(); + return BlogPost::find()->active()->pubDate()->typePublic()->orderBy(['id' => SORT_ASC])->limit($limit)->offset($offset)->all(); } public function getAll(): DataProviderInterface { - $query = BlogPost::find()->active()->pubDate()->with('category'); + $query = BlogPost::find()->active()->pubDate()->typePublic()->with('category'); return $this->getProvider($query); } public function getAllByCategory(BlogCategory $category): DataProviderInterface { - $query = BlogPost::find()->active()->pubDate()->andWhere(['category_id' => $category->id])->with('category'); + $query = BlogPost::find()->active()->pubDate()->typePublic()->andWhere(['category_id' => $category->id])->with('category'); return $this->getProvider($query); } public function findNext(int $id): ?BlogPost { - return BlogPost::find()->active()->pubDate()->andWhere(['>', 'id', $id])->one(); + return BlogPost::find()->active()->pubDate()->typePublic()->andWhere(['>', 'id', $id])->one(); } public function findPrev(int $id): ?BlogPost { - return BlogPost::find()->active()->pubDate()->andWhere(['<', 'id', $id])->orderBy(['id' => SORT_DESC])->one(); + return BlogPost::find()->active()->pubDate()->typePublic()->andWhere(['<', 'id', $id])->orderBy(['id' => SORT_DESC])->one(); } public function getAllByTag(BlogTag $tag): DataProviderInterface { - $query = BlogPost::find()->alias('p')->active('p')->with('category'); + $query = BlogPost::find()->alias('p')->active('p')->typePublic('p')->with('category'); $query->joinWith(['blogTagAssignments ta'], false); $query->andWhere(['ta.tag_id' => $tag->id]); $query->groupBy('p.id'); @@ -55,7 +55,7 @@ class BlogPostReadRepository public function getByTagsId(BlogPost $post, array $tag_ids, int $limit = 15): DataProviderInterface { - $query = BlogPost::find()->alias('p')->active('p')->with('category'); + $query = BlogPost::find()->alias('p')->active('p')->typePublic('p')->with('category'); $query->joinWith(['blogTagAssignments ta'], false); $query->andWhere(['ta.tag_id' => $tag_ids]); $query->andWhere(['!=', 'p.id', $post->id]); @@ -91,4 +91,9 @@ class BlogPostReadRepository { return BlogPost::find()->andWhere(['slug' => $slug])->one(); } + + public function findPreview($id): ?BlogPost + { + return BlogPost::find()->andWhere(['id' => $id])->one(); + } } \ No newline at end of file diff --git a/common/modules/blog/services/BlogPostManageService.php b/common/modules/blog/services/BlogPostManageService.php index e67edcd..742041c 100644 --- a/common/modules/blog/services/BlogPostManageService.php +++ b/common/modules/blog/services/BlogPostManageService.php @@ -35,7 +35,7 @@ class BlogPostManageService $this->transaction = $transaction; } - public function create(BlogPostForm $form): BlogPost + public function create(BlogPostForm $form, $type = BlogPost::TYPE_PUBLIC): BlogPost { $category = $this->categories->get($form->category_id); @@ -47,6 +47,7 @@ class BlogPostManageService $form->content, $form->published_at, $form->video, + $type, new Meta( $form->meta->title, $form->meta->description, @@ -91,6 +92,8 @@ class BlogPostManageService public function edit($id, BlogPostForm $form): void { $post = $this->posts->get($id); + BlogPostHelper::saveRevision($post); + $category = $this->categories->get($form->category_id); $post->edit( @@ -101,6 +104,7 @@ class BlogPostManageService $form->content, $form->published_at, $form->video, + $post->type, new Meta( $form->meta->title, $form->meta->description, @@ -129,9 +133,10 @@ class BlogPostManageService $this->transaction->wrap(function () use ($post, $form) { $post->revokeTags(); + //$post->doRevision(); $this->posts->save($post); + //$post->stopRevision(); - $tag_updated = false; if (is_array($form->tags->new_tags) && !empty($form->tags->new_tags)) { foreach ( $form->tags->new_tags as $tag_id => $tag_name ) { if ( ! $tag = $this->tags->findByName( $tag_name ) ) { @@ -139,13 +144,9 @@ class BlogPostManageService $this->tags->save( $tag ); } $post->assignTag( $tag->id ); - $tag_updated = true; } } - - if ($tag_updated) { - $this->posts->save( $post ); - } + $this->posts->save( $post ); }); } @@ -168,4 +169,42 @@ class BlogPostManageService $post = $this->posts->get($id); $this->posts->remove($post); } + + public function removePreviews(): void + { + $posts = BlogPost::find()->andWhere(['type' => BlogPost::TYPE_PREVIEW])->all(); + foreach ($posts as $post) { + $post->delete(); + } + } + + public function clearHistory(BlogPost $post): void + { + BlogPost::deleteAll(['revision_id' => $post->id]); + } + + public function restoreHistory($from_id, $id): void + { + $post = $this->posts->get($id); + $from = $this->posts->get($from_id); + + // remove current revision + $this->posts->remove($post); + + // copy image + $path = \Yii::getAlias('@staticRoot/origin/posts'); + $parts = pathinfo($from->image); + copy($path . '/' . $from->id . '.' . $parts['extension'], $path . '/' . $id . '.' . $parts['extension']); + $from->createThumbs(); + + $from->id = $id; + $from->type = BlogPost::TYPE_PUBLIC; + $from->revision_id = null; + + // restore revision to current + $this->posts->save($from); + + // delete never revisions + BlogPost::deleteAll(['AND', ['revision_id' => $from->id], ['>', 'revision_at', $from->revision_at]]); + } } \ No newline at end of file diff --git a/common/modules/blog/views/manage/post/_form.php b/common/modules/blog/views/manage/post/_form.php index 6be3c16..cc3a4a9 100644 --- a/common/modules/blog/views/manage/post/_form.php +++ b/common/modules/blog/views/manage/post/_form.php @@ -168,7 +168,7 @@ $this->registerJs($js2); 'class' => 'btn btn-info', 'value'=>'preview', 'name'=>'submit_preview', - 'formaction' => Url::to(Yii::$app->params['frontendHostInfo'] . '/blog/post/preview'), + 'formaction' => Url::to(['/blog/manage/post/create-preview', 'id' => $model->_post ? $model->_post->id : null]), 'formtarget' => '_blank', ]) ?>
diff --git a/common/modules/blog/views/manage/post/view.php b/common/modules/blog/views/manage/post/view.php index 38ecebf..acdf7ef 100644 --- a/common/modules/blog/views/manage/post/view.php +++ b/common/modules/blog/views/manage/post/view.php @@ -8,6 +8,7 @@ use yii\widgets\DetailView; /* @var $this yii\web\View */ /* @var $post \common\modules\blog\entities\BlogPost */ /* @var $modificationsProvider yii\data\ActiveDataProvider */ +/* @var $history \common\modules\blog\entities\BlogPost[] */ $title = $post->title; $this->title = $title; @@ -33,114 +34,172 @@ $this->params['breadcrumbs'][] = $title; ]) ?>

-
-
-
- $post, - 'attributes' => [ - 'id', - [ - 'attribute' => 'status', - 'value' => BlogPostHelper::statusLabel($post->status), - 'format' => 'raw', - ], - 'title', - [ - 'attribute' => 'category_id', - 'value' => ArrayHelper::getValue($post, 'category.name'), - ], - [ - 'label' => Yii::t('post', 'Tags'), - 'format' => 'raw', - 'value' => ' ' . implode(' ', ArrayHelper::getColumn($post->tags, 'name')), - ], - ], - ]) ?> -
-
- - image): ?> -
-
-
- getThumbFileUrl('image', 'thumb_gallery_view'), [ - 'class' => 'thumbnail', - 'width' => 300, - ]) ?> -
-
- - - image && $post->video): ?> -
-
-
- - video), [ - 'width' => 300, - 'class' => 'thumbnail', - ]) ?> -
+ +
+
+ +
+
+
+ $post, + 'attributes' => [ + 'id', + [ + 'attribute' => 'status', + 'value' => BlogPostHelper::statusLabel($post->status), + 'format' => 'raw', + ], + 'title', + [ + 'attribute' => 'category_id', + 'value' => ArrayHelper::getValue($post, 'category.name'), + ], + [ + 'label' => Yii::t('post', 'Tags'), + 'format' => 'raw', + 'value' => ' ' . implode(' ', ArrayHelper::getColumn($post->tags, 'name')), + ], + ], + ]) ?> +
+
+ + image): ?> +
+
+
+ getThumbFileUrl('image', 'thumb_gallery_view'), [ + 'class' => 'thumbnail', + 'width' => 300, + ]) ?> +
+
+ + + image && $post->video): ?> +
+
+
+ + video), [ + 'width' => 300, + 'class' => 'thumbnail', + ]) ?> +
+
+ + + video): ?> +
+
+
+ $post->video, + 'style' => '', + ]) ?> +
+
+ + +
+
+
+ formatter->asNtext($post->description) ?> +
+
+ +
+
+
+ formatter->asHtml($post->content, [ + 'Attr.AllowedRel' => array('nofollow'), + 'HTML.SafeObject' => true, + 'Output.FlashCompat' => true, + 'HTML.SafeIframe' => true, + 'URI.SafeIframeRegexp'=>'%^(https?:)?//(www\.youtube(?:-nocookie)?\.com/embed/|player\.vimeo\.com/video/)%', + ]) ?> +
+
+ +
+
+
+ $post, + 'attributes' => [ + [ + 'attribute' => 'meta.title', + 'value' => $post->meta->title, + ], + [ + 'attribute' => 'meta.description', + 'value' => $post->meta->description, + ], + [ + 'attribute' => 'meta.keywords', + 'value' => $post->meta->keywords, + ], + ], + ]) ?> +
+
+
- - - video): ?> -
-
-
- $post->video, - 'style' => '', - ]) ?> +
+
+
+
+ + +
    + +
  • + revision_id): ?> + revision_at) ?> + → + + get('frontendUrlManager')->createAbsoluteUrl(['/blog/post/preview', 'id' => $item->id])), [ + 'style' => 'font-size:11px;', + 'target' => '_blank', + ]) ?> + + | + + $item->id], [ + 'style' => 'font-size:11px; color: red', + 'data' => [ + 'confirm' => Yii::t('blog', 'Are you sure you want to restore this history item?'), + 'method' => 'post', + ], + ]) ?> + + + + +
  • + +
+ + $post->id], [ + 'class' => 'btn btn-danger btn-sm pull-right', + 'data' => [ + 'confirm' => Yii::t('blog', 'Are you sure you want to remove this history?'), + 'method' => 'post', + ], + ]) ?> + +
+ + +
- - -
-
-
- formatter->asNtext($post->description) ?> -
-
- -
-
-
- formatter->asHtml($post->content, [ - 'Attr.AllowedRel' => array('nofollow'), - 'HTML.SafeObject' => true, - 'Output.FlashCompat' => true, - 'HTML.SafeIframe' => true, - 'URI.SafeIframeRegexp'=>'%^(https?:)?//(www\.youtube(?:-nocookie)?\.com/embed/|player\.vimeo\.com/video/)%', - ]) ?> -
-
- -
-
-
- $post, - 'attributes' => [ - [ - 'attribute' => 'meta.title', - 'value' => $post->meta->title, - ], - [ - 'attribute' => 'meta.description', - 'value' => $post->meta->description, - ], - [ - 'attribute' => 'meta.keywords', - 'value' => $post->meta->keywords, - ], - ], - ]) ?> -
-
+
+ +
diff --git a/static/cache/posts/368_287_13.jpg b/static/cache/posts/368_287_13.jpg deleted file mode 100644 index 79b0077..0000000 Binary files a/static/cache/posts/368_287_13.jpg and /dev/null differ diff --git a/static/cache/posts/370_325_13.jpg b/static/cache/posts/370_325_13.jpg deleted file mode 100644 index c514197..0000000 Binary files a/static/cache/posts/370_325_13.jpg and /dev/null differ diff --git a/static/cache/posts/683_407_13.jpg b/static/cache/posts/683_407_13.jpg deleted file mode 100644 index 23ec295..0000000 Binary files a/static/cache/posts/683_407_13.jpg and /dev/null differ diff --git a/static/cache/posts/94_94_13.jpg b/static/cache/posts/94_94_13.jpg deleted file mode 100644 index da37c33..0000000 Binary files a/static/cache/posts/94_94_13.jpg and /dev/null differ diff --git a/static/cache/posts/admin_13.jpg b/static/cache/posts/admin_13.jpg deleted file mode 100644 index 681eda1..0000000 Binary files a/static/cache/posts/admin_13.jpg and /dev/null differ diff --git a/static/cache/posts/home_slider_13.jpg b/static/cache/posts/home_slider_13.jpg deleted file mode 100644 index 0c12773..0000000 Binary files a/static/cache/posts/home_slider_13.jpg and /dev/null differ diff --git a/static/cache/posts/list_13.jpg b/static/cache/posts/list_13.jpg deleted file mode 100644 index b71e8c0..0000000 Binary files a/static/cache/posts/list_13.jpg and /dev/null differ diff --git a/static/cache/posts/origin_13.jpg b/static/cache/posts/origin_13.jpg deleted file mode 100644 index 0d6e742..0000000 Binary files a/static/cache/posts/origin_13.jpg and /dev/null differ diff --git a/static/cache/posts/thumb_13.jpg b/static/cache/posts/thumb_13.jpg deleted file mode 100644 index dc9e0a1..0000000 Binary files a/static/cache/posts/thumb_13.jpg and /dev/null differ diff --git a/static/cache/posts/thumb_gallery_view_13.jpg b/static/cache/posts/thumb_gallery_view_13.jpg deleted file mode 100644 index 960a451..0000000 Binary files a/static/cache/posts/thumb_gallery_view_13.jpg and /dev/null differ diff --git a/static/origin/posts/13.jpg b/static/origin/posts/13.jpg deleted file mode 100644 index d67313b..0000000 Binary files a/static/origin/posts/13.jpg and /dev/null differ diff --git a/vagrant/nginx/log/static-error.log b/vagrant/nginx/log/static-error.log index c88694c..c4cefcb 100644 --- a/vagrant/nginx/log/static-error.log +++ b/vagrant/nginx/log/static-error.log @@ -19,3 +19,27 @@ 2018/07/06 10:17:57 [error] 1920#1920: *1225 open() "/app/static/cache/posts/blog_post_-1.jpg" failed (2: No such file or directory), client: 192.168.83.1, server: static.morework.local, request: "GET /cache/posts/blog_post_-1.jpg HTTP/1.1", host: "static.morework.local" 2018/07/06 10:18:44 [error] 1920#1920: *1228 open() "/app/static/cache/posts/blog_post_-1.jpg" failed (2: No such file or directory), client: 192.168.83.1, server: static.morework.local, request: "GET /cache/posts/blog_post_-1.jpg HTTP/1.1", host: "static.morework.local", referrer: "http://morework.local/blog/post/preview" 2018/07/06 10:20:25 [error] 1920#1920: *1232 open() "/app/static/cache/posts/blog_post_-1.jpg" failed (2: No such file or directory), client: 192.168.83.1, server: static.morework.local, request: "GET /cache/posts/blog_post_-1.jpg HTTP/1.1", host: "static.morework.local", referrer: "http://morework.local/blog/post/preview" +2018/07/25 14:48:26 [error] 1933#1933: *552 open() "/app/static/cache/posts/blog_post_13.jpg" failed (2: No such file or directory), client: 192.168.83.1, server: static.morework.local, request: "GET /cache/posts/blog_post_13.jpg HTTP/1.1", host: "static.morework.local", referrer: "http://morework.local/blog/post/preview?id=22" +2018/07/25 14:49:11 [error] 1933#1933: *558 open() "/app/static/cache/posts/blog_post_23.jpg" failed (2: No such file or directory), client: 192.168.83.1, server: static.morework.local, request: "GET /cache/posts/blog_post_23.jpg HTTP/1.1", host: "static.morework.local", referrer: "http://morework.local/blog/post/preview?id=23" +2018/07/25 14:49:57 [error] 1933#1933: *558 open() "/app/static/cache/posts/blog_post_24.png" failed (2: No such file or directory), client: 192.168.83.1, server: static.morework.local, request: "GET /cache/posts/blog_post_24.png HTTP/1.1", host: "static.morework.local", referrer: "http://morework.local/blog/post/preview?id=24" +2018/07/25 14:50:22 [error] 1933#1933: *558 open() "/app/static/cache/posts/blog_post_25.png" failed (2: No such file or directory), client: 192.168.83.1, server: static.morework.local, request: "GET /cache/posts/blog_post_25.png HTTP/1.1", host: "static.morework.local", referrer: "http://morework.local/blog/post/preview?id=25" +2018/07/25 14:55:07 [error] 1933#1933: *583 open() "/app/static/cache/posts/blog_post_26.png" failed (2: No such file or directory), client: 192.168.83.1, server: static.morework.local, request: "GET /cache/posts/blog_post_26.png HTTP/1.1", host: "static.morework.local", referrer: "http://morework.local/blog/post/preview?id=26" +2018/07/25 14:55:25 [error] 1933#1933: *583 open() "/app/static/cache/posts/blog_post_26.png" failed (2: No such file or directory), client: 192.168.83.1, server: static.morework.local, request: "GET /cache/posts/blog_post_26.png HTTP/1.1", host: "static.morework.local" +2018/07/25 14:55:32 [error] 1933#1933: *583 open() "/app/static/cache/posts/blog_post_26.png" failed (2: No such file or directory), client: 192.168.83.1, server: static.morework.local, request: "GET /cache/posts/blog_post_26.png HTTP/1.1", host: "static.morework.local" +2018/07/25 15:14:57 [error] 1933#1933: *638 open() "/app/static/cache/posts/blog_post_28.png" failed (2: No such file or directory), client: 192.168.83.1, server: static.morework.local, request: "GET /cache/posts/blog_post_28.png HTTP/1.1", host: "static.morework.local", referrer: "http://morework.local/blog/post/preview?id=28" +2018/07/25 15:19:30 [error] 1933#1933: *663 open() "/app/static/cache/posts/blog_post_30.png" failed (2: No such file or directory), client: 192.168.83.1, server: static.morework.local, request: "GET /cache/posts/blog_post_30.png HTTP/1.1", host: "static.morework.local", referrer: "http://morework.local/blog/post/preview?id=30" +2018/07/25 15:33:18 [error] 1933#1933: *669 open() "/app/static/cache/posts/blog_post_31.png" failed (2: No such file or directory), client: 192.168.83.1, server: static.morework.local, request: "GET /cache/posts/blog_post_31.png HTTP/1.1", host: "static.morework.local", referrer: "http://morework.local/blog/post/preview?id=31" +2018/07/25 15:35:13 [error] 1933#1933: *676 open() "/app/static/cache/posts/blog_post_32.png" failed (2: No such file or directory), client: 192.168.83.1, server: static.morework.local, request: "GET /cache/posts/blog_post_32.png HTTP/1.1", host: "static.morework.local", referrer: "http://morework.local/blog/post/preview?id=32" +2018/07/25 20:06:07 [error] 1933#1933: *946 open() "/app/static/cache/posts/blog_post_53.jpg" failed (2: No such file or directory), client: 192.168.83.1, server: static.morework.local, request: "GET /cache/posts/blog_post_53.jpg HTTP/1.1", host: "static.morework.local", referrer: "http://morework.local/blog/post/preview?id=53" +2018/07/25 23:05:07 [error] 1933#1933: *1256 open() "/app/static/cache/posts/thumb_gallery_view_68.jpg" failed (2: No such file or directory), client: 192.168.83.1, server: static.morework.local, request: "GET /cache/posts/thumb_gallery_view_68.jpg HTTP/1.1", host: "static.morework.local", referrer: "http://admin.morework.local/blog/manage/post/view/68" +2018/07/25 23:36:51 [error] 1933#1933: *1389 open() "/app/static/cache/posts/thumb_gallery_view_27.png" failed (2: No such file or directory), client: 192.168.83.1, server: static.morework.local, request: "GET /cache/posts/thumb_gallery_view_27.png HTTP/1.1", host: "static.morework.local", referrer: "http://admin.morework.local/blog/manage/post/view/27" +2018/07/25 23:47:55 [error] 1933#1933: *1465 open() "/app/static/cache/posts/thumb_gallery_view_83.png" failed (2: No such file or directory), client: 192.168.83.1, server: static.morework.local, request: "GET /cache/posts/thumb_gallery_view_83.png HTTP/1.1", host: "static.morework.local", referrer: "http://admin.morework.local/blog/manage/post/view/83" +2018/07/25 23:48:13 [error] 1933#1933: *1465 open() "/app/static/cache/posts/thumb_gallery_view_83.png" failed (2: No such file or directory), client: 192.168.83.1, server: static.morework.local, request: "GET /cache/posts/thumb_gallery_view_83.png HTTP/1.1", host: "static.morework.local", referrer: "http://admin.morework.local/blog/manage/post/update?id=83" +2018/07/25 23:48:13 [error] 1933#1933: *1465 open() "/app/static/cache/posts/thumb_gallery_view_83.png" failed (2: No such file or directory), client: 192.168.83.1, server: static.morework.local, request: "GET /cache/posts/thumb_gallery_view_83.png HTTP/1.1", host: "static.morework.local", referrer: "http://admin.morework.local/blog/manage/post/update?id=83" +2018/07/25 23:50:33 [error] 1933#1933: *1497 open() "/app/static/cache/posts/thumb_gallery_view_83.png" failed (2: No such file or directory), client: 192.168.83.1, server: static.morework.local, request: "GET /cache/posts/thumb_gallery_view_83.png HTTP/1.1", host: "static.morework.local", referrer: "http://admin.morework.local/blog/manage/post/view/83" +2018/07/25 23:50:39 [error] 1933#1933: *1497 open() "/app/static/cache/posts/thumb_gallery_view_83.png" failed (2: No such file or directory), client: 192.168.83.1, server: static.morework.local, request: "GET /cache/posts/thumb_gallery_view_83.png HTTP/1.1", host: "static.morework.local", referrer: "http://admin.morework.local/blog/manage/post/update?id=83" +2018/07/25 23:50:39 [error] 1933#1933: *1497 open() "/app/static/cache/posts/thumb_gallery_view_83.png" failed (2: No such file or directory), client: 192.168.83.1, server: static.morework.local, request: "GET /cache/posts/thumb_gallery_view_83.png HTTP/1.1", host: "static.morework.local", referrer: "http://admin.morework.local/blog/manage/post/update?id=83" +2018/07/25 23:51:08 [error] 1933#1933: *1497 open() "/app/static/cache/posts/thumb_gallery_view_83.png" failed (2: No such file or directory), client: 192.168.83.1, server: static.morework.local, request: "GET /cache/posts/thumb_gallery_view_83.png HTTP/1.1", host: "static.morework.local", referrer: "http://admin.morework.local/blog/manage/post/view/83" +2018/07/25 23:51:14 [error] 1933#1933: *1497 open() "/app/static/cache/posts/thumb_gallery_view_83.png" failed (2: No such file or directory), client: 192.168.83.1, server: static.morework.local, request: "GET /cache/posts/thumb_gallery_view_83.png HTTP/1.1", host: "static.morework.local", referrer: "http://admin.morework.local/blog/manage/post/update?id=83" +2018/07/25 23:51:14 [error] 1933#1933: *1497 open() "/app/static/cache/posts/thumb_gallery_view_83.png" failed (2: No such file or directory), client: 192.168.83.1, server: static.morework.local, request: "GET /cache/posts/thumb_gallery_view_83.png HTTP/1.1", host: "static.morework.local", referrer: "http://admin.morework.local/blog/manage/post/update?id=83" +2018/07/26 15:10:09 [error] 1933#1933: *1523 open() "/app/static/cache/posts/thumb_gallery_view_83.png" failed (2: No such file or directory), client: 192.168.83.1, server: static.morework.local, request: "GET /cache/posts/thumb_gallery_view_83.png HTTP/1.1", host: "static.morework.local", referrer: "http://admin.morework.local/blog/manage/post/view/83"