<!-- 
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Fri May 24 17:06:27 UTC 2013

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary add field=key&field=summary to the URL of your request.
For example:
http://www.doctrine-project.org/jira/si/jira.issueviews:issue-xml/DC-728/DC-728.xml?field=key&field=summary
-->
<rss version="0.92" >
<channel>
    <title>Doctrine Project</title>
    <link>http://www.doctrine-project.org/jira</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>5.2.7</version>
        <build-number>850</build-number>
        <build-date>21-02-2013</build-date>
    </build-info>

<item>
            <title>[DC-728] Updating slug in I18N behaviour yields non-unique slug</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-728</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;There seems to be a bug in the way, doctrine tries to find a unique slug for a table that is I18N-enabled and has a slug in it.&lt;/p&gt;

&lt;p&gt;Following example:&lt;/p&gt;
&lt;div class=&quot;preformatted panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;preformattedContent panelContent&quot;&gt;
&lt;pre&gt;Problem:
  actAs:
    I18n:
      fields: [name]
      actAs:
        Sluggable: { fields: [name], uniqueBy: [lang, name], canUpdate: true }
  columns:
    name: { type: string(255), notnull: true }
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt; 

&lt;p&gt;Now, if we insert a new entry, the slug get&apos;s created as expected. If we now insert another entry that would yield the same slug, the slug is made unique by adding the postfix as expected - all well so far.&lt;/p&gt;

&lt;p&gt;Now, if we try to update the entry with the slug with the postfix, what i think is an error happens (Excerpt from Sluggable.php, lib/Doctrine/Template/Listener/Sluggable.php):&lt;/p&gt;

&lt;div class=&quot;preformatted panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;preformattedContent panelContent&quot;&gt;
&lt;pre&gt; 
public function getUniqueSlug($record, $slugFromFields)
...
if ($record-&amp;gt;exists()) {
            $identifier = $record-&amp;gt;identifier();
            $whereString .= &apos; AND r.&apos; . implode(&apos; != ? AND r.&apos;, $table-&amp;gt;getIdentifierColumnNames()) . &apos; != ?&apos;;
            $whereParams = array_merge($whereParams, array_values($identifier));
        }

        foreach ($this-&amp;gt;_options[&apos;uniqueBy&apos;] as $uniqueBy) {
            if (is_null($record-&amp;gt;$uniqueBy)) {
                $whereString .= &apos; AND r.&apos;.$uniqueBy.&apos; IS NULL&apos;;
            } else {
                $whereString .= &apos; AND r.&apos;.$uniqueBy.&apos; = ?&apos;;
                $value = $record-&amp;gt;$uniqueBy;
                if ($value instanceof Doctrine_Record) {
                    $value = current((array) $value-&amp;gt;identifier());
                }
                $whereParams[] = $value;
            }
        }
...
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt; 

&lt;p&gt;So, the $record-&amp;gt;exists() check evaluates to true and $table-&amp;gt;getIdentifierColumnNames() yields the fields id and lang, so the whereString is something like&lt;/p&gt;
&lt;div class=&quot;preformatted panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;preformattedContent panelContent&quot;&gt;
&lt;pre&gt; 
AND r.id != ? AND r.lang != ?
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt; 

&lt;p&gt;Now for the problematic part:&lt;br/&gt;
uniqueBy is lang and name; so the code adds to the whereString:&lt;/p&gt;
&lt;div class=&quot;preformatted panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;preformattedContent panelContent&quot;&gt;
&lt;pre&gt; 
AND r.lang = ? AND r.name = ?
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt; 

&lt;p&gt;So the resulting whereString has something like&lt;/p&gt;
&lt;div class=&quot;preformatted panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;preformattedContent panelContent&quot;&gt;
&lt;pre&gt; 
r.lang != ? AND r.lang = ?
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt; 
&lt;p&gt;which will never yield a result in my eyes, thus, the postfix is never incremented and the slug defaults to the the slug of name without postfix.&lt;/p&gt;</description>
                <environment>Symfony 1.4.5&lt;br/&gt;
Doctrine ORM</environment>
            <key id="11474">DC-728</key>
            <summary>Updating slug in I18N behaviour yields non-unique slug</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/open.png">Open</status>
                    <resolution id="-1">Unresolved</resolution>
                                <assignee username="jwage">Jonathan H. Wage</assignee>
                                <reporter username="vsknight">Florian Aschenbrenner</reporter>
                        <labels>
                    </labels>
                <created>Fri, 11 Jun 2010 05:35:43 +0000</created>
                <updated>Tue, 5 Oct 2010 11:28:43 +0000</updated>
                                    <version>1.2.0</version>
                <version>1.2.1</version>
                <version>1.2.2</version>
                                                <component>I18n</component>
                <component>Sluggable</component>
                        <due></due>
                    <votes>5</votes>
                        <watches>5</watches>
                        <comments>
                    <comment id="13408" author="rodrigobb" created="Thu, 24 Jun 2010 13:11:47 +0000"  >&lt;p&gt;Hi,&lt;/p&gt;

&lt;p&gt;We&apos;ve also found this problem and make a temporal workaround. But maybe our workaround can give someone an idea on how to fix the bug so I&apos;m pasting the changed code here&lt;/p&gt;

&lt;p&gt;In file &lt;em&gt;sfDoctrinePlugin\lib\vendor\doctrine\Doctrine\Template\Listener\Sluggable.php&lt;/em&gt; (getUniqueSlug method)&lt;/p&gt;

&lt;p&gt;Replace&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;&lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($record-&amp;gt;exists()) {
  $identifier = $record-&amp;gt;identifier();
  $whereString .= &apos; AND r.&apos; . implode(&apos; != ? AND r.&apos;, $table-&amp;gt;getIdentifierColumnNames()) . &apos; != ?&apos;;
  $whereParams = array_merge($whereParams, array_values($identifier));
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;With&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;&lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($record-&amp;gt;exists()) {
  $identifier = $record-&amp;gt;identifier();
  $commonFields = array_uintersect($table-&amp;gt;getIdentifierColumnNames(), $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_options[&apos;uniqueBy&apos;], &lt;span class=&quot;code-quote&quot;&gt;&quot;strcasecmp&quot;&lt;/span&gt;);
  foreach ($commonFields as $key =&amp;gt; $value)
    unset ($identifier[$value]);
  
  $whereFields = array_diff($table-&amp;gt;getIdentifierColumnNames(), $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_options[&apos;uniqueBy&apos;]);
  $whereString .= &apos; AND r.&apos; . implode(&apos; != ? AND r.&apos;, $whereFields) . &apos; != ?&apos;;
  $whereParams = array_merge($whereParams, array_values($identifier));
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</comment>
                    <comment id="14532" author="caponica" created="Tue, 5 Oct 2010 11:28:43 +0000"  >&lt;p&gt;Rodrigo, I think the solution is simpler than you might expect...&lt;/p&gt;

&lt;p&gt;The problem is that it is doing an AND where it should be doing an OR to find records other than the current one.&lt;/p&gt;

&lt;p&gt;So, you just need to replace this part of Sluggable::getUniqueSlug():&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-style: solid;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeHeader panelHeader&quot; style=&quot;border-bottom-width: 1px;border-bottom-style: solid;&quot;&gt;&lt;b&gt;Sluggable::getUniqueSlug()&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;...
        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($record-&amp;gt;exists()) {
            $identifier = $record-&amp;gt;identifier();
            $whereString .= &apos; AND r.&apos; . implode(&apos; != ? AND r.&apos;, $table-&amp;gt;getIdentifierColumnNames()) . &apos; != ?&apos;;
            $whereParams = array_merge($whereParams, array_values($identifier));
        }
...
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;With this code (the 3rd line has extra brackets and OR instead of AND):&lt;/p&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border-style: solid;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeHeader panelHeader&quot; style=&quot;border-bottom-width: 1px;border-bottom-style: solid;&quot;&gt;&lt;b&gt;Sluggable::getUniqueSlug() (modified)&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;        &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; ($record-&amp;gt;exists()) {
            $identifier = $record-&amp;gt;identifier();
            $whereString .= &apos; AND (r.&apos; . implode(&apos; != ? OR r.&apos;, $table-&amp;gt;getIdentifierColumnNames()) . &apos; != ?)&apos;;
            $whereParams = array_merge($whereParams, array_values($identifier));
        }
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;


&lt;p&gt;In more detail, the WHERE clause being built up is saying: &lt;br/&gt;
&quot;find me records WHERE (the slug begins with the same string) AND (it&apos;s not the same record) AND (the other key uniqueBy values are the same)&quot;&lt;/p&gt;

&lt;p&gt;However, to check that it&apos;s not the same record you just need one of the key values to be different (not all of them) so the check should be something like:&lt;/p&gt;
&lt;div class=&quot;preformatted panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;preformattedContent panelContent&quot;&gt;
&lt;pre&gt;... AND (p.id != &apos;2&apos; OR p.lang != &apos;en&apos;) ...
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;instead of:&lt;/p&gt;
&lt;div class=&quot;preformatted panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;preformattedContent panelContent&quot;&gt;
&lt;pre&gt;... AND p.id != &apos;2&apos; AND p.lang != &apos;en&apos; ...
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The modification to the code as stated above generates queries that look like this, which I&apos;m pretty sure is correct:&lt;/p&gt;
&lt;div class=&quot;preformatted panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;preformattedContent panelContent&quot;&gt;
&lt;pre&gt;... WHERE (p.url LIKE &apos;foo%&apos; AND (p.id != &apos;2&apos; OR p.lang != &apos;en&apos;) AND p.lang = &apos;en&apos; AND p.other_uniqueby_field = &apos;1&apos;)
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;


&lt;p&gt;C&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>
</channel>
</rss>