Git Product home page Git Product logo

Comments (35)

pdugas avatar pdugas commented on May 28, 2024

Getting the same fault here. Am using it along with @stof's DoctrineExtensionsBundle and Symfony2. My setup is using the following versions in case it's of use:

  • doctrine 2.1.0BETA1
  • doctrine-dbal 2.0.5
  • doctrine-common origin/3.0.x
  • gedmo-doctrine-extensions master
  • DoctrineExtensionsBundle origin/HEAD

PS: I'm with @MHeleniak, thanks for the great work.

from doctrineextensions.

pdugas avatar pdugas commented on May 28, 2024

Been doing some more poking around. Added a line in lib/Gedmo/Tree/Mapping/Driver/Annotation.php to throw an exception id it ever sees the "tree" tag for a class in readExtendedMetadata(). It never gets there. Not sure if the issue is with $meta->getReflectionClass() or reader->getClassAnnotations() or what.

from doctrineextensions.

pdugas avatar pdugas commented on May 28, 2024

The call to $this->reader->getClassAnnotations() is returning an array with integer indexes according to a xdebug trace.

-> Doctrine\Common\Annotations\FileCacheReader->getClassAnnotations(class ReflectionClass) .../vendor/gedmo-doctrine-extensions/lib/Gedmo/Tree/Mapping/Driver/Annotation.php:117
    -> ReflectionClass->getName() .../vendor/doctrine-common/lib/Doctrine/Common/Annotations/FileCacheReader.php:55
        >=> '...\\Entity\\FaqCategory'
    >=> array (0 => class Doctrine\ORM\Mapping\Table { public $name = 'faq_category'; public $schema = NULL; public $indexes = NULL; public $uniqueConstraints = array (...); public $value = NULL }, 1 => class Doctrine\ORM\Mapping\Entity { public $repositoryClass = 'Gedmo\\Tree\\Entity\\Repository\\NestedTreeRepository'; public $readOnly = FALSE; public $value = NULL }, 2 => class Gedmo\Mapping\Annotation\Tree { public $type = 'nested'; public $value = NULL }, 3 => class Gedmo\Mapping\Annotation\Loggable { public $logEntryClass = NULL; public $value = NULL })

while the subsequent tests seem to expect the keys to be the annotation namespace\names.

Me thinks this is another issue with the annotation changes in D2.

from doctrineextensions.

pdugas avatar pdugas commented on May 28, 2024

My git skills are zero so I'll just put the patch here. This resolves the issue with Tree. Something along the same lines will be needed for the other extensions. I've not looked to see if any property annotations are similarly impacted.

--- orig/lib/Gedmo/Tree/Mapping/Driver/Annotation.php   2011-05-24 21:05:04.942081346 -0400
+++ fixed/lib/Gedmo/Tree/Mapping/Driver/Annotation.php  2011-05-24 20:56:37.281336774 -0400
@@ -112,16 +112,15 @@
     public function readExtendedMetadata($meta, array &$config) {
         $class = $meta->getReflectionClass();
         // class annotations
-        $classAnnotations = $this->reader->getClassAnnotations($class);
-        if (isset($classAnnotations[self::TREE])) {
-            $annot = $classAnnotations[self::TREE];
+        $annot = $this->reader->getClassAnnotation($class, self::TREE);
+        if (null !== $annot) {
             if (!in_array($annot->type, $this->strategies)) {
                 throw new InvalidMappingException("Tree type: {$annot->type} is not available.");
             }
             $config['strategy'] = $annot->type;
         }
-        if (isset($classAnnotations[self::CLOSURE])) {
-            $annot = $classAnnotations[self::CLOSURE];
+        $annot = $this->reader->getClassAnnotation($class, self::CLOSURE);
+        if (null !== $annot) {
             if (!class_exists($annot->class)) {
                 throw new InvalidMappingException("Tree closure class: {$annot->class} does not exist.");
             }

Cheers!

from doctrineextensions.

j avatar j commented on May 28, 2024

I have the same exact error. Pdugas' fix seemed to work for Tree.

from doctrineextensions.

l3pp4rd avatar l3pp4rd commented on May 28, 2024

OK, the main reason for this issue is that symfony2 doctrine bundle uses indexed annotation reader, same reader is expected for my extensions. But I see that somehow this reader gets changed in the DIC, because in doctrine bundle config, I see that service id - annotation_reader is set to indexed reader.
This is very confusing and I probably will use the patch from @pdugas to update all extensions in this way. So far I can tell that you can better do forced injection of indexed annotation reader, which is in Symfony\Bundle\DoctrineBundle\Annotations\AnnotationReader

from doctrineextensions.

stof avatar stof commented on May 28, 2024

@l3pp4rd The goal is to remove the use of the IndexedReader totally in Doctrine as @schmittjoh said that checking with instanceof has better performance than using get_class() to index the annotations. So the change is the good solution.

from doctrineextensions.

l3pp4rd avatar l3pp4rd commented on May 28, 2024

if it reduces issues and complexity its good enough for me :)

from doctrineextensions.

mattab avatar mattab commented on May 28, 2024

I started symfony today and am probably doing something wrong, but using the latest code, and symfony2 B4, i still get the same error:

PHP Fatal error:  Class 'Gedmo\Timestampable\TimestampableListener' not found in D:\www\Symfony\app\cache\dev\appDevDebugProjectContainer.php on line 210
PHP Stack trace:
PHP   1. {main}() D:\www\Symfony\app\console:0
PHP   2. Symfony\Component\Console\Application->run() D:\www\Symfony\app\console:16
PHP   3. Symfony\Bundle\FrameworkBundle\Console\Application->doRun() D:\www\Symfony\vendor\symfony\src\Symfony\Component\Console\Application.php:119
PHP   4. Symfony\Component\Console\Application->doRun() D:\www\Symfony\vendor\symfony\src\Symfony\Bundle\FrameworkBundle\Console\Application.php:75
PHP   5. Symfony\Component\Console\Command\Command->run() D:\www\Symfony\vendor\symfony\src\Symfony\Component\Console\Application.php:193
[...]

The code that is mentionned above, in Symfony/vendor/gedmo-doctrine-extensions/lib/Gedmo/Tree/Mapping/Driver/Annotation.php

Looks like:

    // class annotations
    if ($annot = $this->reader->getClassAnnotation($class, self::TREE)) {
        if (!in_array($annot->type, $this->strategies)) {
            throw new InvalidMappingException("Tree type: {$annot->type} is not available.");
        }
        $config['strategy'] = $annot->type;
    }

so it looks like the patched version...

Would someone be able to help? I'm completely new to Symfony and Doctrine so, I welcome any tip!

My goal is to create a table that represents locations (Country contains Regions contain cities, which a Tree would be nice for I guess ;))

from doctrineextensions.

stof avatar stof commented on May 28, 2024

Your error message says that the listener is not found (and the place where the error occur is not what you pasted but the container). This error is probably caused by a misconfiguration of your autoloader. Check that the Gedmo namespace is registered properly.

from doctrineextensions.

stof avatar stof commented on May 28, 2024

btw, your issue has nothing to do with the issue on which you commented (which is fixed). So in this case, you should have opened a new one.

from doctrineextensions.

mattab avatar mattab commented on May 28, 2024

stof thanks for the quick response. I'm sorry in fact, that my copy-paste failed to copy the correct message!

I indeed have this error:

Generating entities for namespace "DZ"
 [ErrorException]
  Notice: Undefined index: strategy in D:\www\Symfony\vendor\gedmo-doctrine-extensions\lib\Gedmo\Tree\TreeListener.php line 72

The Location entity looks like: http://pastebin.com/QrLmqkmY

And my config file like:

stof_doctrine_extensions:
    default_locale: en_US
    orm:
        default: ~

Any help greatly appreciated thanks :)

from doctrineextensions.

l3pp4rd avatar l3pp4rd commented on May 28, 2024

hi @mattab you need to set the @gedmo\Tree(strategy="nested") for instance or closure, read the lib/doc, annotations.md or tree.md to see some examples. And for better performance add TreeRoot field

from doctrineextensions.

l3pp4rd avatar l3pp4rd commented on May 28, 2024

also I noticed that you do not use cascade onDelete="SET NULL" for parent relation. all this can be found in examples. I recommend you to use tree repository for your entity since it has some functions for usual tree operations, like path, reorder and so on

from doctrineextensions.

mattab avatar mattab commented on May 28, 2024

Thanks for pointing this issue (I also added the cascade onDelete and will try to use the tree repo, I think I understand what it means).

After adding the missing annotation I now get:
No identifier/primary key specified for Entity 'Stof\DoctrineExtensionsBundle\Entity\LogEntry'. Every Entity must have an identifier/primary key.

I know this is not related to current bug report, so maybe there is a better place for me to ask,
please forgive my ignorance :)

from doctrineextensions.

stof avatar stof commented on May 28, 2024

This is weird. The EntityGenerator should work properly as the class uses protected properties (or maybe you use an old version of Doctrine. The issue was fixed for protected properties in 2.0.2 or 2.0.3 IIRC)

from doctrineextensions.

l3pp4rd avatar l3pp4rd commented on May 28, 2024

we recently have issues with entity generator, since it handles everything differently. Try disabling the loggable behavior and translatable when you use entity generator. extensions are sugar on top, not the core of doctrine. and because of that it has conflicts with such thing as generator.. I recommend simply to generate the entities first, when enable extensions.

from doctrineextensions.

mattab avatar mattab commented on May 28, 2024

Looking at Symfony/vendor/doctrine-common/lib/Doctrine/Common/Version.php
I see: const VERSION = '3.0.0-DEV';

Is there somehow a way to avoid parsing this class since I don't plan to use it (I think)?

Maybe I can customize the config file to only load/parse the Tree related classes?

from doctrineextensions.

mattab avatar mattab commented on May 28, 2024

l3pp4rd just saw your comment after mine... I would love to know how to disable loggable/translatable indeed? :)

from doctrineextensions.

stof avatar stof commented on May 28, 2024

What he needs to disable is not the behaviors but the mapping of the bundle (and if you don't use the extensions, this can stay disabled):

doctrine:
    orm:
        entity_managers:
             default:
                   mappings:
                          StofDoctrineExtensionsBundle: false

from doctrineextensions.

stof avatar stof commented on May 28, 2024

@mattab I was talking of the version of the ORM, not of Common. the entity generator is not part of Doctrine Common

from doctrineextensions.

stof avatar stof commented on May 28, 2024

and to disable the listeners, you don't want, this is done in the configuration of my bundle. Look at the doc: https://github.com/stof/DoctrineExtensionsBundle/blob/master/Resources/doc/index.rst

from doctrineextensions.

mattab avatar mattab commented on May 28, 2024

I have edited config.yml as follows

doctrine:
    dbal:
        driver:   %database_driver%
        host:     %database_host%
        dbname:   %database_name%
        user:     %database_user%
        password: %database_password%
        charset:  utf8
    orm:
        auto_generate_proxy_classes: %kernel.debug%
        auto_mapping: true
        entity_managers:
            default:
                  mappings:
                         StofDoctrineExtensionsBundle: false

Then I get Unrecognized options "auto_mapping" under "doctrine.orm"

If I remove auto_mapping: true

I then get

Generating entities for namespace "DZ"
  [RuntimeException]
  Namespace "DZ" does not contain any mapped entities.

I guess the config file is causing some problem?

from doctrineextensions.

stof avatar stof commented on May 28, 2024

You should keep the auto_mapping. I haven't put the whole doctrine config, only the part disabling the mapping of the bundle. (you could also use explicit mapping but this means registering your own bundle using MyBundle: ~ in the mapping section)

from doctrineextensions.

mattab avatar mattab commented on May 28, 2024

Thanks for pointing to the solution again, It is not obvious when new to so many concepts ;-)

now I am trying to disable the listener on Loggable and wrote in my config file:

doctrine:
dbal:
[...]
orm:
auto_generate_proxy_classes: %kernel.debug%
auto_mapping: true
mappings:
StofDoctrineExtensionsBundle: ~
DZDestinationBundle: ~
stof_doctrine_extensions:
default_locale: en_US
orm:
default:
loggable: false

But unfortunately it looks like the logger thing is still parsed:
No identifier/primary key specified for Entity 'Stof\DoctrineExtensionsBundle\Entity\LogEntry'. Every Entity must have an identifier/primary key.

Any thoughts?

from doctrineextensions.

stof avatar stof commented on May 28, 2024

If you put StofDoctrineExtensionsBundle: ~, you activate the maping (which is useless as you added the automapping again). Disabling it is done by putting it to false, as shown previously

from doctrineextensions.

l3pp4rd avatar l3pp4rd commented on May 28, 2024

try clear the cache :) rm -Rf app/cache/* php bin/build_boostrap.php

from doctrineextensions.

stof avatar stof commented on May 28, 2024

Here is how it should look for the easy way to go (using automapping):

doctrine:
    orm:
        auto_mapping: true
        entity_managers:
             default:
                   mappings:
                          StofDoctrineExtensionsBundle: false

from doctrineextensions.

mattab avatar mattab commented on May 28, 2024

After setting StofDoctrineExtensionsBundle: false compiling entities WORK!! :)

Thank you stof and l3pp4rd for your help... Now I can try using the Tree Cheers!

from doctrineextensions.

sergeda avatar sergeda commented on May 28, 2024

Hi.
Can somebody help one more nube?
I can't get it to work. I'm trying to generate entity with sluggable behaivor but on generation I've got this error:
Undefined index: slug in /var/www/development3/vendor/gedmo-doctrine-e
xtensions/lib/Gedmo/Sluggable/Mapping/Driver/Yaml.php line 68
my config.yml:
doctrine:
orm:
auto_mapping: true
stof_doctrine_extensions:
orm:
default:
sluggable: true

and yml for entity:
fields:
title:
type: string
length: '150'
gedmo:
- sluggable
slug:
type: string
length: 128
gedmo:
slug:
separator: _
style: camel

from doctrineextensions.

l3pp4rd avatar l3pp4rd commented on May 28, 2024

when you generate the entities turn off extensions. extensions are not a part of doctrine core and never will. It does not add any annotations and generator does not know how to behave with those. So just disable the extensions in your config when generating entities

from doctrineextensions.

sergeda avatar sergeda commented on May 28, 2024

Thank you a lot l3pp4rd.
Can you please tell me how to temporaly disable extentions?
Or I should remove all configs from all files?

from doctrineextensions.

 avatar commented on May 28, 2024

I would like to clarify that either open or closed issues are NOT support forum espiecially it it does not in any way relate to the issue.

Can we comply with this? Thanks in advance.

from doctrineextensions.

l3pp4rd avatar l3pp4rd commented on May 28, 2024

@sergeda by not attaching the listeners, or if you use symfony2 read https://github.com/stof/StofDoctrineExtensionsBundle/blob/master/Resources/doc/index.rst

from doctrineextensions.

sergeda avatar sergeda commented on May 28, 2024

Thank you a lot. And sorry for silly question.

from doctrineextensions.

Related Issues (20)

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.