PHPackages                             yeroon/doctrine-fictures-extra-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. yeroon/doctrine-fictures-extra-bundle

ActiveSymfony-bundle[Database &amp; ORM](/categories/database)

yeroon/doctrine-fictures-extra-bundle
=====================================

Adds a command to validate, drop and create schema and load fixtures in one go.

0.1.2(11y ago)01.5kMITPHPPHP ~5.4

Since Sep 1Pushed 11y ago1 watchersCompare

[ Source](https://github.com/yeroon/doctrine-fixtures-extra-bundle)[ Packagist](https://packagist.org/packages/yeroon/doctrine-fictures-extra-bundle)[ RSS](/packages/yeroon-doctrine-fictures-extra-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (4)Used By (0)

Yeroon Doctrine Fixtures Extra Bundle
=====================================

[](#yeroon-doctrine-fixtures-extra-bundle)

The Yeroon Doctrine Fixtures Extra Bundle adds a command to your Symfony application to recreate your database schema and to load fixtures in one go. When run, it:

- Validates your schema (`doctrine:schema:validate`)
- When valid, drops the database (`doctrine:database:drop`)
- Recreates the database (`doctrine:database:create`)
- Rebuilds the schema (`doctrine:schema:update`)
- And finally loads your fixtures (`doctrine:fixtures:load`)

This way, only *one* command is needed to re-create an up-to-date database with data for your `dev` environment. Other environments are supported, but not recommended (Data *will* be lost, ofcourse).

Features
--------

[](#features)

- Supports multiple Entity Managers.
- Event-driven. Event Listeners can be attached to extend functionality (see 'Events').
- Aborts when your schema is not valid.
- Built on top of existing Doctrine commands.
- Doctrine MongoDB ODM support thorugh an additional command.
- Supports multiple Document Managers for Doctrine MongoDB ODM.

Dependencies
------------

[](#dependencies)

- DoctrineBundle
- DoctrineFixturesBundle

Installation
------------

[](#installation)

### 1. Add yeroon/doctrine-fixtures-extra-bundle to your composer.json:

[](#1-add-yeroondoctrine-fixtures-extra-bundle-to-your-composerjson)

```
"require": {
    ...
    "yeroon/doctrine-fixtures-extra-bundle": "~0.1.*",
}

```

### 2. Add DoctrineFixturesExtraBundle to your AppKernel:

[](#2-add-doctrinefixturesextrabundle-to-your-appkernel)

```
// app/AppKernel.php
public function registerBundles()
{
    if (in_array($this->getEnvironment(), array('dev', 'test'))) {
        // ..
        $bundles[] = new Yeroon\Bundle\DoctrineFixturesExtraBundle\YeroonDoctrineFixturesExtraBundle();
    }
}

```

The example above adds the Bundle in the `dev` and `test` environments only (recommended).

Events
======

[](#events)

The command triggers six events. The events, in order, are:

event namedescriptioninitTriggered at the start of the command. Useful to add checks or validation. For example, the"`WarnUserEventListener` is configured to listen to this event.on\_validate\_schemaHappens when the schema gets validated (Immediately after `doctrine:schema:validate`)on\_drop\_databaseHappens when the database will be dropped (Immediately after `doctrine:database:drop`)on\_create\_databaseHappens when the database is (re)created (Immediately after `doctrine:database:create`)on\_schema\_updateHappens when the schema gets updated (Immediately after `doctrine:schema:update`)on\_load\_fixtureHappens when the fixtures are loaded (Immediately after `doctrine:fixtures:load`)Examples
========

[](#examples)

Example 1: Standard behaviour
-----------------------------

[](#example-1-standard-behaviour)

Below is a sample output of the command:

```
$ php app/console yeroon:doctrine:fixtures:rebuildandload
WARNING! You are about to drop the database(s) and rebuild the schema(s). ALL data will be lost. Are you sure you wish to continue? (y/n)y
[Mapping]  OK - The mapping files are correct.
[Database] OK - The database schema is in sync with the mapping files.
Dropped database for connection named `my_database`
Created database for connection named `my_database`
Updating database schema...
Database schema updated successfully! "5" queries were executed
  > purging database
  > loading Productr\Bundle\CatalogBundle\DataFixtures\ORM\ExampleFixtureLoader

```

It first asks if you want to continue. If yes, it will check the current mapping against your database with the `doctrine:schema:validate` command. If it is not valid the Command will abort. If it is valid, the Command will drop the entire database and recreate it using the `doctrine:database:drop` and `doctrine:database:create` commands. When that is done, the command `doctrine:schema:update` will be executed to create the schema. Finally, your fixtures will be loaded through the `doctrine:fixtures:load`. Now you have a database in sync with your schema and filled with fixture data!

Example 2: Attach EventListeners to purge a Solr index and insert new data
--------------------------------------------------------------------------

[](#example-2-attach-eventlisteners-to-purge-a-solr-index-and-insert-new-data)

This example shows you how you can can attach event listeners that deletes data from your Solr core, and inserts new data when fixtures are loaded.

Write custom Event Listener to delete Solr documents:

```
// file: src/Acme/YourBundle/EventListener/SolrPurgeEventListener.php
