Пример #1
0
 public function testValidate()
 {
     $o = new Db_Object_Builder('Page');
     $o->build();
     $this->assertTrue($o->validate());
 }
Пример #2
0
 * and save a reference for it (for convenience)
 * @var Config_Simple $appConfig
 */
$appConfig = Config::factory(Config::Simple, 'main');
$appConfig->setData($config);
Registry::set('main', $appConfig, 'config');
/**
 * Convert the data of main_config file
 * in to the general form of configuration
 * and save a reference for it (for convenience)
 * @var Config_Simple $appConfig
 */
/*
 * Starting the application
 */
$app = new Application($appConfig);
$app->setAutoloader($autoloader);
$app->init();
//  build objects
$objectFiles = File::scanFiles($config['object_configs'], array('.php'), false, File::Files_Only);
foreach ($objectFiles as $file) {
    $object = substr(basename($file), 0, -4);
    echo 'build ' . $object . ' : ';
    $builder = new Db_Object_Builder($object);
    if ($builder->build()) {
        echo 'OK';
    } else {
        echo 'Error! ' . strip_tags(implode(', ', $builder->getErrors()));
    }
    echo "\n";
}
Пример #3
0
 /**
  * Save field configuration options
  */
 public function savefieldAction()
 {
     $this->_checkCanEdit();
     $manager = new Backend_Orm_Manager();
     $object = Request::post('objectName', 'string', false);
     $objectField = Request::post('objectField', 'string', false);
     $name = Request::post('name', 'string', false);
     if (!$object) {
         Response::jsonError($this->_lang->WRONG_REQUEST);
     }
     if (!$name) {
         Response::jsonError($this->_lang->FILL_FORM, array(array('id' => 'name', 'msg' => $this->_lang->CANT_BE_EMPTY)));
     }
     try {
         /**
          * @var Db_Object_Config
          */
         $objectCfg = Db_Object_Config::getInstance($object);
     } catch (Exception $e) {
         Response::jsonError($this->_lang->WRONG_REQUEST . ' code 2');
     }
     $oFields = array_keys($objectCfg->getFieldsConfig());
     if ($objectField !== $name && in_array($name, $oFields, true)) {
         Response::jsonError($this->_lang->FILL_FORM, array(array('id' => 'name', 'msg' => $this->_lang->SB_UNIQUE)));
     }
     $unique = Request::post('unique', 'str', '');
     $newConfig = array();
     $newConfig['type'] = Request::post('type', 'str', '');
     $newConfig['title'] = Request::post('title', 'str', '');
     $newConfig['unique'] = $unique === false ? '' : $unique;
     $newConfig['db_isNull'] = Request::post('db_isNull', 'boolean', false);
     $newConfig['required'] = Request::post('required', 'boolean', false);
     $newConfig['validator'] = Request::post('validator', 'string', '');
     if ($newConfig['type'] == 'link') {
         if ($newConfig['db_isNull']) {
             $newConfig['required'] = false;
         }
         /**
          * Process link field
          */
         $newConfig['link_config']['link_type'] = Request::post('link_type', 'str', 'object');
         if ($newConfig['link_config']['link_type'] === Db_Object_Config::Link_DICTIONARY) {
             $newConfig['link_config']['object'] = Request::post('dictionary', 'str', '');
             $newConfig['db_type'] = 'varchar';
             $newConfig['db_len'] = 255;
             $newConfig['db_isNull'] = false;
             if ($newConfig['required']) {
                 $newConfig['db_default'] = false;
             } else {
                 $newConfig['db_default'] = '';
             }
         } else {
             $linkedObject = Request::post('object', 'string', false);
             if (!$linkedObject) {
                 Response::jsonError($this->_lang->FILL_FORM, array(array('id' => 'object', 'msg' => $this->_lang->CANT_BE_EMPTY)));
             }
             try {
                 $cf = Db_Object_Config::getInstance($linkedObject);
             } catch (Exception $e) {
                 Response::jsonError($this->_lang->FILL_FORM, array(array('id' => 'object', 'msg' => $this->_lang->INVALID_VALUE)));
             }
             $newConfig['link_config']['object'] = $linkedObject;
             switch ($newConfig['link_config']['link_type']) {
                 case Db_Object_Config::LINK_OBJECT_LIST:
                     $newConfig['db_type'] = 'longtext';
                     $newConfig['db_isNull'] = false;
                     $newConfig['db_default'] = '';
                     break;
                 case Db_Object_Config::LINK_OBJECT:
                     $newConfig['db_isNull'] = (bool) (!$newConfig['required']);
                     $newConfig['db_type'] = 'bigint';
                     $newConfig['db_default'] = false;
                     $newConfig['db_unsigned'] = true;
                     break;
             }
         }
     } elseif ($newConfig['type'] == 'encrypted') {
         $setDefault = Request::post('set_default', 'boolean', false);
         if (!$setDefault) {
             $newConfig['db_default'] = false;
         } else {
             $newConfig['db_default'] = Request::post('db_default', 'string', false);
         }
         $newConfig['db_type'] = 'longtext';
         $newConfig['is_search'] = false;
         $newConfig['allow_html'] = false;
     } else {
         $setDefault = Request::post('set_default', 'boolean', false);
         /*
          * Process std field
          */
         $newConfig['db_type'] = Request::post('db_type', 'str', 'false');
         if (!$newConfig['db_type']) {
             Response::jsonError($this->_lang->FILL_FORM, array(array('id' => 'db_type', 'msg' => $this->_lang->CANT_BE_EMPTY)));
         }
         if ($newConfig['db_type'] == 'bool' || $newConfig['db_type'] == 'boolean') {
             /*
              * boolean
              */
             $newConfig['required'] = false;
             $newConfig['db_default'] = (int) Request::post('db_default', 'bool', false);
         } elseif (in_array($newConfig['db_type'], Db_Object_Builder::$intTypes, true)) {
             /*
              * integer
              */
             $newConfig['db_default'] = Request::post('db_default', 'integer', false);
             $newConfig['db_unsigned'] = Request::post('db_unsigned', 'bool', false);
         } elseif (in_array($newConfig['db_type'], Db_Object_Builder::$floatTypes)) {
             /*
              * float
              */
             $newConfig['db_default'] = Request::post('db_default', 'float', false);
             $newConfig['db_unsigned'] = Request::post('db_unsigned', 'bool', false);
             $newConfig['db_scale'] = Request::post('db_scale', 'integer', 0);
             $newConfig['db_precision'] = Request::post('db_precision', 'integer', 0);
         } elseif (in_array($newConfig['db_type'], Db_Object_Builder::$charTypes, true)) {
             /*
              * char
              */
             $newConfig['db_default'] = Request::post('db_default', 'string', false);
             $newConfig['db_len'] = Request::post('db_len', 'integer', 255);
             $newConfig['is_search'] = Request::post('is_search', 'bool', false);
             $newConfig['allow_html'] = Request::post('allow_html', 'bool', false);
         } elseif (in_array($newConfig['db_type'], Db_Object_Builder::$textTypes, true)) {
             /*
              * text
              */
             $newConfig['db_default'] = Request::post('db_default', 'string', false);
             $newConfig['is_search'] = Request::post('is_search', 'bool', false);
             $newConfig['allow_html'] = Request::post('allow_html', 'bool', false);
             if (!$newConfig['required']) {
                 $newConfig['db_isNull'] = true;
             }
         } elseif (in_array($newConfig['db_type'], Db_Object_Builder::$dateTypes, true)) {
             /*
              * date
              */
             if (!$newConfig['required']) {
                 $newConfig['db_isNull'] = true;
             }
         } else {
             Response::jsonError($this->_lang->FILL_FORM, array(array('id' => 'db_type', 'msg' => $this->_lang->INVALID_VALUE)));
         }
         if (!$setDefault) {
             $newConfig['db_default'] = false;
         }
     }
     /**
      * @todo Rename
      */
     if ($objectField != $name && !empty($objectField)) {
         $objectCfg->setFieldconfig($objectField, $newConfig);
         $renameResult = $manager->renameField($objectCfg, $objectField, $name);
         switch ($renameResult) {
             case Backend_Orm_Manager::ERROR_EXEC:
                 Response::jsonError($this->_lang->CANT_EXEC);
                 break;
             case Backend_Orm_Manager::ERROR_FS_LOCALISATION:
                 Response::jsonError($this->_lang->CANT_WRITE_FS . ' (' . $this->_lang->LOCALIZATION_FILE . ')');
                 break;
         }
     } else {
         $objectCfg->setFieldconfig($name, $newConfig);
         $objectCfg->fixConfig();
     }
     if ($objectCfg->save()) {
         $builder = new Db_Object_Builder($object);
         $builder->build();
         Response::jsonSuccess();
     } else {
         Response::jsonError($this->_lang->CANT_WRITE_FS);
     }
 }
Пример #4
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']));
     }
 }