]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Added migration for user group
authorNicolas LÅ“uillet <nicolas@loeuillet.org>
Tue, 6 Sep 2016 18:21:49 +0000 (20:21 +0200)
committerThomas Citharel <tcit@tcit.fr>
Fri, 23 Jun 2017 07:18:39 +0000 (09:18 +0200)
Just a first draft of #805

app/DoctrineMigrations/Version20160906180558.php [new file with mode: 0644]
app/config/config.yml
app/config/routing.yml
src/Wallabag/UserBundle/Entity/Group.php [new file with mode: 0644]
src/Wallabag/UserBundle/Entity/User.php

diff --git a/app/DoctrineMigrations/Version20160906180558.php b/app/DoctrineMigrations/Version20160906180558.php
new file mode 100644 (file)
index 0000000..227bb20
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+
+namespace Application\Migrations;
+
+use Doctrine\DBAL\Migrations\AbstractMigration;
+use Doctrine\DBAL\Schema\Schema;
+
+/**
+ * Auto-generated Migration: Please modify to your needs!
+ */
+class Version20160906180558 extends AbstractMigration
+{
+    /**
+     * @param Schema $schema
+     */
+    public function up(Schema $schema)
+    {
+        $this->addSql('CREATE TABLE `wallabag_group` (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, roles LONGTEXT NOT NULL, UNIQUE INDEX UNIQ_B2305B375E237E06 (name), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
+        $this->addSql('CREATE TABLE wallabag_user_group (user_id INT NOT NULL, group_id INT NOT NULL, INDEX IDX_6E85169A76ED395 (user_id), INDEX IDX_6E85169FE54D947 (group_id), PRIMARY KEY(user_id, group_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB');
+        $this->addSql('ALTER TABLE wallabag_user_group ADD CONSTRAINT FK_6E85169A76ED395 FOREIGN KEY (user_id) REFERENCES `wallabag_user` (id)');
+        $this->addSql('ALTER TABLE wallabag_user_group ADD CONSTRAINT FK_6E85169FE54D947 FOREIGN KEY (group_id) REFERENCES `wallabag_group` (id)');
+    }
+
+    /**
+     * @param Schema $schema
+     */
+    public function down(Schema $schema)
+    {
+        $this->abortIf($this->connection->getDatabasePlatform()->getName() == 'sqlite', 'Migration can only be executed safely on \'mysql\'.');
+
+        $this->addSql('ALTER TABLE wallabag_user_group DROP FOREIGN KEY FK_6E85169FE54D947');
+        $this->addSql('DROP TABLE `wallabag_group`');
+        $this->addSql('DROP TABLE wallabag_user_group');
+    }
+}
index 2bc5e3b359292de4e5ff477d2fc976b81ab484f0..f1d93aaadca1b4aabc5d34d0582cbefa0e6d9df2 100644 (file)
@@ -178,6 +178,8 @@ fos_user:
     db_driver: orm
     firewall_name: secured_area
     user_class: Wallabag\UserBundle\Entity\User
+    group:
+        group_class: Wallabag\UserBundle\Entity\Group
     registration:
         confirmation:
             enabled: "%fosuser_confirmation%"
index 0bd2d130675140d54ee3f9c7d4d5b1acb20553e7..9c916f7dd6233274d778a19e57b06a00211bf213 100644 (file)
@@ -41,6 +41,10 @@ homepage:
 fos_user:
     resource: "@FOSUserBundle/Resources/config/routing/all.xml"
 
+fos_user_group:
+    resource: "@FOSUserBundle/Resources/config/routing/group.xml"
+    prefix: /group
+
 fos_oauth_server_token:
     resource: "@FOSOAuthServerBundle/Resources/config/routing/token.xml"
 
diff --git a/src/Wallabag/UserBundle/Entity/Group.php b/src/Wallabag/UserBundle/Entity/Group.php
new file mode 100644 (file)
index 0000000..9145959
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+
+namespace Wallabag\UserBundle\Entity;
+
+use FOS\UserBundle\Model\Group as BaseGroup;
+use Doctrine\ORM\Mapping as ORM;
+
+/**
+ * @ORM\Entity
+ * @ORM\Table(name="`group`")
+ */
+class Group extends BaseGroup
+{
+    /**
+     * @ORM\Id
+     * @ORM\Column(type="integer")
+     * @ORM\GeneratedValue(strategy="AUTO")
+     */
+    protected $id;
+}
index aba76ca74a262e3ddcc83b90d26519a0af151d2d..781f7b03f4c05dccd35261352d35cf48940330c6 100644 (file)
@@ -98,8 +98,16 @@ class User extends BaseUser implements TwoFactorInterface, TrustedComputerInterf
     private $authCode;
 
     /**
-     * @var bool
-     *
+     * @ORM\ManyToMany(targetEntity="Wallabag\UserBundle\Entity\Group")
+     * @ORM\JoinTable(name="user_group",
+     *      joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
+     *      inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")}
+     * )
+     */
+    protected $groups;
+
+    /**
+     * @var bool Enabled yes/no
      * @ORM\Column(type="boolean")
      */
     private $twoFactorAuthentication = false;