示例#1
0
 public function init()
 {
     // Add ordering
     $criteria = new CDbCriteria();
     $criteria->order = "SCHEMA_NAME ASC";
     $schemata = Schema::model()->findAll($criteria);
     $dbSeperator = "_";
     $items = $root = $children = $items = array();
     foreach ($schemata as $schema) {
         // Find prefix in name
         if ($position = strpos($schema->SCHEMA_NAME, $dbSeperator)) {
             $prefix = substr($schema->SCHEMA_NAME, 0, $position);
             $root[$prefix] = $prefix;
             $children[$prefix][] = substr($schema->SCHEMA_NAME, $position + 1);
         } else {
             $root[] = $schema->SCHEMA_NAME;
         }
     }
     $i = 0;
     foreach ($root as $key => $item) {
         $childs = array();
         $childrenCount = count($children[$item]);
         if ($childrenCount > 1) {
             foreach ($children[$item] as $child) {
                 $childs[] = array('text' => CHtml::link($child, SchemaController::createUrl("/schema/" . $item . $dbSeperator . $child)));
             }
         } else {
             if ($childrenCount == 1) {
                 $name = $item . $dbSeperator . $children[$item][0];
             } else {
                 $name = $item;
             }
             $items[] = array('text' => CHtml::link($name, SchemaController::createUrl("/schema/" . $name)));
             $i++;
             continue;
         }
         $items[] = array('text' => $childrenCount == 0 ? CHtml::link($item, SchemaController::createUrl("/schema/" . $item)) : $item, 'expanded' => $i == 0 ? true : false, 'children' => $childs);
         $i++;
     }
     $this->data = $items;
     parent::init();
 }
示例#2
0
文件: SchemaTest.php 项目: cebe/chive
 /**
  * Tests to drop a database.
  */
 public function testDrop()
 {
     // Load schema
     $schema = Schema::model()->findByPk('schematest2');
     // Drop
     $this->assertEquals(true, $schema->delete());
     // Load again
     $this->assertEquals(null, Schema::model()->findByPk('schematest2'));
 }
示例#3
0
 /**
  * Loads the current schema.
  *
  * @return	Schema
  */
 public function loadSchema()
 {
     if (is_null($this->_schema)) {
         $this->_schema = Schema::model()->findByPk($this->schema);
         if (is_null($this->_schema)) {
             throw new CHttpException(500, 'The requested schema does not exist.');
         }
     }
     return $this->_schema;
 }
示例#4
0
文件: ExportPage.php 项目: cebe/chive
 /**
  * Runs the form.
  */
 private function runForm()
 {
     // @todo: Load all exporters
     $exporterNames = array('SqlExporter', 'CsvExporter');
     // Instantiate supported exporters
     $this->exporters = array();
     foreach ($exporterNames as $exporter) {
         $supported = call_user_func(array($exporter, 'getSupportedModes'));
         if (in_array($this->mode, $supported)) {
             $this->exporters[] = new $exporter($this->mode);
         }
     }
     // Create the object list
     $this->objects = array();
     if ($this->mode == 'objects') {
         // Load schema
         $schema = Schema::model()->findByPk($this->schema);
         // Tables
         $tables = $schema->tables;
         if (count($tables) > 0) {
             $data = array();
             foreach ($tables as $table) {
                 $data['t:' . $table->TABLE_NAME] = $table->TABLE_NAME;
             }
             $this->objects[Yii::t('core', 'tables')] = $data;
         }
         // Views
         $views = $schema->views;
         if (count($views) > 0) {
             $data = array();
             foreach ($views as $view) {
                 $data['v:' . $view->TABLE_NAME] = $view->TABLE_NAME;
             }
             $this->objects[Yii::t('core', 'views')] = $data;
         }
         // Routines
         $routines = $schema->routines;
         if (count($routines) > 0) {
             $data = array();
             foreach ($routines as $routine) {
                 $data['r:' . $routine->ROUTINE_NAME] = $routine->ROUTINE_NAME;
             }
             $this->objects[Yii::t('core', 'routines')] = $data;
         }
     }
 }
示例#5
0
 public function actionCreateSchema()
 {
     $schema = new SchemaPrivilege();
     $schema->User = $this->user;
     $schema->Host = $this->host;
     if (isset($_POST['SchemaPrivilege'])) {
         $schema->attributes = $_POST['SchemaPrivilege'];
         if ($sql = $schema->save()) {
             $response = new AjaxResponse();
             $response->addNotification('success', Yii::t('core', 'successAddSchemaSpecificPrivileges', array('{user}' => $schema->User, '{host}' => $schema->Host, '{schema}' => $schema->Db)), null);
             $response->refresh = true;
             $this->sendJSON($response);
         }
     }
     // Prepare all schemata
     $schemata = $existing = array();
     $allSchemata = Schema::model()->findAll();
     $allExisting = SchemaPrivilege::model()->findAllByAttributes(array('User' => $this->user, 'Host' => $this->host));
     foreach ($allExisting as $existing1) {
         $existing[] = $existing1->Db;
     }
     foreach ($allSchemata as $schema1) {
         if (array_search($schema1->SCHEMA_NAME, $existing) === false) {
             $schemata[$schema1->SCHEMA_NAME] = $schema1->SCHEMA_NAME;
         }
     }
     $this->render('schemaPrivilegeForm', array('schema' => $schema, 'schemata' => $schemata));
 }