Skip to content

Change SonataPageBundle entities #1806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

eerison
Copy link
Contributor

@eerison eerison commented May 27, 2025

Copy link

github-actions bot commented May 27, 2025

Thanks for the PR 😍

How to test these changes in your application

  1. Define the SYMFONY_ENDPOINT environment variable:

    # On Unix-like (BSD, Linux and macOS)
    export SYMFONY_ENDPOINT=https://raw.githubusercontent.com/symfony/recipes-contrib/flex/pull-1806/index.json
    # On Windows
    SET SYMFONY_ENDPOINT=https://raw.githubusercontent.com/symfony/recipes-contrib/flex/pull-1806/index.json
  2. Install the package(s) related to this recipe:

    composer req symfony/flex
    composer req 'sonata-project/page-bundle:^4.9'
  3. Don't forget to unset the SYMFONY_ENDPOINT environment variable when done:

    # On Unix-like (BSD, Linux and macOS)
    unset SYMFONY_ENDPOINT
    # On Windows
    SET SYMFONY_ENDPOINT=

Diff between recipe versions

In order to help with the review stage, I'm in charge of computing the diff between the various versions of patched recipes.
I'm going keep this comment up to date with any updates of the attached patch.

sonata-project/page-bundle

3.9 vs 4.0
diff --git a/sonata-project/page-bundle/3.9/config/packages/sonata_page.yaml b/sonata-project/page-bundle/4.0/config/packages/sonata_page.yaml
index 6268a933..a8991ddc 100644
--- a/sonata-project/page-bundle/3.9/config/packages/sonata_page.yaml
+++ b/sonata-project/page-bundle/4.0/config/packages/sonata_page.yaml
@@ -1,16 +1,15 @@
 sonata_block:
-    context_manager: sonata.page.block.context_manager
     default_contexts: [sonata_page_bundle]
 
 sonata_admin:
     assets:
         extra_javascripts:
-            - bundles/sonatapage/sonata-page.back.min.js
+            - bundles/sonatapage/app.js
         extra_stylesheets:
-            - bundles/sonatapage/sonata-page.back.min.css
+            - bundles/sonatapage/app.css
 
+# https://docs.sonata-project.org/projects/SonataPageBundle/en/4.x/reference/advanced_configuration/
 sonata_page:
-    slugify_service: sonata.page.slugify.cocur
     multisite: host
     use_streamed_response: false
 
@@ -33,6 +32,7 @@ sonata_page:
     ignore_uri_patterns:
         - ^/admin\/   # ignore admin route, ie route containing 'admin'
 
+    #https://docs.sonata-project.org/projects/SonataPageBundle/en/4.x/reference/page_composer/
     default_template: default
     templates:
         default:
@@ -74,9 +74,3 @@ sonata_page:
     catch_exceptions:
         not_found: [404]    # render 404 page with "not_found" key (name generated: _page_internal_error_{key})
         fatal:     [500]    # so you can use the same page for different http errors or specify specific page for each error
-
-    class:
-        page: 'App\Entity\SonataPagePage'
-        snapshot: 'App\Entity\SonataPageSnapshot'
-        block: 'App\Entity\SonataPageBlock'
-        site: 'App\Entity\SonataPageSite'
diff --git a/sonata-project/page-bundle/3.9/config/routes/sonata_page.yaml b/sonata-project/page-bundle/4.0/config/routes/sonata_page.yaml
index 764a52b0..f824032f 100644
--- a/sonata-project/page-bundle/3.9/config/routes/sonata_page.yaml
+++ b/sonata-project/page-bundle/4.0/config/routes/sonata_page.yaml
@@ -1,11 +1,3 @@
-#sonata_page_api:
-#    resource: '@SonataPageBundle/Resources/config/routing/api.xml'
-#    prefix: /
-
-#sonata_page_cache:
-#    resource: '@SonataPageBundle/Resources/config/routing/cache.xml'
-#    prefix: /
-
 sonata_page_exceptions:
     resource: '@SonataPageBundle/Resources/config/routing/exceptions.xml'
     prefix: /
diff --git a/sonata-project/page-bundle/4.0/post-install.txt b/sonata-project/page-bundle/4.0/post-install.txt
new file mode 100644
index 00000000..51058e42
--- /dev/null
+++ b/sonata-project/page-bundle/4.0/post-install.txt
@@ -0,0 +1,13 @@
+ * Your Page is almost ready:
+    1. Generate a migration for Sonata Page Database php bin/console doctrine:migrations:diff
+        
+            If you use Doctrine Attribute Reference, You must change Sonata Entities generated in Entity folder.
+            You can check more details at https://www.doctrine-project.org/projects/doctrine-orm/en/current/reference/attributes-reference.html
+
+            You can also use Rector to refactor, check more details at https://getrector.org/blog/how-to-upgrade-annotations-to-attributes
+        
+    2. Apply the migration generated php bin/console doctrine:migrations:migrate --no-interaction
+    3. Create your first site: bin/console sonata:page:create-site --enabled --name=localhost --locale=- --host=localhost --relativePath=- --enabledFrom=now --enabledTo=- --default
+        After you generate your site, You will see few commands to execute to have your Site ready.
+
+  * Read the documentation at https://docs.sonata-project.org/projects/SonataPageBundle/en/4.x/
diff --git a/sonata-project/page-bundle/3.9/src/Entity/SonataPageBlock.php b/sonata-project/page-bundle/4.0/src/Entity/SonataPageBlock.php
index 417e8b47..b7144825 100644
--- a/sonata-project/page-bundle/3.9/src/Entity/SonataPageBlock.php
+++ b/sonata-project/page-bundle/4.0/src/Entity/SonataPageBlock.php
@@ -5,13 +5,11 @@ declare(strict_types=1);
 namespace App\Entity;
 
 use Doctrine\ORM\Mapping as ORM;
-use JMS\Serializer\Annotation as Serializer;
 use Sonata\PageBundle\Entity\BaseBlock;
 
 /**
  * @ORM\Entity
  * @ORM\Table(name="page__block")
- * @ORM\HasLifecycleCallbacks
  */
 class SonataPageBlock extends BaseBlock
 {
@@ -19,63 +17,8 @@ class SonataPageBlock extends BaseBlock
      * @ORM\Id
      * @ORM\Column(type="integer")
      * @ORM\GeneratedValue(strategy="AUTO")
-     * // Serializer\Groups(groups={"sonata_api_read","sonata_api_write","sonata_search"})
      *
      * @var int
      */
     protected $id;
-
-    /**
-     * @ORM\OneToMany(
-     *     targetEntity="App\Entity\SonataPageBlock",
-     *     mappedBy="parent", cascade={"remove", "persist"}, orphanRemoval=true
-     * )
-     * @ORM\OrderBy({"position"="ASC"})
-     *
-     * @var SonataPageBlock[]
-     */
-    protected $children;
-
-    /**
-     * @ORM\ManyToOne(
-     *     targetEntity="App\Entity\SonataPageBlock",
-     *     inversedBy="children"
-     * )
-     * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE")
-     *
-     * @var SonataPageBlock
-     */
-    protected $parent;
-
-    /**
-     * @ORM\ManyToOne(
-     *     targetEntity="App\Entity\SonataPagePage",
-     *     inversedBy="blocks", cascade={"persist"}
-     * )
-     * @ORM\JoinColumn(name="page_id", referencedColumnName="id", onDelete="CASCADE")
-     *
-     * @var SonataPagePage
-     */
-    protected $page;
-
-    public function getId()
-    {
-        return $this->id;
-    }
-
-    /**
-     * @ORM\PrePersist
-     */
-    public function prePersist(): void
-    {
-        parent::prePersist();
-    }
-
-    /**
-     * @ORM\PreUpdate
-     */
-    public function preUpdate(): void
-    {
-        parent::preUpdate();
-    }
 }
diff --git a/sonata-project/page-bundle/3.9/src/Entity/SonataPagePage.php b/sonata-project/page-bundle/4.0/src/Entity/SonataPagePage.php
index b9f2fbdd..eed26221 100644
--- a/sonata-project/page-bundle/3.9/src/Entity/SonataPagePage.php
+++ b/sonata-project/page-bundle/4.0/src/Entity/SonataPagePage.php
@@ -5,13 +5,11 @@ declare(strict_types=1);
 namespace App\Entity;
 
 use Doctrine\ORM\Mapping as ORM;
-use JMS\Serializer\Annotation as Serializer;
 use Sonata\PageBundle\Entity\BasePage;
 
 /**
  * @ORM\Entity
  * @ORM\Table(name="page__page")
- * @ORM\HasLifecycleCallbacks
  */
 class SonataPagePage extends BasePage
 {
@@ -19,95 +17,8 @@ class SonataPagePage extends BasePage
      * @ORM\Id
      * @ORM\Column(type="integer")
      * @ORM\GeneratedValue(strategy="AUTO")
-     * // Serializer\Groups(groups={"sonata_api_read","sonata_api_write","sonata_search"})
      *
      * @var int
      */
     protected $id;
-
-    /**
-     * @ORM\OneToMany(
-     *     targetEntity="App\Entity\SonataPagePage",
-     *     mappedBy="parent", cascade={"persist"}, orphanRemoval=false
-     * )
-     * @ORM\OrderBy({"position"="ASC"})
-     *
-     * @var SonataPagePage[]
-     */
-    protected $children;
-
-    /**
-     * @ORM\OneToMany(
-     *     targetEntity="App\Entity\SonataPageBlock",
-     *     mappedBy="page", cascade={"remove", "persist", "refresh", "merge", "detach"}, orphanRemoval=false
-     * )
-     * @ORM\OrderBy({"position"="ASC"})
-     *
-     * @var SonataPageBlock[]
-     */
-    protected $blocks;
-
-    /**
-     * @ORM\ManyToOne(
-     *     targetEntity="App\Entity\SonataPageSite",
-     *     cascade={"persist"}
-     * )
-     * @ORM\JoinColumn(name="site_id", referencedColumnName="id", onDelete="CASCADE")
-     *
-     * @var SonataPageSite
-     */
-    protected $site;
-
-    /**
-     * @ORM\ManyToOne(
-     *     targetEntity="App\Entity\SonataPagePage",
-     *     inversedBy="children", cascade={"persist"}
-     * )
-     * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE")
-     *
-     * @var SonataPagePage
-     */
-    protected $parent;
-
-    /**
-     * @ORM\OneToMany(
-     *     targetEntity="App\Entity\SonataPagePage",
-     *     mappedBy="target", orphanRemoval=false
-     * )
-     *
-     * @var SonataPagePage[]
-     */
-    protected $sources;
-
-    /**
-     * @ORM\ManyToOne(
-     *     targetEntity="App\Entity\SonataPagePage",
-     *     inversedBy="sources", cascade={"persist"}
-     * )
-     * @ORM\JoinColumn(name="target_id", referencedColumnName="id", onDelete="CASCADE")
-     *
-     * @var SonataPagePage
-     */
-    protected $target;
-
-    public function getId()
-    {
-        return $this->id;
-    }
-
-    /**
-     * @ORM\PrePersist
-     */
-    public function prePersist(): void
-    {
-        parent::prePersist();
-    }
-
-    /**
-     * @ORM\PreUpdate
-     */
-    public function preUpdate(): void
-    {
-        parent::preUpdate();
-    }
 }
diff --git a/sonata-project/page-bundle/3.9/src/Entity/SonataPageSite.php b/sonata-project/page-bundle/4.0/src/Entity/SonataPageSite.php
index 9d2b688a..7a195aac 100644
--- a/sonata-project/page-bundle/3.9/src/Entity/SonataPageSite.php
+++ b/sonata-project/page-bundle/4.0/src/Entity/SonataPageSite.php
@@ -5,13 +5,11 @@ declare(strict_types=1);
 namespace App\Entity;
 
 use Doctrine\ORM\Mapping as ORM;
-use JMS\Serializer\Annotation as Serializer;
 use Sonata\PageBundle\Entity\BaseSite;
 
 /**
  * @ORM\Entity
  * @ORM\Table(name="page__site")
- * @ORM\HasLifecycleCallbacks
  */
 class SonataPageSite extends BaseSite
 {
@@ -19,30 +17,8 @@ class SonataPageSite extends BaseSite
      * @ORM\Id
      * @ORM\Column(type="integer")
      * @ORM\GeneratedValue(strategy="AUTO")
-     * \\ Serializer\Groups(groups={"sonata_api_read","sonata_api_write","sonata_search"})
      *
      * @var int
      */
     protected $id;
-
-    public function getId()
-    {
-        return $this->id;
-    }
-
-    /**
-     * @ORM\PrePersist
-     */
-    public function prePersist(): void
-    {
-        parent::prePersist();
-    }
-
-    /**
-     * @ORM\PreUpdate
-     */
-    public function preUpdate(): void
-    {
-        parent::preUpdate();
-    }
 }
diff --git a/sonata-project/page-bundle/3.9/src/Entity/SonataPageSnapshot.php b/sonata-project/page-bundle/4.0/src/Entity/SonataPageSnapshot.php
index 9560a863..bbd3637d 100644
--- a/sonata-project/page-bundle/3.9/src/Entity/SonataPageSnapshot.php
+++ b/sonata-project/page-bundle/4.0/src/Entity/SonataPageSnapshot.php
@@ -5,7 +5,6 @@ declare(strict_types=1);
 namespace App\Entity;
 
 use Doctrine\ORM\Mapping as ORM;
-use JMS\Serializer\Annotation as Serializer;
 use Sonata\PageBundle\Entity\BaseSnapshot;
 
 /**
@@ -22,36 +21,8 @@ class SonataPageSnapshot extends BaseSnapshot
      * @ORM\Id
      * @ORM\Column(type="integer")
      * @ORM\GeneratedValue(strategy="AUTO")
-     * // Serializer\Groups(groups={"sonata_api_read","sonata_api_write","sonata_search"})
      *
      * @var int
      */
     protected $id;
-
-    /**
-     * @ORM\ManyToOne(
-     *     targetEntity="App\Entity\SonataPageSite",
-     *     cascade={"persist"}
-     * )
-     * @ORM\JoinColumn(name="site_id", referencedColumnName="id", onDelete="CASCADE")
-     *
-     * @var SonataPageSite
-     */
-    protected $site;
-
-    /**
-     * @ORM\ManyToOne(
-     *     targetEntity="App\Entity\SonataPagePage",
-     *     cascade={"persist"}
-     * )
-     * @ORM\JoinColumn(name="page_id", referencedColumnName="id", onDelete="CASCADE")
-     *
-     * @var SonataPagePage
-     */
-    protected $page;
-
-    public function getId()
-    {
-        return $this->id;
-    }
 }
4.0 vs 4.9
diff --git a/sonata-project/page-bundle/4.0/post-install.txt b/sonata-project/page-bundle/4.9/post-install.txt
index 51058e42..96ae9577 100644
--- a/sonata-project/page-bundle/4.0/post-install.txt
+++ b/sonata-project/page-bundle/4.9/post-install.txt
@@ -1,11 +1,5 @@
  * Your Page is almost ready:
     1. Generate a migration for Sonata Page Database php bin/console doctrine:migrations:diff
-        
-            If you use Doctrine Attribute Reference, You must change Sonata Entities generated in Entity folder.
-            You can check more details at https://www.doctrine-project.org/projects/doctrine-orm/en/current/reference/attributes-reference.html
-
-            You can also use Rector to refactor, check more details at https://getrector.org/blog/how-to-upgrade-annotations-to-attributes
-        
     2. Apply the migration generated php bin/console doctrine:migrations:migrate --no-interaction
     3. Create your first site: bin/console sonata:page:create-site --enabled --name=localhost --locale=- --host=localhost --relativePath=- --enabledFrom=now --enabledTo=- --default
         After you generate your site, You will see few commands to execute to have your Site ready.
diff --git a/sonata-project/page-bundle/4.0/src/Entity/SonataPageBlock.php b/sonata-project/page-bundle/4.9/src/Entity/SonataPageBlock.php
index b7144825..0412b8d7 100644
--- a/sonata-project/page-bundle/4.0/src/Entity/SonataPageBlock.php
+++ b/sonata-project/page-bundle/4.9/src/Entity/SonataPageBlock.php
@@ -4,21 +4,16 @@ declare(strict_types=1);
 
 namespace App\Entity;
 
+use Doctrine\DBAL\Types\Types;
 use Doctrine\ORM\Mapping as ORM;
-use Sonata\PageBundle\Entity\BaseBlock;
+use Sonata\PageBundle\Entity\BasePage;
 
-/**
- * @ORM\Entity
- * @ORM\Table(name="page__block")
- */
-class SonataPageBlock extends BaseBlock
+#[ORM\Entity]
+#[ORM\Table(name: 'page__page')]
+class SonataPagePage extends BasePage
 {
-    /**
-     * @ORM\Id
-     * @ORM\Column(type="integer")
-     * @ORM\GeneratedValue(strategy="AUTO")
-     *
-     * @var int
-     */
+    #[ORM\Id]
+    #[ORM\Column(type: Types::INTEGER)]
+    #[ORM\GeneratedValue]
     protected $id;
 }
diff --git a/sonata-project/page-bundle/4.0/src/Entity/SonataPagePage.php b/sonata-project/page-bundle/4.9/src/Entity/SonataPagePage.php
index eed26221..0412b8d7 100644
--- a/sonata-project/page-bundle/4.0/src/Entity/SonataPagePage.php
+++ b/sonata-project/page-bundle/4.9/src/Entity/SonataPagePage.php
@@ -4,21 +4,16 @@ declare(strict_types=1);
 
 namespace App\Entity;
 
+use Doctrine\DBAL\Types\Types;
 use Doctrine\ORM\Mapping as ORM;
 use Sonata\PageBundle\Entity\BasePage;
 
-/**
- * @ORM\Entity
- * @ORM\Table(name="page__page")
- */
+#[ORM\Entity]
+#[ORM\Table(name: 'page__page')]
 class SonataPagePage extends BasePage
 {
-    /**
-     * @ORM\Id
-     * @ORM\Column(type="integer")
-     * @ORM\GeneratedValue(strategy="AUTO")
-     *
-     * @var int
-     */
+    #[ORM\Id]
+    #[ORM\Column(type: Types::INTEGER)]
+    #[ORM\GeneratedValue]
     protected $id;
 }
diff --git a/sonata-project/page-bundle/4.0/src/Entity/SonataPageSite.php b/sonata-project/page-bundle/4.9/src/Entity/SonataPageSite.php
index 7a195aac..f230fd22 100644
--- a/sonata-project/page-bundle/4.0/src/Entity/SonataPageSite.php
+++ b/sonata-project/page-bundle/4.9/src/Entity/SonataPageSite.php
@@ -4,21 +4,16 @@ declare(strict_types=1);
 
 namespace App\Entity;
 
+use Doctrine\DBAL\Types\Types;
 use Doctrine\ORM\Mapping as ORM;
 use Sonata\PageBundle\Entity\BaseSite;
 
-/**
- * @ORM\Entity
- * @ORM\Table(name="page__site")
- */
+#[ORM\Entity]
+#[ORM\Table(name: 'page__site')]
 class SonataPageSite extends BaseSite
 {
-    /**
-     * @ORM\Id
-     * @ORM\Column(type="integer")
-     * @ORM\GeneratedValue(strategy="AUTO")
-     *
-     * @var int
-     */
+    #[ORM\Id]
+    #[ORM\Column(type: Types::INTEGER)]
+    #[ORM\GeneratedValue]
     protected $id;
 }
diff --git a/sonata-project/page-bundle/4.0/src/Entity/SonataPageSnapshot.php b/sonata-project/page-bundle/4.9/src/Entity/SonataPageSnapshot.php
index bbd3637d..4d9c329d 100644
--- a/sonata-project/page-bundle/4.0/src/Entity/SonataPageSnapshot.php
+++ b/sonata-project/page-bundle/4.9/src/Entity/SonataPageSnapshot.php
@@ -4,25 +4,16 @@ declare(strict_types=1);
 
 namespace App\Entity;
 
+use Doctrine\DBAL\Types\Types;
 use Doctrine\ORM\Mapping as ORM;
 use Sonata\PageBundle\Entity\BaseSnapshot;
 
-/**
- * @ORM\Entity
- * @ORM\Table(name="page__snapshot", indexes={
- *     @ORM\Index(
- *         name="idx_snapshot_dates_enabled", columns={"publication_date_start", "publication_date_end","enabled"
- *     })
- * })
- */
+#[ORM\Entity]
+#[ORM\Table(name: 'page__snapshot')]
 class SonataPageSnapshot extends BaseSnapshot
 {
-    /**
-     * @ORM\Id
-     * @ORM\Column(type="integer")
-     * @ORM\GeneratedValue(strategy="AUTO")
-     *
-     * @var int
-     */
+    #[ORM\Id]
+    #[ORM\Column(type: Types::INTEGER)]
+    #[ORM\GeneratedValue]
     protected $id;
 }

@eerison eerison force-pushed the update-sonata-page-recipes branch from 574e0d9 to a1e9f10 Compare May 27, 2025 17:02
@eerison eerison force-pushed the update-sonata-page-recipes branch from a1e9f10 to c6a751a Compare May 27, 2025 17:07
@eerison eerison closed this May 27, 2025
@eerison eerison deleted the update-sonata-page-recipes branch May 27, 2025 17:11
@eerison eerison restored the update-sonata-page-recipes branch May 27, 2025 17:11
@eerison eerison deleted the update-sonata-page-recipes branch May 27, 2025 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant