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);
         }
     }
 }
Esempio n. 2
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);
 }
Esempio n. 3
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);
 }
 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);
 }
 /**
  * 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);
 }
Esempio n. 6
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);
     }
 }
Esempio n. 7
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);
 }
Esempio n. 8
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]);
             }
         }
     }
 }
Esempio n. 9
0
 public function actionParse($command)
 {
     $cr = new CConsoleCommandRunner();
     $cr->addCommands(APP_PATH . 'commands');
     p($cr->run(array('yiic', $command, 'parsePosts')));
 }
 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);
     }
 }
Esempio n. 11
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_);
     }
 }
Esempio n. 12
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));
     }
 }
Esempio n. 13
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);
 }
Esempio n. 14
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);
}
Esempio n. 15
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");
 }
Esempio n. 16
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;
 }
 private function refreshACL()
 {
     $runner = new CConsoleCommandRunner();
     $runner->addCommands(Yii::getPathOfAlias('application.commands'));
     $runner->run(array('yiic', 'acl'));
 }
Esempio n. 18
0
 public function addCommandsFromModules($modules)
 {
     foreach ($modules as $id => $data) {
         $this->runner->addCommands($id . '.commands');
     }
 }
Esempio n. 19
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;
             }
         }
     }
 }
Esempio n. 20
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;
 }