Esempio n. 1
0
 /**
  * Drops tables
  */
 public function actionDrop()
 {
     $response = new AjaxResponse();
     if (!Yii::app()->getRequest()->getParam('redirectOnSuccess')) {
         $response->refresh = true;
     }
     $response->executeJavaScript('sideBar.loadTables(schema);');
     $tables = (array) $_POST['tables'];
     $droppedTables = $droppedSqls = array();
     foreach ($tables as $table) {
         $tableObj = Table::model()->findByPk(array('TABLE_SCHEMA' => $this->schema, 'TABLE_NAME' => $table));
         $tableObj->throwExceptions = true;
         try {
             $sql = $tableObj->delete();
             $droppedTables[] = $table;
             $droppedSqls[] = $sql;
         } catch (DbException $ex) {
             $response->addNotification('error', Yii::t('core', 'errorDropTable', array('{table}' => $table)), $ex->getText(), $ex->getSql());
         }
     }
     $count = count($droppedTables);
     if ($count > 0) {
         $response->addNotification('success', Yii::t('core', 'successDropTable', array($count, '{table}' => $droppedTables[0], '{tableCount}' => $count)), $count > 1 ? implode(', ', $droppedTables) : null, implode("\n", $droppedSqls));
         if (Yii::app()->getRequest()->getParam('redirectOnSuccess')) {
             $response->redirectUrl = '#tables';
         }
     }
     $this->sendJSON($response);
 }
Esempio n. 2
0
 /**
  * Drops views.
  */
 public function actionDrop()
 {
     $response = new AjaxResponse();
     $response->refresh = true;
     $response->executeJavaScript('sideBar.loadViews(schema);');
     $views = (array) $_POST['views'];
     $droppedViews = $droppedSqls = array();
     foreach ($views as $view) {
         $viewObj = View::model()->findByPk(array('TABLE_SCHEMA' => $this->schema, 'TABLE_NAME' => $view));
         try {
             $sql = $viewObj->delete();
             $droppedViews[] = $view;
             $droppedSqls[] = $sql;
         } catch (DbException $ex) {
             $response->addNotification('error', Yii::t('core', 'errorDropView', array('{view}' => $view)), $ex->getText(), $ex->getSql());
         }
     }
     $count = count($droppedViews);
     if ($count > 0) {
         $response->addNotification('success', Yii::t('core', 'successDropView', array($count, '{view}' => $droppedViews[0], '{viewCount}' => $count)), $count > 1 ? implode(', ', $droppedViews) : null, implode("\n", $droppedSqls));
     }
     $this->sendJSON($response);
 }
Esempio n. 3
0
 /**
  * Drop a schema.
  */
 public function actionDrop()
 {
     $response = new AjaxResponse();
     $response->refresh = true;
     $response->executeJavaScript('sideBar.loadSchemata()');
     $schemata = (array) $_POST['schemata'];
     $droppedSchemata = $droppedSqls = array();
     Schema::$db = Yii::app()->getDb();
     foreach ($schemata as $schema) {
         $schemaObj = Schema::model()->findByPk($schema);
         $schemaObj->throwExceptions = true;
         try {
             $sql = $schemaObj->delete();
             $droppedSchemata[] = $schema;
             $droppedSqls[] = $sql;
         } catch (DbException $ex) {
             $response->addNotification('error', Yii::t('core', 'errorDropSchema', array('{schema}' => $schema)), $ex->getText(), $ex->getSql());
         }
     }
     $count = count($droppedSchemata);
     if ($count > 0) {
         $response->addNotification('success', Yii::t('core', 'successDropSchema', array($count, '{schema}' => $droppedSchemata[0], '{schemaCount}' => $count)), $count > 1 ? implode(', ', $droppedSchemata) : null, implode("\n", $droppedSqls));
     }
     $this->sendJSON($response);
 }
Esempio n. 4
0
 public function runImport()
 {
     $response = new AjaxResponse();
     $response->refresh = true;
     $response->executeJavaScript('sideBar.loadTables("' . $this->schema . '")');
     $this->mimeType = CFileHelper::getMimeType($this->file);
     $filesize = filesize($this->file);
     // Open file and set position to last position
     switch ($this->mimeType) {
         // GZip - Files
         case 'application/x-gzip':
             $handle = gzopen($this->file, 'r');
             $content = gzread($handle, $filesize);
             gzclose($handle);
             break;
             // BZip - Files
         // BZip - Files
         case 'application/x-bzip2':
             $handle = bzopen($this->file, 'r');
             $content = bzread($handle, $filesize);
             bzclose($handle);
             break;
             // All other files (plain text)
         // All other files (plain text)
         default:
             $content = file_get_contents($this->file);
             break;
     }
     $sqlSplitter = new SqlSplitter($content);
     $queries = $sqlSplitter->getQueries();
     foreach ($queries as $query) {
         try {
             $cmd = $this->db->createCommand($query);
             # Do NOT prepare the statement, because of double quoting
             $cmd->execute();
         } catch (CDbException $ex) {
             $dbException = new DbException($cmd);
             if (!in_array(@$dbException->getNumber(), $this->ignoreErrorNumbers)) {
                 $dbException = new DbException($cmd);
                 $response->addNotification('error', Yii::t('core', 'errorExecuteQuery'), $dbException->getText() . '  ' . $dbException->getNumber(), StringUtil::cutText($dbException->getSql(), 100));
                 $response->addData('error', true);
                 $response->refresh = true;
                 @unlink($this->file);
                 return $response;
             }
         }
     }
     $response->addNotification('success', Yii::t('core', 'successImportFile'), Yii::t('core', 'executedQueries') . ":" . count($queries));
     // We cannot output json here, see: http://jquery.malsup.com/form/#file-upload
     Yii::app()->end($response);
 }