Commit c306c20e authored by Tino Goratsch's avatar Tino Goratsch

- renamed the Model class to AbstractRepository and moved it into the ACP3\Core\Model namespace

- added  the new FloodBarrierAwareRepositoryInterface and used it for the Comments module
- reworked the FloodBarrierValidationRule
parent f0c1b820
<?php <?php
namespace ACP3\Core\Model;
namespace ACP3\Core; use ACP3\Core\DB;
/** /**
* Class Model * Class AbstractRepository
* @package ACP3\Core * @package ACP3\Core\Model
*/ */
class Model abstract class AbstractRepository
{ {
/** /**
* The name of the default sql table * The name of the sql table
*/ */
const TABLE_NAME = ''; const TABLE_NAME = '';
/** /**
......
<?php
namespace ACP3\Core\Model;
/**
* Class FloodBarrierAwareRepositoryInterface
* @package ACP3\Core\Model
*/
interface FloodBarrierAwareRepositoryInterface
{
/**
* @param $ipAddress
*
* @return mixed
*/
public function getLastDateFromIp($ipAddress);
}
\ No newline at end of file
...@@ -7,7 +7,7 @@ use ACP3\Core\DB; ...@@ -7,7 +7,7 @@ use ACP3\Core\DB;
* Class NestedSetRepository * Class NestedSetRepository
* @package ACP3\Core\NestedSet * @package ACP3\Core\NestedSet
*/ */
class NestedSetRepository extends \ACP3\Core\Model class NestedSetRepository extends \ACP3\Core\Model\AbstractRepository
{ {
/** /**
* Die aktuelle Seite mit allen untergeordneten Seiten selektieren * Die aktuelle Seite mit allen untergeordneten Seiten selektieren
......
<?php <?php
namespace ACP3\Core\Validator\ValidationRules; namespace ACP3\Core\Validator\ValidationRules;
use ACP3\Core\Date; use ACP3\Core\Date;
use ACP3\Core\Model\FloodBarrierAwareRepositoryInterface;
/** /**
* Class FloodBarrierValidationRule * Class FloodBarrierValidationRule
* @package ACP3\Core\Validator\ValidationRules * @package ACP3\Core\Validator\ValidationRules
*/ */
class FloodBarrierValidationRule extends AbstractValidationRule abstract class AbstractFloodBarrierValidationRule extends AbstractValidationRule
{ {
const NAME = 'flood_barrier';
/** /**
* @var \ACP3\Core\Date * @var \ACP3\Core\Date
*/ */
protected $date; protected $date;
/**
* @var \ACP3\Core\Model\FloodBarrierAwareRepositoryInterface
*/
protected $repository;
/** /**
* FloodBarrierValidationRule constructor. * FloodBarrierValidationRule constructor.
* *
* @param \ACP3\Core\Date $date * @param \ACP3\Core\Date $date
* @param \ACP3\Core\Model\FloodBarrierAwareRepositoryInterface $repository
*/ */
public function __construct(Date $date) public function __construct(
Date $date,
FloodBarrierAwareRepositoryInterface $repository)
{ {
$this->date = $date; $this->date = $date;
$this->repository = $repository;
} }
/** /**
...@@ -30,7 +37,8 @@ class FloodBarrierValidationRule extends AbstractValidationRule ...@@ -30,7 +37,8 @@ class FloodBarrierValidationRule extends AbstractValidationRule
*/ */
public function isValid($data, $field = '', array $extra = []) public function isValid($data, $field = '', array $extra = [])
{ {
$floodTime = !empty($extra['last_date']) ? $this->date->timestamp($extra['last_date'], true) + 30 : 0; $date = $this->repository->getLastDateFromIp($extra['ip']);
$floodTime = !empty($date) ? $this->date->timestamp($date, true) + 30 : 0;
$time = $this->date->timestamp('now', true); $time = $this->date->timestamp('now', true);
return $floodTime <= $time; return $floodTime <= $time;
......
...@@ -7,12 +7,6 @@ services: ...@@ -7,12 +7,6 @@ services:
tags: tags:
- { name: core.validator.validation_rule } - { name: core.validator.validation_rule }
core.validator.validation_rules.flood_barrier_validation_rule:
class: ACP3\Core\Validator\ValidationRules\FloodBarrierValidationRule
arguments: [@core.date]
tags:
- { name: core.validator.validation_rule }
core.validator.validation_rules.form_token_validation_rule: core.validator.validation_rules.form_token_validation_rule:
class: ACP3\Core\Validator\ValidationRules\FormTokenValidationRule class: ACP3\Core\Validator\ValidationRules\FormTokenValidationRule
arguments: [@core.request, @core.session] arguments: [@core.request, @core.session]
......
...@@ -7,7 +7,7 @@ use ACP3\Core; ...@@ -7,7 +7,7 @@ use ACP3\Core;
* Class ArticleRepository * Class ArticleRepository
* @package ACP3\Modules\ACP3\Articles\Model * @package ACP3\Modules\ACP3\Articles\Model
*/ */
class ArticleRepository extends Core\Model class ArticleRepository extends Core\Model\AbstractRepository
{ {
const TABLE_NAME = 'articles'; const TABLE_NAME = 'articles';
......
...@@ -8,7 +8,7 @@ use ACP3\Core; ...@@ -8,7 +8,7 @@ use ACP3\Core;
* Class CategoryRepository * Class CategoryRepository
* @package ACP3\Modules\ACP3\Categories\Model * @package ACP3\Modules\ACP3\Categories\Model
*/ */
class CategoryRepository extends Core\Model class CategoryRepository extends Core\Model\AbstractRepository
{ {
const TABLE_NAME = 'categories'; const TABLE_NAME = 'categories';
......
...@@ -8,7 +8,7 @@ use ACP3\Core; ...@@ -8,7 +8,7 @@ use ACP3\Core;
* Class CommentRepository * Class CommentRepository
* @package ACP3\Modules\ACP3\Comments\Model * @package ACP3\Modules\ACP3\Comments\Model
*/ */
class CommentRepository extends Core\Model class CommentRepository extends Core\Model\AbstractRepository implements Core\Model\FloodBarrierAwareRepositoryInterface
{ {
const TABLE_NAME = 'comments'; const TABLE_NAME = 'comments';
......
...@@ -5,6 +5,7 @@ parameters: ...@@ -5,6 +5,7 @@ parameters:
comments.helpers.fqdn: 'ACP3\Modules\ACP3\Comments\Helpers' comments.helpers.fqdn: 'ACP3\Modules\ACP3\Comments\Helpers'
comments.model.commentrepository.fqdn: 'ACP3\Modules\ACP3\Comments\Model\CommentRepository' comments.model.commentrepository.fqdn: 'ACP3\Modules\ACP3\Comments\Model\CommentRepository'
comments.validator.fqdn: 'ACP3\Modules\ACP3\Comments\Validator' comments.validator.fqdn: 'ACP3\Modules\ACP3\Comments\Validator'
comments.validator.validation_rules.flood_barrier_validation_rule.fqdn: 'ACP3\Modules\ACP3\Comments\Validator\ValidationRules\FloodBarrierValidationRule'
comments.validator.validation_rules.user_name_validation_rule.fqdn: 'ACP3\Modules\ACP3\Comments\Validator\ValidationRules\UserNameValidationRule' comments.validator.validation_rules.user_name_validation_rule.fqdn: 'ACP3\Modules\ACP3\Comments\Validator\ValidationRules\UserNameValidationRule'
comments.installer.schema.fqdn: 'ACP3\Modules\ACP3\Comments\Installer\Schema' comments.installer.schema.fqdn: 'ACP3\Modules\ACP3\Comments\Installer\Schema'
comments.installer.migration.fqdn: 'ACP3\Modules\ACP3\Comments\Installer\Migration' comments.installer.migration.fqdn: 'ACP3\Modules\ACP3\Comments\Installer\Migration'
...@@ -37,7 +38,13 @@ services: ...@@ -37,7 +38,13 @@ services:
comments.validator: comments.validator:
class: %comments.validator.fqdn% class: %comments.validator.fqdn%
arguments: ['@core.lang', @core.validator, '@core.validator.rules.misc', '@core.modules', '@comments.model.commentrepository'] arguments: ['@core.lang', @core.validator, '@core.validator.rules.misc', '@core.modules']
comments.validator.validation_rules.flood_barrier_validation_rule:
class: %comments.validator.validation_rules.flood_barrier_validation_rule.fqdn%
arguments: [@core.date, @comments.model.commentrepository]
tags:
- { name: core.validator.validation_rule }
comments.validator.validation_rules.user_name_validation_rule: comments.validator.validation_rules.user_name_validation_rule:
class: %comments.validator.validation_rules.user_name_validation_rule.fqdn% class: %comments.validator.validation_rules.user_name_validation_rule.fqdn%
......
...@@ -4,6 +4,7 @@ namespace ACP3\Modules\ACP3\Comments; ...@@ -4,6 +4,7 @@ namespace ACP3\Modules\ACP3\Comments;
use ACP3\Core; use ACP3\Core;
use ACP3\Modules\ACP3\Captcha\Validator\ValidationRules\CaptchaValidationRule; use ACP3\Modules\ACP3\Captcha\Validator\ValidationRules\CaptchaValidationRule;
use ACP3\Modules\ACP3\Comments\Model\CommentRepository; use ACP3\Modules\ACP3\Comments\Model\CommentRepository;
use ACP3\Modules\ACP3\Comments\Validator\ValidationRules\FloodBarrierValidationRule;
/** /**
* Class Validator * Class Validator
...@@ -15,10 +16,6 @@ class Validator extends Core\Validator\AbstractValidator ...@@ -15,10 +16,6 @@ class Validator extends Core\Validator\AbstractValidator
* @var \ACP3\Core\Modules * @var \ACP3\Core\Modules
*/ */
protected $modules; protected $modules;
/**
* @var \ACP3\Modules\ACP3\Comments\Model\CommentRepository
*/
protected $commentRepository;
/** /**
* @var \ACP3\Core\Validator\Validator * @var \ACP3\Core\Validator\Validator
*/ */
...@@ -27,25 +24,22 @@ class Validator extends Core\Validator\AbstractValidator ...@@ -27,25 +24,22 @@ class Validator extends Core\Validator\AbstractValidator
/** /**
* Validator constructor. * Validator constructor.
* *
* @param \ACP3\Core\Lang $lang * @param \ACP3\Core\Lang $lang
* @param \ACP3\Core\Validator\Validator $validator * @param \ACP3\Core\Validator\Validator $validator
* @param \ACP3\Core\Validator\Rules\Misc $validate * @param \ACP3\Core\Validator\Rules\Misc $validate
* @param \ACP3\Core\Modules $modules * @param \ACP3\Core\Modules $modules
* @param \ACP3\Modules\ACP3\Comments\Model\CommentRepository $commentRepository
*/ */
public function __construct( public function __construct(
Core\Lang $lang, Core\Lang $lang,
Core\Validator\Validator $validator, Core\Validator\Validator $validator,
Core\Validator\Rules\Misc $validate, Core\Validator\Rules\Misc $validate,
Core\Modules $modules, Core\Modules $modules
CommentRepository $commentRepository
) )
{ {
parent::__construct($lang, $validate); parent::__construct($lang, $validate);
$this->validator = $validator; $this->validator = $validator;
$this->modules = $modules; $this->modules = $modules;
$this->commentRepository = $commentRepository;
} }
/** /**
...@@ -60,11 +54,11 @@ class Validator extends Core\Validator\AbstractValidator ...@@ -60,11 +54,11 @@ class Validator extends Core\Validator\AbstractValidator
$this->validator $this->validator
->addConstraint(Core\Validator\ValidationRules\FormTokenValidationRule::NAME) ->addConstraint(Core\Validator\ValidationRules\FormTokenValidationRule::NAME)
->addConstraint( ->addConstraint(
Core\Validator\ValidationRules\FloodBarrierValidationRule::NAME, FloodBarrierValidationRule::NAME,
[ [
'message' => $this->lang->t('system', 'flood_no_entry_possible'), 'message' => $this->lang->t('system', 'flood_no_entry_possible'),
'extra' => [ 'extra' => [
'last_date' => $this->commentRepository->getLastDateFromIp($ip) 'ip' => $ip
] ]
]) ])
->addConstraint( ->addConstraint(
......
<?php
namespace ACP3\Modules\ACP3\Comments\Validator\ValidationRules;
use ACP3\Core\Validator\ValidationRules\AbstractFloodBarrierValidationRule;
/**
* Class FloodBarrierValidationRule
* @package ACP3\Modules\ACP3\Comments\Validator\ValidationRules
*/
class FloodBarrierValidationRule extends AbstractFloodBarrierValidationRule
{
const NAME = 'comments_flood_barrier';
}
\ No newline at end of file
...@@ -8,7 +8,7 @@ use ACP3\Core; ...@@ -8,7 +8,7 @@ use ACP3\Core;
* Class EmoticonRepository * Class EmoticonRepository
* @package ACP3\Modules\ACP3\Emoticons\Model * @package ACP3\Modules\ACP3\Emoticons\Model
*/ */
class EmoticonRepository extends Core\Model class EmoticonRepository extends Core\Model\AbstractRepository
{ {
const TABLE_NAME = 'emoticons'; const TABLE_NAME = 'emoticons';
......
...@@ -8,7 +8,7 @@ use ACP3\Core; ...@@ -8,7 +8,7 @@ use ACP3\Core;
* Class FilesRepository * Class FilesRepository
* @package ACP3\Modules\ACP3\Files\Model * @package ACP3\Modules\ACP3\Files\Model
*/ */
class FilesRepository extends Core\Model class FilesRepository extends Core\Model\AbstractRepository
{ {
const TABLE_NAME = 'files'; const TABLE_NAME = 'files';
......
...@@ -8,7 +8,7 @@ use ACP3\Core; ...@@ -8,7 +8,7 @@ use ACP3\Core;
* Class Model * Class Model
* @package ACP3\Modules\ACP3\Gallery * @package ACP3\Modules\ACP3\Gallery
*/ */
class GalleryRepository extends Core\Model class GalleryRepository extends Core\Model\AbstractRepository
{ {
const TABLE_NAME = 'gallery'; const TABLE_NAME = 'gallery';
......
...@@ -7,7 +7,7 @@ use ACP3\Core; ...@@ -7,7 +7,7 @@ use ACP3\Core;
* Class PictureRepository * Class PictureRepository
* @package ACP3\Modules\ACP3\Gallery\Model * @package ACP3\Modules\ACP3\Gallery\Model
*/ */
class PictureRepository extends Core\Model class PictureRepository extends Core\Model\AbstractRepository
{ {
const TABLE_NAME = 'gallery_pictures'; const TABLE_NAME = 'gallery_pictures';
......
...@@ -8,7 +8,7 @@ use ACP3\Core; ...@@ -8,7 +8,7 @@ use ACP3\Core;
* Class GuestbookRepository * Class GuestbookRepository
* @package ACP3\Modules\ACP3\Guestbook\Model * @package ACP3\Modules\ACP3\Guestbook\Model
*/ */
class GuestbookRepository extends Core\Model class GuestbookRepository extends Core\Model\AbstractRepository
{ {
const TABLE_NAME = 'guestbook'; const TABLE_NAME = 'guestbook';
......
<?php <?php
namespace ACP3\Modules\ACP3\Menus\Model; namespace ACP3\Modules\ACP3\Menus\Model;
use ACP3\Core\Model; use ACP3\Core\Model\AbstractRepository;
/** /**
* Class MenuItemRepository * Class MenuItemRepository
* @package ACP3\Modules\ACP3\Menus\Model * @package ACP3\Modules\ACP3\Menus\Model
*/ */
class MenuItemRepository extends Model class MenuItemRepository extends AbstractRepository
{ {
const TABLE_NAME = 'menu_items'; const TABLE_NAME = 'menu_items';
......
...@@ -7,7 +7,7 @@ use ACP3\Core; ...@@ -7,7 +7,7 @@ use ACP3\Core;
* Class Model * Class Model
* @package ACP3\Modules\ACP3\Menus * @package ACP3\Modules\ACP3\Menus
*/ */
class MenuRepository extends Core\Model class MenuRepository extends Core\Model\AbstractRepository
{ {
const TABLE_NAME = 'menus'; const TABLE_NAME = 'menus';
......
...@@ -8,7 +8,7 @@ use ACP3\Core; ...@@ -8,7 +8,7 @@ use ACP3\Core;
* Class NewsRepository * Class NewsRepository
* @package ACP3\Modules\ACP3\News\Model * @package ACP3\Modules\ACP3\News\Model
*/ */
class NewsRepository extends Core\Model class NewsRepository extends Core\Model\AbstractRepository
{ {
const TABLE_NAME = 'news'; const TABLE_NAME = 'news';
......
...@@ -7,7 +7,7 @@ use ACP3\Core; ...@@ -7,7 +7,7 @@ use ACP3\Core;
* Class AccountHistoryRepository * Class AccountHistoryRepository
* @package ACP3\Modules\ACP3\Newsletter\Model * @package ACP3\Modules\ACP3\Newsletter\Model
*/ */
class AccountHistoryRepository extends Core\Model class AccountHistoryRepository extends Core\Model\AbstractRepository
{ {
const TABLE_NAME = 'newsletter_account_history'; const TABLE_NAME = 'newsletter_account_history';
......
<?php <?php
namespace ACP3\Modules\ACP3\Newsletter\Model; namespace ACP3\Modules\ACP3\Newsletter\Model;
use ACP3\Core\Model; use ACP3\Core\Model\AbstractRepository;
use ACP3\Modules\ACP3\Newsletter\Helper\AccountStatus; use ACP3\Modules\ACP3\Newsletter\Helper\AccountStatus;
/** /**
* Class AccountRepository * Class AccountRepository
* @package ACP3\Modules\ACP3\Newsletter\Model * @package ACP3\Modules\ACP3\Newsletter\Model
*/ */
class AccountRepository extends Model class AccountRepository extends AbstractRepository
{ {
const TABLE_NAME = 'newsletter_accounts'; const TABLE_NAME = 'newsletter_accounts';
......
...@@ -8,7 +8,7 @@ use ACP3\Core; ...@@ -8,7 +8,7 @@ use ACP3\Core;
* Class NewsletterRepository * Class NewsletterRepository
* @package ACP3\Modules\ACP3\Newsletter * @package ACP3\Modules\ACP3\Newsletter
*/ */
class NewsletterRepository extends Core\Model class NewsletterRepository extends Core\Model\AbstractRepository
{ {
const TABLE_NAME = 'newsletters'; const TABLE_NAME = 'newsletters';
......
...@@ -7,7 +7,7 @@ use ACP3\Core; ...@@ -7,7 +7,7 @@ use ACP3\Core;
* Class PrivilegeRepository * Class PrivilegeRepository
* @package ACP3\Modules\ACP3\Permissions\Model * @package ACP3\Modules\ACP3\Permissions\Model
*/ */
class PrivilegeRepository extends Core\Model class PrivilegeRepository extends Core\Model\AbstractRepository
{ {
const TABLE_NAME = 'acl_privileges'; const TABLE_NAME = 'acl_privileges';
......
...@@ -7,7 +7,7 @@ use ACP3\Core; ...@@ -7,7 +7,7 @@ use ACP3\Core;
* Class ResourceRepository * Class ResourceRepository
* @package ACP3\Modules\ACP3\Permissions\Model * @package ACP3\Modules\ACP3\Permissions\Model
*/ */
class ResourceRepository extends Core\Model class ResourceRepository extends Core\Model\AbstractRepository
{ {
const TABLE_NAME = 'acl_resources'; const TABLE_NAME = 'acl_resources';
......
...@@ -7,7 +7,7 @@ use ACP3\Core; ...@@ -7,7 +7,7 @@ use ACP3\Core;
* Class Model * Class Model
* @package ACP3\Modules\ACP3\Permissions * @package ACP3\Modules\ACP3\Permissions
*/ */
class RoleRepository extends Core\Model class RoleRepository extends Core\Model\AbstractRepository
{ {
const TABLE_NAME = 'acl_roles'; const TABLE_NAME = 'acl_roles';
......
...@@ -7,7 +7,7 @@ use ACP3\Core; ...@@ -7,7 +7,7 @@ use ACP3\Core;
* Class RuleRepository * Class RuleRepository
* @package ACP3\Modules\ACP3\Permissions\Model * @package ACP3\Modules\ACP3\Permissions\Model
*/ */
class RuleRepository extends Core\Model class RuleRepository extends Core\Model\AbstractRepository
{ {
const TABLE_NAME = 'acl_rules'; const TABLE_NAME = 'acl_rules';
......
...@@ -7,7 +7,7 @@ use ACP3\Core; ...@@ -7,7 +7,7 @@ use ACP3\Core;
* Class UserRolesRepository * Class UserRolesRepository
* @package ACP3\Modules\ACP3\Permissions\Model * @package ACP3\Modules\ACP3\Permissions\Model
*/ */
class UserRoleRepository extends Core\Model class UserRoleRepository extends Core\Model\AbstractRepository
{ {
const TABLE_NAME = 'acl_user_roles'; const TABLE_NAME = 'acl_user_roles';
......
...@@ -7,7 +7,7 @@ use ACP3\Core; ...@@ -7,7 +7,7 @@ use ACP3\Core;
* Class AnswerRepository * Class AnswerRepository
* @package ACP3\Modules\ACP3\Polls\Model * @package ACP3\Modules\ACP3\Polls\Model
*/ */
class AnswerRepository extends Core\Model class AnswerRepository extends Core\Model\AbstractRepository
{ {
const TABLE_NAME = 'poll_answers'; const TABLE_NAME = 'poll_answers';
......
...@@ -8,7 +8,7 @@ use ACP3\Core; ...@@ -8,7 +8,7 @@ use ACP3\Core;
* Class Model * Class Model
* @package ACP3\Modules\ACP3\Polls * @package ACP3\Modules\ACP3\Polls
*/ */
class PollRepository extends Core\Model class PollRepository extends Core\Model\AbstractRepository
{ {
const TABLE_NAME = 'polls'; const TABLE_NAME = 'polls';
......
...@@ -7,7 +7,7 @@ use ACP3\Core; ...@@ -7,7 +7,7 @@ use ACP3\Core;
* Class VoteRepository * Class VoteRepository
* @package ACP3\Modules\ACP3\Polls\Model * @package ACP3\Modules\ACP3\Polls\Model
*/ */
class VoteRepository extends Core\Model class VoteRepository extends Core\Model\AbstractRepository
{ {
const TABLE_NAME = 'poll_votes'; const TABLE_NAME = 'poll_votes';
......
...@@ -7,7 +7,7 @@ use ACP3\Core; ...@@ -7,7 +7,7 @@ use ACP3\Core;
* Class SeoRepository * Class SeoRepository
* @package ACP3\Modules\ACP3\Seo\Model * @package ACP3\Modules\ACP3\Seo\Model
*/ */
class SeoRepository extends Core\Model class SeoRepository extends Core\Model\AbstractRepository
{ {
const TABLE_NAME = 'seo'; const TABLE_NAME = 'seo';
......
...@@ -7,7 +7,7 @@ use ACP3\Core; ...@@ -7,7 +7,7 @@ use ACP3\Core;
* Class ModuleRepository * Class ModuleRepository
* @package ACP3\Modules\ACP3\System\Model * @package ACP3\Modules\ACP3\System\Model
*/ */
class ModuleRepository extends Core\Model class ModuleRepository extends Core\Model\AbstractRepository
{ {
const TABLE_NAME = 'modules'; const TABLE_NAME = 'modules';
......
...@@ -7,7 +7,7 @@ use ACP3\Core; ...@@ -7,7 +7,7 @@ use ACP3\Core;
* Class SettingsRepository * Class SettingsRepository
* @package ACP3\Modules\ACP3\System\Model * @package ACP3\Modules\ACP3\System\Model
*/ */
class SettingsRepository extends Core\Model class SettingsRepository extends Core\Model\AbstractRepository
{ {
const TABLE_NAME = 'settings'; const TABLE_NAME = 'settings';
......
...@@ -8,7 +8,7 @@ use ACP3\Core; ...@@ -8,7 +8,7 @@ use ACP3\Core;
* Class Model * Class Model
* @package ACP3\Modules\ACP3\Users * @package ACP3\Modules\ACP3\Users
*/ */
class UserRepository extends Core\Model class UserRepository extends Core\Model\AbstractRepository
{ {
const TABLE_NAME = 'users'; const TABLE_NAME = 'users';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment