From 1d1d681f8988fef259d887b5a0d24d680e0d2bd7 Mon Sep 17 00:00:00 2001 From: Julien Rosset Date: Wed, 17 May 2023 18:54:25 +0200 Subject: [PATCH] Add StofDoctrineExtensions (Timestampable) --- .env | 2 +- .idea/php.xml | 3 + .idea/web_edm.iml | 3 + composer.json | 37 +-- composer.lock | 291 ++++++++++++++++-- config/bundles.php | 21 +- config/packages/stof_doctrine_extensions.yaml | 7 + migrations/Version20230517165002.php | 46 +++ src/Entity/Document.php | 10 +- symfony.lock | 12 + 10 files changed, 370 insertions(+), 62 deletions(-) create mode 100644 config/packages/stof_doctrine_extensions.yaml create mode 100644 migrations/Version20230517165002.php diff --git a/.env b/.env index 55e5605..084056d 100644 --- a/.env +++ b/.env @@ -25,7 +25,7 @@ APP_SECRET=d484088b38870d327fe91ef10147c41d # # DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db" # DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=8.0.32&charset=utf8mb4" -DATABASE_URL="mysql://web_edm:%env(DATABASE_PASSWORD)%@127.0.0.1:3306/app?serverVersion=10.11.3-MariaDB&charset=utf8mb4" +DATABASE_URL="mysql://web_edm:%env(DATABASE_PASSWORD)%@127.0.0.1:3306/web_edm?serverVersion=10.11.3-MariaDB&charset=utf8mb4" # DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=15&charset=utf8" ###< doctrine/doctrine-bundle ### diff --git a/.idea/php.xml b/.idea/php.xml index 1d02b4c..4fa0002 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -138,6 +138,9 @@ + + + diff --git a/.idea/web_edm.iml b/.idea/web_edm.iml index 248fcd8..bf33080 100644 --- a/.idea/web_edm.iml +++ b/.idea/web_edm.iml @@ -130,6 +130,9 @@ + + + diff --git a/composer.json b/composer.json index 2dc1c6a..378fe4e 100644 --- a/composer.json +++ b/composer.json @@ -4,25 +4,26 @@ "minimum-stability": "stable", "prefer-stable": true, "require": { - "php": ">=8.1", - "ext-ctype": "*", - "ext-iconv": "*", - "doctrine/annotations": "^2.0", - "doctrine/doctrine-bundle": "^2.9", + "php": ">=8.1", + "ext-ctype": "*", + "ext-iconv": "*", + "doctrine/annotations": "^2.0", + "doctrine/doctrine-bundle": "^2.9", "doctrine/doctrine-migrations-bundle": "^3.2", - "doctrine/orm": "^2.15", - "phpdocumentor/reflection-docblock": "^5.3", - "phpstan/phpdoc-parser": "^1.20", - "symfony/asset": "6.2.*", - "symfony/console": "6.2.*", - "symfony/doctrine-messenger": "6.2.*", - "symfony/dotenv": "6.2.*", - "symfony/expression-language": "6.2.*", - "symfony/flex": "^2", - "symfony/form": "6.2.*", - "symfony/framework-bundle": "6.2.*", - "symfony/http-client": "6.2.*", - "symfony/intl": "6.2.*", + "doctrine/orm": "^2.15", + "phpdocumentor/reflection-docblock": "^5.3", + "phpstan/phpdoc-parser": "^1.20", + "stof/doctrine-extensions-bundle": "^1.7", + "symfony/asset": "6.2.*", + "symfony/console": "6.2.*", + "symfony/doctrine-messenger": "6.2.*", + "symfony/dotenv": "6.2.*", + "symfony/expression-language": "6.2.*", + "symfony/flex": "^2", + "symfony/form": "6.2.*", + "symfony/framework-bundle": "6.2.*", + "symfony/http-client": "6.2.*", + "symfony/intl": "6.2.*", "symfony/mailer": "6.2.*", "symfony/mime": "6.2.*", "symfony/monolog-bundle": "^3.0", diff --git a/composer.lock b/composer.lock index 0788099..4975535 100644 --- a/composer.lock +++ b/composer.lock @@ -1,22 +1,71 @@ { - "_readme": [ + "_readme": [ "This file locks the dependencies of your project to a known state", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a736a817c023df9a07c982ffb5f7b2c9", - "packages": [ + "content-hash": "27ec98e1e5ebc13fb8e85dbf04b0edaa", + "packages": [ { - "name": "doctrine/annotations", - "version": "2.0.1", - "source": { - "type": "git", - "url": "https://github.com/doctrine/annotations.git", + "name": "behat/transliterator", + "version": "v1.5.0", + "source": { + "type": "git", + "url": "https://github.com/Behat/Transliterator.git", + "reference": "baac5873bac3749887d28ab68e2f74db3a4408af" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Behat/Transliterator/zipball/baac5873bac3749887d28ab68e2f74db3a4408af", + "reference": "baac5873bac3749887d28ab68e2f74db3a4408af", + "shasum": "" + }, + "require": { + "php": ">=7.2" + }, + "require-dev": { + "chuyskywalker/rolling-curl": "^3.1", + "php-yaoi/php-yaoi": "^1.0", + "phpunit/phpunit": "^8.5.25 || ^9.5.19" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Behat\\Transliterator\\": "src/Behat/Transliterator" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Artistic-1.0" + ], + "description": "String transliterator", + "keywords": [ + "i18n", + "slug", + "transliterator" + ], + "support": { + "issues": "https://github.com/Behat/Transliterator/issues", + "source": "https://github.com/Behat/Transliterator/tree/v1.5.0" + }, + "time": "2022-03-30T09:27:43+00:00" + }, + { + "name": "doctrine/annotations", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/doctrine/annotations.git", "reference": "e157ef3f3124bbf6fe7ce0ffd109e8a8ef284e7f" }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/annotations/zipball/e157ef3f3124bbf6fe7ce0ffd109e8a8ef284e7f", + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/annotations/zipball/e157ef3f3124bbf6fe7ce0ffd109e8a8ef284e7f", "reference": "e157ef3f3124bbf6fe7ce0ffd109e8a8ef284e7f", "shasum": "" }, @@ -1450,25 +1499,135 @@ "issues": "https://github.com/egulias/EmailValidator/issues", "source": "https://github.com/egulias/EmailValidator/tree/4.0.1" }, - "funding": [ + "funding": [ { - "url": "https://github.com/egulias", + "url": "https://github.com/egulias", "type": "github" } ], - "time": "2023-01-14T14:17:03+00:00" + "time": "2023-01-14T14:17:03+00:00" }, { - "name": "monolog/monolog", + "name": "gedmo/doctrine-extensions", + "version": "v3.11.1", + "source": { + "type": "git", + "url": "https://github.com/doctrine-extensions/DoctrineExtensions.git", + "reference": "ae4bdf0d567e06b6bb1902a560ee78961b230953" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine-extensions/DoctrineExtensions/zipball/ae4bdf0d567e06b6bb1902a560ee78961b230953", + "reference": "ae4bdf0d567e06b6bb1902a560ee78961b230953", + "shasum": "" + }, + "require": { + "behat/transliterator": "~1.2", + "doctrine/annotations": "^1.13 || ^2.0", + "doctrine/collections": "^1.2 || ^2.0", + "doctrine/common": "^2.13 || ^3.0", + "doctrine/event-manager": "^1.2 || ^2.0", + "doctrine/persistence": "^2.2 || ^3.0", + "php": "^7.2 || ^8.0", + "psr/cache": "^1 || ^2 || ^3", + "symfony/cache": "^4.4 || ^5.3 || ^6.0", + "symfony/deprecation-contracts": "^2.1 || ^3.0" + }, + "conflict": { + "doctrine/cache": "<1.11", + "doctrine/dbal": "<2.13.1 || ^3.0 <3.2", + "doctrine/mongodb-odm": "<2.3", + "doctrine/orm": "<2.10.2", + "sebastian/comparator": "<2.0" + }, + "require-dev": { + "doctrine/cache": "^1.11 || ^2.0", + "doctrine/dbal": "^2.13.1 || ^3.2", + "doctrine/doctrine-bundle": "^2.3", + "doctrine/mongodb-odm": "^2.3", + "doctrine/orm": "^2.10.2", + "friendsofphp/php-cs-fixer": "^3.4.0,<3.10", + "nesbot/carbon": "^2.55", + "phpstan/phpstan": "^1.9", + "phpstan/phpstan-doctrine": "^1.0", + "phpstan/phpstan-phpunit": "^1.0", + "phpunit/phpunit": "^8.5 || ^9.5", + "symfony/console": "^4.4 || ^5.3 || ^6.0", + "symfony/phpunit-bridge": "^6.0", + "symfony/yaml": "^4.4 || ^5.3 || ^6.0" + }, + "suggest": { + "doctrine/mongodb-odm": "to use the extensions with the MongoDB ODM", + "doctrine/orm": "to use the extensions with the ORM", + "symfony/cache": "to cache parsed annotations" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.12-dev" + } + }, + "autoload": { + "psr-4": { + "Gedmo\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Gediminas Morkevicius", + "email": "gediminas.morkevicius@gmail.com" + }, + { + "name": "Gustavo Falco", + "email": "comfortablynumb84@gmail.com" + }, + { + "name": "David Buchmann", + "email": "david@liip.ch" + } + ], + "description": "Doctrine behavioral extensions", + "homepage": "http://gediminasm.org/", + "keywords": [ + "Blameable", + "behaviors", + "doctrine", + "extensions", + "gedmo", + "loggable", + "nestedset", + "odm", + "orm", + "sluggable", + "sortable", + "timestampable", + "translatable", + "tree", + "uploadable" + ], + "support": { + "email": "gediminas.morkevicius@gmail.com", + "issues": "https://github.com/doctrine-extensions/DoctrineExtensions/issues", + "source": "https://github.com/doctrine-extensions/DoctrineExtensions/tree/v3.11.1", + "wiki": "https://github.com/Atlantic18/DoctrineExtensions/tree/main/doc" + }, + "time": "2023-02-20T19:24:07+00:00" + }, + { + "name": "monolog/monolog", "version": "3.3.1", - "source": { - "type": "git", - "url": "https://github.com/Seldaek/monolog.git", + "source": { + "type": "git", + "url": "https://github.com/Seldaek/monolog.git", "reference": "9b5daeaffce5b926cac47923798bba91059e60e2" }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Seldaek/monolog/zipball/9b5daeaffce5b926cac47923798bba91059e60e2", + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/9b5daeaffce5b926cac47923798bba91059e60e2", "reference": "9b5daeaffce5b926cac47923798bba91059e60e2", "shasum": "" }, @@ -2031,16 +2190,90 @@ "time": "2021-07-14T16:46:02+00:00" }, { - "name": "symfony/asset", - "version": "v6.2.7", - "source": { - "type": "git", - "url": "https://github.com/symfony/asset.git", + "name": "stof/doctrine-extensions-bundle", + "version": "v1.7.1", + "source": { + "type": "git", + "url": "https://github.com/stof/StofDoctrineExtensionsBundle.git", + "reference": "fa650e60e174afa06c09e28a54fb1854af04c7fe" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/stof/StofDoctrineExtensionsBundle/zipball/fa650e60e174afa06c09e28a54fb1854af04c7fe", + "reference": "fa650e60e174afa06c09e28a54fb1854af04c7fe", + "shasum": "" + }, + "require": { + "gedmo/doctrine-extensions": "^2.3.4 || ^3.0.0", + "php": "^7.1.3 || ^8.0", + "symfony/config": "^4.4 || ^5.2 || ^6.0", + "symfony/dependency-injection": "^4.4 || ^5.2 || ^6.0", + "symfony/event-dispatcher": "^4.4 || ^5.2 || ^6.0", + "symfony/http-kernel": "^4.4 || ^5.2 || ^6.0" + }, + "require-dev": { + "symfony/mime": "^4.4 || ^5.2 || ^6.0", + "symfony/phpunit-bridge": "^v5.2.4 || ^6.0", + "symfony/security-core": "^4.4 || ^5.2 || ^6.0" + }, + "suggest": { + "doctrine/doctrine-bundle": "to use the ORM extensions", + "doctrine/mongodb-odm-bundle": "to use the MongoDB ODM extensions", + "symfony/mime": "To use the Mime component integration for Uploadable" + }, + "type": "symfony-bundle", + "extra": { + "branch-alias": { + "dev-main": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Stof\\DoctrineExtensionsBundle\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Christophe Coevoet", + "email": "stof@notk.org" + } + ], + "description": "Integration of the gedmo/doctrine-extensions with Symfony", + "homepage": "https://github.com/stof/StofDoctrineExtensionsBundle", + "keywords": [ + "behaviors", + "doctrine2", + "extensions", + "gedmo", + "loggable", + "nestedset", + "sluggable", + "sortable", + "timestampable", + "translatable", + "tree" + ], + "support": { + "issues": "https://github.com/stof/StofDoctrineExtensionsBundle/issues", + "source": "https://github.com/stof/StofDoctrineExtensionsBundle/tree/v1.7.1" + }, + "time": "2022-09-30T11:52:24+00:00" + }, + { + "name": "symfony/asset", + "version": "v6.2.7", + "source": { + "type": "git", + "url": "https://github.com/symfony/asset.git", "reference": "223df790e684ecc7bc37323c2d1e265129ca02de" }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/asset/zipball/223df790e684ecc7bc37323c2d1e265129ca02de", + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/asset/zipball/223df790e684ecc7bc37323c2d1e265129ca02de", "reference": "223df790e684ecc7bc37323c2d1e265129ca02de", "shasum": "" }, diff --git a/config/bundles.php b/config/bundles.php index 0457f99..e18835f 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -1,14 +1,15 @@ ['all' => true], - Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true], - Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true], - Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true], - Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true], - Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true], - Twig\Extra\TwigExtraBundle\TwigExtraBundle::class => ['all' => true], - Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true], - Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true], - Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true], + Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], + Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true], + Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true], + Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true], + Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true], + Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true], + Twig\Extra\TwigExtraBundle\TwigExtraBundle::class => ['all' => true], + Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true], + Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true], + Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true], + Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle::class => ['all' => true], ]; diff --git a/config/packages/stof_doctrine_extensions.yaml b/config/packages/stof_doctrine_extensions.yaml new file mode 100644 index 0000000..6979b41 --- /dev/null +++ b/config/packages/stof_doctrine_extensions.yaml @@ -0,0 +1,7 @@ +# Read the documentation: https://symfony.com/doc/current/bundles/StofDoctrineExtensionsBundle/index.html +# See the official DoctrineExtensions documentation for more details: https://github.com/doctrine-extensions/DoctrineExtensions/tree/main/doc +stof_doctrine_extensions: + default_locale: en_US + orm: + default: + timestampable: true \ No newline at end of file diff --git a/migrations/Version20230517165002.php b/migrations/Version20230517165002.php new file mode 100644 index 0000000..31fae8f --- /dev/null +++ b/migrations/Version20230517165002.php @@ -0,0 +1,46 @@ +addSql('CREATE TABLE document (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, name VARCHAR(255) NOT NULL, description LONGTEXT DEFAULT NULL, creation DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', modification DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_D8698A76A76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB' + ); + $this->addSql('CREATE TABLE document_tag (document_id int NOT NULL, tag_id int NOT NULL, INDEX IDX_D0234567C33F7837 (document_id), INDEX IDX_D0234567BAD26311 (tag_id), PRIMARY KEY(document_id, tag_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB' + ); + $this->addSql('CREATE TABLE tag (id int AUTO_INCREMENT NOT NULL, name varchar(50) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB' + ); + $this->addSql('CREATE TABLE user (id INT AUTO_INCREMENT NOT NULL, username VARCHAR(180) NOT NULL, roles LONGTEXT NOT NULL COMMENT \'(DC2Type:json)\', password VARCHAR(255) NOT NULL, UNIQUE INDEX UNIQ_8D93D649F85E0677 (username), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB' + ); + $this->addSql('CREATE TABLE messenger_messages (id bigint AUTO_INCREMENT NOT NULL, body longtext NOT NULL, headers longtext NOT NULL, queue_name varchar(190) NOT NULL, created_at datetime NOT NULL, available_at datetime NOT NULL, delivered_at datetime DEFAULT NULL, INDEX IDX_75EA56E0FB7336F0 (queue_name), INDEX IDX_75EA56E0E3BD61CE (available_at), INDEX IDX_75EA56E016BA31DB (delivered_at), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB' + ); + $this->addSql('ALTER TABLE document ADD CONSTRAINT FK_D8698A76A76ED395 FOREIGN KEY (user_id) REFERENCES user (id)'); + $this->addSql('ALTER TABLE document_tag ADD CONSTRAINT FK_D0234567C33F7837 FOREIGN KEY (document_id) REFERENCES document (id) ON DELETE CASCADE'); + $this->addSql('ALTER TABLE document_tag ADD CONSTRAINT FK_D0234567BAD26311 FOREIGN KEY (tag_id) REFERENCES tag (id) ON DELETE CASCADE'); + } + + public function down (Schema $schema): void { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE document DROP FOREIGN KEY FK_D8698A76A76ED395'); + $this->addSql('ALTER TABLE document_tag DROP FOREIGN KEY FK_D0234567C33F7837'); + $this->addSql('ALTER TABLE document_tag DROP FOREIGN KEY FK_D0234567BAD26311'); + $this->addSql('DROP TABLE document'); + $this->addSql('DROP TABLE document_tag'); + $this->addSql('DROP TABLE tag'); + $this->addSql('DROP TABLE user'); + $this->addSql('DROP TABLE messenger_messages'); + } +} diff --git a/src/Entity/Document.php b/src/Entity/Document.php index 18fd530..c5c1000 100644 --- a/src/Entity/Document.php +++ b/src/Entity/Document.php @@ -7,6 +7,7 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; +use Gedmo\Mapping\Annotation\Timestampable; #[ORM\Entity(repositoryClass: DocumentRepository::class)] class Document @@ -26,17 +27,18 @@ class Document #[ORM\Column(type: Types::TEXT, nullable: true)] private ?string $description = null; - #[ORM\Column(type: Types::DATETIME_MUTABLE)] + #[ORM\Column(type: Types::DATETIME_IMMUTABLE)] + #[Timestampable(on: 'create')] private ?\DateTimeInterface $creation = null; - #[ORM\Column(type: Types::DATETIME_MUTABLE)] + #[ORM\Column(type: Types::DATETIME_IMMUTABLE)] + #[Timestampable] private ?\DateTimeInterface $modification = null; #[ORM\ManyToMany(targetEntity: Tag::class, inversedBy: 'documents')] private Collection $tags; - public function __construct() - { + public function __construct () { $this->tags = new ArrayCollection(); } diff --git a/symfony.lock b/symfony.lock index 938fa01..a29fe66 100644 --- a/symfony.lock +++ b/symfony.lock @@ -49,6 +49,18 @@ "./tests/bootstrap.php" ] }, + "stof/doctrine-extensions-bundle": { + "version": "1.7", + "recipe": { + "repo": "github.com/symfony/recipes-contrib", + "branch": "main", + "version": "1.2", + "ref": "e805aba9eff5372e2d149a9ff56566769e22819d" + }, + "files": [ + "./config/packages/stof_doctrine_extensions.yaml" + ] + }, "symfony/console": { "version": "6.2", "recipe": {