コード例 #1
0
ファイル: Translator.php プロジェクト: vgrish/dvelum
 /**
  * Get object fields translation
  * @param boolean $autoCreate , otional default - true
  * @return Config_Abstract | boolean false
  */
 public function getTranslation($autoCreate = true)
 {
     if ($this->_translation) {
         return $this->_translation;
     }
     if (!file_exists($this->_mainConfig)) {
         if (!$autoCreate) {
             return false;
         }
         //create translation config
         if (!Config_File_Array::create($this->_mainConfig)) {
             return false;
         }
     }
     $this->_translation = Config::factory(Config::File_Array, $this->_mainConfig);
     if (!empty($this->_extTranslations)) {
         foreach ($this->_extTranslations as $path) {
             $extCfg = Config::factory(Config::File_Array, $path);
             foreach ($extCfg as $k => $v) {
                 if (!$this->_translation->offsetExists($k)) {
                     $this->_translation->set($k, $v);
                 }
             }
         }
     }
     return $this->_translation;
 }
コード例 #2
0
ファイル: Manager.php プロジェクト: vgrish/dvelum
 /**
  * Create dictionary
  * @param string $name
  * @return boolean
  */
 public function create($name)
 {
     if (!file_exists($this->_path . $name . '.php') && Config_File_Array::create($this->_path . $name . '.php')) {
         self::$_validDictionary[$name] = true;
         $this->resetCache();
         return true;
     }
     return false;
 }
コード例 #3
0
ファイル: Manager.php プロジェクト: vgrish/dvelum
 public function createConnection($id)
 {
     foreach ($this->_config as $devType => $data) {
         if ($this->connectionExists($devType, $id)) {
             return false;
         }
     }
     foreach ($this->_config as $devType => $data) {
         if (!Config_File_Array::create($this->_config[$devType]['dir'] . $id . '.php')) {
             return false;
         }
         $c = $this->getConnection($devType, $id);
         $c->setData(array('username' => '', 'password' => '', 'dbname' => '', 'host' => '', 'charset' => 'UTF8', 'prefix' => '', 'adapter' => 'Mysqli', 'adapterNamespace' => 'Db_Adapter'));
         if (!$c->save()) {
             return false;
         }
     }
     return true;
 }
コード例 #4
0
ファイル: Controller.php プロジェクト: vgrish/dvelum
 public function connectobjectAction()
 {
     $connectionId = Request::post('connId', 'string', false);
     $connectionType = Request::post('type', 'integer', false);
     $table = Request::post('table', 'string', false);
     if ($connectionId === false || $connectionType === false || $table === false) {
         Response::jsonError($this->_lang->WRONG_REQUEST);
     }
     $cfg = $this->_manager->getConnection($connectionType, $connectionId);
     if (!$cfg) {
         Response::jsonError($this->_lang->WRONG_REQUEST);
     }
     $cfg = $cfg->__toArray();
     try {
         $db = Zend_Db::factory($cfg['adapter'], $cfg);
         $db->query('SET NAMES ' . $cfg['charset']);
         $tables = $db->listTables();
     } catch (Exception $e) {
         Response::jsonError($this->_lang->CANT_CONNECT . ' ' . $e->getMessage());
     }
     $import = new Db_Object_Import();
     if (!$import->isValidPrimaryKey($db, $table)) {
         $errors = $import->getErrors();
         if (!empty($errors)) {
             $errors = '<br>' . implode('<br>', $errors);
         } else {
             $errors = '';
         }
         Response::jsonError($this->_lang->DB_CANT_CONNECT_TABLE . ' ' . $this->_lang->DB_MSG_UNIQUE_PRIMARY . ' ' . $errors);
     }
     $manager = new Db_Object_Manager();
     $newObjectName = strtolower(str_replace('_', '', $table));
     if ($manager->objectExists($newObjectName)) {
         $newObjectName = strtolower(str_replace('_', '', $cfg['dbname'])) . $newObjectName;
         if ($manager->objectExists($newObjectName)) {
             $k = 0;
             $alphabet = Utils_String::alphabetEn();
             while ($manager->objectExists($newObjectName)) {
                 if (!isset($alphabet[$k])) {
                     Response::jsonError('Can not create unique object name' . $errors);
                 }
                 $newObjectName .= $alphabet[$k];
                 $k++;
             }
         }
     }
     $config = $import->createConfigByTable($db, $table, $cfg['prefix']);
     $config['connection'] = $connectionId;
     if (!$config) {
         $errors = $import->getErrors();
         if (!empty($errors)) {
             $errors = '<br>' . implode('<br>', $errors);
         } else {
             $errors = '';
         }
         Response::jsonError($this->_lang->DB_CANT_CONNECT_TABLE . ' ' . $errors);
     } else {
         $path = $this->_configMain->get('object_configs') . $newObjectName . '.php';
         if (!Config_File_Array::create($path)) {
             Response::jsonError($this->_lang->CANT_WRITE_FS . ' ' . $path);
         }
         $cfg = Config::factory(Config::File_Array, $path);
         $cfg->setData($config);
         if (!$cfg->save()) {
             Response::jsonError($this->_lang->CANT_WRITE_FS . ' ' . $path);
         }
     }
     Response::jsonSuccess();
 }
コード例 #5
0
ファイル: Controller.php プロジェクト: vgrish/dvelum
 /**
  * Create Db_Object
  * @param string $name - object name
  * @param array $data - object config
  */
 protected function _createObject($name, array $data)
 {
     $usePrefix = $data['use_db_prefix'];
     $connectionManager = new Db_Manager($this->_configMain);
     $connection = $connectionManager->getDbConnection($data['connection']);
     $connectionCfg = $connectionManager->getDbConfig($data['connection']);
     //$db = Model::getGlobalDbConnection();
     $db = $connection;
     $tables = $db->listTables();
     $oConfigPath = Db_Object_Config::getConfigPath();
     $tableName = $data['table'];
     if ($usePrefix) {
         $tableName = $connectionCfg->get('prefix') . $tableName;
     }
     if (in_array($tableName, $tables, true)) {
         Response::jsonError($this->_lang->FILL_FORM, array(array('id' => 'table', 'msg' => $this->_lang->SB_UNIQUE)));
     }
     if (file_exists($oConfigPath . strtolower($name) . '.php')) {
         Response::jsonError($this->_lang->FILL_FORM, array(array('id' => 'name', 'msg' => $this->_lang->SB_UNIQUE)));
     }
     /*
      * Write object config
      */
     if (!Config_File_Array::create($oConfigPath . $name . '.php')) {
         Response::jsonError($this->_lang->CANT_WRITE_FS);
     }
     $cfg = Config::factory(Config::File_Array, $oConfigPath . strtolower($name) . '.php');
     /*
      * Add fields config
      */
     $data['fields'] = array();
     $cfg->setData($data);
     $cfg->save();
     try {
         $cfg = Db_Object_Config::getInstance($name);
         $cfg->setObjectTitle($data['title']);
         if (!$cfg->save()) {
             Response::jsonError($this->_lang->CANT_WRITE_FS);
         }
         /*
          * Build database
          */
         $builder = new Db_Object_Builder($name);
         $builder->build();
     } catch (Exception $e) {
         Response::jsonError($this->_lang->CANT_EXEC . 'code 2');
     }
     Response::jsonSuccess();
 }
コード例 #6
0
ファイル: Controller.php プロジェクト: vgrish/dvelum
 public function dbcheckAction()
 {
     $host = Request::post('host', 'str', '');
     $port = Request::post('port', 'int', 0);
     $prefix = Request::post('prefix', 'str', '');
     $installDocs = Request::post('install_docs', 'boolean', false);
     $this->_session->set('install_docs', $installDocs);
     $params = array('host' => $host, 'username' => Request::post('username', 'str', false), 'password' => Request::post('password', 'str', false), 'dbname' => Request::post('dbname', 'str', false), 'adapter' => 'Mysqli', 'adapterNamespace' => 'Db_Adapter');
     if ($port != 0) {
         $params['port'] = $port;
     }
     $flag = false;
     if ($params['host'] && $params['username'] && $params['dbname']) {
         try {
             $zendDb = Zend_Db::factory('Mysqli', $params);
             $zendDb->getServerVersion();
             $data['success'] = true;
             $data['msg'] = $this->_dictionary['SUCCESS_DB_CHECK'];
             $flag = true;
         } catch (Exception $e) {
             $data['success'] = false;
             $data['msg'] = $this->_dictionary['FAILURE_DB_CHECK'];
         }
     } else {
         $data['success'] = false;
         $data['msg'] = $this->_dictionary['REQUIRED_DB_SETTINGS'];
     }
     if ($flag) {
         try {
             $configs = array($this->_docRoot . 'system/config/db/prod/default.php', $this->_docRoot . 'system/config/db/dev/default.php', $this->_docRoot . 'system/config/db/prod/error.php', $this->_docRoot . 'system/config/db/dev/error.php');
             foreach ($configs as $path) {
                 if (Config_File_Array::create($path) === false) {
                     throw new Exception();
                 }
                 $config = Config::factory(Config::File_Array, $path);
                 $config->setData($params);
                 $config->set('charset', 'UTF8');
                 $config->set('prefix', $prefix);
                 if (!$config->save()) {
                     throw new Exception();
                 }
             }
         } catch (Exception $e) {
             $data['success'] = false;
             $data['msg'] = $this->_dictionary['CONNECTION_SAVE_FAIL'];
         }
     }
     Response::jsonSuccess($data);
 }