Symfony2 SyliusRbacBundle Setup - symfony

I am exploring the option of using SyliusRbacBundle for my app. I manage to install it along with FosUserBundle. When I got to the setup part I got the following error on running the command 'sylius:rbac:initialize' following the instructions found here: http://docs.sylius.org/en/latest/bundles/SyliusRbacBundle/setup.html#setup-roles-and-permissions-in-the-database
Initializing Sylius RBAC roles and permissions.
Adding permission "Update product". (app.product_update)
Adding permission "Create product". (app.product_create)
Adding permission "Manage product". (app.product_manage)
[Doctrine\DBAL\DBALException]
An exception occurred while executing 'INSERT INTO sylius_role (code, name,
description, security_roles, tree_left, tree_right, tree_level, created_at
, updated_at, parent_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' with params
["root", "Root", null, "a:0:{}", null, null, null, "2015-05-11 16:45:34",
"2015-05-11 16:45:34", null]:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'tree_left' ca
nnot be null
[PDOException]
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'tree_left' ca
nnot be null
sylius:rbac:initialize
This is how my config.yml looks like:
sylius_rbac:
driver: doctrine/orm
security_roles:
ROLE_ADMINISTRATION_ACCESS: Can access backend
roles:
app.admin:
name: Administrator
description: Administrator
app.product_manager:
name: Product Manager
description: muchos productos
permissions: [app.product_update, app.product_create]
roles_hierarchy:
app.admin: [app.product_manager]
permissions:
app.product_update: Update product
app.product_create: Create product
app.product_manage: Manage product
permissions_hierarchy:
app.product_manage: [app.product_create, app.product_update]
Any one has a clue how to solve it?
Thanks!

The Sylius/Rbac uses the tree behaviour from the Atlantic18/DoctrineExtensions.
You can use this in a Symfony system using the stof/StofDoctrineExtensionsBundle.
Once it has been installed you would need to enable the tree behaviour in your app/config/config.yml like..
stof_doctrine_extensions:
orm:
default:
tree: true
This should make the listener register correctly and then your fields to be auto-populated.

Related

How to override Product model in Sylius?

I am working on Sylius 1.2.8. I have overridden Product model and it is working fine but when I add a new product with attributes:
<?php
...
$em = $this->container->get('sylius.manager.product');
/**
* #var \Sylius\Component\Product\Model\ProductAttributeValueInterface $attribute
* #var \Sylius\Component\Core\Model\ProductInterface $product
*/
$product->addAttribute($attribute);
$em->persist($product);
$em->flush();
It throws this error:
An exception occurred while executing 'INSERT INTO
sylius_product_attribute_value (locale_code, text_value,
boolean_value, integer_value, float_value, datetime_value, date_value,
json_value, product_id, attribute_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?,
?, ?)' with params ["en_US", null, null, null, null, null, null,
"[\"013ea12a-1aff-4050-8107-20b53ada73ce\"]", null, 28]:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'product_id' cannot be null
My custom Product Model looks like this:
namespace AppBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Sylius\Component\Core\Model\Product as BaseProduct;
class Product extends BaseProduct implements ProductInterface
{
public function __construct()
{
parent::__construct();
}
}
And my config file:
sylius_product:
driver: doctrine/orm
resources:
product:
classes:
repository: AppBundle\Doctrine\ORM\ProductRepository
model: AppBundle\Entity\Product
I have found a similar question asked :stackoverflow.com/q/22919004/6248367. But this does not solve my problem neither does it answer why application fails. This answer is also 4 years old. Can someone help me fix this?
Edit: This error is also thrown in admin whenever I create a new product and add attributes to it at the same time. Workaround is to first create product, then add attributes.
I have figured out the problem. As #czende mentioned properly check the configuration.
In my case I had set the wrong class in subject while overriding the attribute:
sylius_product:
driver: doctrine/orm
resources:
product:
classes:
repository: AppBundle\Doctrine\ORM\ProductRepository
model: AppBundle\Entity\Product
sylius_attribute:
driver: doctrine/orm
resources:
product:
# Make sure to provide the correct Product class in the subject.
subject: AppBundle\Entity\Product
attribute:
classes:
model: AppBundle\Entity\ProductAttribute
repository: AppBundle\Doctrine\ORM\ProductAttributeRepository
Also make sure to use mappedSuperclass in the mapping config instead of entity as commented by Michał Marcinkowski in issue #3997
AppBundle\Entity\ProductAttribute:
type: mappedSuperclass
table: sylius_product_attribute
EDIT: To debug what's wrong, start by checking warnings in symfony debug bar. It can narrow down your search area for bug. It can also hint you if something is wrong in your configuration file.

Flyway "ORA-00955: name is already used by an existing object"

We are trying to use Flyway to manage our database schema updates with the following spring-boot configuration:
spring:
datasource:
driver-class-name: oracle.jdbc.OracleDriver
password: ${java_user_password}
url: ${DB_URL}
username: JAVA_USER
flyway:
locations: classpath:/db/migration
user: SUPER_USER
password: ${password_of_super_user}
baseline-on-migrate: true
url: ${DB_URL}
schema: JAVA_USER
Flyway version 5.1.4.
The configuration is working in Oracle 12.1.0.2.0 Standard Edition but not in Enterprise edition. We keep getting the following error:
SQL State : 42000
Error Code : 955
Message : ORA-00955: name is already used by an existing object
Line : 17
Statement : CREATE TABLE "JAVA_USER"."flyway_schema_history" (
"installed_rank" INT NOT NULL,
"version" VARCHAR2(50),
"description" VARCHAR2(200) NOT NULL,
"type" VARCHAR2(20) NOT NULL,
"script" VARCHAR2(1000) NOT NULL,
"checksum" INT,
"installed_by" VARCHAR2(100) NOT NULL,
"installed_on" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
"execution_time" INT NOT NULL,
"success" NUMBER(1) NOT NULL
)
Any idea why? Before starting the spring-boot application we delete all objects under the schemas.
Thanks!

SQL error using FR3DLdapBundle and FOSUserBundle with Symfony 2.8

When I log out and try to log back in again, it gives me the same error:
(An exception occurred while executing ‘INSERT INTO fos_user (username, username_canonical, email, email_canonical, enabled, salt, password, last_login, confirmation_token, password_requested_at, roles, dn, code_utilisateur) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)’ with params [“riemann”, “riemann”, “riemann#ldap.forumsys.com”, “riemann#ldap.forumsys.com”, 1, null, “”, “2018-05-23 21:26:15”, null, null, “a:1:{i:0;s:9:\”ROLE_USER\”;}”, “uid=riemann,dc=example,dc=com”, null]:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicata du champ ‘riemann#ldap.forumsys.com’ pour la clef ‘UNIQ_957A6479A0D96FBF’)
As if it is trying to insert at the places to update the user.
You need to change the order of the chain providers.
providers: [fos_userbundle, fr3d_ldapbundle]

FOSUserBundle: User being persisted and password is null when password confirmation doesn't match during registration

When implementing the following user story with the most recent version of FOSUserBundle (dev-master), instead of the form being invalidated because the passwords don't match, the data attempted to get persisted and fails because the passwords transformed to null values.
Why does this occur?
Feature Scenario:
Scenario: Trying to register with non verified password
Given I am on the "Login" page
And I follow "Sign Up"
When I fill in the following:
| Email | foo#bar.com |
| Username | jdoe |
| Password | bar |
| Verification | foo |
And I press "Register"
Then I should be on the Registration page
And I should see "The entered passwords don't match"
Error:
An exception occurred while executing 'INSERT INTO user_account (username, username_canonical, email, email_canonical, enabled, salt, password, last_login, locked, expired, expires_at, confirmation_token, password_requested_at, roles, credentials_expired, credentials_expire_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' with params ["jdoe", "jdoe", "foo#bar.com", "foo#bar.com", 1, "9z59n57td20cs88kw8gg8css80g0css", null, null, 0, 0, null, null, null, "a:0:{}", 0, null]:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'password' cannot be null
This occurs if you are using the Symfony 2.4 Validation API with newer versions of FOSUserBundle, which has recently started using the new Validation API introduced in Symfony 2.5.
The Validation API version may have been explicitly defined in app/config/config.yml as a workaround for a bug in Symfony 2.5 that affected the UniqueEntity constraint on the User model (ie. signing up with the same email address): https://github.com/FriendsOfSymfony/FOSUserBundle/issues/1516#issuecomment-47204302
validation:
enabled: true
enable_annotations: true
api: 2.4 # remove this line to fix the issue

Symfony - can't get multiple file upload to work

I'm using VichUploaderBundle to upload files for a gallery. I have two entities - the first one is Gallery, and the second is GalleryImage.
THis is the code:
http://pastebin.com/2nWAK2iH - Gallery Entity
http://pastebin.com/JWzWzZp2 - GalleryImage Entity
http://pastebin.com/TnZr24Sp - GalleryImageType Form
http://pastebin.com/9C8H25sn - GalleryType Form
http://tny.cz/26e859f6 - The Controller (part of it)
No matter what I do, I always get
"An exception occurred while executing 'INSERT INTO GalleryImage (image_name, gallery_id) VALUES (?, ?)' with params [null, 8]:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'image_name' cannot be null"
Any ideas what I'm doing wrong?
Thanks
UPDATE
The new GalleryImage file: http://pastebin.com/uKtqg4HE
Looks like the #Uploadable class annotation is missing in the GalleryImage class.

Resources