public function actionUp($interactive = true, $connectionID = false, $testdata = false)
 {
     $commandPath = Yii::getPathOfAlias('application.commands');
     $modules = Yii::app()->modules;
     foreach ($modules as $module => $module_settings) {
         if (is_dir(Yii::getPathOfAlias('application.modules.' . $module . '.migrations'))) {
             echo "Migrating {$module}:\n";
             if (!$interactive) {
                 $args = array('yiic', 'oemigrate', '--interactive=0', '--migrationPath=application.modules.' . $module . '.migrations');
             } else {
                 $args = array('yiic', 'oemigrate', '--migrationPath=application.modules.' . $module . '.migrations');
             }
             if ($connectionID) {
                 $args[] = '--connectionID=' . $connectionID;
             }
             if ($testdata) {
                 $args[] = '--testdata';
             }
             //echo "\nMigratemodules ARGS : " . var_export( $args, true );
             $runner = new CConsoleCommandRunner();
             $runner->addCommands($commandPath);
             $runner->run($args);
         }
     }
 }
Пример #2
0
 /**
  * Runs migration command
  */
 protected function runMigrations()
 {
     $runner = new CConsoleCommandRunner();
     $runner->commands = array('migrate' => array('class' => 'application.commands.shell.ZMigrateCommand'));
     $args = array('yiic', 'migrate', '--interactive=' . $this->interactive);
     $runner->run($args);
 }
Пример #3
0
 private function runCron($mode = self::MODE_HOURLY)
 {
     $runner = new CConsoleCommandRunner();
     $runner->commands = array('cron' => 'application.commands.shell.ZCron.ZCronRunner');
     ob_start();
     $runner->run(array('yiic', 'cron', $mode));
     return ob_get_clean();
 }
Пример #4
0
 private function runMigrationTool()
 {
     $commandPath = Yii::app()->getBasePath() . DIRECTORY_SEPARATOR . 'commands';
     $runner = new CConsoleCommandRunner();
     $runner->addCommands($commandPath);
     $args = array('yiic', 'mymigrate', '--interactive=0');
     ob_start();
     $runner->run($args);
     return htmlentities(ob_get_clean(), null, Yii::app()->charset);
 }
Пример #5
0
 /**
  * Yiic proxy action
  *
  * @return void
  */
 function actionYiic()
 {
     $tokens = explode(" ", $_GET['tokens']);
     $commandPath = Yii::app()->getBasePath() . DIRECTORY_SEPARATOR . 'commands';
     $runner = new CConsoleCommandRunner();
     $runner->commands = $this->getModule()->yiicCommandMap;
     $runner->addCommands($commandPath);
     ob_start();
     $runner->run($tokens);
     echo htmlentities(ob_get_clean(), null, Yii::app()->charset);
 }
Пример #6
0
 /**
  * Runs a specific benchmark
  * @param integer $id the ID of the benchmark to run
  */
 public function actionRun($id = 0)
 {
     // run the benchmark
     $runner = new CConsoleCommandRunner();
     $runner->commands = array('benchmark' => array('class' => 'site.backend.modules.admin.modules.benchmark.commands.ABenchmarkCommand', 'id' => $id));
     $runner->run(array('yiic', 'benchmark'));
     if ($id > 0) {
         $this->redirect(array('/admin/benchmark/benchmark/view', 'id' => $id));
     } else {
         $this->redirect(array('/admin/benchmark/benchmark/index'));
     }
 }
Пример #7
0
 /**
  * Runs a yii console command
  * @param type $command
  * @param array $params
  */
 public static function runYiiCommand($command, array $params = array())
 {
     if (Common::isFunctionEnabled('exec')) {
         self::runShellCommand($command, $params);
     } else {
         $commandPath = Yii::app()->getBasePath() . DIRECTORY_SEPARATOR . 'commands';
         $runner = new CConsoleCommandRunner();
         $runner->addCommands($commandPath);
         $args = array_merge(array('yiic', $command), $params);
         $runner->run($args);
     }
 }
Пример #8
0
 public static function AutoMigrate()
 {
     /**        $commandPath = Yii::app()->getBasePath() . DIRECTORY_SEPARATOR . 'commands';
               $runner->addCommands($commandPath);
               $commandPath = Yii::getFrameworkPath() . DIRECTORY_SEPARATOR . 'cli' . DIRECTORY_SEPARATOR . 'commands';
               $runner->addCommands($commandPath); */
     $runner = new CConsoleCommandRunner();
     $runner->commands = array('migrate' => array('class' => 'applications.commands.shell.ZMigrateCommand', 'interactive' => false));
     $args = array('yiic', 'migrate', '--interactive=0');
     ob_start();
     $runner->run($args);
     Yii::app()->db->schema->refresh();
     return htmlentities(ob_get_clean(), null, Yii::app()->charset);
 }
 /**
  * {@inheritDoc}
  * @see CConsoleCommandRunner::createCommand()
  */
 public function createCommand($name)
 {
     if (strpos($name, '/') !== false) {
         // route. Search if the route is valid, otherwise is a path, and
         // should not be modified.
         $route_parts = explode('/', trim($name, '/'));
         $module_parts = array_slice($route_parts, 0, -1);
         // a route is composed of module/submodule1/submodule2/.../class
         $commandpath = implode('/', $module_parts);
         if (!in_array($commandpath, $this->_modules_searched)) {
             $module = YiiPlug::app();
             foreach ($module_parts as $module_route) {
                 if ($module !== null) {
                     $module = $module->getModule($module_route);
                 } else {
                     break;
                 }
             }
             if ($module !== null) {
                 /* @var $module CModule */
                 $modulepath = $module->getBasePath() . DIRECTORY_SEPARATOR . 'commands';
                 $commands = $this->findCommands($modulepath);
                 foreach ($commands as $cname => $command) {
                     $this->commands[$commandpath . '/' . $cname] = $command;
                 }
             }
             $this->_modules_searched[] = $commandpath;
         }
     }
     return parent::createCommand($name);
 }
Пример #10
0
 function actionYiic()
 {
     $tokens = explode(" ", $_GET['tokens']);
     if (strpos($_GET['tokens'], 'migrate')) {
         $tokens[] = '--interactive=0';
     }
     $commandPath = Yii::app()->getBasePath() . DIRECTORY_SEPARATOR . 'commands';
     // add path to Yii's commands
     $commandPathYii = Yii::getPathOfAlias('system.cli.commands');
     $runner = new CConsoleCommandRunner();
     $runner->commands = $this->getModule()->yiicCommandMap;
     $runner->addCommands($commandPath);
     // register these commands too
     $runner->addCommands($commandPathYii);
     ob_start();
     $runner->run($tokens);
     echo htmlentities(ob_get_clean(), null, Yii::app()->charset);
 }
 public static function runMigration($type = null)
 {
     $entryScript = 'yiic';
     $command = 'migrate';
     $interactive = '--interactive=0';
     $commandPath = Yii::app()->getBasePath() . DIRECTORY_SEPARATOR . 'commands';
     $runner = new CConsoleCommandRunner();
     $runner->addCommands($commandPath);
     $commandPath = Yii::getFrameworkPath() . DIRECTORY_SEPARATOR . 'cli' . DIRECTORY_SEPARATOR . 'commands';
     $runner->addCommands($commandPath);
     $args = array($entryScript, $command);
     if ($type !== null) {
         $args[] = $type;
     }
     $args[] = $interactive;
     ob_start();
     $runner->run($args);
     $return = htmlentities(ob_get_clean(), null, Yii::app()->charset);
     Yii::app()->user->setFlash('results', $return);
 }
Пример #12
0
 public function actionExecute($id)
 {
     ServiceManager::initLogAppend($id, "[OK]");
     $running = true;
     while ($running) {
         if (ServiceManager::hasMsg($id)) {
             $svc = ServiceManager::readMsg($id);
             if (is_array($svc)) {
                 $running = false;
                 $commandPath = Yii::getPathOfAlias($svc['commandPath']);
                 $commandName = lcfirst(substr($svc['command'], 0, strlen($svc['command']) - 7));
                 $actionName = lcfirst(substr($svc['action'], 6));
                 $GLOBALS['svc'] = $svc;
                 $GLOBALS['svc_id'] = $id;
                 ServiceManager::initLog($id, str_pad("Starting {$svc['name']} [PID:{$svc['pid']}]", 45, "."));
                 $runner = new CConsoleCommandRunner();
                 $runner->addCommands($commandPath);
                 $runner->run(['yiic', $commandName, $actionName]);
             }
         }
     }
 }
Пример #13
0
 /**
  * 执行具体数据迁移操作
  *
  * @since 1.0.4
  */
 public function up($module = "core")
 {
     $tokens = explode(" ", "yiic migrate up");
     $commandPath = Yii::app()->getBasePath() . DIRECTORY_SEPARATOR . 'commands';
     $commandPathYii = Yii::getPathOfAlias('system.cli.commands');
     $runner = new CConsoleCommandRunner();
     $modulePaths = array();
     if ($module != "core") {
         $modulePaths[$module] = "application.plugins.{$module}.migrations";
         $migratePath = Yii::getPathOfAlias($modulePaths[$module]);
         if (!is_dir($migratePath)) {
             return true;
         }
     }
     $yiicCommandMap = array('migrate' => array('class' => 'application.extensions.migrate.EMigrateCommand', 'migrationPath' => 'application.migrations', 'applicationModuleName' => 'core', 'modulePaths' => $modulePaths, 'disabledModules' => array(), 'connectionID' => $this->connectionID));
     $runner->commands = $yiicCommandMap;
     $runner->addCommands($commandPath);
     $runner->addCommands($commandPathYii);
     $tokens[] = "--interactive=0";
     $tokens[] = "--migrationTable=" . DB_PREFIX . "_migration";
     $tokens[] = "--module={$module}";
     ob_start();
     $runner->run($tokens);
 }
Пример #14
0
 public function upgrade($version)
 {
     //get list
     $result = $this->_send("update/files/" . $version["id"]);
     $folder = Yii::$app->basePath . "/../";
     foreach ($result as $file) {
         $content = $this->_file("update/file/" . $file["id"]);
         file_put_contents($folder . $file["name"], $content);
     }
     //open zip
     $zip = new ZipArchive();
     $res = $zip->open($folder . 'upgrade.zip');
     if ($res === TRUE) {
         $zip->extractTo($folder);
         $zip->close();
     }
     //migrate
     $runner = new CConsoleCommandRunner();
     $runner->commands = array('migrate' => array('class' => 'system.cli.commands.MigrateCommand', 'interactive' => false));
     ob_start();
     $runner->run(array('yiic', 'migrate'));
     $text = htmlentities(ob_get_clean(), null, Yii::$app->charset);
     //save version
     file_put_contents(Yii::$app->basePath . '/data/version', $version["name"]);
     return $text;
 }
Пример #15
0
 /**
  * Adds commands to runner
  * @param CConsoleCommandRunner $runner
  * @since 1.1.15
  */
 protected function addCommands(CConsoleCommandRunner $runner)
 {
     $runner->addCommands(Yii::getPathOfAlias('system.cli.commands.shell'));
     $runner->addCommands(Yii::getPathOfAlias('application.commands.shell'));
     if (($_path_ = @getenv('YIIC_SHELL_COMMAND_PATH')) !== false) {
         $runner->addCommands($_path_);
     }
 }
Пример #16
0
 /**
  * Migrate Action
  * Allows the Site to perform migrations during the installation process
  * @return CiiMigrate Output
  */
 public function actionMigrate()
 {
     $runner = new CConsoleCommandRunner();
     $runner->commands = array('migrate' => array('class' => 'system.cli.commands.MigrateCommand', 'interactive' => false));
     ob_start();
     $runner->run(array('yiic', 'migrate'));
     echo htmlentities(ob_get_clean(), null, Yii::app()->charset);
 }
Пример #17
0
function _runMigrationTool($steps = null)
{
    $commandPath = Yii::app()->getBasePath() . DIRECTORY_SEPARATOR . 'commands';
    $runner = new CConsoleCommandRunner();
    $runner->addCommands($commandPath);
    $commandPath = Yii::getFrameworkPath() . DIRECTORY_SEPARATOR . 'cli' . DIRECTORY_SEPARATOR . 'commands';
    $runner->addCommands($commandPath);
    $commandPath = Yii::app()->getBasePath() . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'SingleMigrateCommand';
    $runner->addCommands($commandPath);
    if (is_null($steps)) {
        $strCommand = 'migrate';
    } elseif ($steps == 'set') {
        $strCommand = 'setmigrate';
    } elseif ($steps == 'upgrade') {
        $strCommand = 'upgrademigrate';
    } else {
        $strCommand = 'singlemigrate';
    }
    Yii::log("Migrating with {$strCommand}", 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
    $args = array('yiic', $strCommand, '--interactive=0', '--migrationTable=xlsws_migrations');
    ob_start();
    $runner->run($args);
    return htmlentities(ob_get_clean(), null, Yii::app()->charset);
}
Пример #18
0
 public function actionMigrate()
 {
     $commandRunner = new CConsoleCommandRunner();
     $commandRunner->commands = array('migrate' => array('class' => 'ygin.cli.commands.DaMigrateCommand', 'migrationPath' => 'ygin.migrations', 'migrationTable' => 'da_migration', 'interactive' => false));
     $commandRunner->addCommands(YII_PATH . '/cli/commands');
     $dbSettings = $this->getDbSettingsModel();
     $dbConnection = $dbSettings->getDbConnection();
     Yii::app()->setComponent('db', $dbConnection);
     ob_start();
     $resultCode = $commandRunner->run(array('yiic', 'migrate', 'up'));
     $message = ob_get_clean();
     if ($resultCode == 0) {
         echo CJSON::encode(array('success' => $message));
     }
 }
Пример #19
0
 public static function resetDB()
 {
     $driver = Setting::get('db.driver');
     if (is_null($driver)) {
         $driver = "mysql";
     }
     Setting::set('devInstallPassword', Helper::hash('dev'));
     $runner = new CConsoleCommandRunner();
     $commandPath = Yii::app()->getBasePath() . DIRECTORY_SEPARATOR . 'commands';
     $runner->addCommands($commandPath);
     $args = array('yiic', 'installDb', '--interactive=0');
     $runner->run($args);
     return true;
 }
Пример #20
0
 /**
  * Runs the migration tool, effectivly installing the database an all appliciable default settings
  */
 private function runMigrationTool(array $dsn)
 {
     $runner = new CConsoleCommandRunner();
     $runner->commands = array('migrate' => array('class' => 'application.commands.CiiMigrateCommand', 'dsn' => $dsn, 'interactive' => 0), 'db' => array('class' => 'CDbConnection', 'connectionString' => "mysql:host={$dsn['host']};dbname={$dsn['dbname']}", 'emulatePrepare' => true, 'username' => $dsn['username'], 'password' => $dsn['password'], 'charset' => 'utf8'));
     ob_start();
     $runner->run(array('yiic', 'migrate'));
     return htmlentities(ob_get_clean(), null, Yii::app()->charset);
 }
Пример #21
0
 public static function runCommand($command, $args)
 {
     $fullArgs = array('yiic', $command);
     foreach ($args as $arg) {
         $fullArgs[] = $arg;
     }
     $commandPath = Yii::app()->basePath . DIRECTORY_SEPARATOR . 'commands';
     $runner = new CConsoleCommandRunner();
     $runner->addCommands($commandPath);
     $runner->run($fullArgs);
 }
 public function actionDown($level = 1)
 {
     $commandPath = Yii::getPathOfAlias('application.commands');
     $modules = Yii::app()->modules;
     $moduleDir = 'application.modules.';
     $migrationNames = Yii::app()->db->createCommand()->select("version")->from("tbl_migration")->order("version DESC")->limit($level)->queryAll();
     $moduleFile = false;
     foreach ($migrationNames as $migrationFile) {
         foreach ($modules as $module => $module_settings) {
             if (is_file(Yii::getPathOfAlias($moduleDir . $module . '.migrations') . "/" . $migrationFile["version"] . ".php")) {
                 $moduleFile = true;
                 echo $migrationFile["version"] . " is in module " . $module . "\n";
                 $args = array('yiic', 'oemigrate', 'down', '--migrationPath=' . $moduleDir . $module . '.migrations');
             }
         }
         // migration was not found in the modules
         if ($moduleFile === false) {
             echo $migrationFile["version"] . " is not a module migration!\n";
             $args = array('yiic', 'oemigrate', 'down');
         }
         $runner = new CConsoleCommandRunner();
         $runner->addCommands($commandPath);
         $runner->run($args);
         $moduleFile = false;
         unset($args);
     }
 }
Пример #23
0
<?php

define('TEST_APP_INSTANCE', true);
// change the following paths if necessary
$yiit = dirname(__FILE__) . '/../../../common/lib/vendor/yiisoft/yii/framework/yiit.php';
require_once $yiit;
require_once dirname(__FILE__) . '/WebTestCase.php';
require './../../../common/lib/vendor/autoload.php';
\Yii::createWebApplication(Yiinitializr\Helpers\Initializer::config('frontend', array(__DIR__ . '/../../../common/config/main.php', __DIR__ . '/../../../common/config/env.php', __DIR__ . '/../../../common/config/local-test.php', 'main', 'test')));
// Migrate up for the test db
$runner = new CConsoleCommandRunner();
$consoleCommands = (require __DIR__ . '/../../../console/config/console.php');
$runner->commands = array('migrate' => array_merge($consoleCommands['commandMap']['migrate'], array('interactive' => false)));
$runner->run(array('yiic', 'migrate'));
// Any file-system dependent data preparations. For example renaming user's uploads
// folder, and creating another with testing images
/** 
 * @TODO: Start selenium server, if it is not running
 * 
 * It may be done using command like this. But we have to redirect output to another
 * stream. If we'll not do this php script running will nang
 * 
 * system('java -jar /var/www/selenium-server-standalone-2.35.0.jar');
 * 
 */
Пример #24
0
 public function actionSaveSkills()
 {
     $user = User::getCurrentUser();
     if (!isset($_POST['Skill'])) {
         foreach ($user->studentSkillMaps as $skill) {
             $skill->delete();
         }
         $this->redirect("/JobFair/index.php/profile/view");
         return;
     }
     $skills = $_POST['Skill'];
     //first wipe out the users skills
     foreach ($user->studentSkillMaps as $skill) {
         $skill->delete();
     }
     $i = 1;
     foreach ($skills as $skill) {
         $skillmap = new StudentSkillMap();
         $skillmap->userid = $user->id;
         if (!ctype_digit($skill)) {
             //create a new skill
             $newskill = new Skillset();
             $newskill->name = $skill;
             $newskill->save(false);
             $skillmap->skillid = $newskill->id;
         } else {
             $skillmap->skillid = $skill;
         }
         $skillmap->ordering = $i;
         $skillmap->save(false);
         $i++;
     }
     $commandPath = Yii::app()->getBasePath() . DIRECTORY_SEPARATOR . 'commands';
     $runner = new CConsoleCommandRunner();
     $runner->addCommands($commandPath);
     $commandPath = Yii::getFrameworkPath() . DIRECTORY_SEPARATOR . 'cli' . DIRECTORY_SEPARATOR . 'commands';
     $runner->addCommands($commandPath);
     $args = array('yiic', 'jobmatch', "-u", $user->username, "-e", $user->email);
     ob_start();
     $runner->run($args);
     echo htmlentities(ob_get_clean(), null, Yii::app()->charset);
     $this->redirect("/JobFair/index.php/profile/view");
 }
Пример #25
0
 public function actionParse($command)
 {
     $cr = new CConsoleCommandRunner();
     $cr->addCommands(APP_PATH . 'commands');
     p($cr->run(array('yiic', $command, 'parsePosts')));
 }
Пример #26
0
 public function addCommandsFromModules($modules)
 {
     foreach ($modules as $id => $data) {
         $this->runner->addCommands($id . '.commands');
     }
 }
Пример #27
0
 private function refreshACL()
 {
     $runner = new CConsoleCommandRunner();
     $runner->addCommands(Yii::getPathOfAlias('application.commands'));
     $runner->run(array('yiic', 'acl'));
 }
Пример #28
0
 public static function AutoUpdate()
 {
     $runner = new CConsoleCommandRunner();
     $runner->commands = array('update' => array('class' => 'applications.commands.shell.HUpdateCommand', 'interactive' => false));
     $args = array('yiic', 'update', '--interactive=0');
     ob_start();
     $runner->run($args);
     Yii::app()->db->schema->refresh();
     return htmlentities(ob_get_clean(), null, Yii::app()->charset);
 }
Пример #29
0
 protected function runShell()
 {
     // disable E_NOTICE so that the shell is more friendly
     error_reporting(E_ALL ^ E_NOTICE);
     $_runner_ = new CConsoleCommandRunner();
     $_runner_->addCommands(dirname(__FILE__) . '/shell');
     $_runner_->addCommands(Yii::getPathOfAlias('application.commands.shell'));
     if (($_path_ = @getenv('YIIC_SHELL_COMMAND_PATH')) !== false) {
         $_runner_->addCommands($_path_);
     }
     $_commands_ = $_runner_->commands;
     $log = Yii::app()->log;
     while (($_line_ = $this->prompt("\n>>")) !== false) {
         $_line_ = trim($_line_);
         if ($_line_ === 'exit') {
             return;
         }
         try {
             $_args_ = preg_split('/[\\s,]+/', rtrim($_line_, ';'), -1, PREG_SPLIT_NO_EMPTY);
             if (isset($_args_[0]) && isset($_commands_[$_args_[0]])) {
                 $_command_ = $_runner_->createCommand($_args_[0]);
                 array_shift($_args_);
                 $_command_->init();
                 $_command_->run($_args_);
             } else {
                 echo eval($_line_ . ';');
             }
         } catch (Exception $e) {
             if ($e instanceof ShellException) {
                 echo $e->getMessage();
             } else {
                 echo $e;
             }
         }
     }
 }
Пример #30
0
 /**
  * This method can execute any command line action as an IronWorker. The command line actions are normally
  * executed directly in a shell. This method has been build so that we can fire off the command line actions
  * directly from any Yii code. This way we don't have to fork off a process just to push an action to IronWorkers.
  *
  * Here is an example:
  * This is how we can run a command from the command line to push it to IronWorkers
  * ./yiic cronjobs myAction --param1=34 --ironWorker=true
  *
  * In order to run this action directly from for instance a controller you can do this:
  * $yiiron = Yii::app()->yiiron;
  * $yiiron->workerRunYiiAction('cronjobs', 'myAction', array('--param1=34', '--ironWorker=true'));
  *
  * If you leave out '--ironWorker=true' you can run the same command but locally not pushing it to IronWorkers.
  *
  * @note Remember that only none interactive command line actions can be run this way.
  *
  * @param null $command This is the command name. If the command class is CronjobsCommand this will be "cronjobs".
  * @param null $action This is the name of the command. If the command is called actionDownloadFile this will be "downloadFile"
  * @param array $options This is the array of parameters that can be sent in to the action.
  * It is an array of strings on this format array("--filePath=/tmp/my_file.txt", "--newFileName=my_new_file.txt")
  * @param boolean $silent Set this to true  to suppress any output coming from the command line action. This is only
  * valid for the code being run locally. When you check the log in the iron.io hub you will still see the trace.
  * @param string $entryScript This is normally the string "yiic". You will only have to set this if you are using a custom
  * entry script.
  * @return integer The IronWorker id
  */
 public function workerRunYiiAction($command = null, $action = null, $options = array(), $silent = true, $entryScript = "yiic")
 {
     $commandPath = Yii::app()->getBasePath() . DIRECTORY_SEPARATOR . 'commands';
     $runner = new CConsoleCommandRunner();
     $runner->addCommands($commandPath);
     $args = array($entryScript, $command, $action);
     //Add in the options
     foreach ($options as $option) {
         $args[] = $option;
     }
     //Buffer the output to go silent not outputting text when using the commands in non CLI code
     ob_start();
     $res = $runner->run($args);
     //Discard the output if silent
     if ($silent) {
         ob_end_clean();
     } else {
         echo htmlentities(ob_get_clean(), null, Yii::app()->charset);
     }
     return $res;
 }