/**
  * Truncate the given models
  *
  * @param array $modelsToTruncate An array of models (names) to truncate
  * @return void
  * @todo Improve testability by extracting the model object retrieval part.
  */
 public function truncateModels($modelsToTruncate)
 {
     foreach ($modelsToTruncate as $modelName) {
         $this->_shell->out(__('Truncate model %s...', $modelName), 1, Shell::VERBOSE);
         $model = ClassRegistry::init($modelName);
         $datasource = $model->getDataSource();
         $datasource->truncate($model->table);
     }
 }
 /**
  * Runs task
  */
 protected function _run()
 {
     $this->_Process = new TaskProcess($this->_task['command'] . $this->_argsToString($this->_task['arguments']), $this->_task['path']);
     $this->_Process->setTimeout($this->_task['timeout']);
     try {
         $this->_Process->start(function ($type, $buffer) {
             if ('err' === $type) {
                 $this->_Shell->err($buffer);
                 $this->_task['stderr'] .= $buffer;
             } else {
                 $this->_Shell->out($buffer);
                 $this->_task['stdout'] .= $buffer;
             }
             $this->_TaskServer->updated($this->_task);
         });
         while ($this->_Process->isRunning()) {
             $this->_task['process_id'] = (int) $this->_Process->getPid();
             $this->_TaskServer->updateStatistics($this->_task);
             $this->_Process->checkTimeout();
             sleep(Configure::read('Task.checkInterval'));
             if ($this->_TaskServer->mustStop($this->_task['id'])) {
                 $this->_Process->stop(Configure::read('Task.stopTimeout'));
                 $this->_task['code'] = 143;
                 $this->_task['code_string'] = TaskProcess::$exitCodes[143];
                 return $this->_stopped(true);
             }
         }
         $this->_task['code'] = $this->_Process->getExitCode();
         $this->_task['code_string'] = $this->_Process->getExitCodeText();
     } catch (Exception $Exception) {
         $this->_task['code'] = 134;
         $this->_task['code_string'] = $Exception->getMessage();
     }
     $this->_stopped(false);
 }
Example #3
0
 function out($data)
 {
     if (is_scalar($data)) {
         parent::out($data);
     } else {
         parent::out(print_r($data, true));
     }
 }
 /**
  * Modifies the out method for prettier formatting
  *
  * @param string $sString String to output.
  * @param boolean $bNewline If true, the outputs gets an added newline.
  */
 function out($sString, $bNewline = true)
 {
     return parent::out("  " . $sString, $bNewline);
 }
Example #5
0
 /**
  * Overwrites parent method to introduce the "quiet" variant
  * 
  * @access public
  */
 function out($msg = '')
 {
     if (!$this->quiet) {
         parent::out($msg);
     }
 }
 /**
  * Overrides standard shell output to allow /r without /n
  *
  * Outputs a single or multiple messages to stdout. If no parameters
  * are passed outputs just a newline.
  *
  * @param mixed $message A string or a an array of strings to output
  * @param integer $newlines Number of newlines to append
  * @return integer Returns the number of bytes returned from writing to stdout.
  * @access public
  */
 public function out($message = NULL, $newLines = 0, $level = 1)
 {
     return parent::out($message, $newLines);
 }
 /**
  * Modifies the out method for prettier formatting
  *
  * @param string $string String to output.
  * @param boolean $newline If true, the outputs gets an added newline.
  */
 function out($string = '', $newline = true)
 {
     return parent::out(' ' . $string, $newline);
 }
Example #8
0
 /**
  * Overrides standard shell output to allow /r without /n
  *
  * Outputs a single or multiple messages to stdout. If no parameters
  * are passed outputs just a newline.
  *
  * @param mixed $message A string or a an array of strings to output
  * @param integer $newlines Number of newlines to append
  * @return integer Returns the number of bytes returned from writing to stdout.
  * @access public
  */
 public function out($message = null, $newLines = 0)
 {
     return parent::out($message, $newLines);
 }
Example #9
0
 function out($str = '')
 {
     $str = date('Y-m-d H:i:s') . ' ' . $str;
     return parent::out($str);
 }
 /**
  * Prints a message
  *
  * @return void
  */
 public function out($message = '')
 {
     parent::out($message);
 }
Example #11
0
 function out($str = null, $newlines = 1, $level = Shell::NORMAL)
 {
     if ($newlines > 0) {
         $str = date('Y-m-d H:i:s') . ' ' . $str;
     }
     return parent::out($str, $newlines, $level);
 }