Re-Create the table with modified column.

@param string $table
@param string $action
@param array $params
343499
private function recreateTable($table, $action, $params)
    {
        $this->db->transaction(function() use($table, $action, $params) {
            $quotedTable = $this->db->quoteName($table);
            $columns = $this->columns($table);
            $indexes = $this->indexes($table);
            $oldColumns = '"' . str_replace(',', '","', str_replace('"', '""', implode(',', array_keys($columns)))) . '"';

            // 1. rename the old table
            $oldTable = 't' . uniqid();
            $this->db->exec("ALTER TABLE {$quotedTable} RENAME TO {$oldTable}");

            if ($action == 'addColumn') {
                $column  = $params['column'];
                $options = $params['options'];

                // 2. create the new table with the new column
                $columns[$column] = $options;
                $this->createTable($table, $columns);
                $newColumns = '"' . str_replace(',', '","', str_replace('"', '""', implode(',', array_keys($columns)))) . '"';

                // 3. copy the contents across from the original table
                /** @noinspection SqlNoDataSourceInspection */
                $quotedColumn = $this->db->quoteName($column);
                $zero = $this->zero($options['type']);
                $this->db->exec("INSERT INTO {$quotedTable} ({$newColumns}) SELECT {$oldColumns}, ? AS {$quotedColumn} FROM {$oldTable}", [$zero]);
            }
            else if ($action == 'dropColumn') {
                $column = $params['column'];

                // 2. create the new table without dropped column
                unset($columns[$column]);
                $this->createTable($table, $columns);
                $newColumns = '"' . str_replace(',', '","', str_replace('"', '""', implode(',', array_keys($columns)))) . '"';

                /** @noinspection SqlDialectInspection */
                //$this->db->exec('DELETE FROM _comments WHERE table_name = ? AND column_name = ?', [$table, $column]);

                // 3. copy the contents across from the original table
                /** @noinspection SqlNoDataSourceInspection */
                $this->db->exec("INSERT INTO {$quotedTable} ({$newColumns}) SELECT {$newColumns} FROM {$oldTable}");

                $indexes = array_filter($indexes, function($index) use ($column) {
                    return !in_array($column, $index['columns']);
                });
            }
            else if ($action == 'renameColumn') {
                $from = $params['from'];
                $to   = $params['to'];
                if ($from != $to) {
                    // 2. create the new table with renamed column
                    $columns[$from]['name'] = $to;
                    $newColumns = [];
                    foreach ($columns as $attr) {
                        $newColumns[$attr['name']] = $attr;
                    }
                    $this->createTable($table, $newColumns);
                    $newColumns = '"' . str_replace(',', '","', str_replace('"', '""', implode(',', array_keys($newColumns)))) . '"';

                    /** @noinspection SqlDialectInspection */
                    //$this->db->exec('DELETE FROM _comments WHERE table_name = ? AND column_name = ?', [$table, $from]);

                    // 3. copy the contents across from the original table
                    /** @noinspection SqlNoDataSourceInspection */
                    $this->db->exec("INSERT INTO {$quotedTable} ({$newColumns}) SELECT {$oldColumns} FROM {$oldTable}");

                    foreach ($indexes as $name => $index) {
                        $pos = array_search($from, $index['columns']);
                        if ($pos !== false) {
                            $indexes[$name]['columns'][$pos] = $to;
                            $newName = str_replace('_' . $from . '_', '_' . $to . '_', $name);
                            if ($newName != $name) {
                                $indexes[$name]['name'] = $newName;
                                $indexes[$newName] = $indexes[$name];
                                unset($indexes[$name]);
                            }
                        }
                    }
                }
            }
            else if ($action == 'addPrimary') {
                $idxColumns = $params['columns'];

                // 2. create the new table with primary key
                $definition = [];
                foreach ($columns as $column => $attr) {
                    $definition[$column] = $this->db->quoteName($column) . ' ' . $this->compileColumnDefinition($attr);
                }
                $definition = implode(', ', $definition);
                $idxColumns = '"' . str_replace(',', '","', str_replace('"', '""', implode(',', $idxColumns))) . '"';
                /** @noinspection SqlNoDataSourceInspection */
                $this->db->exec("CREATE TABLE {$quotedTable} ({$definition}, PRIMARY KEY ($idxColumns))");

                // 3. copy the contents across from the original table
                /** @noinspection SqlNoDataSourceInspection */
                $this->db->exec("INSERT INTO {$quotedTable} ({$oldColumns}) SELECT {$oldColumns} FROM {$oldTable}");
            }
            else if ($action == 'dropIndex') {
                $primary = isset($params['primary']) ? $params['primary'] : false ;
                if ($primary) {
                    $indexes = array_filter($indexes, function($index) {
                        return !$index['primary'];
                    });
                }
                else {
                    $name = $params['name'];
                    $indexes = array_filter($indexes, function($index) use ($name) {
                        return $index['name'] != $name;
                    });
                }
                $this->createTable($table, $columns);
                $this->db->exec("INSERT INTO {$quotedTable} ({$oldColumns}) SELECT {$oldColumns} FROM {$oldTable}");
            }

            // 4. drop the old table
            /** @noinspection SqlNoDataSourceInspection */
            $this->db->exec("DROP TABLE {$oldTable}");

            // 5. Create the indexes
            foreach ($indexes as $attr) {
                $this->addIndex($table, $attr['columns'], $attr);
            }
        });
    }
730331
private function createTable(Table &$table) {
        $annotations = $this->getClassSettings();
        $create = false;
        foreach ($annotations as $columnName => $descArray) {
            $create = true;
            $dbColumnName = Util::camelTo_($columnName);

            if (isset($descArray['attrs']['primary']) && $descArray['attrs']['primary']) {
                $table->setPrimaryKey($dbColumnName);
            }

            if (isset($descArray['attrs']['reference'])) { // Reference not ReferenceMany
                $onDelete = (isset($descArray['attrs']['reference']['onDelete'])) ?
                        $descArray['attrs']['reference']['onDelete'] : 'RESTRICT';
                $onUpdate = (isset($descArray['attrs']['reference']['onUpdate'])) ?
                        $descArray['attrs']['reference']['onUpdate'] : 'RESTRICT';
                $table->addReference($dbColumnName, $descArray['attrs']['reference']['table'], $descArray['attrs']['reference']['column'], $onDelete, $onUpdate);

                $refTable = new Table($descArray['attrs']['reference']['table'], $table->getConnection());
                $refColumns = $refTable->getColumns();
                if (!empty($refColumns[$descArray['attrs']['reference']['column']]['charset'])) {
                    $descArray['attrs']['charset'] = $refColumns[$descArray['attrs']['reference']['column']]['charset'];
                    $descArray['attrs']['collation'] = $refColumns[$descArray['attrs']['reference']['column']]['collation'];
                }

                unset($descArray['attrs']['reference']['table']);
                unset($descArray['attrs']['reference']['column']);
                unset($descArray['attrs']['reference']['model']);

                if (isset($descArray['attrs']['reference']['onUpdate']))
                    unset($descArray['attrs']['reference']['onUpdate']);
                if (isset($descArray['attrs']['reference']['onDelete']))
                    unset($descArray['attrs']['reference']['onDelete']);

                if (!empty($descArray['attrs']['reference'])) {
                    $descArray['attrs'] = array_merge($descArray['attrs'], $descArray['attrs']['reference']);
                    unset($descArray['attrs']['reference']);
                }
            }

            $table->addColumn($dbColumnName, $this->parseAttributes($columnName, $descArray));
            $this->checkIndexes($dbColumnName, $descArray, $table);
        }

        return ($create) ? $table->getConnection()->createTable($table, false) : false;
    }
1340962
function update( $table, $data, $where = array(), $params = array() ) {

        if ( empty( $data ) ) return;

        $set = array();

        foreach ( $data as $column => $value ) {

            $set[] = $this->quoteIdentifier( $column ) . " = " . $this->quote( $value );

        }

        if ( !is_array( $where ) ) $where = array( $where );
        if ( !is_array( $params ) ) $params = array_slice( func_get_args(), 3 );

        $table = $this->rewriteTable( $table );
        $query = "UPDATE " . $this->quoteIdentifier( $table );
        $query .= " SET " . implode( ", ", $set );
        $query .= $this->getSuffix( $where );

        $this->onQuery( $query, $params );

        $statement = $this->prepare( $query );
        $statement->execute( $params );

        return $statement;

    }
755532
public static function dropConstraint($table, $name, $ifExists = false, $action = null)
    {
        $query = static::getQuery();

        return static::build(
            'ALTER TABLE',
            $query->quoteName($table),
            'DROP CONSTRAINT',
            $ifExists ? 'IF EXISTS' : null,
            $query->quoteName($name),
            $action
        );
    }
1088544
public function doAction( $action, $params = array() )
    {
        if ( isset( $this->actions[ $action ] ) )
        {
            foreach( $this->actions[ $action ] as $callback )
            {
                call_user_func_array( $callback[ 'callback' ], $params );

                if ( $this->debug )
                {
                    echo PHP_EOL . '->ACTION: ' . $action . ' -> '
                            . $this->_serializeCallback( $callback[ 'callback' ] )
                            . ' + Priority: ' . $callback[ 'priority' ]
                            . PHP_EOL;
                }
            }
        }
    }
747927
public function modifyTable()
    {
        $table = $this->getTable();
        $primary_string = $this->getParameter('primary_string');

        if(!$primary_string) {
            $this->exceptionError('Need set parameter "primary_string" in table '.$table->getName());
        }

        if(!$table->hasColumn($primary_string)) {
            $this->exceptionError('Not found column "'.$primary_string.'" in table '.$table->getName());
        }
    }
766257
private function exec($action, $table, $values)
    {
        $action = strtolower($action);
        if (!isset($this->stmt[$action][$table])) {
            if ($this->transaction === false && $action != 'select') {
                $this->transaction = true;
                $this->db->exec('BEGIN IMMEDIATE');
            }
            switch ($action) {
                case 'select':
                    if ($table == 'sitemap') {
                        $stmt = $this->db->prepare('SELECT docid, hash, updated, deleted FROM sitemap WHERE path = ?', 'assoc');
                    }
                    break;
                case 'insert':
                    if ($table == 'search') {
                        $stmt = $this->db->insert('search', array('path', 'title', 'description', 'keywords', 'content'));
                    } elseif ($table == 'sitemap') {
                        $stmt = $this->db->insert('sitemap', array('docid', 'category_id', 'path', 'info', 'image', 'content', 'hash', 'updated', 'deleted'));
                    } elseif ($table == 'categories') {
                        $stmt = $this->db->insert('categories', array('category', 'parent'));
                    }
                    break;
                case 'update':
                    if ($table == 'search') {
                        $stmt = $this->db->update('search', 'docid', array('path', 'title', 'description', 'keywords', 'content'));
                    } elseif ($table == 'sitemap') {
                        $stmt = $this->db->update('sitemap', 'docid', array('category_id', 'path', 'info', 'image', 'content', 'hash', 'updated', 'deleted'));
                    }
                    break;
                case 'delete':
                    if ($table == 'search') {
                        $stmt = $this->db->prepare('DELETE FROM search WHERE docid = ?');
                    } elseif ($table == 'sitemap') {
                        $stmt = $this->db->prepare('DELETE FROM sitemap WHERE docid = ?');
                    }
                    break;
            }
            $this->stmt[$action][$table] = (isset($stmt)) ? $stmt : null;
        }
        $result = $this->db->execute($this->stmt[$action][$table], $values);
        if ($action == 'select') {
            $row = $this->db->fetch($this->stmt[$action][$table]);

            return (!empty($row)) ? $row : false;
        } else {
            return $result;
        }
    }
146695
public function handleController(
        $controller, $action = null, array $params = null, $model = null
    ) {

        ! $model || $model = $this->modelFactory->create(null, $model);

        $this->setController(
            $this->controllerFactory->create($params, $controller, $model)
        );

        if (!is_null($action)) {
            $this->setControllerResult(
                $this->executeMethod($this->getController(), $action, $params, $model)
            );
        }
    }
928855
private function createActionMiddleware($action, array $params){
        $middlewares    = [];

        $middlewares[]  = $this->container->get("core.middleware.action")
            ->setAction($action)
            ->setParams($params)
        ;

        return $middlewares;
    }
1090862
public function updateTable($table, ...$tables)
    {
        $instance = $this->updateQueryInstance();

        $instance->updateQuery()->table($table, ...$tables);

        return $instance;
    }
70327
public function make(Table $table, $action, array $ids = [], array $options = [])
    {
        $count       = count($ids);
        $options     = $this->_getOptions($options, $count);
        $redirectUrl = $options['redirect'];
        $messages    = new JSON($options['messages']);

        $event = EventManager::trigger($this->_getEventName($action), $this->_controller, ['ids' => $ids]);
        $ids   = (array) $event->getData('ids');
        $count = count($ids);

        if (!$action) {
            $this->Flash->error($messages->get('no_action'));
            return $this->_controller->redirect($redirectUrl);
        }

        if ($count <= 0) {
            $this->Flash->error($messages->get('no_choose'));
            return $this->_controller->redirect($redirectUrl);
        }

        $this->_loadBehavior($table);
        if ($table->process($action, $ids)) {
            return $this->_process($action, $messages, $redirectUrl, $ids);
        }

        $this->Flash->error(__d('core', 'An error has occurred. Please try again.'));
        return $this->_controller->redirect($redirectUrl);
    }
608232
private function createIndex(Table $table, array $columns)
    {
        if (count($columns) > 0) {
            $indexPrefix = "idx_" . RdsDeliveryExecutionService::TABLE_NAME . "_";

            // Index names are limited to 63 characters in PostgreSQL (64 in MySQL)
            $indexName = substr($indexPrefix . implode("_", $columns), 0, 63);

            $table->addIndex($columns, $indexName);
        }
    }
1120828
public function update(string $table) {
		// set the main action
		$this->action('UPDATE');
		// set the destination table
		list($this->Table) = Query\Convert::columnToPlaceholder($this->Quote ,$table);
		// return self to the next method
		return $this;
	}
776464
public function run($action = null, $params = [])
    {
        $this->action = $action;
        $this->params = $params;

        /*
         * Check security token.
         */
        if (!$this->verifyCsrfToken()) {
            return Response::make(Lang::get('backend::lang.page.invalid_token.label'), 403);
        }

        /*
         * Check forced HTTPS protocol.
         */
        if (!$this->verifyForceSecure()) {
            return Redirect::secure(Request::path());
        }

        /*
         * Determine if this request is a public action.
         */
        $isPublicAction = in_array($action, $this->publicActions);

        /*
         * Check that user is logged in and has permission to view this page
         */
        if (!$isPublicAction) {

            /*
             * Not logged in, redirect to login screen or show ajax error.
             */
            if (!BackendAuth::check()) {
                return Request::ajax()
                    ? Response::make(Lang::get('backend::lang.page.access_denied.label'), 403)
                    : Backend::redirectGuest('backend/auth');
            }

            /*
             * Check access groups against the page definition
             */
            if ($this->requiredPermissions && !$this->user->hasAnyAccess($this->requiredPermissions)) {
                return Response::make(View::make('backend::access_denied'), 403);
            }
        }

        /*
         * Extensibility
         */
        if ($event = $this->fireSystemEvent('backend.page.beforeDisplay', [$action, $params])) {
            return $event;
        }

        /*
         * Set the admin preference locale
         */
        BackendPreference::setAppLocale();
        BackendPreference::setAppFallbackLocale();

        /*
         * Execute AJAX event
         */
        if ($ajaxResponse = $this->execAjaxHandlers()) {
            return $ajaxResponse;
        }

        /*
         * Execute postback handler
         */
        if (
            ($handler = post('_handler')) &&
            ($handlerResponse = $this->runAjaxHandler($handler)) &&
            $handlerResponse !== true
        ) {
            return $handlerResponse;
        }

        /*
         * Execute page action
         */
        $result = $this->execPageAction($action, $params);

        if (!is_string($result)) {
            return $result;
        }

        return Response::make($result, $this->statusCode);
    }
1002410
public function _execute( $action, $params = array() ) 
	{
		if ( method_exists( $this, 'action_'.$action ) ) 
		{
			call_user_func( array( $this, 'action_'.$action ), $params );
		} 
		else 
		{
			CCCli::line( "There is no action {$action}.", 'red' );
		}
	}
210440
public function createTable($table, $options)
    {
        $table = $this->buildRealTableName($table);
        $sql = $this->getSchema()->getCreateTableSql($table, $options);
        $ret = $this->query($sql);
        return $ret;
    }
1161484
protected function modifyColumnFromActiveTable($table, $key, $val, $dbForge, &$status, $active, $current)
    {
        if( $active !== $current )
        {
            $dbForge->modifyColumn($table, [$key => $val]);
            $status = true;
        }
        else
        {
            $status = false;
        }
    }