Esempio n. 1
0
 /**
  * @param null $con
  * @return int
  * @throws Exception
  * @throws PropelException
  */
 public function save($con = null)
 {
     $userId = sfContext::getInstance()->getUser()->getSubscriberId();
     if ($userId) {
         $this->setUpdatedUserId($userId);
         if ($this->isNew()) {
             $this->setCreatedUserId($userId);
         }
     }
     $con = Propel::getConnection();
     try {
         $con->begin();
         $ret = parent::save($con);
         // update schema_has_user table
         $schemaId = $this->getId();
         $mode = sfContext::getInstance()->getRequest()->getParameter('action');
         if ($userId && $schemaId) {
             //see if there's already an entry in the table and if not, add it
             $criteria = new Criteria();
             $criteria->add(SchemaHasUserPeer::USER_ID, $userId);
             $SchemaHasUsersColl = $this->getSchemaHasUsers($criteria, $con);
             if (!count($SchemaHasUsersColl)) {
                 $schemaUser = new SchemaHasUser();
                 $schemaUser->setSchemaId($schemaId);
                 $schemaUser->setUserId($userId);
                 $schemaUser->setIsRegistrarFor(true);
                 $schemaUser->setIsAdminFor(true);
                 $schemaUser->setIsMaintainerFor(true);
                 $schemaUser->save($con);
             }
         }
         $con->commit();
         return $ret;
     } catch (Exception $e) {
         $con->rollback();
         throw $e;
     }
 }