Added basic fields and migration for MySQL

This commit is contained in:
Jan Böhmer 2023-04-02 19:10:36 +02:00
parent e7e57fa412
commit 047c82791b
4 changed files with 138 additions and 0 deletions

View file

@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20230402170923 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE part_lots ADD id_owner INT DEFAULT NULL');
$this->addSql('ALTER TABLE part_lots ADD CONSTRAINT FK_EBC8F94321E5A74C FOREIGN KEY (id_owner) REFERENCES `users` (id) ON DELETE SET NULL');
$this->addSql('CREATE INDEX IDX_EBC8F94321E5A74C ON part_lots (id_owner)');
$this->addSql('ALTER TABLE projects ADD CONSTRAINT FK_5C93B3A4727ACA70 FOREIGN KEY (parent_id) REFERENCES projects (id)');
$this->addSql('ALTER TABLE storelocations ADD id_owner INT DEFAULT NULL, ADD part_owner_must_match TINYINT(1) NOT NULL');
$this->addSql('ALTER TABLE storelocations ADD CONSTRAINT FK_751702021E5A74C FOREIGN KEY (id_owner) REFERENCES `users` (id) ON DELETE SET NULL');
$this->addSql('CREATE INDEX IDX_751702021E5A74C ON storelocations (id_owner)');
$this->addSql('ALTER TABLE users ADD about_me LONGTEXT DEFAULT \'\' NOT NULL');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE log CHANGE level level TINYINT(1) NOT NULL');
$this->addSql('ALTER TABLE part_lots DROP FOREIGN KEY FK_EBC8F94321E5A74C');
$this->addSql('DROP INDEX IDX_EBC8F94321E5A74C ON part_lots');
$this->addSql('ALTER TABLE part_lots DROP id_owner');
$this->addSql('ALTER TABLE projects DROP FOREIGN KEY FK_5C93B3A4727ACA70');
$this->addSql('ALTER TABLE `storelocations` DROP FOREIGN KEY FK_751702021E5A74C');
$this->addSql('DROP INDEX IDX_751702021E5A74C ON `storelocations`');
$this->addSql('ALTER TABLE `storelocations` DROP id_owner, DROP part_owner_must_match');
$this->addSql('ALTER TABLE `users` DROP about_me');
}
}

View file

@ -26,6 +26,7 @@ use App\Entity\Base\AbstractDBElement;
use App\Entity\Base\TimestampTrait;
use App\Entity\Contracts\NamedElementInterface;
use App\Entity\Contracts\TimeStampableInterface;
use App\Entity\UserSystem\User;
use App\Validator\Constraints\Selectable;
use App\Validator\Constraints\ValidPartLot;
use DateTime;
@ -111,6 +112,13 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named
*/
protected Part $part;
/**
* @var User|null The owner of this part lot
* @ORM\ManyToOne(targetEntity="App\Entity\UserSystem\User")
* @ORM\JoinColumn(name="id_owner", referencedColumnName="id", nullable=true, onDelete="SET NULL")
*/
protected ?User $owner;
public function __clone()
{
if ($this->id) {
@ -304,6 +312,28 @@ class PartLot extends AbstractDBElement implements TimeStampableInterface, Named
return $this;
}
/**
* Returns the owner of this part lot.
* @return User|null
*/
public function getOwner(): ?User
{
return $this->owner;
}
/**
* Sets the owner of this part lot.
* @param User|null $owner
* @return PartLot
*/
public function setOwner(?User $owner): PartLot
{
$this->owner = $owner;
return $this;
}
public function getName(): string
{
return $this->description;

View file

@ -25,6 +25,7 @@ namespace App\Entity\Parts;
use App\Entity\Attachments\StorelocationAttachment;
use App\Entity\Base\AbstractPartsContainingDBElement;
use App\Entity\Parameters\StorelocationParameter;
use App\Entity\UserSystem\User;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
@ -89,6 +90,19 @@ class Storelocation extends AbstractPartsContainingDBElement
*/
protected bool $limit_to_existing_parts = false;
/**
* @var User|null The owner of this storage location
* @ORM\ManyToOne(targetEntity="App\Entity\UserSystem\User")
* @ORM\JoinColumn(name="id_owner", referencedColumnName="id", nullable=true, onDelete="SET NULL")
*/
protected ?User $owner;
/**
* @var bool If this is set to true, only parts lots, which are owned by the same user as the store location are allowed to be stored here.
* @ORM\Column(type="boolean")
*/
protected bool $part_owner_must_match = false;
/**
* @var Collection<int, StorelocationAttachment>
* @ORM\OneToMany(targetEntity="App\Entity\Attachments\StorelocationAttachment", mappedBy="element", cascade={"persist", "remove"}, orphanRemoval=true)
@ -166,6 +180,49 @@ class Storelocation extends AbstractPartsContainingDBElement
return $this;
}
/**
* Returns the owner of this storage location
* @return User|null
*/
public function getOwner(): ?User
{
return $this->owner;
}
/**
* Sets the owner of this storage location
* @param User|null $owner
* @return Storelocation
*/
public function setOwner(?User $owner): Storelocation
{
$this->owner = $owner;
return $this;
}
/**
* If this is set to true, only parts lots, which are owned by the same user as the store location are allowed to be stored here.
* @return bool
*/
public function isPartOwnerMustMatch(): bool
{
return $this->part_owner_must_match;
}
/**
* If this is set to true, only parts lots, which are owned by the same user as the store location are allowed to be stored here.
* @param bool $part_owner_must_match
* @return Storelocation
*/
public function setPartOwnerMustMatch(bool $part_owner_must_match): Storelocation
{
$this->part_owner_must_match = $part_owner_must_match;
return $this;
}
/********************************************************************************
*
* Setters

View file

@ -103,6 +103,13 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
*/
protected string $instock_comment_w = '';
/**
* @var string A self-description of the user
* @ORM\Column(type="text", options={"default": ""})
* @Groups({"full", "import"})
*/
protected string $aboutMe = '';
/** @var int The version of the trusted device cookie. Used to invalidate all trusted device cookies at once.
* @ORM\Column(type="integer")
*/