webonaute / doctrinefixturesgeneratorbundle Goto Github PK
View Code? Open in Web Editor NEWGenerate Fixture from your existing data in your database. You can specify the Entity name and the IDs you want to import in your fixture.
Generate Fixture from your existing data in your database. You can specify the Entity name and the IDs you want to import in your fixture.
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!
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;
}
}
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.
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 :
<?php
namespace AdminBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class AdminBundle extends Bundle
{
public function __toString()
{
return $this->getPath();
}
}
I said hacky because of the __toString method.
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 !
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.
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!
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".
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.
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
When using v2.0-alpha I got this error. Downgrading to v1.3.7 solved it.
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;
}
Incoming feature.
console.ERROR: Error thrown while running command "'doctrine:generate:fixture'". Message: "Command "doctrine:generate:fixture" is not defined.
On symfony 4.1
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:
While the generated namespace is singular:
This forces me to change the namespace in every generated file so I can actually load the fixtures. Am I missing something?
The FixtureGenerator doesn't look for the real class names in getReference() line and sometimes you will receive proxy class names instead. This mix of real class names and proxy class names can be result in wrong references.
When launching doctrine:fixtures:load , after my own fixtures are loaded, test fixtures from the Webonaute try to load too:
loading [1] Webonaute\DoctrineFixturesGeneratorBundle\DataFixtures\ORM\LoadTestRelated
I had to delete LoadTest and LoadTestRelated in the vendor directory to get it to work.
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
DoctrineFixtureGenerator::__construct() must be an instance of Symfony\Bridge\Doctrine\RegistryInterface, instance of Doctrine\Bundle\DoctrineBundle\Registry given
your bundle works well but it's a bit useless if we have to specifiy every ids we want in fixtures ...
i agree it's great to be able to filter , but by default, it should take everything in database , no ?
hope you ll update this :)
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');
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.
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.
This bundle still don't support Symfony4?
sensio-generator-bundle conflict
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
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.