Kohana Minion cli 学习
阅读原文时间:2023年07月10日阅读:1

1、E:\html\tproject\framebota\platform\bootstrap.php

Kohana::modules(array(
'auth' => MODPATH.'auth', // Basic authentication
'cache' => MODPATH.'cache', // Caching with multiple backends
'codebench' => MODPATH.'codebench', // Benchmarking tool
'database' => MODPATH.'database', // Database access
'image' => MODPATH.'image', // Image manipulation
'minion' => MODPATH.'minion', // CLI Tasks
'orm' => MODPATH.'orm', // Object Relationship Mapping
'unittest' => MODPATH.'unittest', // Unit testing
'userguide' => MODPATH.'userguide', // User guide and API documentation

'captcha'    => MODPATH.'captcha',    // captcha  
'export'     => MODPATH.'export',     // export pdf excel etc  
'common'     => MODPATH.'common',     // mixture common unit

//bota all service: it is lazy load  
'bapi'       => SVCPATH.'bapi',       // bota userguide  
'member'     => SVCPATH.'member',     // member center  
'corper'     => SVCPATH.'corper',     // corper center  
'order'      => SVCPATH.'order',      // order center

'line'       => SVCPATH.'line',       // travel line  
'hotel'      => SVCPATH.'hotel',      // ours and ota hotel  
'car'        => SVCPATH.'car',        // use car service  
'visa'       => SVCPATH.'visa',       // visa  
'piao'       => SVCPATH.'piao',       // on day ticket  
'tuan'       => SVCPATH.'tuan',       // sell  
'flight'     => SVCPATH.'flight',     // flight to supplier  
'train'      => SVCPATH.'train2',      // train to supplier  
));

2、E:\html\tproject\framebota\platform\classes\Task\Flight\Airport.php

<?php defined('SYSPATH') or die('No direct script access.');

/**
* 更新机场名称信息
* 数据来源携程 http://sec-m.ctrip.com/restapi/soa2/13076/getpoicontent
* Class Task_Flight_Airport
*/
class Task_Flight_Airport extends Minion_Task
{
protected $_options = array``(

'foo' => 'bar'``,

'bar' => NULL,

);

/\*\*  
 \* @param array $params  
 \*/  
protected function \_execute(array $params)  
{  

     Kohana::$log->add(Log::DEBUG, __FILE__."\t".__LINE__."\t\t\t" . var_export($params, true));
$url = 'http://sec-m.ctrip.com/restapi/soa2/13076/getpoicontent';
$rows = ORM::factory('Flight_Airport')
->where('countycode', '=', 'CN')
->where_open()
->or_where('modtime', '<', DB::expr('DATE_SUB(NOW(),INTERVAL 2 DAY)')) ->or_where('modtime', '=', NULL)
->where_close()
->limit(20)
->order_by('modtime', 'ASC')
->order_by('hot', 'ASC')
->find_all();
$curl = CURL::factory($url);
foreach ($rows as $row) {
$code = $row->code;
$result = $curl
->data(array('key' => $code))
->method('post')
->execute();
$result = json_decode($result);
$result = json_decode($result->content);
$result = $result->Data;
$names = array();
$result = array_filter($result, function ($v) use ($code) {
return isset($v->Country) and $v->Country == '中国' and
isset($v->CountryCode) and $v->CountryCode == 'CN' and
isset($v->Code) and $v->Code == $code;
});
foreach ($result as $k => $v) {
if (strstr($v->Name, '机场')) {
$names[$k] = 0;
} else {
$names[$k] = 1;
}
};
array_multisort($names, SORT_NUMERIC, SORT_ASC, $result);
if ($result) {
$result = current($result);
if (isset($result->Datas) and count($result->Datas) and !strstr($result->Name, '机场')) {
$result->Datas = array_filter($result->Datas, function ($v) use ($code) {
return $v->Code == $code;
});
if ($result->Datas) {
$result = (object)array_merge((array)$result, (array)current(Arr::path((array)$result, 'Datas')));
}
}
$row->set('name', strtoupper($result->EName))
->set('_name', $result->Name)
->set('_shortname', UTF8::strlen($result->Name) > 4 ? str_replace('国际', '', $result->Name) : $result->Name);
}
$row->set('modtime', DB::expr('NOW()'))
->save();
}
if ($rows->count() == 0) {
echo '没有变更';
} else {
echo '完成';
}
}
}

3、执行:

# php index.php --task=user:userList --foo=foobar --bar=liuchao

php index.php --task=User_UserList --foo=foobar --bar=liuchao

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章