Commit bf528dec by san58

реализация применения фильтров

1 parent 8289f5ad
...@@ -89,7 +89,7 @@ class ScanController extends Controller ...@@ -89,7 +89,7 @@ class ScanController extends Controller
$csv_skip_row++; $csv_skip_row++;
else else
{ {
$status = (Collection::apply_filter($host, $filters['after'])===false?Filter::STATUS_OFF:Filter::STATUS_ON); $status = (Collection::apply_filter($host, $filters['after'])===false?Host::STATUS_OFF:Host::STATUS_ON);
$db_request = Yii::$app->db->createCommand(); $db_request = Yii::$app->db->createCommand();
if ($db_request) if ($db_request)
{ {
......
...@@ -51,11 +51,37 @@ class AjaxController extends Controller ...@@ -51,11 +51,37 @@ class AjaxController extends Controller
*/ */
public function actionCalcStatus() public function actionCalcStatus()
{ {
$query = (new Query())->from('{{%host}}'); $update = [
foreach ($query->batch(10) as $hosts) { Host::STATUS_OFF => [],
Host::STATUS_ON => []
} ];
$filters = Collection::get_filter(Filter::TYPE_AFTER);
$query = (new Query())->select('id, domain')->from('{{%host}}');
if ($query)
foreach ($query->batch(1000) as $hosts)
{
foreach ($hosts as $host)
$update[(Collection::apply_filter($host['domain'], $filters) === false ? Host::STATUS_OFF : Host::STATUS_ON)][] = $host['id'];
unset($host);
if (count($update[Filter::STATUS_OFF])>0)
{
Yii::$app->db->createCommand()
->update('{{%host}}', ['status' => Host::STATUS_OFF], ['in', 'id', $update[Host::STATUS_OFF]])
->execute();
$update[Host::STATUS_OFF] = [];
}
if (count($update[Host::STATUS_ON])>0)
{
Yii::$app->db->createCommand()
->update('{{%host}}', ['status' => Host::STATUS_ON], ['in', 'id', $update[Host::STATUS_ON]])
->execute();
$update[Host::STATUS_ON] = [];
}
}
unset($hosts);
unset($query);
unset($filters);
unset($update);
return [ return [
'controller' => 'ajax', 'controller' => 'ajax',
'is_guest' => Yii::$app->user->isGuest, 'is_guest' => Yii::$app->user->isGuest,
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!