mirror of
https://github.com/friendica/friendica
synced 2025-04-24 13:50:10 +00:00
Add fields to Report entity
- Add clock dependency to Moderation\Factory\Report - Change DateTime field to DateTimeImmutable to satisfy Clock return type - Add category, status and resolution constants
This commit is contained in:
parent
d29a84ae46
commit
76de49a25c
13 changed files with 543 additions and 222 deletions
|
@ -25,24 +25,30 @@ use Friendica\BaseEntity;
|
|||
use Friendica\Core\Logger;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Moderation\Factory;
|
||||
use Friendica\Moderation\Collection;
|
||||
use Friendica\Network\HTTPException\NotFoundException;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Report extends \Friendica\BaseRepository
|
||||
final class Report extends \Friendica\BaseRepository
|
||||
{
|
||||
protected static $table_name = 'report';
|
||||
|
||||
/**
|
||||
* @var \Friendica\Moderation\Factory\Report
|
||||
*/
|
||||
/** @var Factory\Report */
|
||||
protected $factory;
|
||||
/** @var Factory\Report\Post */
|
||||
protected $postFactory;
|
||||
/** @var Factory\Report\Rule */
|
||||
protected $ruleFactory;
|
||||
|
||||
public function __construct(Database $database, LoggerInterface $logger, \Friendica\Moderation\Factory\Report $factory)
|
||||
public function __construct(Database $database, LoggerInterface $logger, Factory\Report $factory, Factory\Report\Post $postFactory, Factory\Report\Rule $ruleFactory)
|
||||
{
|
||||
parent::__construct($database, $logger, $factory);
|
||||
|
||||
$this->factory = $factory;
|
||||
$this->factory = $factory;
|
||||
$this->postFactory = $postFactory;
|
||||
$this->ruleFactory = $postFactory;
|
||||
}
|
||||
|
||||
public function selectOneById(int $lastInsertId): \Friendica\Moderation\Entity\Report
|
||||
|
@ -53,34 +59,43 @@ class Report extends \Friendica\BaseRepository
|
|||
public function save(\Friendica\Moderation\Entity\Report $Report)
|
||||
{
|
||||
$fields = [
|
||||
'uid' => $Report->uid,
|
||||
'reporter-id' => $Report->reporterId,
|
||||
'cid' => $Report->cid,
|
||||
'comment' => $Report->comment,
|
||||
'category' => $Report->category,
|
||||
'rules' => $Report->rules,
|
||||
'forward' => $Report->forward,
|
||||
'reporter-id' => $Report->reporterCid,
|
||||
'uid' => $Report->reporterUid,
|
||||
'cid' => $Report->cid,
|
||||
'gsid' => $Report->gsid,
|
||||
'comment' => $Report->comment,
|
||||
'forward' => $Report->forward,
|
||||
'category-id' => $Report->category,
|
||||
'public-remarks' => $Report->publicRemarks,
|
||||
'private-remarks' => $Report->privateRemarks,
|
||||
'last-editor-uid' => $Report->lastEditorUid,
|
||||
'assigned-uid' => $Report->assignedUid,
|
||||
'status' => $Report->status,
|
||||
'resolution' => $Report->resolution,
|
||||
'created' => $Report->created->format(DateTimeFormat::MYSQL),
|
||||
'edited' => $Report->edited ? $Report->edited->format(DateTimeFormat::MYSQL) : null,
|
||||
];
|
||||
|
||||
$postUriIds = $Report->postUriIds;
|
||||
|
||||
if ($Report->id) {
|
||||
$this->db->update(self::$table_name, $fields, ['id' => $Report->id]);
|
||||
} else {
|
||||
$fields['created'] = DateTimeFormat::utcNow();
|
||||
$this->db->insert(self::$table_name, $fields, Database::INSERT_IGNORE);
|
||||
|
||||
$Report = $this->selectOneById($this->db->lastInsertId());
|
||||
}
|
||||
$newReportId = $this->db->lastInsertId();
|
||||
|
||||
$this->db->delete('report-post', ['rid' => $Report->id]);
|
||||
|
||||
foreach ($postUriIds as $uriId) {
|
||||
if (Post::exists(['uri-id' => $uriId])) {
|
||||
$this->db->insert('report-post', ['rid' => $Report->id, 'uri-id' => $uriId]);
|
||||
} else {
|
||||
Logger::notice('Post does not exist', ['uri-id' => $uriId, 'report' => $Report]);
|
||||
foreach ($Report->posts as $post) {
|
||||
if (Post::exists(['uri-id' => $post->uriId])) {
|
||||
$this->db->insert('report-post', ['rid' => $newReportId, 'uri-id' => $post->uriId, 'status' => $post->status]);
|
||||
} else {
|
||||
Logger::notice('Post does not exist', ['uri-id' => $post->uriId, 'report' => $Report]);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($Report->rules as $rule) {
|
||||
$this->db->insert('report-rule', ['rid' => $newReportId, 'line-id' => $rule->lineId, 'text' => $rule->text]);
|
||||
}
|
||||
|
||||
$Report = $this->selectOneById($this->db->lastInsertId());
|
||||
}
|
||||
|
||||
return $Report;
|
||||
|
@ -88,13 +103,14 @@ class Report extends \Friendica\BaseRepository
|
|||
|
||||
protected function _selectOne(array $condition, array $params = []): BaseEntity
|
||||
{
|
||||
$fields = $this->db->selectFirst(static::$table_name, [], $condition, $params);
|
||||
$fields = $this->db->selectFirst(self::$table_name, [], $condition, $params);
|
||||
if (!$this->db->isResult($fields)) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
$postUriIds = array_column($this->db->selectToArray('report-post', ['uri-id'], ['rid' => $condition['id'] ?? 0]), 'uri-id');
|
||||
$reportPosts = new Collection\Report\Posts(array_map([$this->postFactory, 'createFromTableRow'], $this->db->selectToArray('report-post', ['uri-id', 'status'], ['rid' => $condition['id'] ?? 0])));
|
||||
$reportRules = new Collection\Report\Rules(array_map([$this->ruleFactory, 'createFromTableRow'], $this->db->selectToArray('report-rule', ['line-id', 'line-text'], ['rid' => $condition['id'] ?? 0])));
|
||||
|
||||
return $this->factory->createFromTableRow($fields, $postUriIds);
|
||||
return $this->factory->createFromTableRow($fields, $reportPosts, $reportRules);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue