1
0
Fork 0
mirror of https://github.com/wallabag/wallabag.git synced 2025-08-31 18:31:02 +00:00

Move source files directly under src/ directory

This commit is contained in:
Yassine Guedidi 2024-02-19 00:39:48 +01:00
parent 804261bc26
commit a37b385c23
190 changed files with 19 additions and 21 deletions

271
src/Entity/Annotation.php Normal file
View file

@ -0,0 +1,271 @@
<?php
namespace Wallabag\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation\Exclude;
use JMS\Serializer\Annotation\ExclusionPolicy;
use JMS\Serializer\Annotation\Groups;
use JMS\Serializer\Annotation\SerializedName;
use JMS\Serializer\Annotation\VirtualProperty;
use Symfony\Component\Validator\Constraints as Assert;
use Wallabag\CoreBundle\Helper\EntityTimestampsTrait;
/**
* Annotation.
*
* @ORM\Table(name="annotation")
* @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\AnnotationRepository")
* @ORM\HasLifecycleCallbacks()
* @ExclusionPolicy("none")
*/
class Annotation
{
use EntityTimestampsTrait;
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="text", type="text")
*
* @Groups({"entries_for_user", "export_all"})
*/
private $text;
/**
* @var \DateTime
*
* @ORM\Column(name="created_at", type="datetime")
*/
private $createdAt;
/**
* @var \DateTime
*
* @ORM\Column(name="updated_at", type="datetime")
*/
private $updatedAt;
/**
* @var string
*
* @Assert\Length(
* max = 10000,
* maxMessage = "validator.quote_length_too_high"
* )
* @ORM\Column(name="quote", type="text")
*
* @Groups({"entries_for_user", "export_all"})
*/
private $quote;
/**
* @var array
*
* @ORM\Column(name="ranges", type="array")
*
* @Groups({"entries_for_user", "export_all"})
*/
private $ranges;
/**
* @Exclude
*
* @ORM\ManyToOne(targetEntity="Wallabag\CoreBundle\Entity\User")
*/
private $user;
/**
* @Exclude
*
* @ORM\ManyToOne(targetEntity="Wallabag\CoreBundle\Entity\Entry", inversedBy="annotations")
* @ORM\JoinColumn(name="entry_id", referencedColumnName="id", onDelete="cascade")
*/
private $entry;
/*
* @param User $user
*/
public function __construct(User $user)
{
$this->user = $user;
}
/**
* Get id.
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set text.
*
* @param string $text
*
* @return Annotation
*/
public function setText($text)
{
$this->text = $text;
return $this;
}
/**
* Get text.
*
* @return string
*/
public function getText()
{
return $this->text;
}
/**
* Get created.
*
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Get updated.
*
* @return \DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* Get quote.
*
* @return string
*/
public function getQuote()
{
return $this->quote;
}
/**
* Set quote.
*
* @param string $quote
*
* @return Annotation
*/
public function setQuote($quote)
{
$this->quote = $quote;
return $this;
}
/**
* Get ranges.
*
* @return array
*/
public function getRanges()
{
return $this->ranges;
}
/**
* Set ranges.
*
* @param array $ranges
*
* @return Annotation
*/
public function setRanges($ranges)
{
$this->ranges = $ranges;
return $this;
}
/**
* Set user.
*
* @param User $user
*
* @return Annotation
*/
public function setUser($user)
{
$this->user = $user;
return $this;
}
/**
* Get user.
*
* @return User
*/
public function getUser()
{
return $this->user;
}
/**
* @VirtualProperty
* @SerializedName("user")
*/
public function getUserName()
{
return $this->user->getName();
}
/**
* Set entry.
*
* @param Entry $entry
*
* @return Annotation
*/
public function setEntry($entry)
{
$this->entry = $entry;
$entry->setAnnotation($this);
return $this;
}
/**
* Get entry.
*
* @return Entry
*/
public function getEntry()
{
return $this->entry;
}
/**
* @VirtualProperty
* @SerializedName("annotator_schema_version")
*/
public function getVersion()
{
return 'v1.0';
}
}

View file

@ -0,0 +1,48 @@
<?php
namespace Wallabag\CoreBundle\Entity\Api;
use Doctrine\ORM\Mapping as ORM;
use FOS\OAuthServerBundle\Entity\AccessToken as BaseAccessToken;
/**
* @ORM\Table("oauth2_access_tokens")
* @ORM\Entity
* @ORM\AttributeOverrides({
* @ORM\AttributeOverride(name="token",
* column=@ORM\Column(
* name = "token",
* type = "string",
* length = 191
* )
* ),
* @ORM\AttributeOverride(name="scope",
* column=@ORM\Column(
* name = "scope",
* type = "string",
* length = 191
* )
* )
* })
*/
class AccessToken extends BaseAccessToken
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="Wallabag\CoreBundle\Entity\Api\Client", inversedBy="accessTokens")
* @ORM\JoinColumn(nullable=false)
*/
protected $client;
/**
* @ORM\ManyToOne(targetEntity="Wallabag\CoreBundle\Entity\User")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE")
*/
protected $user;
}

View file

@ -0,0 +1,44 @@
<?php
namespace Wallabag\CoreBundle\Entity\Api;
use OpenApi\Annotations as OA;
class ApplicationInfo
{
/**
* @var string
* @OA\Property(
* description="Name of the application.",
* type="string",
* example="wallabag",
* )
*/
public $appname;
/**
* @var string
* @OA\Property(
* description="Version number of the application.",
* type="string",
* example="2.5.2",
* )
*/
public $version;
/**
* @var bool
* @OA\Property(
* description="Indicates whether registration is allowed. See PUT /api/user.",
* type="boolean"
* )
*/
public $allowed_registration;
public function __construct($version, $allowed_registration)
{
$this->appname = 'wallabag';
$this->version = $version;
$this->allowed_registration = $allowed_registration;
}
}

View file

@ -0,0 +1,48 @@
<?php
namespace Wallabag\CoreBundle\Entity\Api;
use Doctrine\ORM\Mapping as ORM;
use FOS\OAuthServerBundle\Entity\AuthCode as BaseAuthCode;
/**
* @ORM\Table("oauth2_auth_codes")
* @ORM\Entity
* @ORM\AttributeOverrides({
* @ORM\AttributeOverride(name="token",
* column=@ORM\Column(
* name = "token",
* type = "string",
* length = 191
* )
* ),
* @ORM\AttributeOverride(name="scope",
* column=@ORM\Column(
* name = "scope",
* type = "string",
* length = 191
* )
* )
* })
*/
class AuthCode extends BaseAuthCode
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="Wallabag\CoreBundle\Entity\Api\Client")
* @ORM\JoinColumn(nullable=false)
*/
protected $client;
/**
* @ORM\ManyToOne(targetEntity="Wallabag\CoreBundle\Entity\User")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE")
*/
protected $user;
}

124
src/Entity/Api/Client.php Normal file
View file

@ -0,0 +1,124 @@
<?php
namespace Wallabag\CoreBundle\Entity\Api;
use Doctrine\ORM\Mapping as ORM;
use FOS\OAuthServerBundle\Entity\Client as BaseClient;
use JMS\Serializer\Annotation\Groups;
use JMS\Serializer\Annotation\SerializedName;
use JMS\Serializer\Annotation\VirtualProperty;
use OpenApi\Annotations as OA;
use Wallabag\CoreBundle\Entity\User;
/**
* @ORM\Table("oauth2_clients")
* @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\Api\ClientRepository")
*/
class Client extends BaseClient
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
*
* @ORM\Column(name="name", type="text", nullable=false)
*
* @OA\Property(
* description="Name of the API client",
* type="string",
* example="Default Client",
* )
*
* @Groups({"user_api_with_client"})
*/
protected $name;
/**
* @ORM\OneToMany(targetEntity="Wallabag\CoreBundle\Entity\Api\RefreshToken", mappedBy="client", cascade={"remove"})
*/
protected $refreshTokens;
/**
* @ORM\OneToMany(targetEntity="Wallabag\CoreBundle\Entity\Api\AccessToken", mappedBy="client", cascade={"remove"})
*/
protected $accessTokens;
/**
* @var string
*
* @OA\Property(
* description="Client secret used for authorization",
* type="string",
* example="2lmubx2m9vy80ss8c4wwcsg8ok44s88ocwcc8wo0w884oc8440",
* )
*
* @SerializedName("client_secret")
* @Groups({"user_api_with_client"})
*/
protected $secret;
/**
* @ORM\ManyToOne(targetEntity="Wallabag\CoreBundle\Entity\User", inversedBy="clients")
*/
private $user;
public function __construct(User $user)
{
parent::__construct();
$this->user = $user;
}
/**
* Get name.
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set name.
*
* @param string $name
*
* @return Client
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* @return User
*/
public function getUser()
{
return $this->user;
}
/**
* @VirtualProperty
*
* @OA\Property(
* description="Client secret used for authorization",
* type="string",
* example="3_1lpybsn0od40css4w4ko8gsc8cwwskggs8kgg448ko0owo4c84",
* )
*
* @SerializedName("client_id")
* @Groups({"user_api_with_client"})
*/
public function getClientId()
{
return $this->getId() . '_' . $this->getRandomId();
}
}

View file

@ -0,0 +1,48 @@
<?php
namespace Wallabag\CoreBundle\Entity\Api;
use Doctrine\ORM\Mapping as ORM;
use FOS\OAuthServerBundle\Entity\RefreshToken as BaseRefreshToken;
/**
* @ORM\Table("oauth2_refresh_tokens")
* @ORM\Entity
* @ORM\AttributeOverrides({
* @ORM\AttributeOverride(name="token",
* column=@ORM\Column(
* name = "token",
* type = "string",
* length = 191
* )
* ),
* @ORM\AttributeOverride(name="scope",
* column=@ORM\Column(
* name = "scope",
* type = "string",
* length = 191
* )
* )
* })
*/
class RefreshToken extends BaseRefreshToken
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="Wallabag\CoreBundle\Entity\Api\Client", inversedBy="refreshTokens")
* @ORM\JoinColumn(nullable=false)
*/
protected $client;
/**
* @ORM\ManyToOne(targetEntity="Wallabag\CoreBundle\Entity\User")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE")
*/
protected $user;
}

543
src/Entity/Config.php Normal file
View file

@ -0,0 +1,543 @@
<?php
namespace Wallabag\CoreBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Config.
*
* @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\ConfigRepository")
* @ORM\Table(
* name="`config`",
* indexes={
* @ORM\Index(name="config_feed_token", columns={"feed_token"}, options={"lengths"={255}}),
* }
* )
*/
class Config
{
public const REDIRECT_TO_HOMEPAGE = 0;
public const REDIRECT_TO_CURRENT_PAGE = 1;
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*
* @Groups({"config_api"})
*/
private $id;
/**
* @var int
*
* @Assert\NotBlank()
* @Assert\Range(
* min = 1,
* max = 100000,
* maxMessage = "validator.item_per_page_too_high"
* )
* @ORM\Column(name="items_per_page", type="integer", nullable=false)
*
* @Groups({"config_api"})
*/
private $itemsPerPage;
/**
* @var string
*
* @Assert\NotBlank()
* @ORM\Column(name="language", type="string", nullable=false)
*
* @Groups({"config_api"})
*/
private $language;
/**
* @var string|null
*
* @ORM\Column(name="feed_token", type="string", nullable=true)
*
* @Groups({"config_api"})
*/
private $feedToken;
/**
* @var int|null
*
* @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
*
* @ORM\Column(name="reading_speed", type="float", nullable=true)
*
* @Groups({"config_api"})
*/
private $readingSpeed;
/**
* @var string|null
*
* @ORM\Column(name="pocket_consumer_key", type="string", nullable=true)
*/
private $pocketConsumerKey;
/**
* @var int|null
*
* @ORM\Column(name="action_mark_as_read", type="integer", nullable=true, options={"default" = 0})
*
* @Groups({"config_api"})
*/
private $actionMarkAsRead;
/**
* @var int|null
*
* @ORM\Column(name="list_mode", type="integer", nullable=true)
*
* @Groups({"config_api"})
*/
private $listMode;
/**
* @var int|null
*
* @ORM\Column(name="display_thumbnails", type="integer", nullable=true, options={"default" = 1})
*
* @Groups({"config_api"})
*/
private $displayThumbnails;
/**
* @var string|null
*
* @ORM\Column(name="font", type="text", nullable=true)
*
* @Groups({"config_api"})
*/
private $font;
/**
* @var float|null
*
* @ORM\Column(name="fontsize", type="float", nullable=true)
*
* @Groups({"config_api"})
*/
private $fontsize;
/**
* @var float|null
*
* @ORM\Column(name="line_height", type="float", nullable=true)
*
* @Groups({"config_api"})
*/
private $lineHeight;
/**
* @var float|null
*
* @ORM\Column(name="max_width", type="float", nullable=true)
*
* @Groups({"config_api"})
*/
private $maxWidth;
/**
* @var string|null
*
* @ORM\Column(name="custom_css", type="text", nullable=true)
*/
private $customCSS;
/**
* @ORM\OneToOne(targetEntity="Wallabag\CoreBundle\Entity\User", inversedBy="config")
*/
private $user;
/**
* @var ArrayCollection<TaggingRule>
*
* @ORM\OneToMany(targetEntity="Wallabag\CoreBundle\Entity\TaggingRule", mappedBy="config", cascade={"remove"})
* @ORM\OrderBy({"id" = "ASC"})
*/
private $taggingRules;
/**
* @var ArrayCollection<IgnoreOriginUserRule>
*
* @ORM\OneToMany(targetEntity="Wallabag\CoreBundle\Entity\IgnoreOriginUserRule", mappedBy="config", cascade={"remove"})
* @ORM\OrderBy({"id" = "ASC"})
*/
private $ignoreOriginRules;
/*
* @param User $user
*/
public function __construct(User $user)
{
$this->user = $user;
$this->taggingRules = new ArrayCollection();
$this->ignoreOriginRules = new ArrayCollection();
}
/**
* Get id.
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set itemsPerPage.
*
* @param int $itemsPerPage
*
* @return Config
*/
public function setItemsPerPage($itemsPerPage)
{
$this->itemsPerPage = $itemsPerPage;
return $this;
}
/**
* Get itemsPerPage.
*
* @return int
*/
public function getItemsPerPage()
{
return $this->itemsPerPage;
}
/**
* Set language.
*
* @param string $language
*
* @return Config
*/
public function setLanguage($language)
{
$this->language = $language;
return $this;
}
/**
* Get language.
*
* @return string
*/
public function getLanguage()
{
return $this->language;
}
/**
* Set user.
*
* @return Config
*/
public function setUser(?User $user = null)
{
$this->user = $user;
return $this;
}
/**
* Get user.
*
* @return User
*/
public function getUser()
{
return $this->user;
}
/**
* Set feed Token.
*
* @param string $feedToken
*
* @return Config
*/
public function setFeedToken($feedToken)
{
$this->feedToken = $feedToken;
return $this;
}
/**
* Get feedToken.
*
* @return string
*/
public function getFeedToken()
{
return $this->feedToken;
}
/**
* Set Feed Limit.
*
* @param int $feedLimit
*
* @return Config
*/
public function setFeedLimit($feedLimit)
{
$this->feedLimit = $feedLimit;
return $this;
}
/**
* Get Feed Limit.
*
* @return int
*/
public function getFeedLimit()
{
return $this->feedLimit;
}
/**
* Set readingSpeed.
*
* @param float $readingSpeed
*
* @return Config
*/
public function setReadingSpeed($readingSpeed)
{
$this->readingSpeed = $readingSpeed;
return $this;
}
/**
* Get readingSpeed.
*
* @return float
*/
public function getReadingSpeed()
{
return $this->readingSpeed;
}
/**
* Set pocketConsumerKey.
*
* @param string $pocketConsumerKey
*
* @return Config
*/
public function setPocketConsumerKey($pocketConsumerKey)
{
$this->pocketConsumerKey = $pocketConsumerKey;
return $this;
}
/**
* Get pocketConsumerKey.
*
* @return string
*/
public function getPocketConsumerKey()
{
return $this->pocketConsumerKey;
}
/**
* @return int
*/
public function getActionMarkAsRead()
{
return $this->actionMarkAsRead;
}
/**
* @param int $actionMarkAsRead
*
* @return Config
*/
public function setActionMarkAsRead($actionMarkAsRead)
{
$this->actionMarkAsRead = $actionMarkAsRead;
return $this;
}
/**
* @return int
*/
public function getListMode()
{
return $this->listMode;
}
/**
* @param int $listMode
*
* @return Config
*/
public function setListMode($listMode)
{
$this->listMode = $listMode;
return $this;
}
public function getDisplayThumbnails(): bool
{
return (bool) $this->displayThumbnails;
}
/**
* @return Config
*/
public function setDisplayThumbnails(bool $displayThumbnails)
{
$this->displayThumbnails = $displayThumbnails ? 1 : 0;
return $this;
}
public function getFont(): ?string
{
return $this->font;
}
/**
* @return $this
*/
public function setFont(string $font): self
{
$this->font = $font;
return $this;
}
public function getFontsize(): ?float
{
return $this->fontsize;
}
/**
* @return $this
*/
public function setFontsize(float $fontsize): self
{
$this->fontsize = $fontsize;
return $this;
}
public function getLineHeight(): ?float
{
return $this->lineHeight;
}
/**
* @return $this
*/
public function setLineHeight(float $lineHeight): self
{
$this->lineHeight = $lineHeight;
return $this;
}
public function getMaxWidth(): ?float
{
return $this->maxWidth;
}
/**
* @return $this
*/
public function setMaxWidth(float $maxWidth): self
{
$this->maxWidth = $maxWidth;
return $this;
}
public function getCustomCSS(): ?string
{
return $this->customCSS;
}
/**
* @return $this
*/
public function setCustomCSS(?string $customCSS): self
{
$this->customCSS = $customCSS;
return $this;
}
/**
* @return Config
*/
public function addTaggingRule(TaggingRule $rule)
{
$this->taggingRules[] = $rule;
return $this;
}
/**
* @return ArrayCollection<TaggingRule>
*/
public function getTaggingRules()
{
return $this->taggingRules;
}
/**
* @return Config
*/
public function addIgnoreOriginRule(IgnoreOriginUserRule $rule)
{
$this->ignoreOriginRules[] = $rule;
return $this;
}
/**
* @return ArrayCollection<IgnoreOriginUserRule>
*/
public function getIgnoreOriginRules()
{
return $this->ignoreOriginRules;
}
}

1040
src/Entity/Entry.php Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,70 @@
<?php
namespace Wallabag\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\RulerZ\Validator\Constraints as RulerZAssert;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Ignore Origin rule.
*
* @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\IgnoreOriginInstanceRuleRepository")
* @ORM\Table(name="`ignore_origin_instance_rule`")
*/
class IgnoreOriginInstanceRule implements IgnoreOriginRuleInterface, RuleInterface
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @Assert\NotBlank()
* @Assert\Length(max=255)
* @RulerZAssert\ValidRule(
* allowed_variables={"host","_all"},
* allowed_operators={"=","~"}
* )
* @ORM\Column(name="rule", type="string", nullable=false)
*/
private $rule;
/**
* Get id.
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set rule.
*
* @return IgnoreOriginRuleInterface
*/
public function setRule(string $rule)
{
$this->rule = $rule;
return $this;
}
/**
* Get rule.
*
* @return string
*/
public function getRule()
{
return $this->rule;
}
}

View file

@ -0,0 +1,12 @@
<?php
namespace Wallabag\CoreBundle\Entity;
interface IgnoreOriginRuleInterface
{
public function getId();
public function setRule(string $rule);
public function getRule();
}

View file

@ -0,0 +1,97 @@
<?php
namespace Wallabag\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\RulerZ\Validator\Constraints as RulerZAssert;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Ignore Origin rule.
*
* @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\IgnoreOriginUserRuleRepository")
* @ORM\Table(name="`ignore_origin_user_rule`")
*/
class IgnoreOriginUserRule implements IgnoreOriginRuleInterface, RuleInterface
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @Assert\NotBlank()
* @Assert\Length(max=255)
* @RulerZAssert\ValidRule(
* allowed_variables={"host","_all"},
* allowed_operators={"=","~"}
* )
* @ORM\Column(name="rule", type="string", nullable=false)
*/
private $rule;
/**
* @ORM\ManyToOne(targetEntity="Wallabag\CoreBundle\Entity\Config", inversedBy="ignoreOriginRules")
*/
private $config;
/**
* Get id.
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set rule.
*
* @return IgnoreOriginRuleInterface
*/
public function setRule(string $rule)
{
$this->rule = $rule;
return $this;
}
/**
* Get rule.
*
* @return string
*/
public function getRule()
{
return $this->rule;
}
/**
* Set config.
*
* @return IgnoreOriginUserRule
*/
public function setConfig(Config $config)
{
$this->config = $config;
return $this;
}
/**
* Get config.
*
* @return Config
*/
public function getConfig()
{
return $this->config;
}
}

View file

@ -0,0 +1,36 @@
<?php
namespace Wallabag\CoreBundle\Entity;
use Craue\ConfigBundle\Entity\BaseSetting;
use Doctrine\ORM\Mapping as ORM;
/**
* InternalSetting.
*
* Re-define setting so we can override length attribute to fix utf8mb4 issue.
*
* @ORM\Entity(repositoryClass="Craue\ConfigBundle\Repository\SettingRepository")
* @ORM\Table(name="`internal_setting`")
* @ORM\AttributeOverrides({
* @ORM\AttributeOverride(name="name",
* column=@ORM\Column(
* length = 191
* )
* ),
* @ORM\AttributeOverride(name="section",
* column=@ORM\Column(
* length = 191
* )
* )
* })
*/
class InternalSetting extends BaseSetting
{
/**
* @var string|null
*
* @ORM\Column(name="value", type="string", nullable=true, length=191)
*/
protected $value;
}

View file

@ -0,0 +1,7 @@
<?php
namespace Wallabag\CoreBundle\Entity;
interface RuleInterface
{
}

View file

@ -0,0 +1,204 @@
<?php
namespace Wallabag\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Wallabag\CoreBundle\Helper\EntityTimestampsTrait;
/**
* SiteCredential.
*
* @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\SiteCredentialRepository")
* @ORM\Table(name="`site_credential`")
* @ORM\HasLifecycleCallbacks()
*/
class SiteCredential
{
use EntityTimestampsTrait;
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @Assert\NotBlank()
* @Assert\Length(max=255)
* @ORM\Column(name="host", type="string", length=255)
*/
private $host;
/**
* @var string
*
* @Assert\NotBlank()
* @ORM\Column(name="username", type="text")
*/
private $username;
/**
* @var string
*
* @Assert\NotBlank()
* @ORM\Column(name="password", type="text")
*/
private $password;
/**
* @var \DateTime
*
* @ORM\Column(name="createdAt", type="datetime")
*/
private $createdAt;
/**
* @var \DateTime
*
* @ORM\Column(name="updated_at", type="datetime")
*/
private $updatedAt;
/**
* @ORM\ManyToOne(targetEntity="Wallabag\CoreBundle\Entity\User", inversedBy="siteCredentials")
*/
private $user;
/*
* @param User $user
*/
public function __construct(User $user)
{
$this->user = $user;
}
/**
* Get id.
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set host.
*
* @param string $host
*
* @return SiteCredential
*/
public function setHost($host)
{
$this->host = $host;
return $this;
}
/**
* Get host.
*
* @return string
*/
public function getHost()
{
return $this->host;
}
/**
* Set username.
*
* @param string $username
*
* @return SiteCredential
*/
public function setUsername($username)
{
$this->username = $username;
return $this;
}
/**
* Get username.
*
* @return string
*/
public function getUsername()
{
return $this->username;
}
/**
* Set password.
*
* @param string $password
*
* @return SiteCredential
*/
public function setPassword($password)
{
$this->password = $password;
return $this;
}
/**
* Get password.
*
* @return string
*/
public function getPassword()
{
return $this->password;
}
/**
* Set createdAt.
*
* @param \DateTime $createdAt
*
* @return SiteCredential
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* Get createdAt.
*
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Get updatedAt.
*
* @return \DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* @return User
*/
public function getUser()
{
return $this->user;
}
}

153
src/Entity/Tag.php Normal file
View file

@ -0,0 +1,153 @@
<?php
namespace Wallabag\CoreBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use JMS\Serializer\Annotation\ExclusionPolicy;
use JMS\Serializer\Annotation\Expose;
use JMS\Serializer\Annotation\XmlRoot;
/**
* Tag.
*
* @XmlRoot("tag")
* @ORM\Table(
* name="`tag`",
* options={"collate"="utf8mb4_bin", "charset"="utf8mb4"},
* indexes={
* @ORM\Index(name="tag_label", columns={"label"}, options={"lengths"={255}}),
* }
* )
* @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\TagRepository")
* @ExclusionPolicy("all")
*/
class Tag
{
/**
* @var int
*
* @Expose
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @Expose
* @ORM\Column(name="label", type="text")
*/
private $label;
/**
* @Expose
* @Gedmo\Slug(fields={"label"}, prefix="t:")
* @ORM\Column(length=128, unique=true)
*/
private $slug;
/**
* @ORM\ManyToMany(targetEntity="Entry", mappedBy="tags", cascade={"persist"})
*/
private $entries;
public function __construct()
{
$this->entries = new ArrayCollection();
}
public function __toString()
{
return $this->label;
}
/**
* Get id.
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set label.
*
* @param string $label
*
* @return Tag
*/
public function setLabel($label)
{
$this->label = mb_convert_case($label, \MB_CASE_LOWER);
return $this;
}
/**
* Get label.
*
* @return string
*/
public function getLabel()
{
return $this->label;
}
public function getSlug()
{
return $this->slug;
}
public function addEntry(Entry $entry)
{
if ($this->entries->contains($entry)) {
return;
}
$this->entries->add($entry);
$entry->addTag($this);
}
public function removeEntry(Entry $entry)
{
if (!$this->entries->contains($entry)) {
return;
}
$this->entries->removeElement($entry);
$entry->removeTag($this);
}
public function hasEntry($entry)
{
return $this->entries->contains($entry);
}
/**
* Get entries for this tag.
*
* @return ArrayCollection<Entry>
*/
public function getEntries()
{
return $this->entries;
}
public function getEntriesByUserId($userId)
{
$filteredEntries = new ArrayCollection();
foreach ($this->entries as $entry) {
if ($entry->getUser()->getId() === $userId) {
$filteredEntries->add($entry);
}
}
return $filteredEntries;
}
}

142
src/Entity/TaggingRule.php Normal file
View file

@ -0,0 +1,142 @@
<?php
namespace Wallabag\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation\Exclude;
use JMS\Serializer\Annotation\Groups;
use JMS\Serializer\Annotation\XmlRoot;
use Symfony\Bridge\RulerZ\Validator\Constraints as RulerZAssert;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Tagging rule.
*
* @XmlRoot("tagging_rule")
* @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\TaggingRuleRepository")
* @ORM\Table(name="`tagging_rule`")
* @ORM\Entity
*/
class TaggingRule implements RuleInterface
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @Assert\NotBlank()
* @Assert\Length(max=255)
* @RulerZAssert\ValidRule(
* allowed_variables={"title", "url", "isArchived", "isStared", "content", "language", "mimetype", "readingTime", "domainName"},
* allowed_operators={">", "<", ">=", "<=", "=", "is", "!=", "and", "not", "or", "matches", "notmatches"}
* )
* @ORM\Column(name="rule", type="string", nullable=false)
*
* @Groups({"export_tagging_rule"})
*/
private $rule;
/**
* @var array<string>
*
* @Assert\NotBlank()
* @ORM\Column(name="tags", type="simple_array", nullable=false)
*
* @Groups({"export_tagging_rule"})
*/
private $tags = [];
/**
* @Exclude
*
* @ORM\ManyToOne(targetEntity="Wallabag\CoreBundle\Entity\Config", inversedBy="taggingRules")
*/
private $config;
/**
* Get id.
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set rule.
*
* @param string $rule
*
* @return TaggingRule
*/
public function setRule($rule)
{
$this->rule = $rule;
return $this;
}
/**
* Get rule.
*
* @return string
*/
public function getRule()
{
return $this->rule;
}
/**
* Set tags.
*
* @param array <string> $tags
*
* @return TaggingRule
*/
public function setTags(array $tags)
{
$this->tags = $tags;
return $this;
}
/**
* Get tags.
*
* @return array<string>
*/
public function getTags()
{
return $this->tags;
}
/**
* Set config.
*
* @return TaggingRule
*/
public function setConfig(Config $config)
{
$this->config = $config;
return $this;
}
/**
* Get config.
*
* @return Config
*/
public function getConfig()
{
return $this->config;
}
}

411
src/Entity/User.php Normal file
View file

@ -0,0 +1,411 @@
<?php
namespace Wallabag\CoreBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\Groups;
use JMS\Serializer\Annotation\XmlRoot;
use Nelmio\ApiDocBundle\Annotation\Model;
use OpenApi\Annotations as OA;
use Scheb\TwoFactorBundle\Model\BackupCodeInterface;
use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface as EmailTwoFactorInterface;
use Scheb\TwoFactorBundle\Model\Google\TwoFactorInterface as GoogleTwoFactorInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Wallabag\CoreBundle\Entity\Api\Client;
use Wallabag\CoreBundle\Helper\EntityTimestampsTrait;
/**
* User.
*
* @XmlRoot("user")
* @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\UserRepository")
* @ORM\Table(name="`user`")
* @ORM\HasLifecycleCallbacks()
*
* @UniqueEntity("email")
* @UniqueEntity("username")
*/
class User extends BaseUser implements EmailTwoFactorInterface, GoogleTwoFactorInterface, BackupCodeInterface
{
use EntityTimestampsTrait;
/** @Serializer\XmlAttribute */
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*
* @OA\Property(
* description="The unique numeric id of the user",
* type="int",
* example=12,
* )
*
* @Groups({"user_api", "user_api_with_client"})
*/
protected $id;
/**
* @var string|null
*
* @ORM\Column(name="name", type="text", nullable=true)
*
* @OA\Property(
* description="The personal Name of the user",
* type="string",
* example="Walla Baggger",
* )
*
* @Groups({"user_api", "user_api_with_client"})
*/
protected $name;
/**
* @var string
*
* @OA\Property(
* description="The unique username of the user",
* type="string",
* example="wallabag",
* )
*
* @Groups({"user_api", "user_api_with_client"})
*/
protected $username;
/**
* @var string
*
* @OA\Property(
* description="E-mail address of the user",
* type="string",
* example="wallabag@wallabag.io",
* )
*
* @Groups({"user_api", "user_api_with_client"})
*/
protected $email;
/**
* @var \DateTime
*
* @ORM\Column(name="created_at", type="datetime")
*
* @OA\Property(
* description="Creation date of the user account. (In ISO 8601 format)",
* type="string",
* example="2023-06-27T19:25:44+0000",
* )
*
* @Groups({"user_api", "user_api_with_client"})
*/
protected $createdAt;
/**
* @var \DateTime
*
* @ORM\Column(name="updated_at", type="datetime")
*
* @OA\Property(
* description="Update date of the user account. (In ISO 8601 format)",
* type="string",
* example="2023-06-27T19:37:30+0000",
* )
*
* @Groups({"user_api", "user_api_with_client"})
*/
protected $updatedAt;
/**
* @ORM\OneToMany(targetEntity="Wallabag\CoreBundle\Entity\Entry", mappedBy="user", cascade={"remove"})
*/
protected $entries;
/**
* @ORM\OneToOne(targetEntity="Wallabag\CoreBundle\Entity\Config", mappedBy="user", cascade={"remove"})
*/
protected $config;
/**
* @var ArrayCollection&iterable<\Wallabag\CoreBundle\Entity\SiteCredential>
*
* @ORM\OneToMany(targetEntity="Wallabag\CoreBundle\Entity\SiteCredential", mappedBy="user", cascade={"remove"})
*/
protected $siteCredentials;
/**
* @var ArrayCollection&iterable<\Wallabag\CoreBundle\Entity\Api\Client>
*
* @ORM\OneToMany(targetEntity="Wallabag\CoreBundle\Entity\Api\Client", mappedBy="user", cascade={"remove"})
*/
protected $clients;
/**
* @see getFirstClient() below
*
* @OA\Property(
* 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")
*/
protected $default_client;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $authCode;
/**
* @ORM\Column(name="googleAuthenticatorSecret", type="string", nullable=true)
*/
private $googleAuthenticatorSecret;
/**
* @var array
*
* @ORM\Column(type="json", nullable=true)
*/
private $backupCodes;
/**
* @var bool
*
* @ORM\Column(type="boolean")
*/
private $emailTwoFactor = false;
public function __construct()
{
parent::__construct();
$this->entries = new ArrayCollection();
$this->roles = ['ROLE_USER'];
}
/**
* Set name.
*
* @param string $name
*
* @return User
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name.
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* @return \DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* @return User
*/
public function addEntry(Entry $entry)
{
$this->entries[] = $entry;
return $this;
}
/**
* @return ArrayCollection<Entry>
*/
public function getEntries()
{
return $this->entries;
}
/**
* Set config.
*
* @return User
*/
public function setConfig(?Config $config = null)
{
$this->config = $config;
return $this;
}
/**
* Get config.
*
* @return Config
*/
public function getConfig()
{
return $this->config;
}
/**
* @return bool
*/
public function isEmailTwoFactor()
{
return $this->emailTwoFactor;
}
/**
* @param bool $emailTwoFactor
*/
public function setEmailTwoFactor($emailTwoFactor)
{
$this->emailTwoFactor = $emailTwoFactor;
}
/**
* Used in the user config form to be "like" the email option.
*/
public function isGoogleTwoFactor()
{
return $this->isGoogleAuthenticatorEnabled();
}
public function isEmailAuthEnabled(): bool
{
return $this->emailTwoFactor;
}
public function getEmailAuthCode(): string
{
return $this->authCode;
}
public function setEmailAuthCode(string $authCode): void
{
$this->authCode = $authCode;
}
public function getEmailAuthRecipient(): string
{
return $this->email;
}
public function isGoogleAuthenticatorEnabled(): bool
{
return $this->googleAuthenticatorSecret ? true : false;
}
public function getGoogleAuthenticatorUsername(): string
{
return $this->username;
}
public function getGoogleAuthenticatorSecret(): string
{
return $this->googleAuthenticatorSecret;
}
public function setGoogleAuthenticatorSecret(?string $googleAuthenticatorSecret): void
{
$this->googleAuthenticatorSecret = $googleAuthenticatorSecret;
}
public function setBackupCodes(?array $codes = null)
{
$this->backupCodes = $codes;
}
public function getBackupCodes()
{
return $this->backupCodes;
}
public function isBackupCode(string $code): bool
{
return false === $this->findBackupCode($code) ? false : true;
}
public function invalidateBackupCode(string $code): void
{
$key = $this->findBackupCode($code);
if (false !== $key) {
unset($this->backupCodes[$key]);
}
}
/**
* @return User
*/
public function addClient(Client $client)
{
$this->clients[] = $client;
return $this;
}
/**
* @return ArrayCollection<Client>
*/
public function getClients()
{
return $this->clients;
}
/**
* Only used by the API when creating a new user it'll also return the first client (which was also created at the same time).
*
* @return Client|false
*/
public function getFirstClient()
{
if (!empty($this->clients)) {
return $this->clients->first();
}
return false;
}
/**
* Try to find a backup code from the list of backup codes of the current user.
*
* @param string $code Given code from the user
*
* @return string|false
*/
private function findBackupCode(string $code)
{
foreach ($this->backupCodes as $key => $backupCode) {
// backup code are hashed using `password_hash`
// see ConfigController->otpAppAction
if (password_verify($code, $backupCode)) {
return $key;
}
}
return false;
}
}