1
0
Fork 0
mirror of https://github.com/wallabag/wallabag.git synced 2025-04-23 10:24:12 +00:00

Migrate to JMS attributes

This commit is contained in:
Yassine Guedidi 2025-04-05 15:12:30 +02:00
parent a1440dffda
commit a766826a69
8 changed files with 96 additions and 183 deletions

View file

@ -15,7 +15,7 @@ return RectorConfig::configure()
])
->withRootFiles()
->withImportNames(importShortClasses: false)
->withAttributesSets(symfony: true, doctrine: true, gedmo: true)
->withAttributesSets(symfony: true, doctrine: true, gedmo: true, jms: true)
->withConfiguredRule(ClassPropertyAssignToConstructorPromotionRector::class, [
'inline_public' => true,
])

View file

@ -14,12 +14,11 @@ use Wallabag\Repository\AnnotationRepository;
/**
* Annotation.
*
* @ExclusionPolicy("none")
*/
#[ORM\Table(name: 'annotation')]
#[ORM\Entity(repositoryClass: AnnotationRepository::class)]
#[ORM\HasLifecycleCallbacks]
#[ExclusionPolicy('none')]
class Annotation
{
use EntityTimestampsTrait;
@ -34,10 +33,9 @@ class Annotation
/**
* @var string
*
* @Groups({"entries_for_user", "export_all"})
*/
#[ORM\Column(name: 'text', type: 'text')]
#[Groups(['entries_for_user', 'export_all'])]
private $text;
/**
@ -54,32 +52,26 @@ class Annotation
/**
* @var string
*
* @Groups({"entries_for_user", "export_all"})
*/
#[ORM\Column(name: 'quote', type: 'text')]
#[Assert\Length(max: 10000, maxMessage: 'validator.quote_length_too_high')]
#[Groups(['entries_for_user', 'export_all'])]
private $quote;
/**
* @var array
*
* @Groups({"entries_for_user", "export_all"})
*/
#[ORM\Column(name: 'ranges', type: 'array')]
#[Groups(['entries_for_user', 'export_all'])]
private $ranges;
/**
* @Exclude
*/
#[ORM\ManyToOne(targetEntity: User::class)]
#[Exclude]
private $user;
/**
* @Exclude
*/
#[ORM\JoinColumn(name: 'entry_id', referencedColumnName: 'id', onDelete: 'cascade')]
#[ORM\ManyToOne(targetEntity: Entry::class, inversedBy: 'annotations')]
#[Exclude]
private $entry;
/*
@ -216,10 +208,8 @@ class Annotation
return $this->user;
}
/**
* @VirtualProperty
* @SerializedName("user")
*/
#[VirtualProperty]
#[SerializedName('user')]
public function getUserName()
{
return $this->user->getName();
@ -250,10 +240,8 @@ class Annotation
return $this->entry;
}
/**
* @VirtualProperty
* @SerializedName("annotator_schema_version")
*/
#[VirtualProperty]
#[SerializedName('annotator_schema_version')]
public function getVersion()
{
return 'v1.0';

View file

@ -28,9 +28,9 @@ class Client extends BaseClient
* type="string",
* example="Default Client",
* )
* @Groups({"user_api_with_client"})
*/
#[ORM\Column(name: 'name', type: 'text', nullable: false)]
#[Groups(['user_api_with_client'])]
protected $name;
#[ORM\OneToMany(targetEntity: RefreshToken::class, mappedBy: 'client', cascade: ['remove'])]
@ -47,10 +47,9 @@ class Client extends BaseClient
* type="string",
* example="2lmubx2m9vy80ss8c4wwcsg8ok44s88ocwcc8wo0w884oc8440",
* )
*
* @SerializedName("client_secret")
* @Groups({"user_api_with_client"})
*/
#[SerializedName('client_secret')]
#[Groups(['user_api_with_client'])]
protected $secret;
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'clients')]
@ -95,17 +94,15 @@ class Client extends BaseClient
}
/**
* @VirtualProperty
*
* @OA\Property(
* description="Client secret used for authorization",
* type="string",
* example="3_1lpybsn0od40css4w4ko8gsc8cwwskggs8kgg448ko0owo4c84",
* )
*
* @SerializedName("client_id")
* @Groups({"user_api_with_client"})
*/
#[VirtualProperty]
#[SerializedName('client_id')]
#[Groups(['user_api_with_client'])]
public function getClientId()
{
return $this->getId() . '_' . $this->getRandomId();

View file

@ -21,56 +21,50 @@ class Config
/**
* @var int
*
* @Groups({"config_api"})
*/
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
#[Groups(['config_api'])]
private $id;
/**
* @var int
*
* @Groups({"config_api"})
*/
#[ORM\Column(name: 'items_per_page', type: 'integer', nullable: false)]
#[Assert\NotBlank]
#[Assert\Range(min: 1, max: 100000, maxMessage: 'validator.item_per_page_too_high')]
#[Groups(['config_api'])]
private $itemsPerPage;
/**
* @var string
*
* @Groups({"config_api"})
*/
#[ORM\Column(name: 'language', type: 'string', nullable: false)]
#[Assert\NotBlank]
#[Groups(['config_api'])]
private $language;
/**
* @var string|null
*
* @Groups({"config_api"})
*/
#[ORM\Column(name: 'feed_token', type: 'string', nullable: true)]
#[Groups(['config_api'])]
private $feedToken;
/**
* @var int|null
*
* @Groups({"config_api"})
*/
#[ORM\Column(name: 'feed_limit', type: 'integer', nullable: true)]
#[Assert\Range(min: 1, max: 100000, maxMessage: 'validator.feed_limit_too_high')]
#[Groups(['config_api'])]
private $feedLimit;
/**
* @var float|null
*
* @Groups({"config_api"})
*/
#[ORM\Column(name: 'reading_speed', type: 'float', nullable: true)]
#[Groups(['config_api'])]
private $readingSpeed;
/**
@ -81,58 +75,51 @@ class Config
/**
* @var int|null
*
* @Groups({"config_api"})
*/
#[ORM\Column(name: 'action_mark_as_read', type: 'integer', nullable: true, options: ['default' => 0])]
#[Groups(['config_api'])]
private $actionMarkAsRead;
/**
* @var int|null
*
* @Groups({"config_api"})
*/
#[ORM\Column(name: 'list_mode', type: 'integer', nullable: true)]
#[Groups(['config_api'])]
private $listMode;
/**
* @var int|null
*
* @Groups({"config_api"})
*/
#[ORM\Column(name: 'display_thumbnails', type: 'integer', nullable: true, options: ['default' => 1])]
#[Groups(['config_api'])]
private $displayThumbnails;
/**
* @var string|null
*
* @Groups({"config_api"})
*/
#[ORM\Column(name: 'font', type: 'text', nullable: true)]
#[Groups(['config_api'])]
private $font;
/**
* @var float|null
*
* @Groups({"config_api"})
*/
#[ORM\Column(name: 'fontsize', type: 'float', nullable: true)]
#[Groups(['config_api'])]
private $fontsize;
/**
* @var float|null
*
* @Groups({"config_api"})
*/
#[ORM\Column(name: 'line_height', type: 'float', nullable: true)]
#[Groups(['config_api'])]
private $lineHeight;
/**
* @var float|null
*
* @Groups({"config_api"})
*/
#[ORM\Column(name: 'max_width', type: 'float', nullable: true)]
#[Groups(['config_api'])]
private $maxWidth;
/**

View file

@ -18,7 +18,6 @@ use Wallabag\Repository\EntryRepository;
/**
* Entry.
*
* @XmlRoot("entry")
* @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())")
*/
#[ORM\Table(name: '`entry`')]
@ -32,6 +31,7 @@ use Wallabag\Repository\EntryRepository;
#[ORM\Index(columns: ['user_id', 'is_starred', 'starred_at'])]
#[ORM\Entity(repositoryClass: EntryRepository::class)]
#[ORM\HasLifecycleCallbacks]
#[XmlRoot('entry')]
class Entry
{
use EntityTimestampsTrait;
@ -39,40 +39,36 @@ class Entry
/** @Serializer\XmlAttribute */
/**
* @var int
*
* @Groups({"entries_for_user", "export_all"})
*/
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
#[Groups(['entries_for_user', 'export_all'])]
private $id;
/**
* @var string|null
*
* @Groups({"entries_for_user", "export_all"})
*/
#[ORM\Column(name: 'uid', type: 'string', length: 23, nullable: true)]
#[Groups(['entries_for_user', 'export_all'])]
private $uid;
/**
* @var string|null
*
* @Groups({"entries_for_user", "export_all"})
*/
#[ORM\Column(name: 'title', type: 'text', nullable: true)]
#[Groups(['entries_for_user', 'export_all'])]
private $title;
/**
* Define the url fetched by wallabag (the final url after potential redirections).
*
* @var string|null
*
* @Groups({"entries_for_user", "export_all"})
*/
#[ORM\Column(name: 'url', type: 'text', nullable: true)]
#[Assert\NotBlank]
#[Assert\Url(message: "The url '{{ value }}' is not a valid url")]
#[Groups(['entries_for_user', 'export_all'])]
private $url;
/**
@ -85,20 +81,18 @@ class Entry
* From where user retrieved/found the url (an other article, a twitter, or the given_url if non are provided).
*
* @var string|null
*
* @Groups({"entries_for_user", "export_all"})
*/
#[ORM\Column(name: 'origin_url', type: 'text', nullable: true)]
#[Groups(['entries_for_user', 'export_all'])]
private $originUrl;
/**
* Define the url entered by the user (without redirections).
*
* @var string|null
*
* @Groups({"entries_for_user", "export_all"})
*/
#[ORM\Column(name: 'given_url', type: 'text', nullable: true)]
#[Groups(['entries_for_user', 'export_all'])]
private $givenUrl;
/**
@ -109,159 +103,134 @@ class Entry
/**
* @var bool
*
* @Exclude
*
* @Groups({"entries_for_user", "export_all"})
*/
#[ORM\Column(name: 'is_archived', type: 'boolean')]
#[Exclude]
#[Groups(['entries_for_user', 'export_all'])]
private $isArchived = false;
/**
* @var \DateTimeInterface|null
*
* @Groups({"entries_for_user", "export_all"})
*/
#[ORM\Column(name: 'archived_at', type: 'datetime', nullable: true)]
#[Groups(['entries_for_user', 'export_all'])]
private $archivedAt;
/**
* @var bool
*
* @Exclude
*
* @Groups({"entries_for_user", "export_all"})
*/
#[ORM\Column(name: 'is_starred', type: 'boolean')]
#[Exclude]
#[Groups(['entries_for_user', 'export_all'])]
private $isStarred = false;
/**
* @var string|null
*
* @Groups({"entries_for_user", "export_all"})
*/
#[ORM\Column(name: 'content', type: 'text', nullable: true)]
#[Groups(['entries_for_user', 'export_all'])]
private $content;
/**
* @var \DateTimeInterface
*
* @Groups({"entries_for_user", "export_all"})
*/
#[ORM\Column(name: 'created_at', type: 'datetime')]
#[Groups(['entries_for_user', 'export_all'])]
private $createdAt;
/**
* @var \DateTimeInterface
*
* @Groups({"entries_for_user", "export_all"})
*/
#[ORM\Column(name: 'updated_at', type: 'datetime')]
#[Groups(['entries_for_user', 'export_all'])]
private $updatedAt;
/**
* @var \DateTimeInterface|null
*
* @Groups({"entries_for_user", "export_all"})
*/
#[ORM\Column(name: 'published_at', type: 'datetime', nullable: true)]
#[Groups(['entries_for_user', 'export_all'])]
private $publishedAt;
/**
* @var array|null
*
* @Groups({"entries_for_user", "export_all"})
*/
#[ORM\Column(name: 'published_by', type: 'array', nullable: true)]
#[Groups(['entries_for_user', 'export_all'])]
private $publishedBy;
/**
* @var \DateTimeInterface|null
*
* @Groups({"entries_for_user", "export_all"})
*/
#[ORM\Column(name: 'starred_at', type: 'datetime', nullable: true)]
#[Groups(['entries_for_user', 'export_all'])]
private $starredAt;
/**
* @Groups({"entries_for_user", "export_all"})
*/
#[ORM\JoinTable]
#[ORM\OneToMany(targetEntity: Annotation::class, mappedBy: 'entry', cascade: ['persist', 'remove'])]
#[Groups(['entries_for_user', 'export_all'])]
private $annotations;
/**
* @var string|null
*
* @Groups({"entries_for_user", "export_all"})
*/
#[ORM\Column(name: 'mimetype', type: 'text', nullable: true)]
#[Groups(['entries_for_user', 'export_all'])]
private $mimetype;
/**
* @var string|null
*
* @Groups({"entries_for_user", "export_all"})
*/
#[ORM\Column(name: 'language', type: 'string', length: 20, nullable: true)]
#[Groups(['entries_for_user', 'export_all'])]
private $language;
/**
* @var int
*
* @Groups({"entries_for_user", "export_all"})
*/
#[ORM\Column(name: 'reading_time', type: 'integer', nullable: false)]
#[Groups(['entries_for_user', 'export_all'])]
private $readingTime = 0;
/**
* @var string|null
*
* @Groups({"entries_for_user", "export_all"})
*/
#[ORM\Column(name: 'domain_name', type: 'text', nullable: true)]
#[Groups(['entries_for_user', 'export_all'])]
private $domainName;
/**
* @var string|null
*
* @Groups({"entries_for_user", "export_all"})
*/
#[ORM\Column(name: 'preview_picture', type: 'text', nullable: true)]
#[Groups(['entries_for_user', 'export_all'])]
private $previewPicture;
/**
* @var string|null
*
* @Groups({"entries_for_user", "export_all"})
*/
#[ORM\Column(name: 'http_status', type: 'string', length: 3, nullable: true)]
#[Groups(['entries_for_user', 'export_all'])]
private $httpStatus;
/**
* @var array|null
*
* @Groups({"entries_for_user", "export_all"})
*/
#[ORM\Column(name: 'headers', type: 'array', nullable: true)]
#[Groups(['entries_for_user', 'export_all'])]
private $headers;
/**
* @var bool
*
* @Exclude
*
* @Groups({"entries_for_user", "export_all"})
*/
#[ORM\Column(name: 'is_not_parsed', type: 'boolean', options: ['default' => false])]
#[Exclude]
#[Groups(['entries_for_user', 'export_all'])]
private $isNotParsed = false;
/**
* @Exclude
*
* @Groups({"export_all"})
*/
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'entries')]
#[Exclude]
#[Groups(['export_all'])]
private $user;
#[ORM\JoinTable(name: 'entry_tag')]
@ -400,11 +369,9 @@ class Entry
return $this->isArchived;
}
/**
* @VirtualProperty
* @SerializedName("is_archived")
* @Groups({"entries_for_user", "export_all"})
*/
#[VirtualProperty]
#[SerializedName('is_archived')]
#[Groups(['entries_for_user', 'export_all'])]
public function is_Archived()
{
return (int) $this->isArchived();
@ -441,11 +408,9 @@ class Entry
return $this->isStarred;
}
/**
* @VirtualProperty
* @SerializedName("is_starred")
* @Groups({"entries_for_user", "export_all"})
*/
#[VirtualProperty]
#[SerializedName('is_starred')]
#[Groups(['entries_for_user', 'export_all'])]
public function is_Starred()
{
return (int) $this->isStarred();
@ -490,28 +455,22 @@ class Entry
return $this->user;
}
/**
* @VirtualProperty
* @SerializedName("user_name")
*/
#[VirtualProperty]
#[SerializedName('user_name')]
public function getUserName()
{
return $this->user->getUserName();
}
/**
* @VirtualProperty
* @SerializedName("user_email")
*/
#[VirtualProperty]
#[SerializedName('user_email')]
public function getUserEmail()
{
return $this->user->getEmail();
}
/**
* @VirtualProperty
* @SerializedName("user_id")
*/
#[VirtualProperty]
#[SerializedName('user_id')]
public function getUserId()
{
return $this->user->getId();
@ -666,11 +625,9 @@ class Entry
return $tags;
}
/**
* @VirtualProperty
* @SerializedName("tags")
* @Groups({"entries_for_user", "export_all"})
*/
#[VirtualProperty]
#[SerializedName('tags')]
#[Groups(['entries_for_user', 'export_all'])]
public function getSerializedTags()
{
$data = [];
@ -820,12 +777,11 @@ class Entry
* Used in the entries filter so it's more explicit for the end user than the uid.
* Also used in the API.
*
* @VirtualProperty
* @SerializedName("is_public")
* @Groups({"entries_for_user"})
*
* @return bool
*/
#[VirtualProperty]
#[SerializedName('is_public')]
#[Groups(['entries_for_user'])]
public function isPublic()
{
return null !== $this->uid;

View file

@ -12,38 +12,33 @@ use Wallabag\Repository\TagRepository;
/**
* Tag.
*
* @XmlRoot("tag")
* @ExclusionPolicy("all")
*/
#[ORM\Table(name: '`tag`')]
#[ORM\Index(columns: ['label'])]
#[ORM\Entity(repositoryClass: TagRepository::class)]
#[XmlRoot('tag')]
#[ExclusionPolicy('all')]
class Tag implements \Stringable
{
/**
* @var int
*
* @Expose
*/
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
#[Expose]
private $id;
/**
* @var string
*
* @Expose
*/
#[ORM\Column(name: 'label', type: 'text')]
#[Expose]
private $label;
/**
* @Expose
*/
#[ORM\Column(length: 128, unique: true)]
#[Gedmo\Slug(fields: ['label'], prefix: 't:')]
#[Expose]
private $slug;
#[ORM\ManyToMany(targetEntity: Entry::class, mappedBy: 'tags', cascade: ['persist'])]

View file

@ -12,11 +12,10 @@ use Wallabag\Repository\TaggingRuleRepository;
/**
* Tagging rule.
*
* @XmlRoot("tagging_rule")
*/
#[ORM\Table(name: '`tagging_rule`')]
#[ORM\Entity(repositoryClass: TaggingRuleRepository::class)]
#[XmlRoot('tagging_rule')]
class TaggingRule implements RuleInterface
{
/**
@ -34,27 +33,23 @@ class TaggingRule implements RuleInterface
* allowed_variables={"title", "url", "isArchived", "isStarred", "content", "language", "mimetype", "readingTime", "domainName"},
* allowed_operators={">", "<", ">=", "<=", "=", "is", "!=", "and", "not", "or", "matches", "notmatches"}
* )
*
* @Groups({"export_tagging_rule"})
*/
#[ORM\Column(name: 'rule', type: 'string', nullable: false)]
#[Assert\NotBlank]
#[Assert\Length(max: 255)]
#[Groups(['export_tagging_rule'])]
private $rule;
/**
* @var array<string>
*
* @Groups({"export_tagging_rule"})
*/
#[ORM\Column(name: 'tags', type: 'simple_array', nullable: false)]
#[Assert\NotBlank]
#[Groups(['export_tagging_rule'])]
private $tags = [];
/**
* @Exclude
*/
#[ORM\ManyToOne(targetEntity: Config::class, inversedBy: 'taggingRules')]
#[Exclude]
private $config;
/**

View file

@ -20,14 +20,13 @@ use Wallabag\Repository\UserRepository;
/**
* User.
*
* @XmlRoot("user")
*/
#[ORM\Table(name: '`user`')]
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\HasLifecycleCallbacks]
#[UniqueEntity('email')]
#[UniqueEntity('username')]
#[XmlRoot('user')]
class User extends BaseUser implements EmailTwoFactorInterface, GoogleTwoFactorInterface, BackupCodeInterface
{
use EntityTimestampsTrait;
@ -41,12 +40,11 @@ class User extends BaseUser implements EmailTwoFactorInterface, GoogleTwoFactorI
* type="int",
* example=12,
* )
*
* @Groups({"user_api", "user_api_with_client"})
*/
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
#[Groups(['user_api', 'user_api_with_client'])]
protected $id;
/**
@ -57,9 +55,9 @@ class User extends BaseUser implements EmailTwoFactorInterface, GoogleTwoFactorI
* type="string",
* example="Walla Baggger",
* )
* @Groups({"user_api", "user_api_with_client"})
*/
#[ORM\Column(name: 'name', type: 'text', nullable: true)]
#[Groups(['user_api', 'user_api_with_client'])]
protected $name;
/**
@ -70,9 +68,8 @@ class User extends BaseUser implements EmailTwoFactorInterface, GoogleTwoFactorI
* type="string",
* example="wallabag",
* )
*
* @Groups({"user_api", "user_api_with_client"})
*/
#[Groups(['user_api', 'user_api_with_client'])]
protected $username;
/**
@ -83,9 +80,8 @@ class User extends BaseUser implements EmailTwoFactorInterface, GoogleTwoFactorI
* type="string",
* example="wallabag@wallabag.io",
* )
*
* @Groups({"user_api", "user_api_with_client"})
*/
#[Groups(['user_api', 'user_api_with_client'])]
protected $email;
/**
@ -96,9 +92,9 @@ class User extends BaseUser implements EmailTwoFactorInterface, GoogleTwoFactorI
* type="string",
* example="2023-06-27T19:25:44+0000",
* )
* @Groups({"user_api", "user_api_with_client"})
*/
#[ORM\Column(name: 'created_at', type: 'datetime')]
#[Groups(['user_api', 'user_api_with_client'])]
protected $createdAt;
/**
@ -109,9 +105,9 @@ class User extends BaseUser implements EmailTwoFactorInterface, GoogleTwoFactorI
* type="string",
* example="2023-06-27T19:37:30+0000",
* )
* @Groups({"user_api", "user_api_with_client"})
*/
#[ORM\Column(name: 'updated_at', type: 'datetime')]
#[Groups(['user_api', 'user_api_with_client'])]
protected $updatedAt;
#[ORM\OneToMany(targetEntity: Entry::class, mappedBy: 'user', cascade: ['remove'])]
@ -139,10 +135,9 @@ class User extends BaseUser implements EmailTwoFactorInterface, GoogleTwoFactorI
* description="Default client created during user registration. Used for further authorization",
* ref=@Model(type=Client::class, groups={"user_api_with_client"})
* )
*
* @Groups({"user_api_with_client"})
* @Accessor(getter="getFirstClient")
*/
#[Groups(['user_api_with_client'])]
#[Accessor(getter: 'getFirstClient')]
protected $default_client;
#[ORM\Column(type: 'integer', nullable: true)]