예제 #1
0
파일: Model.php 프로젝트: vgrish/dvelum
 public function importdbfieldsAction()
 {
     $connectionId = Request::post('connectionId', 'string', false);
     $table = Request::post('table', 'string', false);
     $conType = Request::post('type', 'integer', false);
     $fields = Request::post('fields', 'array', false);
     if ($connectionId === false || !$table || empty($fields) || $conType === false) {
         Response::jsonError($this->_lang->WRONG_REQUEST);
     }
     $conManager = new Backend_Orm_Connections_Manager($this->_configMain->get('db_configs'));
     $cfg = $conManager->getConnection($conType, $connectionId);
     if (!$cfg) {
         Response::jsonError($this->_lang->WRONG_REQUEST);
     }
     $cfg = $cfg->__toArray();
     $data = Backend_Designer_Import::checkImportDBFields($cfg, $fields, $table);
     if (!$data) {
         Response::jsonError($this->_lang->WRONG_REQUEST);
     }
     if (!empty($data)) {
         foreach ($data as $field) {
             $this->_object->addField($field);
         }
     }
     $this->_storeProject();
     Response::jsonSuccess();
 }
예제 #2
0
파일: Form.php 프로젝트: vgrish/dvelum
 /**
  * Import DB fields into the form object
  */
 public function importdbfieldsAction()
 {
     $connection = Request::post('connection', 'string', false);
     $table = Request::post('table', 'string', false);
     $conType = Request::post('type', 'integer', false);
     $importFields = Request::post('importfields', 'array', array());
     if ($connection === false || !$table || empty($importFields) || $conType === false) {
         Response::jsonError($this->_lang->WRONG_REQUEST);
     }
     $conManager = new Backend_Orm_Connections_Manager($this->_configMain->get('db_configs'));
     $cfg = $conManager->getConnection($conType, $connection);
     if (!$cfg) {
         Response::jsonError($this->_lang->WRONG_REQUEST);
     }
     $cfg = $cfg->__toArray();
     $tableFields = Backend_Designer_Import::getTableFields($cfg, $table);
     if ($tableFields === false) {
         Response::jsonError($this->_lang->CANT_CONNECT);
     }
     foreach ($importFields as $name) {
         if (isset($tableFields[$name]) && !empty($tableFields[$name])) {
             $this->_importDbField($name, $tableFields[$name]);
         }
     }
     $this->_storeProject();
     Response::jsonSuccess();
 }
예제 #3
0
 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();
 }
예제 #4
0
 /**
  * Get list of database connections
  */
 public function connectionslistAction()
 {
     $manager = new Backend_Orm_Connections_Manager($this->_configMain->get('db_configs'));
     $list = $manager->getConnections(0);
     $data = array();
     if (!empty($list)) {
         foreach ($list as $k => $v) {
             $data[] = array('id' => $k);
         }
     }
     Response::jsonSuccess($data);
 }