示例#1
0
文件: log.php 项目: ZerGabriel/cms-1
 /**
  * 
  * @param Model_Job $job
  * @return void
  */
 public function run(Model_Job $job)
 {
     if (Kohana::$profiling === TRUE) {
         $benchmark = Profiler::start('Rub job', $job->name);
     }
     $this->values(array('job_id' => $job->id))->create();
     $this->set_status(Model_Job::STATUS_RUNNING);
     try {
         $job = $job->job;
         $minion_task = Minion_Task::convert_task_to_class_name($job);
         if (is_array($job)) {
             $passed = call_user_func($job);
         } elseif (class_exists($minion_task)) {
             Minion_Task::factory(array($job))->execute();
             $passed = TRUE;
         } elseif (strpos($job, '::') === FALSE) {
             $function = new ReflectionFunction($job);
             $passed = $function->invoke();
         } else {
             list($class, $method) = explode('::', $job, 2);
             $method = new ReflectionMethod($class, $method);
             $passed = $method->invoke(NULL);
         }
     } catch (Exception $e) {
         $this->failed();
         return;
     }
     $this->complete();
     if (isset($benchmark)) {
         Profiler::stop($benchmark);
     }
 }
示例#2
0
 public function build_validation(Validation $validation)
 {
     return parent::build_validation($validation)->rule('username', 'not_empty')->rule('username', function ($value) {
         return ORM::factory('User')->where('username', '=', $value)->find()->loaded();
     });
     // Check if the username exists
 }
示例#3
0
 public function action_import()
 {
     $this->_view = new View_Install_Import();
     if ($this->request->method() == HTTP_Request::POST) {
         Minion_Task::factory(array('task' => 'migrations:run', 'quiet' => TRUE))->execute();
         $this->_view->imported = TRUE;
     }
 }
示例#4
0
 public function execute(array $options)
 {
     $db = $this->db_params(Kohana::TESTING);
     Minion_Task::factory('db:structure:load')->execute(array('database' => Kohana::TESTING, 'force' => NULL, 'file' => NULL));
     $module_test_schemas = Kohana::find_file('tests/test_data/structure', 'test-schema-' . $db['type'], 'sql', TRUE);
     foreach ($module_test_schemas as $schema) {
         Minion_Task::factory('db:structure:load')->execute(array('database' => Kohana::TESTING, 'force' => NULL, 'file' => $schema));
     }
 }
示例#5
0
 /**
  * Retrieves the current minion task.
  *
  * @return Minion_Task
  */
 protected function _retrieve_task()
 {
     try {
         return Minion_Task::factory($this->_task);
     } catch (Exception $e) {
         echo View::factory('minion/help/error')->set('error', 'Task "' . $this->_task . '" does not exist');
         exit(1);
     }
 }
 public function execute(array $options)
 {
     if ($options['force'] === NULL or 'yes' === Minion_CLI::read('This will destroy all data in the current database. Are you sure? [yes/NO]')) {
         Minion_CLI::write('Dropping Tables', 'green');
         $migrations = new Migrations(array('log' => 'Minion_CLI::write'));
         $migrations->clear_all();
         Minion_Task::factory('db:migrate')->execute($options);
     } else {
         Minion_CLI::write('Nothing done', 'brown');
     }
 }
 protected function _execute(array $options)
 {
     $db = $this->db_params(Kohana::TESTING);
     Minion_Task::factory(array('task' => 'db:structure:load', 'database' => Kohana::TESTING, 'force' => NULL, 'file' => NULL))->execute();
     $structure_files = array_filter(array_map(function ($dir) use($db) {
         $file = $dir . 'tests' . DIRECTORY_SEPARATOR . 'database' . DIRECTORY_SEPARATOR . 'structure' . DIRECTORY_SEPARATOR . strtolower($db['type']) . '.sql';
         return is_file($file) ? $file : NULL;
     }, Kohana::modules()));
     foreach ($structure_files as $schema) {
         Minion_Task::factory(array('task' => 'db:structure:load', 'database' => Kohana::TESTING, 'force' => NULL, 'file' => $schema))->execute();
     }
 }
示例#8
0
 public function execute()
 {
     // try
     $options = isset($this->options) ? $this->options->as_array(FALSE) : array();
     $options['task'] = $this->task;
     $success = FALSE;
     try {
         // create minion task
         $minion = Minion_Task::factory($options);
         // validate options here, to handle invalid tasks
         $validation = Validation::factory($minion->get_options());
         $validation = $minion->build_validation($validation);
         if (!$validation->check()) {
             $errors = $validation->errors(TRUE);
             $error = array_shift($errors);
             // don't execute task, log validation error
             Kohana::$log->add(Log::ERROR, 'Task of id: :id and type: :type failed validation: ":msg"', array(':id' => (string) $this->_id, ':type' => (string) $this->task, ':msg' => $error));
             // no need to retry
             $this->try = $this->max_tries;
             $this->message = $error;
         } else {
             $minion->execute();
             $success = TRUE;
         }
     } catch (Exception $e) {
         $error = Kohana_Exception::text($e);
         Kohana::$log->add(Log::ERROR, 'Task :id failed on try: :try with message :msg', array(':id' => (string) $this->_id, ':msg' => $error, ':try' => $this->try));
         $this->message = $error;
     }
     if ($success) {
         // success, delete task
         $this->delete();
     } else {
         $this->status = 'failed';
         if ($this->try < $this->max_tries) {
             // requeue
             $this->status = 'queued';
             $this->update();
         } else {
             if ($this->keep_failed) {
                 $this->update();
             } else {
                 $this->delete();
             }
         }
     }
     Kohana::$log->write();
     return $success;
 }
示例#9
0
 /**
  * Test import from api
  *
  * @return void
  */
 public function test_api_import()
 {
     // todo: do we really care about keeping this? i say no.
     return $this->markTestSkipped('API import test disabled, it is too fragile');
     $config = Kohana::$config->load('database.TestImport2x');
     if (empty($config)) {
         $this->markTestSkipped('Could not load "database.TestImport2x" config');
     }
     try {
         $task = Minion_Task::factory(array('task' => 'ushahidi:import2x', 'source' => 'api', 'url' => 'http://demo.ushahidi.com', 'clean' => TRUE, 'oauth-client-id' => 'demoapp', 'oauth-client-secret' => 'demopass', 'dest-username' => 'importadmin', 'dest-password' => 'testing'));
         Log::$write_on_add = FALSE;
         // avoid dumping output to stdout
         $task->execute();
     } catch (Exception $e) {
         // Don't hide exception.
         //$this->fail("Minion task ushahidi:import2x threw an exception");
         throw $e;
     }
     // Assert output
     $this->expectOutputRegex("/.*\nCreated 'Classic Report Form', ID: 1.\nImported [0-9]+ tags.\nImported [0-9]+ posts.\nImported [0-9]+ users./");
 }
 protected function _execute(array $options)
 {
     Minion_Task::factory(array('task' => 'db:structure:dump', 'database' => $options['from'], 'force' => $options['force']))->execute();
     Minion_Task::factory(array('task' => 'db:structure:load', 'database' => $options['to'], 'force' => $options['force']))->execute();
 }
示例#11
0
 /**
  * Validate the CLI options.
  *
  * @param Validation The validation object to add rules to
  *
  * @return Validation
  */
 public function build_validation(Validation $validation)
 {
     $val = parent::build_validation($validation);
     $val->rule('count', 'numeric');
     return $val;
 }
示例#12
0
define('PUBLICPATH', DOCROOT . 'public');
//资源目录
define('MODE', '0');
//开发者模式(0:上线模式,1:开发者模式)
// Clean up the configuration vars
unset($application, $modules, $system);
/**
 * Define the start time of the application, used for profiling.
 */
if (!defined('KOHANA_START_TIME')) {
    define('KOHANA_START_TIME', microtime(TRUE));
}
/**
 * Define the memory usage at the start of the application, used for profiling.
 */
if (!defined('KOHANA_START_MEMORY')) {
    define('KOHANA_START_MEMORY', memory_get_usage());
}
// Bootstrap the application
require APPPATH . 'bootstrap' . EXT;
if (PHP_SAPI == 'cli') {
    class_exists('Minion_Task') or die('Please enable the Minion module for CLI support.');
    set_exception_handler(array('Minion_Exception', 'handler'));
    Minion_Task::factory(Minion_CLI::options())->execute();
} else {
    /**
     * Execute the main request. A source of the URI can be passed, eg: $_SERVER['PATH_INFO'].
     * If no source is specified, the URI will be automatically detected.
     */
    echo Request::factory()->execute()->send_headers(TRUE)->body();
}
示例#13
0
 /**
  * Tests that the task name can be found from a class name / object
  *
  * @test
  * @covers Minion_Task::convert_class_to_task
  * @dataProvider provider_convert_class_to_task
  * @param string Expected task name
  * @param mixed  Input class
  */
 public function test_convert_class_to_task($expected, $class)
 {
     $this->assertSame($expected, Minion_Task::convert_class_to_task($class));
 }
 public function build_validation(Validation $validation)
 {
     return parent::build_validation($validation)->rule('version', 'exact_length', array(':value', 10))->rule('version', 'digit')->rule('steps', 'digit');
 }
示例#15
0
 /**
  * Outputs help for this task
  *
  * @return null
  */
 protected function _help(array $params)
 {
     $tasks = $this->_compile_task_list(Kohana::list_files('classes/task'));
     $inspector = new ReflectionClass($this);
     list($description, $tags) = $this->_parse_doccomment($inspector->getDocComment());
     $view = View::factory('minion/help/task')->set('description', $description)->set('tags', (array) $tags)->set('task', Minion_Task::convert_class_to_task($this));
     echo $view;
 }
示例#16
0
文件: add.php 项目: ZerGabriel/cms-1
 public function build_validation(Validation $validation)
 {
     return parent::build_validation($validation)->rule('username', 'not_empty')->rule('password', 'not_empty')->rule('email', 'not_empty')->rule('email', 'email');
 }
示例#17
0
 public function build_validation(Validation $validation)
 {
     return parent::build_validation($validation)->rule('folder', 'is_dir')->rule('database', 'numeric')->rule('filesystem', 'numeric');
 }
示例#18
0
 /**
  * Configure validation of command line parameters - must be provided and the vendor path must be a valid path
  *
  * @param Validation $validation the validation object to configure
  *
  * @return Validation
  */
 public function build_validation(Validation $validation)
 {
     return parent::build_validation($validation)->rule('vendor-path', 'not_empty')->rule('vendor-path', array('Task_Twbs_Publishassets', 'valid_path'))->rule('public-path', 'not_empty')->rule('no-compress', 'numeric')->rule('lint-only', 'numeric')->rule('loop-after', 'numeric');
 }
示例#19
0
 /**
  * Validate parameters passed to the task.
  */
 public function build_validation(Validation $validation)
 {
     return parent::build_validation($validation)->rule('do', 'not_empty')->rule('do', 'in_array', array(':value', array('migrate', 'init_session')));
 }
 /**
  * @covers Task_Feed_Generate::_execute
  * @covers Task_Feed_Generate::build_validation
  */
 public function test_execute()
 {
     $this->env->backup_and_set(array('jam-generated-feed.name1' => array('model' => 'product', 'filter' => 'feed_test', 'view' => 'test/feedtest', 'file' => 'test_file.xml')));
     $task = Minion_Task::factory(array('feed:generate', 'name' => 'name1'));
     $task->execute();
     $this->assertFileEquals(__DIR__ . '/../../../test_data/expected_file.xml', DOCROOT . 'test_file.xml');
     unlink(DOCROOT . 'test_file.xml');
 }
 public function build_validation(Validation $validation)
 {
     return parent::build_validation($validation)->rule('name', 'not_empty')->rule('name', array($this, 'config_exists'));
 }
示例#22
0
 public function build_validation(Validation $validation)
 {
     return parent::build_validation($validation)->rule('view', 'not_empty')->rule('view', 'Kohana::find_file', array('views', ':value'));
 }
示例#23
0
 /**
  * Migrate the db of the this module
  *
  * @param   string  $name  Module name
  * @param   string  $dir   Migration direction up/down
  * @return  void
  */
 private static function migrate($module_name, $dir = 'up')
 {
     try {
         $task = $dir == 'down' ? 'db:migrate:down' : 'db:migrate:up';
         $options = array('task' => $task, 'group' => $module_name, 'quiet' => 'quiet');
         //Call DB migrations for this module
         Minion_Task::factory($options)->execute();
     } catch (Exception $e) {
     }
 }
示例#24
0
 /**
  * Configure validation of command line parameters - must be provided and the vendor path must be a valid path
  *
  * @param Validation $validation the validation object to configure
  *
  * @return Validation
  */
 public function build_validation(Validation $validation)
 {
     return parent::build_validation($validation)->rule('vendor-path', 'not_empty')->rule('vendor-path', array('Task_Twbs_Publishassets', 'valid_path'))->rule('public-path', 'not_empty');
 }
示例#25
0
 public function build_validation(Validation $validation)
 {
     return parent::build_validation($validation)->rule('name', 'not_empty');
 }
示例#26
0
 public function build_validation(Validation $validation)
 {
     $config = Kohana::$config->load('installer');
     $locales = array_keys(I18n::available_langs());
     return parent::build_validation($validation)->rule('db_server', 'not_empty')->rule('db_port', 'not_empty')->rule('db_port', 'numeric')->rule('db_user', 'not_empty')->rule('username', 'not_empty')->rule('email', 'not_empty')->rule('email', 'email')->rule('cache_type', 'not_empty')->rule('cache_type', 'in_array', array(':value', array_keys($this->_installer->cache_types())))->rule('session_type', 'in_array', array(':value', array_keys($this->_installer->session_types())))->rule('db_driver', 'in_array', array(':value', array_keys($this->_installer->database_drivers())))->rule('locale', 'in_array', array(':value', $locales))->rule('admin_dir_name', 'not_empty');
 }
示例#27
0
 public function build_validation(Validation $validation)
 {
     return parent::build_validation($validation)->rule('module', 'not_empty')->rule('module', 'in_array', array(':value', array_keys(Kohana::modules())))->rule('model', 'not_empty')->rule('model', 'Jam::meta');
 }
示例#28
0
 public function build_validation(Validation $validation)
 {
     return parent::build_validation($validation)->rule('module', 'not_empty')->rule('module', 'in_array', array(':value', array_keys(Kohana::modules())))->rule('name', 'not_empty')->rule('type', 'in_array', array(':value', array('number', 'chart')));
 }
示例#29
0
 public function build_validation(Validation $validation)
 {
     return parent::build_validation($validation)->rule('headers', 'not_empty')->rule('resource', 'not_empty');
     // Require this parameter.
 }
示例#30
0
 public function execute(array $options)
 {
     Minion_Task::factory('db:structure:dump')->execute(array('database' => $options['from'], 'force' => $options['force']));
     Minion_Task::factory('db:structure:load')->execute(array('database' => $options['to'], 'force' => $options['force']));
 }