Giter VIP home page Giter VIP logo

doctrinefixturesgeneratorbundle's People

Contributors

andreybolonin avatar andreyserdjuk avatar benji62f avatar head1328 avatar kuldipem avatar n-m avatar pborreli avatar ramzes13 avatar remedge avatar webonaute avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

doctrinefixturesgeneratorbundle's Issues

Ability to exclude vendor mapping

I have the following configuration:

entity_managers:
            default:
                connection: default
                naming_strategy: doctrine.orm.naming_strategy.underscore
                mappings:
                    AppBundle: ~
                    gedmo_translatable:
                        type: annotation
                        prefix: Gedmo\Translatable\Entity
                        dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity"
                        alias: GedmoTranslatable # (optional) it will default to the name set for the mapping
                        is_bundle: false

But it throws

[LogicException]
  No bundle found for entity namespace Gedmo\Translatable\Entity

I have to comment the gedmo_translatable section for now, since I have not yet translated my database.

I know it is said that vendor entities are not supported yet, but how can I ignore that mapping for now without commenting, since I cannot use an annotation to ignore it?

Of course I am left wondering how I will be able to reverse translations in the future, but I guess this is another issue!

Support for Doctrine Custom Mapping Types seems to be missing

It seems like FixtureGenerator::generateFixtureItemStub doesn't support Doctrine Custom Mapping Types which returns object as a PHP value from convertToPHPValue method rather than \DateTime object.
Following code will fail to generate fixtures from database with error message
The class 'AppBundle\Doctrine\Entity\MyCustomValue' was not found in the chain configured namespaces AppBundle\Entity, Webonaute\DoctrineFixturesGeneratorBundle\Entity.

# app/config/config.yml

# Doctrine Configuration
doctrine:
    dbal:
        types:
            my_custom_value: AppBundle\Doctrine\DBAL\MyCustomValueType
// src/AppBundle/Doctrine/DBAL/MyCustomValueType.php
<?php

namespace AppBundle\Doctrine\DBAL;

use AppBundle\Doctrine\Entity\MyCustomValue;
use Doctrine\DBAL\Types\StringType;
use Doctrine\DBAL\Platforms\AbstractPlatform;

class MyCustomValueType extends StringType
{
    const TYPE_NAME = 'my_custom_value';

    public function convertToPHPValue($value, AbstractPlatform $platform)
    {
        $convertedValue = parent::convertToPHPValue($value, $platform);

        return new MyCustomValue($convertedValue);
    }

    public function convertToDatabaseValue($value, AbstractPlatform $platform)
    {
        $value = parent::convertToDatabaseValue($value->__toString(), $platform);

        return $value;
    }

    public function getName()
    {
        return self::TYPE_NAME;
    }
}
// src/AppBundle/Doctrine/Entity/MyCustomValue.php

namespace AppBundle\Doctrine\Entity;

class MyCustomValue
{
    protected $value

    public function __construct($value)
    {
        $this->value = $value;
    }

    public function __toString()
    {
        return $this->value;
    }
}
<?php
// src/AppBundle/Entity/Blog.php

namespace AppBundle\Entity;

use AppBundle\Doctrine\Entity\MyCustomValue;

class Blog
{
    /**
     * @var MyCustomValue
     * @ORM\Column(name="name", type="my_custom_value")
     */
    private $name;

    public function setName(MyCustomValue $name)
    {
        $this->name = $name;

        return $this;
    }

    public function getName() : MyCustomValue
    {
        return $this->name;
    }
}

Annotation throws error

I want to ignore timestamp field. I've followed docs and I get this error.

[Doctrine\Common\Annotations\AnnotationException]                                                                 
  [Semantical Error] The annotation "@Webonaute\DoctrineFixturesGeneratorBundle\Annotations\Property" in property   
  AppBundle\Entity\Room::$modified_at does not exist, or could not be auto-loaded.      

v2.0-dev and Symfony 3.4 non Flex

Hi, thanks for your work !

I managed to make your bundle work under a Sf 3.4 non flex project.

I don't know if there are more to do, because it seams a bit hacky but here is what I did :

  • In every bundle, i.e AdminBundle.php at the bundle root, add a toString method
  • Example :
<?php

namespace AdminBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class AdminBundle extends Bundle
{
    public function __toString()
    {
        return $this->getPath();
    }
}
  • The key point is to give the path, so that the generated classes are created at the right place. With $this->getName(), folders and classes are located at the project root, same level as 'src'.

I said hacky because of the __toString method.

  • Maybe updating the DoctrineFixtureGenerator::generate line 78 could do the trick, since $bundle is an object and not a string, but I didn't dig that much on the SYMFONY_4_BUNDLE_ALIAS constants deep meaning.

Maybe this 'hack' could end in the documentation, because its a pity not to benefits your work on many-to-many snapshot functionnality.

Again thank you for your work !

error in installation

Hi,
Thank you for your bundle. When I try to install it via this command:
composer require Webonaute\DoctrineFixturesGeneratorBundle 'dev-master'

I got following error:
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package webonautedoctrinefixturesgeneratorbundle could not be found in any version, there may be a typo in the package name.

Potential causes:

Read https://getcomposer.org/doc/articles/troubleshooting.md for further common problems.

Installation failed, reverting ./composer.json to its original content.

Can you help me with that please?
Thank you.

Method addRefernece should be a very first after object constructor

Hi,
I found problem in generated files, if object reffered to itself (it is possible in tree structures), fixture throws Error.

Sample:

$item241 = new MenuItem();
$item241->setName("main");
$item241->setRoute("home");
$item241->setRouteParameters(unserialize('a:0:{}'));
$item241->setLft(1);
$item241->setLvl(0);
$item241->setRgt(40);
$item241->setRoot($this->getReference('_reference_TMSolutionMenuBundleEntityMenuItem241'));
$this->addReference('_reference_TMSolutionMenuBundleEntityMenuItem241', $item241);
$item241->setPosition(1);

Should be:

$item241 = new MenuItem();
$this->addReference('_reference_TMSolutionMenuBundleEntityMenuItem241', $item241);
$item241->setName("main");
$item241->setRoute("home");
$item241->setRouteParameters(unserialize('a:0:{}'));
$item241->setLft(1);
$item241->setLvl(0);
$item241->setRgt(40);
$item241->setRoot($this->getReference('_reference_TMSolutionMenuBundleEntityMenuItem241'));
$item241->setPosition(1);

Thx for good tool!

getDialogHelper method not available

on "php bin/console Doctrine:Generate:Fixture --entity=Blog:BlogPost --ids="12 534 124" --name="bug43""

Attempted to call method "getDialogHelper" on class "Webonaute\DoctrineFixturesGeneratorBundle\Command\GenerateDoctrineFixtureCommand".

Exclude columns from fixture

Possible enhancement ...
add a command line option to ignore columns/member variables from the entity if there are columns that need to be left null in the new fixture.

Table 'sfk.wbnt_dfgb_test' doesn't exist

Hi when i m loading fixture after generating then getting error in console
" Base table or view not found: 1146 Table 'sfk.wbnt_dfgb_test' doesn't exist"
How to pass table name is fixtures

Error processing PersistentCollection as a sub-item

Recently ran into an issue when trying to create a fixture from some existing entities. I fixed the issue myself and though you may want to merge the fix into the master branch.

The error:
PHP Fatal error: Call to undefined method Doctrine\ORM\PersistentCollection::getId() in /vendor/webonaute/doctrine-fixtures-generator-bundle/Webonaute/DoctrineFixturesGeneratorBundle/Tool/FixtureGenerator.php on line 262

The Fix: (replace the appropriate lines of FixtureGenerator.php)

    public function generateFixtureItemStub($item)
    {
        $id = $item->getId();

        $code = "";
        $reflexion = new \ReflectionClass($item);
        $properties = $reflexion->getProperties();

        foreach ($properties as $property) {
            $property->setAccessible(true);
            $name = $property->getName();
            if (strpos($name, '_')) {
                $_names = explode('_', $property->getName());
                foreach ($_names as $k => $_name) {
                    $_names[$k] = ucfirst($_name);
                }
                $name = implode('', $_names);
            }
            $setter = "set" . ucfirst($name);
            $getter = "get" . ucfirst($name);
            $comment = "";
            if (method_exists($item, $setter)) {
                $value = $property->getValue($item);

                if (is_integer($value)) {
                    $setValue = $value;
                } elseif (is_bool($value)) {
                    if ($value === true) {
                        $setValue = 1;
                    } else {
                        $setValue = 0;
                    }
                } elseif ($value instanceof \DateTime) {
                    $setValue = "new \\DateTime(\"" . $value->format("Y-m-d H:i:s") . "\")";
                } elseif (is_object($value) && get_class($value) != "Doctrine\\ORM\\PersistentCollection") {
                    //check reference.
                    $relatedReflexion = new \ReflectionClass($value);
                    $relatedId = $value->getId();
                    $setValue = "\$this->getReference('{$this->referencePrefix}{$relatedReflexion->getShortName()}_{$relatedId}')";
                    $comment = "";
                }
                elseif(is_object($value) && get_class($value) == "Doctrine\\ORM\\PersistentCollection"){
                    $setValue = "unserialize('" . serialize($value->getSnapshot()) . "')";
                }
                elseif (is_array($value)) {
                    $setValue = "unserialize('" . serialize($value) . "')";
                } elseif (is_null($value)) {
                    $setValue = "NULL";
                } else {
                    $setValue = '"' . $value . '"';
                }

                $code .= "\n<spaces><spaces>{$comment}\$item{$id}->{$setter}({$setValue});";
            }
        }

        $code .= "\n\n<spaces><spaces>\$this->addReference('{$this->referencePrefix}{$reflexion->getShortName()}_{$id}', \$item{$id});\n";

        return $code;
    }

The namespace is wrong

I'm not sure how people are able to get this bundle working without modifying the namespace in every generated file but I guess their setup is different from mine. I was always getting Class not found errors until I realized that. I looked but I didn't see any configuration for the data fixtures directory. The folder where the fixtures are generated is plural:

https://github.com/Webonaute/DoctrineFixturesGeneratorBundle/blob/master/Generator/DoctrineFixtureGenerator.php#L75

While the generated namespace is singular:

https://github.com/Webonaute/DoctrineFixturesGeneratorBundle/blob/master/Tool/FixtureGenerator.php#L481

This forces me to change the namespace in every generated file so I can actually load the fixtures. Am I missing something?

Install bundle error with composer

Hello, great project!
I've a problem with I try install bundle via composer:

php composer.phar require Webonaute\DoctrineFixturesGeneratorBundle 'dev-master'

return the following error:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - The requested package webonautedoctrinefixturesgeneratorbundle could not be found in any version, there may be a typo in the package name.

Potential causes:
 - A typo in the package name
 - The package is not available in a stable-enough version according to your minimum-stability setting
   see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.

Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.

Installation failed, reverting ./composer.json to its original content.

Do you have any idea?
How I can install the bundle?

I work with the last version of Symfony.

Thanks

dev-master error with symfony 4.4

DoctrineFixtureGenerator::__construct() must be an instance of Symfony\Bridge\Doctrine\RegistryInterface, instance of Doctrine\Bundle\DoctrineBundle\Registry given

Error while loading fixture

When I try load fixture I receive this error:
php app/console doctrine:fixtures:load
[Symfony\Component\Debug\Exception\ContextErrorException]
Notice: Undefined variable: IkNrAcolIrBKqAzpvhKCSeUnR7uESLsSH

Description:
All values in fixture are in quotation marks, but when I trying to load them like below, hash string is interpreted as variable.
$item2->setPassword("$2y$13$IkNrAcolIrBKqAzpvhKCSeUnR7uESLsSH/kHIte8mzAuwshKeF48a");

Solution:
Change the quote on the apostrophe like below or escape all special characters:
$item2->setPassword('$2y$13$IkNrAcolIrBKqAzpvhKCSeUnR7uESLsSH/kHIte8mzAuwshKeF48a');

Doctrine2 Array fields and underscores in properties

Hi!
Great work you've done here, but there is a few problems, with I've fixed in version witch is forked in my profile. I've done this fix because it was really important in my project.

For example - my property was $only_once, but setter and getter looked like setOnlyOnce - your code didn't work.
There was a problem with boolean - the "false" value didn't appear as 0 - it was throwing an exception during loading fixture.
And the very important change - array field for doctrine entity.

Generate fixtures with "UUID" GeneratedValue strategy for id

Names of fixtures' variables are generated automatically. As I see it is concatenation of string "$item" and value of "id" column of record. If your use "UUID" GeneratedValue strategy for "id" property of your entity, then your will have a variable with name like "$item810f5dd4-a4f5-11e6-b400-84a6c8a557e4" with non permitted symbols "-".
I propose to replace "-" with "_" before writing fixtures' files.

Symfony4 support

This bundle still don't support Symfony4?

sensio-generator-bundle conflict

is ->getId() only one supported primary key identificator (id) ?

or is there any possibility how to specify it by e.g. config, or how to make it work with another PK like id.

My tables have PK record_id not just id. So the bundle should know to call ->getRecordId() and not ->getId(). Before this I can't use it, even it is great utility.

thank you

Escape text fields

Some of my fields contain HTML and they are exported incorrectly when double quotes is in text. I've added htmlentities at line 263 $setValue = '"' . htmlentities($value) . '"'; to \Webonaute\DoctrineFixturesGeneratorBundle\Tool\FixtureGenerator::generateFixtureItemStub

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.