TixController.php
2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
namespace app\commands;
use PHPHtmlParser\Dom;
use yii\db\Query;
use yii;
use yii\console\Controller;
use yii\db\Expression;
use yii\helpers\Console;
use app\components\Collection;
use app\models\Host;
use app\models\Filter;
/**
* Парсинг запрещенных ресурсов в РФ.
*/
class TixController extends Controller
{
public $count = 10;
public function beforeAction($action)
{
if (!parent::beforeAction($action)) {
return false;
}
return true;
}
public function options($actionID)
{
return ['count'];
}
public function optionAliases()
{
return ['c' => 'count'];
}
/**
* Парсинг запрещенных ресурсов в РФ.
*/
public function actionIndex()
{
$hosts = (new Query())
->select('id, domain')
->from('{{%host}}')
->where(
[
'wis_status'=>Host::STATUS_WIS_FREE,
'tix_status'=>Host::STATUS_TIX_UNCHECK
]
)
->orderBy(['status'=>SORT_DESC, 'rand()'=>SORT_ASC])
->limit($this->count)
->all();
foreach ($hosts as $h)
{
$host = $h['domain'];
$result = Collection::getTixRawData(Yii::$app->params['tix_url'].$host);
if ($result['errorno'])
echo $result['errorno'] . ' ' . $result['errormessage'];
else if ($result['data']['status']==='OK')
$this->upTix($result['data']['domain'], $result['data']['govalue']);
else
echo '! '.$host.' - '.$result['data']['message'] .' ('.$result['data']['status'].')';
unset($host);
usleep (1000);
}
unset($h);
unset($hosts);
}
private function upTix($domain, $value = 0)
{
echo $domain . ' => ' . $value . "\n";
$update = ['tix'=>(int)$value, 'tix_status' => Host::STATUS_TIX_CHECK, 'tix_date' => new Expression('NOW()')];
Yii::$app->db->createCommand()
->update('{{%host}}', $update, ['domain' => $domain])
->execute();
}
}