Пример #1
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();
 }
Пример #2
0
 /**
  * Create new module
  */
 public function createAction()
 {
     $this->_checkCanEdit();
     $object = Request::post('object', 'string', false);
     if (!$object) {
         Response::jsonError($this->_lang->WRONG_REQUEST);
     }
     $object = Utils_String::formatClassName($object);
     $class = 'Backend_' . $object . '_Controller';
     if (class_exists($class)) {
         Response::jsonError($this->_lang->FILL_FORM, array('id' => 'name', 'msg' => $this->_lang->SB_UNIQUE));
     }
     $designerConfig = Config::factory(Config::File_Array, $this->_configMain['configs'] . 'designer.php');
     $projectFile = $designerConfig->get('configs') . strtolower($object) . '.designer.dat';
     if (file_exists($projectFile)) {
         Response::jsonError($this->_lang->FILE_EXISTS . '(' . $projectFile . ')');
     }
     $actionFile = $designerConfig->get('actionjs_path') . strtolower($object) . '.js';
     if (file_exists($actionFile)) {
         Response::jsonError($this->_lang->FILE_EXISTS . '(' . $actionFile . ')');
     }
     $objectConfig = Db_Object_Config::getInstance($object);
     // Check ACL permissions
     $acl = $objectConfig->getAcl();
     if ($acl) {
         if (!$acl->can(Db_Object_Acl::ACCESS_CREATE, $object) || !$acl->can(Db_Object_Acl::ACCESS_VIEW, $object)) {
             Response::jsonError($this->_lang->get('ACL_ACCESS_DENIED'));
         }
     }
     $manager = new Db_Object_Manager();
     if (!$manager->objectExists($object)) {
         Response::jsonError($this->_lang->FILL_FORM, array('id' => 'object', 'msg' => $this->_lang->INVALID_VALUE));
     }
     $codeGenadApter = $this->_configBackend->get('modules_codegen');
     $codeGen = new $codeGenadApter();
     try {
         if ($objectConfig->isRevControl()) {
             $codeGen->createVcModule($object, $projectFile, $actionFile);
         } else {
             $codeGen->createModule($object, $projectFile, $actionFile);
         }
     } catch (Exception $e) {
         Response::jsonError($e->getMessage());
     }
     $userInfo = User::getInstance()->getInfo();
     $per = Model::factory('Permissions');
     if (!$per->setGroupPermissions($userInfo['group_id'], $object, 1, 1, 1, 1)) {
         Response::jsonError($this->_lang->CANT_EXEC);
     }
     Response::jsonSuccess(array('class' => $class, 'name' => $object, 'active' => true, 'dev' => false, 'title' => $objectConfig->getTitle(), 'designer' => $projectFile));
 }