/** * Drops trigger. */ public function actionDrop() { // Get post vars $triggerName = Yii::app()->request->getPost('trigger'); $response = new AjaxResponse(); try { $trigger = Trigger::model()->findByPk(array('TRIGGER_SCHEMA' => $this->schema, 'TRIGGER_NAME' => $triggerName)); $sql = $trigger->delete(); $response->addNotification('success', Yii::t('core', 'successDropTrigger', array('{trigger}' => $trigger->TRIGGER_NAME)), null, $sql); $response->addData('success', true); } catch (DbException $ex) { $response->addNotification('error', Yii::t('core', 'errorDropTrigger', array('{trigger}' => $triggerName)), $ex->getText(), $ex->getSql()); $response->addData('success', false); } $this->sendJSON($response); }
public function actionDrop() { // Get post vars $indexName = Yii::app()->request->getPost('index'); $response = new AjaxResponse(); try { $index = Index::model()->findByAttributes(array('TABLE_SCHEMA' => $this->schema, 'TABLE_NAME' => $this->table, 'INDEX_NAME' => $indexName)); $index->throwExceptions = true; $sql = $index->delete(); $response->addNotification('success', Yii::t('core', 'successDropIndex', array('{index}' => $index->INDEX_NAME)), null, $sql); $response->addData('success', true); } catch (DbException $ex) { $response->addNotification('error', Yii::t('core', 'errorDropIndex', array('{index}' => $indexName)), $ex->getText(), $ex->getSql()); $response->addData('success', false); } $this->sendJSON($response); }
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); }