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(); }
/** * 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(); }
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(); }