Issue 1:
After i integrated console.command tags into Shopware shopware5/shopware#559 we hade a discussion about Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass and its FrameworkBundle dependency.

A project with symfony/console and symfony/dependency-injection need to copy this CompilerPass. @bcremer and @xabbuh had some ideas to move this class.

Maybe we can optimize command registration over dic somehow.

Issue 2:
Symfony: 2.5.9

Doctrine ORM: 2.4.6

Doctrine bundle: 1.2

Hello -

I have come across a strange issue with processing form collections in Symfony.

I have a User entity that has a collection of List Items associated with it. Each List Item entity also references another entity, Topic. I have setup a UNIQUE constraint on the List Item table that will only allow unique combinations of the User and Topic foreign keys. Essentially - no List Items with a duplicate reference to the Topic entity are allowed for each user.

/**
* @ORM\Entity(repositoryClass="App\MyBundle\Repository\ListItemRepository")
* @ORM\Table(
* name="list_items",
* uniqueConstraints={@ORM\UniqueConstraint(name="list_item_user_topic", columns={"user_id","topic_id"})}
* )
*
* @Gedmo\SoftDeleteable(fieldName="deleted_at", timeAware=true)
*/
class ListItem
{
...

I am using Symfony form builder to build the form. This is working great. I have added javascript for add/remove buttons on the frontend. In general - I am able to save and persist the form collection without any problems.

However - there are time when I will be attempting to persist the User entity and the List Item form collection and it will fail with an integrity constraint violation.

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '6-1' for key 'list_item_user_topic'

This was initially very strange to me because I also have an event listener that is listening to the Doctrine "onFlush" event that does the following:

Check if the entity is a List Item

If it is a List Item, it checks the database for an existing record for that user

Since I am using SoftDeletes - if the record exists and it's been soft deleted - it will un-delete the record and replace the new duplicate record with it - maintaining the record in the database.

If a duplicate record that is published is found - it will simply remove the new duplicate record from the scheduled inserts and keep the one in the database.

This is all happening onFlush - which occurs AFTER handleRequest. What I discovered is that when the form is being processed - something is happening within the handleRequest() method that is swapping out foreign key references on different rows. Like so:

Original Item List for a user:

ID	user_id	topic_id	info

1	10	57	extra info

2	10	83	extra info

3	10	233	extra info

After form passes through the handleRequest() method:

ID	user_id	topic_id	info

1	10	233	extra info

2	10	83	extra info

3	10	57	extra info

This then causes the integrity constraint violation when it attempts to write the first record because it is violating the unique constraint on the List Items table. What I do not understand is how/why the handleRequest() method would be swapping foreign keys on update.

The other really strange thing is that in many cases - the form will persist fine for a user. I hate to use the word "random" here but I have not been able to identify a way to duplicate the issue other than just working with the entity for a while and performing CRUD operations on it. Many times the form persists fine - other times the foreign key references get swapped and I am unable to submit the form to update the entity because of the UNIQUE constraint.

Has anyone experienced similar issues or have some insight on why this might be occurring? Is this a bug in the handleRequest() method? This will occur even if I have not made any changes to the List Item collection. As in - if I edit a user and simply submit the form without making any changes - this behavior will still occur.

public function editAction($id, Request $request)
{
// Get entity manager
$em = $this->getDoctrine()->getManager();

// Fetch data to populate form
$user = $this
->get('user_repository')
->fetchProfileById($id)
->getQuery()
->getSingleResult();

// Build form
$form = $this->createForm('user', $user);

// Handle request
$form->handleRequest($request);

// Form validation
if ($form->isValid())
{
try
{
$em->flush();

$message = 'User updated successfully!';

// Return successful message
$this->get('session')
->getFlashBag()
->add('success', $message);
}
catch (Exception $e)
{
$message = 'There was an error updating the user.' . $e->getMessage();

// Return error message
$this->get('session')
->getFlashBag()
->add('error', $message);
}

// Return view
return new RedirectResponse($this->generateUrl('users_list'));
}
}