Exemple #1
0
 public function testRenameField()
 {
     $o = new Db_Object_Builder('Page');
     $cfg = Db_Object_Config::getInstance('Page');
     $this->assertTrue($cfg->renameField('page_title', 'untitle'));
     $this->assertTrue($o->validate());
     $this->assertTrue($cfg->renameField('untitle', 'page_title'));
     $this->assertTrue($o->validate());
 }
Exemple #2
0
 public function testCheckEngineCompatibility()
 {
     $o = new Db_Object_Builder('Page');
     $this->assertTrue($o->checkEngineCompatibility('myisam'));
     $this->assertTrue($o->checkEngineCompatibility('innodb'));
     $this->assertTrue(is_array($o->checkEngineCompatibility('memory')));
     $invalidEngine = false;
     try {
         $o->checkEngineCompatibility('ksdhuis');
     } catch (Exception $e) {
         $invalidEngine = true;
     }
     $this->assertTrue($invalidEngine);
 }
Exemple #3
0
 /**
  * Use foreign keys
  *
  * @param boolean $boolean
  */
 public static function useForeignKeys($boolean)
 {
     self::$_foreignKeys = (bool) $boolean;
 }
Exemple #4
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);
     }
 }
Exemple #5
0
 /**
  * Run backend application
  */
 protected function _runBackend()
 {
     if ($this->_cache) {
         Blockmanager::setDefaultCache($this->_cache);
     }
     /*
      * Prepare objects
      */
     Db_Object_Builder::useForeignKeys($this->_config->get('foreign_keys'));
     /*
      * Inject Externals exper ino Objects Manager
      */
     if ($this->_config->get('allow_externals')) {
         Db_Object_Manager::setExternalsExpert($this->_getExternalsExpert());
     }
     $cfgBackend = Config::factory(Config::File_Array, $this->_config->get('configs') . 'backend.php');
     Registry::set('backend', $cfgBackend, 'config');
     self::$_templates = $this->_config->get('templates') . 'system/' . $cfgBackend->get('theme') . '/';
     $page = Page::getInstance();
     $page->setTemplatesPath(self::$_templates);
     $user = User::getInstance();
     /*
      * Update "Users Online" statistics
      */
     if ($this->_config->get('usersOnline') && $user->isAuthorized()) {
         Model::factory('Online')->addOnline(session_id(), $user->id);
     }
     /*
      * Start routing
      */
     $router = new Backend_Router();
     $router->route();
     $controller = Request::getInstance()->getPart(1);
     /*
      * Define frontent JS variables
      */
     $res = Resource::getInstance();
     $res->addInlineJs('
         app.wwwRoot = "' . $this->_config->get('wwwroot') . '";
     	app.admin = "' . $this->_config->get('wwwroot') . $this->_config->get('adminPath') . '";
     	app.delimiter = "' . $this->_config->get('urlDelimiter') . '";
     	app.root = "' . $this->_config->get('wwwroot') . $this->_config->get('adminPath') . $this->_config->get('urlDelimiter') . $controller . $this->_config->get('urlDelimiter') . '";
     ');
     /*
      * Load template
      */
     $template = new Template();
     $template->disableCache();
     $template->setProperties(array('wwwRoot' => $this->_config->get('wwwroot'), 'page' => $page, 'urlPath' => $controller, 'resource' => $res, 'path' => self::$_templates, 'adminPath' => $this->_config->get('adminPath'), 'development' => $this->_config->get('development'), 'version' => Config::factory(Config::File_Array, $this->_config->get('configs') . 'versions.php')->get('core'), 'lang' => $this->_config->get('language'), 'modules' => Config::factory(Config::File_Array, $this->_config->get('backend_modules')), 'userModules' => $user->getAvailableModules(), 'useCSRFToken' => $cfgBackend->get('use_csrf_token')));
     Response::put($template->render(self::$_templates . 'layout.php'));
 }
Exemple #6
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";
}
Exemple #7
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']));
     }
 }
Exemple #8
0
 /**
  * Rename field and rebuild the database table
  * @param string $oldname
  * @param string $newName
  * @return boolean
  */
 public function renameField($oldName, $newName)
 {
     $fields = $this->getFieldsConfig();
     $fields[$newName] = $fields[$oldName];
     unset($fields[$oldName]);
     $this->_config->set('fields', $fields);
     $indexes = $this->getIndexesConfig();
     /**
      * Check for indexes for field
      */
     foreach ($indexes as $index => &$config) {
         if (isset($config['columns']) && !empty($config['columns'])) {
             /*
              * Rename index link
              */
             foreach ($config['columns'] as $id => &$value) {
                 if ($value === $oldName) {
                     $value = $newName;
                 }
             }
             unset($value);
         }
     }
     $this->_config->set('indexes', $indexes);
     $builder = new Db_Object_Builder($this->getName(), false);
     return $builder->renameField($oldName, $newName);
 }