public function actionMigration($modelName = null)
    {
        $queryTemplate = <<<EOD
        \$query = <<<SQL
{Query}
SQL;
        \$this->execute(\$query);
EOD;
        $queries = [
            'up' => [],
            'down' => [],
        ];
        /** @var \yii\db\Command $command */
        foreach ($this->getAuditManager()->getDbCommands($modelName, 'up') as $command) {
            $queries['up'][] = strtr($queryTemplate, ['{Query}' => $command->getSql()]);
        }
        foreach ($this->getAuditManager()->getDbCommands($modelName, 'down') as $command) {
            $queries['down'][] = strtr($queryTemplate, ['{Query}' => $command->getSql()]);
        }

        if (empty($queries['up']) && empty($queries['down'])) {
            $this->stdout('Warning: nothing to do, would create an empty migration.'."\n", Console::FG_YELLOW);
            return self::EXIT_CODE_ERROR;
        }


        $name = 'm'.gmdate('ymd_His').'_audit';
        if ($modelName !== null) {
            $parts = explode('\\', $modelName);
            $modelName = end($parts);
            $name .= '_' . $modelName;
        }
        $file = $this->migrationPath . DIRECTORY_SEPARATOR . $name . '.php';

        if ($this->confirm("Create new migration '$file'?")) {
            $content = $this->getTemplate($name, $queries);
            file_put_contents($file, $content);
            $this->stdout("New migration created successfully.\n", Console::FG_GREEN);
        }
        return self::EXIT_CODE_NORMAL;
    }
public function actionMigration($modelName = null)
    {
        $queryTemplate = <<<EOD
        \$query = <<<SQL
{Query}
SQL;
        \$this->execute(\$query);
EOD;
        $queries = [
            'up' => [],
            'down' => [],
        ];
        /** @var \yii\db\Command $command */
        foreach ($this->getAuditManager()->getDbCommands($modelName, 'up') as $command) {
            $queries['up'][] = strtr($queryTemplate, ['{Query}' => $command->getSql()]);
        }
        foreach ($this->getAuditManager()->getDbCommands($modelName, 'down') as $command) {
            $queries['down'][] = strtr($queryTemplate, ['{Query}' => $command->getSql()]);
        }

        if (empty($queries['up']) && empty($queries['down'])) {
            $this->stdout('Warning: nothing to do, would create an empty migration.'."\n", Console::FG_YELLOW);
            return self::EXIT_CODE_ERROR;
        }


        $name = 'm'.gmdate('ymd_His').'_audit';
        if ($modelName !== null) {
            $parts = explode('\\', $modelName);
            $modelName = end($parts);
            $name .= '_' . $modelName;
        }
        $file = $this->migrationPath . DIRECTORY_SEPARATOR . $name . '.php';

        if ($this->confirm("Create new migration '$file'?")) {
            $content = $this->getTemplate($name, $queries);
            file_put_contents($file, $content);
            $this->stdout("New migration created successfully.\n", Console::FG_GREEN);
        }
        return self::EXIT_CODE_NORMAL;
    }
public function actionMigration ( $ modelName = null ) { $ queryTemplate =  <<<EOD
        \$query = <<<SQL
{Query}
SQL;
        \$this->execute(\$query);
EOD ; $ queries = [ 'up' => [ ] , 'down' => [ ] , ] ; /** @var \yii\db\Command $command */ foreach ( $ this -> getAuditManager ( ) -> getDbCommands ( $ modelName , 'up' ) as $ command ) { $ queries [ 'up' ] [ ] = strtr ( $ queryTemplate , [ '{Query}' => $ command -> getSql ( ) ] ) ; } foreach ( $ this -> getAuditManager ( ) -> getDbCommands ( $ modelName , 'down' ) as $ command ) { $ queries [ 'down' ] [ ] = strtr ( $ queryTemplate , [ '{Query}' => $ command -> getSql ( ) ] ) ; } if ( empty ( $ queries [ 'up' ] ) && empty ( $ queries [ 'down' ] ) ) { $ this -> stdout ( 'Warning: nothing to do, would create an empty migration.' . "\n" , Console :: FG_YELLOW ) ; return self :: EXIT_CODE_ERROR ; } $ name = 'm' . gmdate ( 'ymd_His' ) . '_audit' ; if ( $ modelName !== null ) { $ parts = explode ( '\\' , $ modelName ) ; $ modelName = end ( $ parts ) ; $ name .= '_' . $ modelName ; } $ file = $ this -> migrationPath . DIRECTORY_SEPARATOR . $ name . '.php' ; if ( $ this -> confirm ( "Create new migration '$file'?" ) ) { $ content = $ this -> getTemplate ( $ name , $ queries ) ; file_put_contents ( $ file , $ content ) ; $ this -> stdout ( "New migration created successfully.\n" , Console :: FG_GREEN ) ; } return self :: EXIT_CODE_NORMAL ; }
Creates a migration file that install audit database objects.
@param $modelName string model class name
@return int
@throws Exception
Creates a migration file that install audit database objects .