Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Alto
/
rkn
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit dc49f98d
authored
2021-06-08 18:59:40 +0300
by
san58
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
+
1 parent
bf528dec
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
22 deletions
controllers/AjaxController.php
controllers/AjaxController.php
View file @
dc49f98
...
@@ -4,6 +4,8 @@ namespace app\controllers;
...
@@ -4,6 +4,8 @@ namespace app\controllers;
use
app\models\Host
;
use
app\models\Host
;
use
app\models\Filter
;
use
app\components\Collection
;
use
Yii
;
use
Yii
;
use
yii\db\Query
;
use
yii\db\Query
;
use
yii\filters\AccessControl
;
use
yii\filters\AccessControl
;
...
@@ -11,6 +13,7 @@ use yii\web\Controller;
...
@@ -11,6 +13,7 @@ use yii\web\Controller;
use
yii\web\Response
;
use
yii\web\Response
;
use
yii\filters\VerbFilter
;
use
yii\filters\VerbFilter
;
class
AjaxController
extends
Controller
class
AjaxController
extends
Controller
{
{
/**
/**
...
@@ -51,41 +54,50 @@ class AjaxController extends Controller
...
@@ -51,41 +54,50 @@ class AjaxController extends Controller
*/
*/
public
function
actionCalcStatus
()
public
function
actionCalcStatus
()
{
{
$update
=
[
$count_update
=
[
Host
::
STATUS_OFF
=>
0
,
Host
::
STATUS_ON
=>
0
];
Host
::
STATUS_OFF
=>
[],
$update
=
[
Host
::
STATUS_OFF
=>
[],
Host
::
STATUS_ON
=>
[]];
Host
::
STATUS_ON
=>
[]
];
$filters
=
Collection
::
get_filter
(
Filter
::
TYPE_AFTER
);
$filters
=
Collection
::
get_filter
(
Filter
::
TYPE_AFTER
);
$query
=
(
new
Query
())
->
select
(
'id, domain'
)
->
from
(
'{{%host}}'
);
$query
=
(
new
Query
())
->
select
(
'id, domain'
)
->
from
(
'{{%host}}'
);
if
(
$query
)
if
(
$query
)
foreach
(
$query
->
batch
(
1000
)
as
$hosts
)
{
{
foreach
(
$hosts
as
$host
)
foreach
(
$query
->
batch
(
1000
)
as
$hosts
)
$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
()
foreach
(
$hosts
as
$host
)
->
update
(
'{{%host}}'
,
[
'status'
=>
Host
::
STATUS_ON
],
[
'in'
,
'id'
,
$update
[
Host
::
STATUS_ON
]])
$update
[
->
execute
();
(
$update
[
Host
::
STATUS_ON
]
=
[];
Collection
::
apply_filter
(
$host
[
'domain'
],
$filters
)
===
false
?
Host
::
STATUS_OFF
:
Host
::
STATUS_ON
)
][]
=
$host
[
'id'
];
unset
(
$host
);
if
(
count
(
$update
[
Host
::
STATUS_OFF
])
>
0
)
{
Yii
::
$app
->
db
->
createCommand
()
->
update
(
'{{%host}}'
,
[
'status'
=>
Host
::
STATUS_OFF
],
[
'in'
,
'id'
,
$update
[
Host
::
STATUS_OFF
]])
->
execute
();
$count_update
[
Host
::
STATUS_OFF
]
+=
count
(
$update
[
Host
::
STATUS_OFF
]);
$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
();
$count_update
[
Host
::
STATUS_ON
]
+=
count
(
$update
[
Host
::
STATUS_ON
]);
$update
[
Host
::
STATUS_ON
]
=
[];
}
}
}
unset
(
$hosts
);
}
}
unset
(
$hosts
);
unset
(
$query
);
unset
(
$query
);
unset
(
$filters
);
unset
(
$filters
);
unset
(
$update
);
unset
(
$update
);
return
[
return
[
'controller'
=>
'ajax'
,
'controller'
=>
'ajax'
,
'is_guest'
=>
Yii
::
$app
->
user
->
isGuest
,
'is_guest'
=>
Yii
::
$app
->
user
->
isGuest
,
'user_id'
=>
Yii
::
$app
->
user
->
getId
()
'user_id'
=>
Yii
::
$app
->
user
->
getId
(),
'domains'
=>
$count_update
];
];
}
}
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment