예제 #1
0
 /**
  * Update function
  * <ul>
  * <li> Check for update conflict. To report back if conflict is detected.
  * <li> Perform update
  * </ul>
  */
 public function update($baseTable, $baseCurrent, $baseUpdate, $customTable, $customCurrent, $customUpdate, $fetchSql)
 {
     //Base table first.
     $dbo = CalemFactory::getDbo($baseTable);
     try {
         $dbo->beginTransaction();
         $rsMgr = CalemFactory::getResourceManager();
         if (count($baseUpdate) > 0) {
             $tableDd = $rsMgr->getTableDd($baseTable);
             $baseUpdate = $dbo->beforeUpdate($baseTable, $baseCurrent, $baseUpdate);
             $this->updateOneTable($baseTable, $dbo, $baseCurrent['id'], $baseCurrent, $baseUpdate, $tableDd, $fetchSql);
         }
         //custom table
         if ($customTable && count($customUpdate) > 0) {
             $dboCustom = CalemFactory::getDboCustom($customTable);
             $tableDd = $rsMgr->getTableDdCustom($customTable);
             try {
                 $this->updateOneTable($customTable, $dboCustom, $baseCurrent['id'], $customCurrent, $customUpdate, $tableDd);
             } catch (CalemDboDataNotFoundException $dne) {
                 //Data does not exist, so let's do an insertion
                 if ($this->logger->isDebugEnabled()) {
                     $this->logger->debug("Custom field not found for update, so do an insertion, table=" . $baseTable);
                 }
                 $customUpdate['zc_id'] = $baseCurrent['id'];
                 $customDbo = CalemFactory::getDboCustom($customTable);
                 $customDbo->setChangeBulk($customUpdate);
                 $customDbo->insert();
             }
         }
     } catch (CalemDboUpdateConflictException $e) {
         $dbo->rollback();
         throw $e;
     } catch (CalemDataBoException $ex) {
         $dbo->rollback();
         throw $ex;
     } catch (Exception $ex) {
         $errorInfo = $dbo->getErrorInfo();
         $dbo->rollback();
         throw new CalemDataBoException($baseTable, $ex, $errorInfo);
     }
     try {
         //Re-fetch the server record after the change.
         $dbo->onDataUpdated($baseTable, $baseCurrent, $baseUpdate, $customTable, $customCurrent, $customUpdate);
         $dbo->commit();
         if ($fetchSql) {
             $results = $dbo->fetchBySqlParam($fetchSql, array($baseCurrent['id']));
         } else {
             $results = array();
         }
         $feedback = array('table' => $baseTable, 'server' => $results[0]);
     } catch (Exception $ex) {
         $errorInfo = $dbo->getErrorInfo();
         throw new CalemDataBoException($baseTable, $ex, $errorInfo);
     }
     return $feedback;
 }