<!-- 
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Tue May 21 15:33:38 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-1051/DC-1051.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-1051] Timestampable listener does not set timestamp fields on a copy of a Doctrine_Record</title>
                <link>http://www.doctrine-project.org/jira/browse/DC-1051</link>
                <project id="10031" key="DC">Doctrine 1</project>
                        <description>&lt;p&gt;The Timestampable Listener only sets the timestamp if the timestamp field has not been modified:&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; ( ! isset($modified[$createdName])) {
  $event-&amp;gt;getInvoker()-&amp;gt;$createdName = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getTimestamp(&apos;created&apos;, $event-&amp;gt;getInvoker()-&amp;gt;getTable()-&amp;gt;getConnection());
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;When saving a copy of a Doctrine_Record that doesn&apos;t already have the timestamp fields set fails to be updated, leading to integrity constraint violation (&quot;created_at cannot be NULL&quot;).  The reason is that all unset fields in the copy are set to an instance of Doctrine_Null, which is considered to be modifed according to the condition tested for above.  To fix the issue, I modified the code above to read:&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; ( ! isset($modified[$createdName]) || $modified[$createdName] &lt;span class=&quot;code-keyword&quot;&gt;instanceof&lt;/span&gt; Doctrine_Null) {
  $event-&amp;gt;getInvoker()-&amp;gt;$createdName = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;getTimestamp(&apos;created&apos;, $event-&amp;gt;getInvoker()-&amp;gt;getTable()-&amp;gt;getConnection());
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</description>
                <environment></environment>
            <key id="13526">DC-1051</key>
            <summary>Timestampable listener does not set timestamp fields on a copy of a Doctrine_Record</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="jeremyajohnson">Jeremy Johnson</reporter>
                        <labels>
                    </labels>
                <created>Wed, 14 Mar 2012 03:35:04 +0000</created>
                <updated>Thu, 6 Sep 2012 14:26:30 +0000</updated>
                                    <version>1.2.3</version>
                                                <component>Timestampable</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>2</watches>
                        <comments>
                    <comment id="18612" author="blopblop" created="Thu, 6 Sep 2012 10:47:23 +0000"  >&lt;p&gt;Your fix works great, I have also added the fix for the preupdate function and in one more place in the preinsert function.&lt;br/&gt;
Lines affected: 65, 73, 91.&lt;br/&gt;
Attached the file with the fixes:&lt;br/&gt;
( C:\php5\PEAR\symfony\plugins\sfDoctrinePlugin\lib\vendor\doctrine\Doctrine\Template\Listener\Timestampable.php )&lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;code&amp;#93;&lt;/span&gt;&lt;br/&gt;
    /**&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Set the created and updated Timestampable columns when a record is inserted&lt;br/&gt;
     *&lt;/li&gt;
	&lt;li&gt;@param Doctrine_Event $event&lt;/li&gt;
	&lt;li&gt;@return void&lt;br/&gt;
     */&lt;br/&gt;
    public function preInsert(Doctrine_Event $event)&lt;br/&gt;
    {&lt;br/&gt;
        if ( ! $this-&amp;gt;_options&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;created&amp;#39;&amp;#93;&lt;/span&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;disabled&amp;#39;&amp;#93;&lt;/span&gt;) 
&lt;div class=&quot;error&quot;&gt;&lt;span class=&quot;error&quot;&gt;Unknown macro: {            $createdName = $event-&amp;gt;getInvoker()-&amp;gt;getTable()-&amp;gt;getFieldName($this-&amp;gt;_options[&amp;#39;created&amp;#39;][&amp;#39;name&amp;#39;]);            $modified = $event-&amp;gt;getInvoker()-&amp;gt;getModified();            if ( ! isset($modified[$createdName]) || $modified[$createdName] instanceof Doctrine_Null) {
                $event-&amp;gt;getInvoker()-&amp;gt;$createdName = $this-&amp;gt;getTimestamp(&apos;created&apos;, $event-&amp;gt;getInvoker()-&amp;gt;getTable()-&amp;gt;getConnection());
            }        }&lt;/span&gt; &lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;        if ( ! $this-&amp;gt;_options&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;updated&amp;#39;&amp;#93;&lt;/span&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;disabled&amp;#39;&amp;#93;&lt;/span&gt; &amp;amp;&amp;amp; $this-&amp;gt;_options&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;updated&amp;#39;&amp;#93;&lt;/span&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;onInsert&amp;#39;&amp;#93;&lt;/span&gt;) {&lt;br/&gt;
            $updatedName = $event-&amp;gt;getInvoker()&lt;del&gt;&amp;gt;getTable()&lt;/del&gt;&amp;gt;getFieldName($this-&amp;gt;_options&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;updated&amp;#39;&amp;#93;&lt;/span&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;name&amp;#39;&amp;#93;&lt;/span&gt;);&lt;br/&gt;
            $modified = $event-&amp;gt;getInvoker()-&amp;gt;getModified();&lt;br/&gt;
            if ( ! isset($modified&lt;span class=&quot;error&quot;&gt;&amp;#91;$updatedName&amp;#93;&lt;/span&gt;) || $modified&lt;span class=&quot;error&quot;&gt;&amp;#91;$updatedName&amp;#93;&lt;/span&gt; instanceof Doctrine_Null) &lt;/p&gt;
{
                $event-&amp;gt;getInvoker()-&amp;gt;$updatedName = $this-&amp;gt;getTimestamp(&apos;updated&apos;, $event-&amp;gt;getInvoker()-&amp;gt;getTable()-&amp;gt;getConnection());
            }&lt;br/&gt;
        }&lt;br/&gt;
    }&lt;br/&gt;
&lt;br/&gt;
    /**&lt;br/&gt;
     * Set updated Timestampable column when a record is updated&lt;br/&gt;
     *&lt;br/&gt;
     * @param Doctrine_Event $evet&lt;br/&gt;
     * @return void&lt;br/&gt;
     */&lt;br/&gt;
    public function preUpdate(Doctrine_Event $event)&lt;br/&gt;
    {&lt;br/&gt;
        if ( ! $this-&amp;gt;_options&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;updated&amp;#39;&amp;#93;&lt;/span&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;disabled&amp;#39;&amp;#93;&lt;/span&gt;) {&lt;br/&gt;
            $updatedName = $event-&amp;gt;getInvoker()&lt;del&gt;&amp;gt;getTable()&lt;/del&gt;&amp;gt;getFieldName($this-&amp;gt;_options&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;updated&amp;#39;&amp;#93;&lt;/span&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;name&amp;#39;&amp;#93;&lt;/span&gt;);&lt;br/&gt;
			//echo &quot;updatedName: &quot;; var_dump(updatedName);&lt;br/&gt;
            $modified = $event-&amp;gt;getInvoker()-&amp;gt;getModified();&lt;br/&gt;
            if ( ! isset($modified&lt;span class=&quot;error&quot;&gt;&amp;#91;$updatedName&amp;#93;&lt;/span&gt;) || $modified&lt;span class=&quot;error&quot;&gt;&amp;#91;$updatedName&amp;#93;&lt;/span&gt; instanceof Doctrine_Null) {
                $event-&amp;gt;getInvoker()-&amp;gt;$updatedName = $this-&amp;gt;getTimestamp(&apos;updated&apos;, $event-&amp;gt;getInvoker()-&amp;gt;getTable()-&amp;gt;getConnection());
            }
&lt;p&gt;        }&lt;br/&gt;
    }&lt;br/&gt;
&lt;span class=&quot;error&quot;&gt;&amp;#91;/code&amp;#93;&lt;/span&gt;&lt;br/&gt;
------------------&lt;/p&gt;


&lt;p&gt;Also there is another problem too. If you dont disable the widgets of the fields updated_at and created_at, sometimes they are sending the date time information in the $form, and the function preUpdate doesnt update the update_at because the date time has been sent. The best option is to disable the widgets and form validation in global scope, here:&lt;br/&gt;
&amp;lt;?php&lt;/p&gt;

&lt;p&gt;/**&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Project form base class.&lt;br/&gt;
 *&lt;/li&gt;
	&lt;li&gt;@package    dbvui&lt;/li&gt;
	&lt;li&gt;@subpackage form&lt;/li&gt;
	&lt;li&gt;@author     Your name here&lt;/li&gt;
	&lt;li&gt;@version    SVN: $Id: sfDoctrineFormBaseTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $&lt;br/&gt;
 */&lt;br/&gt;
abstract class BaseFormDoctrine extends sfFormDoctrine&lt;br/&gt;
{&lt;br/&gt;
  public function setup()&lt;br/&gt;
  {&lt;br/&gt;
  	//Following code will remove Required validators from these fields.&lt;br/&gt;
  	if (isset($this-&amp;gt;validatorSchema))&lt;br/&gt;
  	{&lt;br/&gt;
  		if (isset($this-&amp;gt;validatorSchema&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;created_at&amp;#39;&amp;#93;&lt;/span&gt;))
  		{
	  		unset($this-&amp;gt;validatorSchema[&apos;created_at&apos;]);
  		}&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;  		if (isset($this-&amp;gt;validatorSchema&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;updated_at&amp;#39;&amp;#93;&lt;/span&gt;))&lt;/p&gt;
  		{
	  		unset($this-&amp;gt;validatorSchema[&apos;updated_at&apos;]);
  		}
&lt;p&gt;  	}&lt;/p&gt;

&lt;p&gt;  	if (isset($this-&amp;gt;widgetSchema))&lt;br/&gt;
  	{&lt;br/&gt;
	  	//following code will remove fields from form&lt;br/&gt;
  		if (isset($this-&amp;gt;widgetSchema&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;created_at&amp;#39;&amp;#93;&lt;/span&gt;))&lt;/p&gt;
  		{
	  		unset($this-&amp;gt;widgetSchema[&apos;created_at&apos;]);
  		}

&lt;p&gt;  		if (isset($this-&amp;gt;widgetSchema&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;#39;updated_at&amp;#39;&amp;#93;&lt;/span&gt;))&lt;/p&gt;
  		{
	  		unset($this-&amp;gt;widgetSchema[&apos;updated_at&apos;]);
  		}
&lt;p&gt;  	}&lt;br/&gt;
  }&lt;br/&gt;
}&lt;/p&gt;</comment>
                    <comment id="18613" author="blopblop" created="Thu, 6 Sep 2012 10:50:41 +0000"  >&lt;p&gt;fixed&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                    <attachment id="11318" name="Timestampable.php" size="5266" author="blopblop" created="Thu, 6 Sep 2012 10:50:40 +0000" />
                </attachments>
            <subtasks>
        </subtasks>
        </item>
</channel>
</rss>