mirror of
https://github.com/openvk/openvk
synced 2025-03-14 13:35:33 +03:00
Совместимость с логами
This commit is contained in:
parent
8a9b111288
commit
308af2a5b1
13 changed files with 7 additions and 285 deletions
|
@ -246,15 +246,5 @@ class Post extends Postable
|
|||
$this->save();
|
||||
}
|
||||
|
||||
function getChangeId(): int
|
||||
{
|
||||
return $this->getRecord()->change_id;
|
||||
}
|
||||
|
||||
function getChangeType(): string
|
||||
{
|
||||
return $this->getRecord()->change_type == 2 ? "new" : "old";
|
||||
}
|
||||
|
||||
use Traits\TRichText;
|
||||
}
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
<?php declare(strict_types=1);
|
||||
namespace openvk\Web\Models\Entities;
|
||||
use openvk\Web\Models\RowModel;
|
||||
use openvk\Web\Util\DateTime;
|
||||
use openvk\Web\Models\Entities\{User, Club, Post};
|
||||
use openvk\Web\Models\Repositories\{Users, Clubs, Posts};
|
||||
use Nette\Database\Table\ActiveRow;
|
||||
use Chandler\Database\DatabaseConnection;
|
||||
|
||||
class PostChangeRecord extends RowModel
|
||||
{
|
||||
protected $tableName = "posts_changes";
|
||||
|
||||
function getId(): int
|
||||
{
|
||||
return $this->getRecord()->id;
|
||||
}
|
||||
|
||||
function getWid(): int
|
||||
{
|
||||
return $this->getRecord()->wall_id;
|
||||
}
|
||||
|
||||
function getAuthorType(): string
|
||||
{
|
||||
return $this->getWid() < 0 ? "club" : "user";
|
||||
}
|
||||
|
||||
function getVid(): int
|
||||
{
|
||||
return $this->getRecord()->virtual_id;
|
||||
}
|
||||
|
||||
function getPost(): ?Post
|
||||
{
|
||||
return (new Posts)->getPostById($this->getWid(), $this->getVid());
|
||||
}
|
||||
|
||||
function getAuthor()
|
||||
{
|
||||
if ($this->getAuthorType() === "club")
|
||||
return (new Clubs)->get($this->getWid());
|
||||
|
||||
return (new Users)->get($this->getWid());
|
||||
}
|
||||
|
||||
function getNewContent(): ?string
|
||||
{
|
||||
return $this->getRecord()->newContent;
|
||||
}
|
||||
|
||||
function getCreationDate(): DateTime
|
||||
{
|
||||
return new DateTime($this->getRecord()->created);
|
||||
}
|
||||
|
||||
function canBeApplied(): bool
|
||||
{
|
||||
return $this->getPost()->getChangeId() != $this->getId();
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
<?php declare(strict_types=1);
|
||||
namespace openvk\Web\Models\Repositories;
|
||||
use openvk\Web\Models\Entities\{Post, User, PostChangeRecord};
|
||||
use Nette\Database\Table\ActiveRow;
|
||||
use Chandler\Database\DatabaseConnection;
|
||||
|
||||
class PostsChanges
|
||||
{
|
||||
private $context;
|
||||
private $changes;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->context = DatabaseConnection::i()->getContext();
|
||||
$this->changes = $this->context->table("posts_changes");
|
||||
}
|
||||
|
||||
function toChangeRecord(?ActiveRow $ar): ?PostChangeRecord
|
||||
{
|
||||
return is_null($ar) ? NULL : new PostChangeRecord($ar);
|
||||
}
|
||||
|
||||
function get(int $id): ?PostChangeRecord
|
||||
{
|
||||
return $this->toChangeRecord($this->changes->get($id));
|
||||
}
|
||||
|
||||
function getListByWid(int $wid): \Traversable
|
||||
{
|
||||
foreach ($this->changes->where("wall_id", $wid)->fetch() as $record)
|
||||
yield new PostChangeRecord($record);
|
||||
}
|
||||
|
||||
function getAllHistoryById(int $wid, int $vid): \Traversable
|
||||
{
|
||||
foreach($this->changes->where(["wall_id" => $wid, "virtual_id" => $vid]) as $record)
|
||||
yield new PostChangeRecord($record);
|
||||
}
|
||||
|
||||
function getHistoryById(int $wid, int $vid, int $page = 1): \Traversable
|
||||
{
|
||||
foreach($this->changes->where(["wall_id" => $wid, "virtual_id" => $vid])->page($page, 5) as $record)
|
||||
yield new PostChangeRecord($record);
|
||||
}
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
<?php declare(strict_types=1);
|
||||
namespace openvk\Web\Presenters;
|
||||
use openvk\Web\Models\Exceptions\TooMuchOptionsException;
|
||||
use openvk\Web\Models\Entities\{Poll, Post, Photo, Video, Club, User, PostChangeRecord};
|
||||
use openvk\Web\Models\Entities\{Poll, Post, Photo, Video, Club, User};
|
||||
use openvk\Web\Models\Entities\Notifications\{MentionNotification, RepostNotification, WallPostNotification};
|
||||
use openvk\Web\Models\Repositories\{Posts, Users, Clubs, Albums, Notes, PostsChanges};
|
||||
use openvk\Web\Models\Repositories\{Posts, Users, Clubs, Albums, Notes};
|
||||
use Chandler\Database\DatabaseConnection;
|
||||
use Nette\InvalidStateException as ISE;
|
||||
use Bhaktaraz\RSSGenerator\Item;
|
||||
|
@ -13,12 +13,10 @@ use Bhaktaraz\RSSGenerator\Channel;
|
|||
final class WallPresenter extends OpenVKPresenter
|
||||
{
|
||||
private $posts;
|
||||
private $changes;
|
||||
|
||||
function __construct(Posts $posts, PostsChanges $changes)
|
||||
function __construct(Posts $posts)
|
||||
{
|
||||
$this->posts = $posts;
|
||||
$this->changes = $changes;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
@ -305,22 +303,10 @@ final class WallPresenter extends OpenVKPresenter
|
|||
if ($editTarget) {
|
||||
$post = $this->posts->getPostById($this->user->id, $editTarget);
|
||||
|
||||
$changes_record = new PostChangeRecord;
|
||||
|
||||
if (OPENVK_ROOT_CONF["openvk"]["preferences"]["wall"]["logChanges"]) {
|
||||
$changes_record->setWall_id($wall);
|
||||
$changes_record->setVirtual_id($editTarget);
|
||||
$changes_record->setNewContent($this->postParam("text"));
|
||||
$changes_record->setCreated(time());
|
||||
$changes_record->save();
|
||||
}
|
||||
|
||||
$post->setEdited(time());
|
||||
$post->setContent($this->postParam("text"));
|
||||
$post->setFlags($flags);
|
||||
$post->setNsfw($this->postParam("nsfw") === "on");
|
||||
$post->setChange_id($changes_record->getId());
|
||||
$post->setChange_type(2);
|
||||
$post->save();
|
||||
} else {
|
||||
$post = new Post;
|
||||
|
@ -523,50 +509,4 @@ final class WallPresenter extends OpenVKPresenter
|
|||
# TODO localize message based on language and ?act=(un)pin
|
||||
$this->flashFail("succ", tr("information_-1"), tr("changes_saved_comment"));
|
||||
}
|
||||
|
||||
function renderPostHistory(int $wall, int $post_id): void
|
||||
{
|
||||
$this->assertUserLoggedIn();
|
||||
|
||||
if(!$this->user->identity->getChandlerUser()->can("access")->model("admin")->whichBelongsTo(NULL))
|
||||
$this->flashFail("err", tr("error"), tr("forbidden"));
|
||||
|
||||
$post = $this->posts->getPostById($wall, $post_id);
|
||||
|
||||
if (!$post) $this->notFound();
|
||||
|
||||
$this->template->post = $post;
|
||||
|
||||
if ($post->getTargetWall() > 0) {
|
||||
$this->template->wallOwner = (new Users)->get($post->getTargetWall());
|
||||
$this->template->isWallOfGroup = false;
|
||||
if($this->template->wallOwner->isBanned())
|
||||
$this->flashFail("err", tr("error"), tr("forbidden"));
|
||||
} else {
|
||||
$this->template->wallOwner = (new Clubs)->get(abs($post->getTargetWall()));
|
||||
$this->template->isWallOfGroup = true;
|
||||
}
|
||||
|
||||
$this->template->cPage = (int) ($_GET["p"] ?? 1);
|
||||
$this->template->cCount = sizeof(iterator_to_array($this->changes->getAllHistoryById($wall, $post_id)));
|
||||
$this->template->changes = iterator_to_array($this->changes->getHistoryById($wall, $post_id, $this->template->cPage));
|
||||
$this->template->cAmount = sizeof($this->template->changes);
|
||||
}
|
||||
|
||||
function renderPostHistoryRestore(int $wall, int $post_id, int $change_id): void
|
||||
{
|
||||
$this->assertUserLoggedIn();
|
||||
|
||||
if(!$this->user->identity->getChandlerUser()->can("access")->model("admin")->whichBelongsTo(NULL))
|
||||
$this->flashFail("err", tr("error"), tr("forbidden"));
|
||||
|
||||
$post = $this->posts->getPostById($wall, $post_id);
|
||||
$change = $this->changes->get($change_id);
|
||||
|
||||
$post->setContent($change->getNewContent());
|
||||
$post->setChange_Id($change->getId());
|
||||
$post->save();
|
||||
|
||||
$this->flashFail("succ", "Успех", "Версия #$change_id применена.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,10 +35,10 @@
|
|||
|
||||
<a n:if="$canDelete ?? false" class="profile_link" style="display:block;width:96%;" href="/wall{$post->getPrettyId()}/delete">{_delete}</a>
|
||||
<a
|
||||
n:if="$thisUser->getChandlerUser()->can('access')->model('admin')->whichBelongsTo(NULL) AND $post->getEditTime() AND OPENVK_ROOT_CONF['openvk']['preferences']['wall']['logChanges']"
|
||||
n:if="$thisUser->getChandlerUser()->can('access')->model('admin')->whichBelongsTo(NULL) AND $post->getEditTime()"
|
||||
style="display:block;width:96%;"
|
||||
class="profile_link"
|
||||
href="/wall{$post->getPrettyId()}/history"
|
||||
href="/admin/logs?type=1&obj_type=Post&obj_id={$post->getId()}"
|
||||
>
|
||||
История изменений
|
||||
</a>
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
{extends "../@layout.xml"}
|
||||
{block title}{_post}{/block}
|
||||
|
||||
{block header}
|
||||
<a href="{$wallOwner->getURL()}">
|
||||
{$wallOwner->getCanonicalName()}
|
||||
</a>
|
||||
»
|
||||
<a href="/wall{$wallOwner->getId() * ($isWallOfGroup ? -1 : 1)}">
|
||||
{_wall}
|
||||
</a>
|
||||
»
|
||||
{_post}
|
||||
{/block}
|
||||
|
||||
{block content}
|
||||
{include "../components/post.xml", post => $post, forceNoCommentsLink => TRUE, forceNoDeleteLink => TRUE}
|
||||
<hr/>
|
||||
<div style="float: left; min-height: 100px; width: 68%;">
|
||||
{include "../components/postChanges.xml",
|
||||
changes => $changes,
|
||||
count => $cCount,
|
||||
page => $cPage,
|
||||
model => "posts",
|
||||
parent => $post }
|
||||
</div>
|
||||
<div style="float: left; min-height: 100px; width: 32%;">
|
||||
<h4>{_actions}</h4>
|
||||
{if isset($thisUser)}
|
||||
{var $canDelete = $post->canBeDeletedBy($thisUser)}
|
||||
{/if}
|
||||
|
||||
<a n:if="$canDelete ?? false" class="profile_link" style="display:block;width:96%;" href="/wall{$post->getPrettyId()}/delete">{_delete}</a>
|
||||
</div>
|
||||
{/block}
|
|
@ -66,7 +66,7 @@
|
|||
<span id="text{$post->getPrettyId()}">{$post->getText()|noescape}</span>
|
||||
|
||||
<div class="edit" id="text_edit{$post->getPrettyId()}" style="display: none;">
|
||||
{include "../textArea.xml", route => "/wall$owner/makePost/{$post->getVirtualId()}"}
|
||||
{include "../textArea.xml", route => "/wall$owner/makePost/{$post->getVirtualId()}", value => $post->getText()}
|
||||
</div>
|
||||
|
||||
<div n:ifcontent class="attachments_b">
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
{var $author = $change->getAuthor()}
|
||||
|
||||
<table border="0" style="font-size: 11px;">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td width="54" valign="top">
|
||||
<a href="{$author->getURL()}">
|
||||
<img src="{$author->getAvatarURL('miniscule')}" width="50" />
|
||||
<span n:if="!$post->isPostedOnBehalfOfGroup() && !($compact ?? false) && $author->isOnline()" class="post-online">{_online}</span>
|
||||
</a>
|
||||
</td>
|
||||
<td width="100%" valign="top">
|
||||
<div class="post-author">
|
||||
<a href="{$author->getURL()}"><b>
|
||||
{$author->getCanonicalName()}
|
||||
</b></a>
|
||||
<img n:if="$author->isVerified()" class="name-checkmark" src="/assets/packages/static/openvk/img/checkmark.png"><br/>
|
||||
</div>
|
||||
<div class="post-content" id="{$change->getId()}">
|
||||
<div class="text" id="text{$change->getId()}">
|
||||
{$change->getNewContent()|noescape}
|
||||
</div>
|
||||
<span class="nobold">
|
||||
{$change->getCreationDate()}
|
||||
</span>
|
||||
<a n:if="$change->canBeApplied()" href="/wall{$post->getPrettyId()}/history/restore{$change->getId()}">
|
||||
| Применить
|
||||
</a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
|
@ -1,12 +0,0 @@
|
|||
<h4 n:if="$showTitle ?? true">История ({$cAmount})</h4>
|
||||
|
||||
{if $cCount > 0}
|
||||
{foreach $changes as $change}
|
||||
{include "postChange.xml", change => $change, post => $post}
|
||||
{/foreach}
|
||||
<div style="margin-top: 11px;">
|
||||
{include "paginator.xml", conf => (object) ["page" => $cPage, "count" => $cCount, "amount" => $cAmount, "perPage" => 5]}
|
||||
</div>
|
||||
{else}
|
||||
Ничего не найдено.
|
||||
{/if}
|
|
@ -47,7 +47,6 @@ services:
|
|||
- openvk\Web\Models\Repositories\Topics
|
||||
- openvk\Web\Models\Repositories\Applications
|
||||
- openvk\Web\Models\Repositories\ContentSearchRepository
|
||||
- openvk\Web\Models\Repositories\PostsChanges
|
||||
- openvk\Web\Models\Repositories\Aliases
|
||||
- openvk\Web\Models\Repositories\BannedLinks
|
||||
- openvk\Web\Models\Repositories\ChandlerGroups
|
||||
|
|
|
@ -141,10 +141,6 @@ routes:
|
|||
handler: "Wall->delete"
|
||||
- url: "/wall{num}_{num}/pin"
|
||||
handler: "Wall->pin"
|
||||
- url: "/wall{num}_{num}/history"
|
||||
handler: "Wall->postHistory"
|
||||
- url: "/wall{num}_{num}/history/restore{num}"
|
||||
handler: "Wall->postHistoryRestore"
|
||||
- url: "/blob_{text}/{?path}.{text}"
|
||||
handler: "Blob->file"
|
||||
placeholders:
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
ALTER TABLE `posts` ADD `change_id` BIGINT UNSIGNED NULL DEFAULT NULL AFTER `deleted`;
|
||||
|
||||
CREATE TABLE `posts_changes` (
|
||||
`id` bigint NOT NULL,
|
||||
`wall_id` bigint NOT NULL,
|
||||
`virtual_id` bigint NOT NULL,
|
||||
`newContent` longtext NOT NULL,
|
||||
`created` bigint NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
||||
|
||||
ALTER TABLE `posts_changes`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
|
||||
ALTER TABLE `posts_changes`
|
||||
MODIFY `id` bigint NOT NULL AUTO_INCREMENT;
|
||||
COMMIT;
|
|
@ -59,7 +59,6 @@ openvk:
|
|||
maxSize: 60000
|
||||
processingLimit: 3000
|
||||
emojiProcessingLimit: 1000
|
||||
logChanges: true
|
||||
commerce: false
|
||||
susLinks:
|
||||
warnings: true
|
||||
|
|
Loading…
Reference in a new issue