Doctrine 1
  1. Doctrine 1
  2. DC-1051

Timestampable listener does not set timestamp fields on a copy of a Doctrine_Record

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.2.3
    • Fix Version/s: None
    • Component/s: Timestampable
    • Labels:
      None

      Description

      The Timestampable Listener only sets the timestamp if the timestamp field has not been modified:

      if ( ! isset($modified[$createdName])) {
        $event->getInvoker()->$createdName = $this->getTimestamp('created', $event->getInvoker()->getTable()->getConnection());
      }
      

      When saving a copy of a Doctrine_Record that doesn't already have the timestamp fields set fails to be updated, leading to integrity constraint violation ("created_at cannot be NULL"). 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:

      if ( ! isset($modified[$createdName]) || $modified[$createdName] instanceof Doctrine_Null) {
        $event->getInvoker()->$createdName = $this->getTimestamp('created', $event->getInvoker()->getTable()->getConnection());
      }
      

        Activity

        Jeremy Johnson created issue -
        blopblop made changes -
        Field Original Value New Value
        Attachment Timestampable.php [ 11318 ]

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Jeremy Johnson
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: