Beispiel #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();
 }
 public function setupDatabase()
 {
     $dbHandler = CalemFactory::getDbHandler();
     $dbSetup = new CalemDbSetup();
     //Using a fake database for the test...
     global $_CALEM_conf;
     //Let's check if the db exists
     $conn = $dbHandler->getDatabaseAdminConnection();
     try {
         //Will not drop a db by code
         $dbSetup->setupDatabaseAndUser($dbHandler, $conn);
         //Release the connection for admin
         $dbHandler->releaseDatabaseAdminConnection();
         //Let's create schema
         $conn = $dbHandler->getCalemConnection();
         $dbSetup->setupSchema($dbHandler, $conn);
         //Let's verify that workorder table is in the database
         //Adding a record to work order and select it out.
         $conn->beginTransaction();
         $inserted = $conn->exec("insert into workorder (id, wo_no) values('1111111111-test', 'wo1')");
         $conn->commit();
         //Make sure we delete this record
         $conn->beginTransaction();
         $deleted = $conn->exec("delete from workorder where id='1111111111-test'");
         $conn->commit();
         if ($inserted == $deleted && $inserted == 1) {
             $this->logger->info("setupCalemDatabase is complete. Database is successfully created");
         } else {
             throw new Exception("Error in validating database setup. workorder inserted=" . $inserted . ", deleted=" . $deleted);
         }
     } catch (Exception $e) {
         $this->logger->error("Error in setting up db, error=" . $e->getMessage());
     }
 }
Beispiel #3
0
 public function init($param)
 {
     $this->param = $param;
     $this->dbHdlr = CalemFactory::getDbHandler();
     $this->dbSetup = new CalemDbSetup();
     $this->conn = $this->dbHdlr->getCalemConnection();
 }
 public function validateInput()
 {
     $this->setDbType($_REQUEST['fi_dbtype']);
     $this->setDbHost($_REQUEST['fi_dbhost']);
     $this->setUsername($_REQUEST['fi_username']);
     $this->setPassword($_REQUEST['fi_password']);
     $this->setDbName($_REQUEST['fi_dbname']);
     //Now validate the info to see if we can load it.
     $rtn = $this->getDbType() && $this->getDbHost() && $this->getUsername() && $this->getDbName();
     if (!$rtn) {
         $this->setErrorMsg($this->calemLang->getMsg('db_info_required'));
         $rtn = false;
     } else {
         //Let's try connecting to the database
         $this->controller->setupDbInfo();
         require_once _CALEM_DIR_ . 'server/include/core/CalemFactory.php';
         try {
             $dbHdlr = CalemFactory::getDbHandler();
             $conn = $dbHdlr->getCalemConnection();
         } catch (Exception $e) {
             $msg = $this->calemLang->getMsg('db_info_exception') . " <br /> " . $e->getMessage();
             $GLOBALS['logger']->error("Error at CalemInstDbinfoController.validateInput: " . $e->getMessage());
             $this->setErrorMsg($msg);
             $rtn = false;
         }
     }
     return $rtn;
 }
 public function __construct()
 {
     $this->logger = LoggerManager::getLogger('CalemDataLoader');
     $this->dbHandler = CalemFactory::getDbHandler();
     $this->conn = $this->dbHandler->getCalemConnection();
     $this->stats = array();
     $this->resourceMgr = CalemFactory::getResourceManager();
 }
 public function validateInput()
 {
     $this->setLoadSample($_REQUEST['fi_load_sample']);
     $this->setUpgrade($_REQUEST['fi_upgrade']);
     $this->setVerifyDb($_REQUEST['fi_verifydb']);
     //Allow sufficient time
     set_time_limit(0);
     //Now creating DB first
     $rtn = true;
     try {
         /**
          * Creating database tables first
          */
         require_once _CALEM_DIR_ . 'server/include/core/database/CalemDbSetup.php';
         $dbSetup = new CalemDbSetup();
         $dbHandler = CalemFactory::getDbHandler();
         $conn = $dbHandler->getCalemConnection();
         $dbSetup->setupSchema($dbHandler, $conn);
         //Verify db setup
         if ($this->getVerifyDb()) {
             $dbSetup->validate();
         }
         //What about upgrade
         if ($this->upgradeHdlr) {
             $GLOBALS['logger']->debug('DbSetupModel: doing an upgrade; hdlr=' . get_class($this->upgradeHdlr));
             $results = $this->upgradeHdlr->upgrade();
             $GLOBALS['logger']->info("upgrade results: " . var_export($results, true));
         }
         //Load Init data
         require_once _CALEM_DIR_ . 'server/setup/CalemLoadInitData.php';
         $loader = new CalemLoadInitData();
         $loader->load();
         //Load sample data if set
         if ($this->getLoadSample()) {
             require_once _CALEM_DIR_ . 'server/setup/CalemLoadSampleData.php';
             $loader = new CalemLoadSampleData();
             $loader->load();
         }
     } catch (Exception $e) {
         $msg = $this->calemLang->getMsg('db_conf_exception') . " <br /> " . $e->getMessage();
         $GLOBALS['logger']->error("Error at CalemInstDbSetupController.validateInput: " . $e->getMessage());
         $this->setErrorMsg($msg);
         $rtn = false;
     }
     return $rtn;
 }
Beispiel #7
0
 public function getCurrentVersion($useFirst = true)
 {
     $rtn = $useFirst ? $rtn = $this->firstVersion : null;
     try {
         $this->initDbo();
         $dh = CalemFactory::getDbHandler();
         if (!$dh->tableExists($this->dbo, 'version')) {
             return $rtn;
         }
         $row = $this->dbo->fetchById(VERSION_ID);
         if ($this->logger->isInfoEnabled()) {
             $this->logger->info('Version row=' . var_export($row, true));
         }
         $rtn = CalemVersion::decode($row);
     } catch (CalemDboDataNotFoundException $dn) {
         require_once _CALEM_DIR_ . 'server/include/util/CalemDebug.php';
         $this->logger->warn('Data not found: ' . CalemDebug::toStackTrace($dn));
     }
     return $rtn;
 }
Beispiel #8
0
 /**
  * Modify data transaction (multiple update, insert, delete passed in)
  */
 public function ModifyDataTran()
 {
     $param = $this->getParamValue(0);
     if ($this->logger->isDebugEnabled()) {
         $this->logger->debug("Invoking ModifyDataTran, param=" . var_export($param, true));
     }
     $result = array();
     //Start a transaction
     $dbHdlr = CalemFactory::getDbHandler();
     $conn = $dbHdlr->getCalemConnection();
     $conn->beginTransaction();
     if (isset($param->UpdateData)) {
         $result['UpdateDataResponse'] = $this->processUpdateData($param->UpdateData);
         if ($result['UpdateDataResponse'][0]['status'] != 0) {
             $result['TranResponse'] = $result['UpdateDataResponse'][0];
             return $result;
         }
     }
     if (isset($param->InsertData)) {
         $result['InsertDataResponse'] = $this->processInsertData($param->InsertData);
         if ($result['InsertDataResponse'][0]['status'] != 0) {
             $result['TranResponse'] = $result['InsertDataResponse'][0];
             return $result;
         }
     }
     if (isset($param->DeleteData)) {
         $result['DeleteDataResponse'] = $this->processDeleteData($param->DeleteData);
         if ($result['DeleteDataResponse'][0]['status'] != 0) {
             $result['TranResponse'] = $result['DeleteDataResponse'][0];
             return $result;
         }
     }
     $result['TranResponse'] = array('status' => 0);
     $conn->commit();
     return $result;
 }
Beispiel #9
0
 public function getNextAssetNo()
 {
     $dbHdlr = CalemFactory::getDbHandler();
     $seq = $dbHdlr->getNextSeq('asset_seq');
     return sprintf($this->conf['asset_no']['format'], $seq);
 }
 public function validateInput()
 {
     $this->setDbType($_REQUEST['fi_dbtype']);
     $this->setDbHost($_REQUEST['fi_dbhost']);
     $this->setAdminUser($_REQUEST['fi_admin_user']);
     $this->setAdminPassword($_REQUEST['fi_admin_password']);
     $this->setDbHost($_REQUEST['fi_dbhost']);
     $this->setUsername($_REQUEST['fi_username']);
     $this->setPassword($_REQUEST['fi_password']);
     $this->setDbName($_REQUEST['fi_dbname']);
     $this->setLoadSample($_REQUEST['fi_load_sample']);
     //Now validate the info to see if we can load it.
     $rtn = $this->getDbType() && $this->getDbHost() && $this->getUsername() && $this->getDbName() && $this->getAdminUser();
     if (!$rtn) {
         $this->setErrorMsg($this->calemLang->getMsg('db_info_required'));
         return false;
     }
     //Allow sufficient time
     set_time_limit(0);
     //Start DB setup
     $rtn = true;
     try {
         //Connecting as Admin first
         $this->controller->setupDbAdminInfo();
         $dbHandler = CalemFactory::getDbHandler();
         $conn = $dbHandler->getDatabaseAdminConnection();
         //Get database setup class.
         require_once _CALEM_DIR_ . 'server/include/core/database/CalemDbSetup.php';
         $dbSetup = new CalemDbSetup();
         //Prepare db info for setup.
         $this->controller->setupDbInfo();
         /**
          * First let's create user and database
          */
         $dbSetup->setupDatabaseAndUser($dbHandler, $conn);
         //Release the connection for admin
         $dbHandler->releaseDatabaseAdminConnection();
         /**
          * Next, creating database tables first
          */
         $conn = $dbHandler->getCalemConnection();
         $dbSetup->setupSchema($dbHandler, $conn);
         $dbSetup->validate();
         //Upgrade if applicable
         $upgradeHdlr = $this->getUpgradeHdlr();
         if ($upgradeHdlr) {
             $GLOBALS['logger']->debug('DbExpressSetupModel: doing an upgrade; hdlr=' . get_class($upgradeHdlr));
             $upgradeHdlr->upgrade();
         }
         //Load Init data
         require_once _CALEM_DIR_ . 'server/setup/CalemLoadInitData.php';
         $loader = new CalemLoadInitData();
         $loader->load();
         //Load sample data if set
         if ($this->getLoadSample()) {
             require_once _CALEM_DIR_ . 'server/setup/CalemLoadSampleData.php';
             $loader = new CalemLoadSampleData();
             $loader->load();
         }
     } catch (Exception $e) {
         $msg = $this->calemLang->getMsg('db_conf_exception') . " <br /> " . $e->getMessage();
         $GLOBALS['logger']->error("Error at CalemInstDbSetupController.validateInput: " . $e->getMessage());
         $this->setErrorMsg($msg);
         $rtn = false;
     }
     return $rtn;
 }
 public function ModifyFieldType()
 {
     $param = $this->getParamValue(0);
     if ($this->logger->isDebugEnabled()) {
         $this->logger->debug("Modify field type, param=" . var_export($param, true));
     }
     $result = array();
     //Processing each row by iterating the param object.
     foreach ($param as $key => $fldObj) {
         $fldAr = CalemJson::objToArray($fldObj);
         //DB change first, followed by file changes
         try {
             $dbHdlr = CalemFactory::getDbHandler();
             $dbHdlr->modifyFieldType($fldAr);
         } catch (CalemDataBoException $e) {
             $result[] = array('id' => $fldAr['id'], 'status' => -1, 'errorInfo' => $e->getErrorInfo()->getData());
             continue;
         } catch (Exception $e2) {
             $ei = new CalemErrorInfo('CalemErrorInfo', $fldAr['id'], $e2->getMessage());
             $result[] = array('id' => $fldAr['id'], 'status' => -1, 'errorInfo' => $ei->getData());
             continue;
         }
         //Update metadata - fake an oldId for code reuse.
         $fldAr['oldId'] = $fldAr['id'];
         $result[] = $this->updateMetadataForFieldName($fldAr);
     }
     return $result;
 }