Browse Source

Ajout d'un workflow

Sangfroid 5 months ago
parent
commit
d1606f7cd8
7 changed files with 187 additions and 5 deletions
  1. 3 2
      composer.json
  2. 90 3
      composer.lock
  3. 36 0
      config/packages/workflow.yaml
  4. 31 0
      migrations/Version20241023221635.php
  5. 15 0
      src/Entity/Article.php
  6. 12 0
      symfony.lock
  7. BIN
      workflow.png

+ 3 - 2
composer.json

@@ -42,6 +42,7 @@
         "symfony/ux-turbo": "^2.21",
         "symfony/validator": "7.1.*",
         "symfony/web-link": "7.1.*",
+        "symfony/workflow": "7.1.*",
         "symfony/yaml": "7.1.*",
         "twig/extra-bundle": "^2.12|^3.0",
         "twig/twig": "^2.12|^3.0"
@@ -77,9 +78,9 @@
     "scripts": {
         "auto-scripts": {
             "cache:clear": "symfony-cmd",
+            "ckeditor:install --tag=4.22.1": "symfony-cmd",
             "assets:install %PUBLIC_DIR%": "symfony-cmd",
-            "importmap:install": "symfony-cmd",
-            "ckeditor:install --tag=4.22.1": "symfony-cmd"
+            "importmap:install": "symfony-cmd"
         },
         "post-install-cmd": [
             "@auto-scripts"

+ 90 - 3
composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "467141bbdc6343d94dba80817b4ecfdc",
+    "content-hash": "3ec795619f12a12c89ef1c6569260bf3",
     "packages": [
         {
             "name": "composer/semver",
@@ -7362,6 +7362,93 @@
             ],
             "time": "2024-05-31T14:57:53+00:00"
         },
+        {
+            "name": "symfony/workflow",
+            "version": "v7.1.1",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/symfony/workflow.git",
+                "reference": "bc9a36fdd6a6fab9f630bd73b428aa06917e17e8"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/symfony/workflow/zipball/bc9a36fdd6a6fab9f630bd73b428aa06917e17e8",
+                "reference": "bc9a36fdd6a6fab9f630bd73b428aa06917e17e8",
+                "shasum": ""
+            },
+            "require": {
+                "php": ">=8.2"
+            },
+            "conflict": {
+                "symfony/event-dispatcher": "<6.4"
+            },
+            "require-dev": {
+                "psr/log": "^1|^2|^3",
+                "symfony/dependency-injection": "^6.4|^7.0",
+                "symfony/error-handler": "^6.4|^7.0",
+                "symfony/event-dispatcher": "^6.4|^7.0",
+                "symfony/expression-language": "^6.4|^7.0",
+                "symfony/http-kernel": "^6.4|^7.0",
+                "symfony/security-core": "^6.4|^7.0",
+                "symfony/stopwatch": "^6.4|^7.0",
+                "symfony/validator": "^6.4|^7.0"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "Symfony\\Component\\Workflow\\": ""
+                },
+                "exclude-from-classmap": [
+                    "/Tests/"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Fabien Potencier",
+                    "email": "fabien@symfony.com"
+                },
+                {
+                    "name": "Grégoire Pineau",
+                    "email": "lyrixx@lyrixx.info"
+                },
+                {
+                    "name": "Symfony Community",
+                    "homepage": "https://symfony.com/contributors"
+                }
+            ],
+            "description": "Provides tools for managing a workflow or finite state machine",
+            "homepage": "https://symfony.com",
+            "keywords": [
+                "petrinet",
+                "place",
+                "state",
+                "statemachine",
+                "transition",
+                "workflow"
+            ],
+            "support": {
+                "source": "https://github.com/symfony/workflow/tree/v7.1.1"
+            },
+            "funding": [
+                {
+                    "url": "https://symfony.com/sponsor",
+                    "type": "custom"
+                },
+                {
+                    "url": "https://github.com/fabpot",
+                    "type": "github"
+                },
+                {
+                    "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
+                    "type": "tidelift"
+                }
+            ],
+            "time": "2024-05-31T14:57:53+00:00"
+        },
         {
             "name": "symfony/yaml",
             "version": "v7.1.5",
@@ -9979,7 +10066,7 @@
     ],
     "aliases": [],
     "minimum-stability": "stable",
-    "stability-flags": [],
+    "stability-flags": {},
     "prefer-stable": true,
     "prefer-lowest": false,
     "platform": {
@@ -9987,6 +10074,6 @@
         "ext-ctype": "*",
         "ext-iconv": "*"
     },
-    "platform-dev": [],
+    "platform-dev": {},
     "plugin-api-version": "2.6.0"
 }

+ 36 - 0
config/packages/workflow.yaml

@@ -0,0 +1,36 @@
+framework:
+    workflows:
+        blog_publishing:
+            type: 'workflow' # or 'state_machine'
+            audit_trail:
+                enabled: true
+            marking_store:
+                type: 'method'
+                property: 'currentPlace'
+            supports:
+                - App\Entity\Article
+            initial_marking: draft
+            places:          # defining places manually is optional
+                - draft
+                - reviewed
+                - rejected
+                - published
+            transitions:
+                to_review:
+                    guard: is_granted('edit, 'article')
+                    from: rejected
+                    to:   reviewed
+                publish:
+                    guard: is_granted('edit', 'article')
+                    from: [reviewed, draft]
+                    to:   published
+                reject:
+                    guard: is_granted('ROLE_MODERATOR')
+                    from: [reviewed, published]
+                    to:   rejected
+                to_draft:
+                    guard: is_granted('edit, 'article')
+                    from: published
+                    to: draft
+
+

+ 31 - 0
migrations/Version20241023221635.php

@@ -0,0 +1,31 @@
+<?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 Version20241023221635 extends AbstractMigration
+{
+    public function getDescription(): string
+    {
+        return '';
+    }
+
+    public function up(Schema $schema): void
+    {
+        // this up() migration is auto-generated, please modify it to your needs
+        $this->addSql('ALTER TABLE article ADD state VARCHAR(64) NOT NULL DEFAULT "draft"');
+    }
+
+    public function down(Schema $schema): void
+    {
+        // this down() migration is auto-generated, please modify it to your needs
+        $this->addSql('ALTER TABLE article DROP state');
+    }
+}

+ 15 - 0
src/Entity/Article.php

@@ -27,6 +27,9 @@ class Article
     #[ORM\JoinColumn(nullable: false)]
     private ?User $author = null;
 
+    #[ORM\Column(length: 64)]
+    private ?string $state = null;
+
     public function __construct(User $author)
     {
         $this->setAuthor($author);
@@ -85,4 +88,16 @@ class Article
 
         return $this;
     }
+
+    public function getState(): ?string
+    {
+        return $this->state;
+    }
+
+    public function setState(string $state): static
+    {
+        $this->state = $state;
+
+        return $this;
+    }
 }

+ 12 - 0
symfony.lock

@@ -288,6 +288,18 @@
             "config/routes/web_profiler.yaml"
         ]
     },
+    "symfony/workflow": {
+        "version": "7.1",
+        "recipe": {
+            "repo": "github.com/symfony/recipes",
+            "branch": "main",
+            "version": "3.3",
+            "ref": "3b2f8ca32a07fcb00f899649053943fa3d8bbfb6"
+        },
+        "files": [
+            "config/packages/workflow.yaml"
+        ]
+    },
     "twig/extra-bundle": {
         "version": "v3.13.0"
     }

BIN
workflow.png