Ejemplo n.º 1
0
 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());
     }
 }
 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;
 }