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
45611519
Commit
45611519
authored
Apr 27, 2022
by
Telenkov Ruslan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
3 done
parent
73649fbf
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
750 additions
and
28 deletions
+750
-28
composer.json
app/composer.json
+2
-0
composer.lock
app/composer.lock
+84
-1
BoxBlock.php
...oot/modules/custom/bootcamp/src/Plugin/Block/BoxBlock.php
+2
-2
myservice.module
app/docroot/modules/custom/myservice/myservice.module
+58
-13
MyService.php
...oot/modules/custom/myservice/src/Controller/MyService.php
+4
-3
MyNodeQueueWorker.php
...om/myservice/src/Plugin/QueueWorker/MyNodeQueueWorker.php
+203
-0
MyQueueWorker.php
...custom/myservice/src/Plugin/QueueWorker/MyQueueWorker.php
+74
-0
MySecondQueueWorker.php
.../myservice/src/Plugin/QueueWorker/MySecondQueueWorker.php
+323
-0
block--page-title-block.html.twig
...palbook/templates/block/block--page-title-block.html.twig
+0
-9
No files found.
app/composer.json
View file @
45611519
...
...
@@ -25,6 +25,7 @@
"drupal/devel_php"
:
"^1.0"
,
"drupal/field_group"
:
"^3.2"
,
"drupal/fontawesome_menu_icons"
:
"^1.9"
,
"drupal/jquery_ui"
:
"^1.4"
,
"drupal/layout_builder_restrictions"
:
"^2.13"
,
"drupal/media_library_block"
:
"^1.0"
,
"drupal/media_library_form_element"
:
"^2.0"
,
...
...
@@ -32,6 +33,7 @@
"drupal/module_filter"
:
"^3.2"
,
"drupal/paragraphs"
:
"^1.13"
,
"drupal/pathauto"
:
"^1.9"
,
"drupal/queue_ui"
:
"^3.0"
,
"drupal/quick_node_clone"
:
"^1.14"
,
"drupal/rabbit_hole"
:
"^2.26"
,
"drupal/recaptcha"
:
"^3.0"
,
...
...
app/composer.lock
View file @
45611519
...
...
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "
26bb62d404a206b96084a0b93b84439e
",
"content-hash": "
854deeed64fa5e16b6ea003e4348660d
",
"packages": [
{
"name": "asm89/stack-cors",
...
...
@@ -3734,6 +3734,89 @@
"documentation": "https://www.drupal.org/docs/8/modules/pathauto"
}
},
{
"name": "drupal/queue_ui",
"version": "3.0.0",
"source": {
"type": "git",
"url": "https://git.drupalcode.org/project/queue_ui.git",
"reference": "3.0.0"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/queue_ui-3.0.0.zip",
"reference": "3.0.0",
"shasum": "6f9dcff081c601668f06c4733e13228e4defed35"
},
"require": {
"drupal/core": "^9.2 || ^10"
},
"require-dev": {
"drupal/queue_order": "^2"
},
"type": "drupal-module",
"extra": {
"drupal": {
"version": "3.0.0",
"datestamp": "1650616744",
"security-coverage": {
"status": "covered",
"message": "Covered by Drupal's security advisory policy"
}
},
"drush": {
"services": {
"drush.services.yml": "^9 || ^10 || ^11"
}
}
},
"notification-url": "https://packages.drupal.org/8/downloads",
"license": [
"GPL-2.0+"
],
"authors": [
{
"name": "floretan",
"homepage": "https://www.drupal.org/user/2743951",
"role": "Maintainer"
},
{
"name": "coltrane",
"homepage": "https://www.drupal.org/user/91990",
"role": "Maintainer"
},
{
"name": "tsphethean",
"homepage": "https://www.drupal.org/user/66163",
"role": "Maintainer"
},
{
"name": "bceyssens",
"homepage": "https://www.drupal.org/user/2811585",
"role": "Maintainer"
},
{
"name": "voleger",
"homepage": "https://www.drupal.org/user/881620",
"role": "Maintainer"
},
{
"name": "voleger",
"homepage": "https://www.drupal.org/user/3260314"
}
],
"description": "Interface and manager for Drupal queues.",
"homepage": "https://www.drupal.org/project/queue_ui",
"keywords": [
"drupal",
"php",
"queue"
],
"support": {
"source": "https://git.drupalcode.org/project/queue_ui",
"issues": "https://www.drupal.org/project/issues/queue_ui"
}
},
{
"name": "drupal/quick_node_clone",
"version": "1.14.0",
...
...
app/docroot/modules/custom/bootcamp/src/Plugin/Block/BoxBlock.php
View file @
45611519
app/docroot/modules/custom/myservice/myservice.module
View file @
45611519
...
...
@@ -9,30 +9,75 @@ use Drupal\node\Entity\Node;
/**
* Implements hook_cron().
*/
function
myservice_cron
()
{
$people
=
\Drupal
::
service
(
'myservice.my'
)
->
getResult
();
//получаю данные с сервиса
$queue
=
\Drupal
::
queue
(
'my_test_queue'
);
//объявляю очередь
$queue
->
createQueue
();
/*function getResult($queue,$url){
//do {
$request = \Drupal::service('myservice.my')->getResult($url);
$result = $request->results; // выкинул служебную информацию
foreach ($result as $row_item){
$queue->createItem($row_item);
}
//$url = $request->next;
//} while ($url);
foreach
(
$people
as
$person
)
$queue
->
createItem
([
//наполняю очередь данными
'name'
=>
$person
->
name
,
]);
$item
=
$queue
->
claimItem
();
// получаю элементы очереди
return $queue;
}
/*
/*function getNodePeople($queue){
$end = time() + 30;
while (time() < $end && ($item = $queue->claimItem())) {
$fieldurl = (string)$item->data->url;
preg_match_all("/\d+/", $fieldurl, $counter);
# Данные которые мы добавляли в очередь находятся в $item->data.
$node = Node::create(array(
'name'
=>
$item
->
data
[
'name'
],
'type' => 'people' ,
'title' => 'people' . $counter[0][0],
'field_name' =>$item->data->name,
'field_height' =>$item->data->height,
'field_mass' =>$item->data->mass,
'field_hair_color' =>$item->data->hair_color,
'field_skin_color' =>$item->data->skin_color,
'field_eye_color' =>$item->data->eye_color,
'field_birth_year' =>$item->data->birth_year,
'field_gender' =>$item->data->gender,
'langcode' => 'ru',
'status' => 1,
));
$node->save();
}
$queue->deleteItem($item); //удаление элементов
}
$queue->deleteQueue(); //удаление очереди
}
*/
function
myservice_cron
()
{
$queue
=
\Drupal
::
queue
(
'my_test_queue'
);
//объявляю очередь
$queue
->
createQueue
();
$request
=
\Drupal
::
service
(
'myservice.my'
)
->
getResult
(
'https://swapi.dev/api/'
);
// $result = $request->results; // выкинул служебную информацию
foreach
(
$request
as
$row_item
){
$queue
->
createItem
(
$row_item
);
}
//getResult($queue,'https://swapi.dev/api/');
//getNodePeople($queue);
}
app/docroot/modules/custom/myservice/src/Controller/MyService.php
View file @
45611519
...
...
@@ -8,13 +8,14 @@ use GuzzleHttp\Client;
class
MyService
{
public
function
getResult
()
public
function
getResult
(
$url
)
{
// Отправка GET-запроса
$request
=
\Drupal
::
httpClient
()
->
get
(
'https://swapi.dev/api/people/'
);
$request
=
\Drupal
::
httpClient
()
->
get
(
$url
);
// Ответ GET-запроса
$response
=
$request
->
getBody
()
->
getContents
();
$result
=
json_decode
(
$response
)
->
results
;
$result
=
json_decode
(
$response
);
return
$result
;
}
...
...
app/docroot/modules/custom/myservice/src/Plugin/QueueWorker/MyNodeQueueWorker.php
0 → 100644
View file @
45611519
<?php
namespace
Drupal\myservice\Plugin\QueueWorker
;
use
Drupal\Core\Queue\QueueWorkerBase
;
use
Drupal\myservice\Plugin\QueueWorker\MyQueueWorker
;
use
Drupal\node\Entity\Node
;
/**
* Process a queue.
*
* @QueueWorker(
* id = "my_node_queue",
* title = @Translation("Create Node"),
* cron = {"time" = 60}
* )
*/
class
MyNodeQueueWorker
extends
QueueWorkerBase
{
// Функция для определения типа материала, для дальнейшего создания ноды по данному типу
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
;
}
public
function
processItem
(
$data
){
$api_url
=
(
string
)
$data
->
url
;
//получаю URL будущей ноды
$type_of_node
=
$this
->
nodeType
(
$api_url
);
//получаю тип ноды
$node_id
=
$this
->
nodeId
(
$api_url
);
preg_match_all
(
"/\d+/"
,
$api_url
,
$counter
);
//Вызываю создание нод для каждого типа материала
if
(
$type_of_node
==
'people'
){
//проверить на наличие ноды по полю id и если она есть
$this
->
createPeopleNode
(
$counter
,
$data
,
$node_id
);
}
elseif
(
$type_of_node
==
'films'
){
$this
->
createFilmsNode
(
$counter
,
$data
,
$node_id
);
}
elseif
(
$type_of_node
==
'planets'
){
$this
->
createPlanetsNode
(
$counter
,
$data
,
$node_id
);
}
elseif
(
$type_of_node
==
'species'
){
$this
->
createSpeciesNode
(
$counter
,
$data
,
$node_id
);
}
elseif
(
$type_of_node
==
'starships'
){
$this
->
createStarshipsNode
(
$counter
,
$data
,
$node_id
);
}
elseif
(
$type_of_node
==
'vehicles'
){
$this
->
createVehiclesNode
(
$counter
,
$data
,
$node_id
);
}
}
/**
* @throws \Drupal\Core\Entity\EntityStorageException
*/
public
function
createPeopleNode
(
$counter
,
$data
,
$node_id
){
$node
=
Node
::
create
(
array
(
'type'
=>
'people'
,
'title'
=>
'people'
.
$counter
[
0
][
0
],
'field_swapi_id'
=>
$node_id
,
'field_name'
=>
$data
->
name
,
'field_height'
=>
$data
->
height
,
'field_mass'
=>
$data
->
mass
,
'field_hair_color'
=>
$data
->
hair_color
,
'field_skin_color'
=>
$data
->
skin_color
,
'field_eye_color'
=>
$data
->
eye_color
,
'field_birth_year'
=>
$data
->
birth_year
,
'field_gender'
=>
$data
->
gender
,
'langcode'
=>
'ru'
,
'status'
=>
1
,
));
$node
->
save
();
}
/**
* @throws \Drupal\Core\Entity\EntityStorageException
*/
public
function
createFilmsNode
(
$counter
,
$data
,
$node_id
){
$node
=
Node
::
create
(
array
(
'type'
=>
'films'
,
'title'
=>
'film'
.
$counter
[
0
][
0
],
'field_swapi_id'
=>
$node_id
,
'field_title'
=>
$data
->
title
,
'field_episode_id'
=>
$data
->
episode_id
,
'field_director'
=>
$data
->
director
,
'field_opening_crawl'
=>
$data
->
opening_crawl
,
'field_producer'
=>
$data
->
producer
,
'field_release_date'
=>
$data
->
release_date
,
'langcode'
=>
'ru'
,
'status'
=>
1
,
));
$node
->
save
();
}
/**
* @throws \Drupal\Core\Entity\EntityStorageException
*/
public
function
createPlanetsNode
(
$counter
,
$data
,
$node_id
){
$node
=
Node
::
create
(
array
(
'type'
=>
'planets'
,
'title'
=>
'planet'
.
$counter
[
0
][
0
],
'field_swapi_id'
=>
$node_id
,
'field_name'
=>
$data
->
name
,
'field_diameter'
=>
$data
->
diameter
,
'field_rotation_period'
=>
$data
->
rotation_period
,
'field_orbital_period'
=>
$data
->
orbital_period
,
'field_gravity '
=>
$data
->
gravity
,
'field_population'
=>
$data
->
population
,
'field_climate'
=>
$data
->
climate
,
'field_terrain'
=>
$data
->
terrain
,
'field_surface_water'
=>
$data
->
surface_water
,
'langcode'
=>
'ru'
,
'status'
=>
1
,
));
$node
->
save
();
}
/**
* @throws \Drupal\Core\Entity\EntityStorageException
*/
public
function
createSpeciesNode
(
$counter
,
$data
,
$node_id
)
{
$node
=
Node
::
create
(
array
(
'type'
=>
'species'
,
'title'
=>
'specie'
.
$counter
[
0
][
0
],
'field_swapi_id'
=>
$node_id
,
'field_name'
=>
$data
->
name
,
'field_language'
=>
$data
->
language
,
'field_skin_colors'
=>
$data
->
skin_colors
,
'field_hair_colors'
=>
$data
->
hair_colors
,
'field_eye_colors'
=>
$data
->
eye_colors
,
'field_designation'
=>
$data
->
designation
,
'field_classification'
=>
$data
->
classification
,
'field_average_lifespan'
=>
$data
->
average_lifespan
,
'field_average_height'
=>
$data
->
average_height
,
'langcode'
=>
'ru'
,
'status'
=>
1
,
));
$node
->
save
();
}
/**
* @throws \Drupal\Core\Entity\EntityStorageException
*/
public
function
createStarshipsNode
(
$counter
,
$data
,
$node_id
){
$node
=
Node
::
create
(
array
(
'type'
=>
'starships'
,
'title'
=>
'starship'
.
$counter
[
0
][
0
],
'field_swapi_id'
=>
$node_id
,
'field_name'
=>
$data
->
name
,
'field_model'
=>
$data
->
model
,
'field_starship_class'
=>
$data
->
starship_class
,
'field_manufacturer'
=>
$data
->
manufacturer
,
'field_cost_in_credits'
=>
$data
->
cost_in_credits
,
'field_length'
=>
$data
->
length
,
'field_crew'
=>
$data
->
crew
,
'field_passengers'
=>
$data
->
passengers
,
'field_max_atmosphering_speed'
=>
$data
->
max_atmosphering_speed
,
'field_hyperdrive_rating'
=>
$data
->
hyperdrive_rating
,
'field_MGLT'
=>
$data
->
MGLT
,
'cargo_capacity'
=>
$data
->
cargo_capacity
,
'field_consumables'
=>
$data
->
consumables
,
'langcode'
=>
'ru'
,
'status'
=>
1
,
));
$node
->
save
();
}
/**
* @throws \Drupal\Core\Entity\EntityStorageException
*/
public
function
createVehiclesNode
(
$counter
,
$data
,
$node_id
){
$node
=
Node
::
create
(
array
(
'type'
=>
'vehicles'
,
'title'
=>
'vehicle'
.
$counter
[
0
][
0
],
'field_swapi_id'
=>
$node_id
,
'field_name'
=>
$data
->
name
,
'field_model'
=>
$data
->
model
,
'field_vehicle_class'
=>
$data
->
vehicle_class
,
'field_manufacturer'
=>
$data
->
manufacturer
,
'field_cost_in_credits'
=>
$data
->
cost_in_credits
,
'field_length'
=>
$data
->
length
,
'field_crew'
=>
$data
->
crew
,
'field_passengers'
=>
$data
->
passengers
,
'field_max_atmosphering_speed'
=>
$data
->
max_atmosphering_speed
,
'cargo_capacity'
=>
$data
->
cargo_capacity
,
'field_consumables'
=>
$data
->
consumables
,
'langcode'
=>
'ru'
,
'status'
=>
1
,
));
$node
->
save
();
}
}
app/docroot/modules/custom/myservice/src/Plugin/QueueWorker/MyQueueWorker.php
0 → 100644
View file @
45611519
<?php
namespace
Drupal\myservice\Plugin\QueueWorker
;
use
Drupal\Core\Queue\QueueWorkerBase
;
/**
* Process a queue.
*
* @QueueWorker(
* id = "my_test_queue",
* title = @Translation("My queue worker"),
* cron = {"time" = 60}
* )
*/
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
;
do
{
$request
=
\Drupal
::
service
(
'myservice.my'
)
->
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
if
(
empty
(
$nids
)){
$queue
->
createItem
(
$row_item
);
}
else
{
$secondQueue
->
createItem
(
$row_item
);
}
}
$url
=
$request
->
next
;
}
while
(
$url
);
}
}
app/docroot/modules/custom/myservice/src/Plugin/QueueWorker/MySecondQueueWorker.php
0 → 100644
View file @
45611519
This diff is collapsed.
Click to expand it.
app/docroot/themes/custom/drupalbook/templates/block/block--page-title-block.html.twig
deleted
100644 → 0
View file @
73649fbf
{#
/**
* @file
* Theme override for page title block.
*
* @ingroup templates
*/
#}
{%
extends
"block--bare.html.twig"
%}
\ No newline at end of file
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