/** * note: listener hook fires after record hook * (non-PHPdoc) * @see branch/vendors/doctrine/Doctrine/Record/Doctrine_Record_Listener#preSave() */ public function preSave(Doctrine_Event $event) { // housekeeping $record = $event->getInvoker(); $this->limitParentDates($record); // set any runtime defaults here if (!$record->getEffectiveDate()) { // effective date defaults to the table's currently set query date $record->{$this->_options['eff_date']} = date($this->date_format); } // sanity checks if (!$record->isModified()) { // no changes? don't check anything return; } // don't save an instantaneous or nonsense record if (!is_null($record->getExpirationDate())) { if ($record->getEffectiveDate() == $record->getExpirationDate()) { throw new Doctrine_Record_SavingNonsenseException("Won't save instantaneous {$record->getTable()->getComponentName()} record with effective & expiration: " . $record->getEffectiveDate()); } elseif ($record->getEffectiveDate() > $record->getExpirationDate()) { throw new Doctrine_Record_SavingNonsenseException("Won't save {$record->getTable()->getComponentName()} record with effective > expiration: " . $record->getEffectiveDate() . " > " . $record->getExpirationDate()); } } /** * validation: can't modify past dates * - can't change expired records (exp_date < today) * - can't change past eff_date (eff_date < today) * - if changing eff_date to future on current record, then this will force creation of new, future record AND truncate the current one TODAY. */ if (Doctrine_Template_Temporal::isTemporalEnforcementSet() && !$this->_options['allow_past_modifications']) { $this->enforceTemporalModConstraints($record); } // after finalizing & checking all the date values, is there a temporal unique constraint violation? $record->enforceTemporalUniqueness(); }