Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
R
r-test
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Jobs
Commits
Open sidebar
Telenkov Ruslan
r-test
Commits
2550e5d1
Commit
2550e5d1
authored
May 06, 2022
by
Telenkov Ruslan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
all done, new functions, one queue
parent
bf04ac5c
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
339 additions
and
35 deletions
+339
-35
MyService.php
...oot/modules/custom/myservice/src/Controller/MyService.php
+325
-5
MyNodeQueueWorker.php
...om/myservice/src/Plugin/QueueWorker/MyNodeQueueWorker.php
+1
-0
MyQueueWorker.php
...custom/myservice/src/Plugin/QueueWorker/MyQueueWorker.php
+13
-30
No files found.
app/docroot/modules/custom/myservice/src/Controller/MyService.php
View file @
2550e5d1
This diff is collapsed.
Click to expand it.
app/docroot/modules/custom/myservice/src/Plugin/QueueWorker/MyNodeQueueWorker.php
View file @
2550e5d1
...
...
@@ -203,4 +203,5 @@ public function processItem($data){
));
$node
->
save
();
}
}
app/docroot/modules/custom/myservice/src/Plugin/QueueWorker/MyQueueWorker.php
View file @
2550e5d1
...
...
@@ -2,7 +2,7 @@
namespace
Drupal\myservice\Plugin\QueueWorker
;
use
Drupal\Core\Queue\QueueWorkerBase
;
use
Drupal\myservice\Controller\MyService
;
/**
* Process a queue.
*
...
...
@@ -18,51 +18,34 @@ class MyQueueWorker extends QueueWorkerBase {
/**
* {@inheritdoc}
*/
public
function
existNode
(
$type
,
$id
){
$query
=
\Drupal
::
entityQuery
(
'node'
)
->
condition
(
'type'
,
$type
)
->
condition
(
'field_swapi_id'
,
$id
);
$nids
=
$query
->
execute
();
return
$nids
;
}
public
function
nodeType
(
$api_url
){
$array_of_url
=
explode
(
'/'
,
$api_url
);
//разделяю адрес АПИ на массив элементов
$type_of_node
=
$array_of_url
[
4
];
// название необходимой ноды - ВСЕГДА четвертый элемент данного массива
return
$type_of_node
;
}
public
function
nodeId
(
$api_url
){
$array_of_url
=
explode
(
'/'
,
$api_url
);
//разделяю адрес АПИ на массив элементов
$node_id
=
$array_of_url
[
5
];
return
$node_id
;
}
// 1 API
public
function
processItem
(
$data
)
{
$queue
=
\Drupal
::
queue
(
'my_node_queue'
);
//объявляю очередь
$secondQueue
=
\Drupal
::
queue
(
'my_second_node_queue'
);
$url
=
$data
;
//$queue = \Drupal::queue('my_node_queue'); //объявляю очередь
// $secondQueue = \Drupal::queue('my_second_node_queue');
$url
=
$data
;
// перезаписываю адреса
$service
=
\Drupal
::
service
(
'myservice.my'
);
//обращаюсь к сервису
do
{
$request
=
\Drupal
::
service
(
'myservice.my'
)
->
getResult
(
$url
);
$request
=
$service
->
getResult
(
$url
);
$result
=
$request
->
results
;
// выкинул служебную информацию
foreach
(
$result
as
$row_item
){
$type
=
$this
->
nodeType
(
$row_item
->
url
);
// получаю ID ноды для дальнейшей проверки из БД
$id
=
$
this
->
nodeId
(
$row_item
->
url
);
// получаю тип ноды для дальнейшей проверки из БД
$nids
=
$
this
->
existNode
(
$type
,
$id
);
// вызываю функцию проверки ноды в БД, если есть, то вернется ID
$type
=
$service
->
nodeType
(
$row_item
->
url
);
// получаю ID ноды для дальнейшей проверки из БД
$id
=
$
service
->
nodeId
(
$row_item
->
url
);
// получаю тип ноды для дальнейшей проверки из БД
$nids
=
$
service
->
existNode
(
$type
,
$id
);
// вызываю функцию проверки ноды в БД, если есть, то вернется ID
if
(
empty
(
$nids
)){
$queue
->
createItem
(
$row_item
);
// $queue->createItem($row_item);
$service
->
createNode
(
$row_item
);
// вызываю метод создания ноды из сервиса
$service
->
updateNode
(
$row_item
);
}
else
{
$se
condQueue
->
createItem
(
$row_item
);
$se
rvice
->
updateNode
(
$row_item
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment