/**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      JobNotes $value A JobNotes object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(JobNotes $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
Exemple #2
0
 public function save(PropelPDO $con = null)
 {
     $isNew = $this->isNew();
     // see if we need to do revision control on the notes
     $updateNotes = in_array(JobPeer::NOTES, $this->modifiedColumns) && strlen($this->getNotes() > 1);
     if (is_null($con)) {
         $con = Propel::getConnection(JobPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $ret = parent::save($con);
         $con->commit();
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
     $arr = $this->createCalendarArray();
     if (!is_null(sfContext::getInstance()->getUser())) {
         $uid = sfContext::getInstance()->getUser()->getUserId();
     } else {
         $uid = 1;
     }
     if ($isNew) {
         $logEntry = new Log();
         $logEntry->setWhen(time());
         $logEntry->setPropelClass("Job");
         $logEntry->setSfGuardUserProfileId($uid);
         $logEntry->setMessage("Job created.");
         $logEntry->setLogMessageTypeId(sfConfig::get("app_log_type_create"));
         $logEntry->setPropelId($this->getId());
         $logEntry->save();
         if ($this->getDate("U") > 0) {
             $event = sfGCalendar::createJobEvent($arr);
             $this->setGCalId($event->id);
             parent::save($con);
         }
     } else {
         if ($this->getDate("U") > 0) {
             if (is_null($this->getGCalId())) {
                 $event = sfGCalendar::createJobEvent($arr);
                 $this->setGCalId($event->id);
                 parent::save($con);
             } else {
                 sfGCalendar::updateJobEventById($this->getGCalId(), $arr);
             }
             if (!is_null($this->getGCalIdCustomUrl())) {
                 if (!is_null($this->getGCalIdCustom())) {
                     $arr["calUrl"] = $this->getGCalIdCustomUrl();
                     sfGCalendar::updateJobEventById($this->getGCalIdCustom(), $arr);
                 } else {
                     $arr["calUrl"] = $url;
                     $event = sfGCalendar::createJobEvent($arr);
                     $this->setGCalIdCustom($event->id);
                 }
             }
         }
     }
     if ($updateNotes) {
         $c = new Criteria();
         $c->add(JobNotesPeer::JOB_ID, $this->getId());
         $c->addDescendingOrderByColumn(JobNotesPeer::ID);
         $old = JobNotesPeer::doSelectOne($c);
         $rev = !is_null($old) ? $old->getRevision() + 1 : 1;
         $jn = new JobNotes();
         $jn->setJobId($this->getId());
         $jn->setNotes($this->getNotes());
         $jn->setRevision($rev);
         $jn->setUserId(sfContext::getInstance()->getUser()->getUserId());
         $jn->save();
     }
 }