Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Minor
-
Resolution: Unresolved
-
Affects Version/s: 1.2.0, 1.2.1, 1.2.2, 1.2.3, 1.2.4
-
Fix Version/s: None
-
Component/s: Behaviors
-
Labels:None
-
Environment:WAMP stack - PHP 5.3
Description
When allowing the user to manually change a slug using 'canUpdate' the slug reverts back to it's default generated value upon subsequent saves. Pre-Update on the Sluggable Listener Template seems to incorrectly decide to regenerate the default value.
Example:
$this->actAs('Sluggable', array('unique'=>true, 'fields'=>array('title'), 'canUpdate'=>true));
$record->description = "An example Item"; $record->title = "Example Title"; $record->save(); echo $record->slug; //"example-title" (Correct) $record->description = "An example Item"; $record->title = "Example Title"; $record->slug = "custom-slug"; $record->save(); echo $record->slug; //"custom-slug" (Correct - First Save) $record->description = "An example Item"; $record->title = "Example Title"; $record->slug = "custom-slug"; $record->save(); echo $record->slug; //"example-title" (Incorrect - Subsequent Save. Has regenerated it's default slug and lost the user defined one - even though we have passed the users custom one to the object prior to saving it.).
As far as I can see this is a problem with the logic in Sluggable::preUpdate() , I recently posted a comment about this here:
http://groups.google.com/group/doctrine-user/browse_thread/thread/d40c6ac733738d4a
In short, I think that the code should be changed from:
To this (i.e. remove the canUpdate conditions from the first inner if):
I have modified my local version of the Doctrine code to use this modification and it seems to (a) not have the problem you reported above and (b) generally work ok. However, I have not run the test suite against it.
C