Ticket #1680 (closed defect: fixed)

Opened 8 months ago

Last modified 6 months ago

Tags

Reported by: gimler Owned by: jwage
Priority: major Milestone: 1.0.6
Component: Import/Export Version: 1.0.3
Severity: Keywords:
Cc: klemens_u Has Test: no
Status: Pending User Response Has Patch: no

Description

when i have a setter in a plugin it doesn't work with the Importer

the Doctrine_Data_Import throw exception in line 198

Invalid fixture element "tags" under "test-1"

the problem is that doctrine search for a method or field but not in the plugins ;(

better use is_callable instate of method_exists

symfony: 1.1.4 doctrine: 1.0.3 php: 5.2.6 os: ubuntu

Attachments

import_patch.txt (1.2 KB) - added by klemens_u 7 months ago.

Change History

Changed 7 months ago by guilhermeblanco

  • mystatus changed from Pending Core Response to Pending User Response

gimler,

We need at least one answer of these two questions:

1- Changing to is_callable solves the issue? 2- Provide models, test case, everything possible for us to reproduce the issue.

Thanks,

Changed 7 months ago by jwage

  • status changed from new to closed
  • resolution set to fixed

(In [5309]) [1.0, 1.1] Changing data fixtures to use is_callable() instead of method_exists() since setters may be not real physical functions (closes #1680)

Changed 7 months ago by jwage

  • milestone changed from 1.0.5 to 1.0.6

Changed 7 months ago by klemens_u

  • status changed from closed to reopened
  • resolution fixed deleted

Something's wrong with this change. It breaks my fixture loading.

I'm using symfony 1.1.7-DEV with the latest sfDoctrinePlugin

I've got a record with an additional custom setter, which is not a database field.

In  http://trac.doctrine-project.org/browser/branches/1.0/lib/Doctrine/Data/Import.php#L199 : Somehow is_callable($obj, 'set' . Doctrine_Inflector::classify($key)) returns false for my custom setter.

I'm not sure if is_callable is correctly used. In the php manual I found an array type usage for objects like this: is_callable(array($obj, 'set' . Doctrine_Inflector::classify($key)), true)

But this again produces other errors. (With fixture elements which reference others)

Please revert this change until further investigation is done.

BTW: What do you mean exactly by "the problem is that doctrine search for a method or field but not in the plugins"? Can you give an example?

Thanks, Klemens

Changed 7 months ago by klemens_u

  • cc klemens_u added

Changed 7 months ago by gimler

  • summary changed from Importer doesn't work with plugin setter to Tags

simple when you add a listener that has a setter:

class TaggableListener extends Doctrine_Record_Listener
{
...
    public function setTags($tagname)
    {
...
    }
...
}

 http://trac.symfony-project.org/browser/plugins/sfDoctrineActAsTaggablePlugin/trunk/lib/TaggableTemplate.class.php

you can't use it in the fixtures:

table:
  alias:
    tags: "efef"

Changed 7 months ago by klemens_u

Changed 7 months ago by klemens_u

Ok I see, thanks gimler. I can confirm that before this fix it wasn't possible to use setters in Doctrine_Template using yaml fixtures.

Unfortunately a few things went wrong with the implemented fix:

1) Simply replacing method_exists() with is_callable() completely breaks the logic of the if-else statement because:

  • if(method_exists()) is used for native setter methods in Doctrine_Record (didn't work anymore)
  • else if ($obj->getTable()->hasField()) is used for the table columns
  • else if ($obj->getTable()->hasRelation()) is used for relations (didn't work anymore either)

2) The used syntax of is_callable() is wrong. For objects it has to be given via array, and the second parameter has a complety different meaning:

  • it was is_callable($obj, 'set' . Doctrine_Inflector::classify($key))
  • it should be is_callable(array($obj, 'set' . Doctrine_Inflector::classify($key)))

I've attached a patch which fixes both issues

Changed 7 months ago by jwage

(In [5320]) [1.0, 1.1] Reverting r5309 (addresses #1680)

Changed 6 months ago by jwage

  • status changed from reopened to closed
  • resolution set to fixed

Fixed in r5321

Note: See TracTickets for help on using tickets.