Skip to content

Commit

Permalink
feat: set length of userAgent and Referer in definition
Browse files Browse the repository at this point in the history
(cherry picked from commit 03e32dc)
  • Loading branch information
tinect committed Apr 27, 2024
1 parent a52cc30 commit 726a857
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/Content/Redirect/RedirectRequestDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

class RedirectRequestDefinition extends EntityDefinition
{
public const ENTITY_NAME = 'tinect_redirects_redirect_request';
public const ENTITY_NAME = 'tinect_redirects_redirect_request';
public const MAX_LENGTH_USER_AGENT = 1024;
public const MAX_LENGTH_REFERER = 1024;

public function getEntityName(): string
{
Expand All @@ -39,8 +41,8 @@ protected function defineFields(): FieldCollection
(new IdField('id', 'id'))->addFlags(new PrimaryKey(), new Required()),
new FkField('tinect_redirects_redirect_id', 'redirectId', RedirectDefinition::class),
new RemoteAddressField('ip_address', 'ipAddress'),
new StringField('user_agent', 'userAgent'),
new StringField('referer', 'referer'),
new StringField('user_agent', 'userAgent', self::MAX_LENGTH_USER_AGENT),
new StringField('referer', 'referer', self::MAX_LENGTH_REFERER),

new ManyToOneAssociationField('redirect', 'tinect_redirects_redirect_id', RedirectDefinition::class, 'id'),
]);
Expand Down
9 changes: 7 additions & 2 deletions src/Message/TinectRedirectUpdateMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Tinect\Redirects\Message;

use Shopware\Core\Framework\MessageQueue\LowPriorityMessageInterface;
use Tinect\Redirects\Content\Redirect\RedirectRequestDefinition;

class TinectRedirectUpdateMessage implements LowPriorityMessageInterface
{
Expand Down Expand Up @@ -44,12 +45,16 @@ public function getIpAddress(): string

public function getUserAgent(): string
{
return $this->userAgent;
return substr($this->userAgent, 0, RedirectRequestDefinition::MAX_LENGTH_USER_AGENT);
}

public function getReferer(): ?string
{
return $this->referer;
if ($this->referer === null) {
return null;
}

return substr($this->referer, 0, RedirectRequestDefinition::MAX_LENGTH_REFERER);
}

public function isCreateRedirect(): bool
Expand Down

0 comments on commit 726a857

Please sign in to comment.