예제 #1
0
 /**
  * Construction of a DBO object
  * @param String table name of the Dbo
  * @param array the initial row value of the Dbo
  */
 public function __construct()
 {
     $this->logger =& LoggerManager::getLogger(get_class($this));
     $this->dbHandler = CalemFactory::getDbHandler();
     $this->conn = $this->dbHandler->getCalemConnection();
     $this->resourceMgr = CalemFactory::getResourceManager();
 }
예제 #2
0
 public function __construct()
 {
     $this->logger = LoggerManager::getLogger('CalemDataLoader');
     $this->dbHandler = CalemFactory::getDbHandler();
     $this->conn = $this->dbHandler->getCalemConnection();
     $this->stats = array();
     $this->resourceMgr = CalemFactory::getResourceManager();
 }
예제 #3
0
 /**
  * Validate that all the tables are in the database
  */
 public function validate()
 {
     global $_CALEM_conf;
     $dbo = new CalemDbo();
     $tbls = $dbo->fetchBySql("SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = '" . $_CALEM_conf['calem_db_name'] . "'");
     //Get tableMap
     $resourceMgr = CalemFactory::getResourceManager();
     $tbMap = $resourceMgr->getTableMap();
     $tableMap = $tbMap->getTableMapNoDropdown($resourceMgr);
     if ($this->logger->isDebugEnabled()) {
         $this->logger->debug("tableMap count=" . count($tableMap) . ", schema count=" . count($tbls));
     }
     if (count($tableMap) > count($tbls)) {
         $this->logger->error("Some tables not in database: dbCount=" . count($tbls) . ", localCount=" . count($tableMap), 0);
     }
     //Let's validate by name here
     $schema = array();
     foreach ($tbls as $val) {
         $schema[] = $val['table_name'];
     }
     $missing = array();
     $missingIdx = array();
     foreach ($tableMap as $table) {
         if (array_search($table, $schema) === false) {
             $missing[] = $table;
         }
         //Verify missing index
         try {
             $idxDb = $this->getIndexByDb($table, $dbo);
             $tblDd = $resourceMgr->getTableDd($table);
             $idx = $this->getIndexByTable($tblDd);
             $ar = $this->arrayDiff($idx, $idxDb);
             if (count($ar) > 0) {
                 $missingIdx = array_merge($missingIdx, $ar);
             }
         } catch (CalemDboDataNotFoundException $e) {
             continue;
         }
     }
     if (count($missing) > 0 || count($missingIdx) > 0) {
         $this->logger->error("Missing items in database: missingTables=" . var_export($missing, true) . ", missingIndexes=" . var_export($missingIdx, true));
         throw new CalemException("Missing tables in database: " . var_export($missing, true) . ", missinIndexes=" . var_export($missingIdx, true), 0);
     }
 }
예제 #4
0
 public function getDropdownEntry($fldAr)
 {
     $rsMgr = CalemFactory::getResourceManager();
     $tbDd = $rsMgr->getTableDd($fldAr['tableId']);
     $fldList = $tbDd->getFields();
     $ar = array();
     foreach ($fldList as $key => $val) {
         if ($key == 'id') {
             continue;
         }
         $ar[$key] = isset($fldAr[$key]) ? $fldAr[$key] : null;
     }
     return $ar;
 }
예제 #5
0
 /**
  * Get a dbo instance for a given table
  */
 public function getDbo($table, $row = null)
 {
     $rsMgr = CalemFactory::getResourceManager();
     $tableDd = $rsMgr->getTableDd($table);
     $dbo = $tableDd->getDbo();
     $dbo = isset($dbo) ? $dbo : 'CalemDbo';
     //CalemDataBo is the default.
     $dboInst = CalemFactory::createInstance($dbo);
     $dboInst->initWithTableName($table, $row);
     return $dboInst;
 }
예제 #6
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;
 }
예제 #7
0
 private function getResourceMgr()
 {
     if (!isset($this->resourceMgr)) {
         $this->resourceMgr = CalemFactory::getResourceManager();
     }
     return $this->resourceMgr;
 }