cron运行
12 34 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
——/ src /仓库/ CommentRepository.php+ + + b / src /仓库/ CommentRepository.php@@ -6,6 +6,7 @@使用App\Entity\Comment;使用App \实体\会议;使用原则\ \ DoctrineBundle \ Repository \ ServiceEntityRepository捆绑销售;使用原则\ \ ManagerRegistry持久性;+使用原则\ ORM \ QueryBuilder;使用原则\ ORM工具\ \分页\ Paginator;/** @@ -16,6 +17,8 @@使用Doctrine\ORM\Tools\Pagination\Paginator;*/ class CommentRepository扩展ServiceEntityRepository {+ private const days_before_rejected_remove = 7;+PAGINATOR_PER_PAGE = 2;公共函数__construct(ManagerRegistry $registry) @@ -23,6 +26,29 @@ class CommentRepository extends ServiceEntityRepository parent::__construct($registry, Comment::class);}+公共函数countoldreject (): int+ {+返回$this->getOldRejectedQueryBuilder()->select('COUNT(c.id)')->getQuery()->getSingleScalarResult();+}++公共函数deleteoldreject (): int+ {+返回$this->getOldRejectedQueryBuilder()->delete()->getQuery()->execute();+}++私有函数getOldRejectedQueryBuilder(): QueryBuilder+ {+返回$this->createQueryBuilder('c')+ - >引入(c。State =:state_rejected or c.state =:state_spam')+ - >引入(c。createdAt <:date')+ - > setParameters ([+ 'state_rejected' => 'rejected',+ 'state_spam' => 'spam',+ 'date' => new \DateTimeImmutable(-self::DAYS_BEFORE_REJECTED_REMOVAL。“天”),+))+;+}+getCommentPaginator(Conference $ Conference, int $offset): Paginator {$query = $this->createQueryBuilder('c')
12 34 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
——/ src /仓库/ CommentRepository.php+ + + b / src /仓库/ CommentRepository.php@@ -6,6 +6,7 @@使用App\Entity\Comment;使用App \实体\会议;使用原则\ \ DoctrineBundle \ Repository \ ServiceEntityRepository捆绑销售;使用原则\ \ ManagerRegistry持久性;+使用原则\ ORM \ QueryBuilder;使用原则\ ORM工具\ \分页\ Paginator;/** @@ -16,6 +17,8 @@使用Doctrine\ORM\Tools\Pagination\Paginator;*/ class CommentRepository扩展ServiceEntityRepository {+ private const days_before_rejected_remove = 7;+PAGINATOR_PER_PAGE = 2;公共函数__construct(ManagerRegistry $registry) @@ -23,6 +26,29 @@ class CommentRepository extends ServiceEntityRepository parent::__construct($registry, Comment::class);}+公共函数countoldreject (): int+ {+返回$this->getOldRejectedQueryBuilder()->select('COUNT(c.id)')->getQuery()->getSingleScalarResult();+}++公共函数deleteoldreject (): int+ {+返回$this->getOldRejectedQueryBuilder()->delete()->getQuery()->execute();+}++私有函数getOldRejectedQueryBuilder(): QueryBuilder+ {+返回$this->createQueryBuilder('c')+ - >引入(c。State =:state_rejected or c.state =:state_spam')+ - >引入(c。createdAt <:date')+ - > setParameters ([+ 'state_rejected' => 'rejected',+ 'state_spam' => 'spam',+ 'date' => new \DateTimeImmutable(-self::DAYS_BEFORE_REJECTED_REMOVAL。“天”),+))+;+}+getCommentPaginator(Conference $ Conference, int $offset): Paginator {$query = $this->createQueryBuilder('c')
提示
对于更复杂的查询,有时查看生成的SQL语句是有用的(它们可以在日志和Web请求的分析器中找到)。
此工作,包括代码示例,是根据知识共享协议BY-NC-SA 4.0许可证。