Example #1
0
 /**
  * Create Database tables
  */
 public function createtablesAction()
 {
     $mainCfgPath = $this->_docRoot . 'system/config/main.php';
     $config = (include $mainCfgPath);
     $inlineConfig = Config::factory(Config::Simple, 'main');
     $inlineConfig->setData($config);
     $app = new Application($inlineConfig);
     $app->init();
     $zendDb = Model::getGlobalDbConnection();
     $installDocs = $this->_session->get('install_docs');
     $config = Config::factory(Config::File_Array, $this->_docRoot . 'install/cfg/cfg.php')->__toArray();
     if ($installDocs) {
         try {
             $dbConfig = $zendDb->getConfig();
             $cmd = 'mysql -h' . escapeshellarg($dbConfig['host']) . ' -P ' . escapeshellarg($dbConfig['port']) . ' -u' . escapeshellarg($dbConfig['username']) . ' -p' . escapeshellarg($dbConfig['password']) . ' -D' . escapeshellarg($dbConfig['dbname']) . ' < ' . escapeshellarg($this->_docRoot . $config['docs_sql']);
             if (system($cmd) === false) {
                 throw new Exception('Cannot exec shell command: ' . $cmd);
             }
         } catch (Exception $e) {
             Response::jsonError($this->_dictionary['INSTALL_DOCS_ERROR'] . ' ' . $e->getMessage());
         }
     }
     $paths = File::scanFiles($this->_docRoot . $config['configsPath'], array('.php'), false, File::Files_Only);
     foreach ($paths as &$v) {
         $v = substr(basename($v), 0, -4);
     }
     unset($v);
     $buildErrors = array();
     if (!empty($paths)) {
         foreach ($paths as $v) {
             $dbObjectBuilder = new Db_Object_Builder($v);
             if (!$dbObjectBuilder->build()) {
                 $buildErrors[] = $v;
             }
         }
     }
     if (!empty($buildErrors)) {
         Response::jsonError($this->_dictionary['BUILD_ERR'] . ' ' . implode(', ', $buildErrors));
     } else {
         Response::jsonSuccess('', array('msg' => $this->_dictionary['DB_DONE']));
     }
 }