Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
P
Project
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
Gorodkov Denis
Project
Commits
c5d0be44
Commit
c5d0be44
authored
May 05, 2022
by
Gorodkov Denis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
parent
f318f4b0
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
113 additions
and
119 deletions
+113
-119
composer.json
app/composer.json
+1
-0
composer.lock
app/composer.lock
+46
-1
mymodule.module
app/docroot/modules/custom/mymodule/mymodule.module
+39
-5
mymodule.services.yml
app/docroot/modules/custom/mymodule/mymodule.services.yml
+1
-0
API.php
app/docroot/modules/custom/mymodule/src/API.php
+20
-4
QueueSwapi.php
...les/custom/mymodule/src/Plugin/QueueWorker/QueueSwapi.php
+6
-7
QueueWorkerNode.php
...ustom/mymodule/src/Plugin/QueueWorker/QueueWorkerNode.php
+0
-38
QueueWorkerSwapi.php
...stom/mymodule/src/Plugin/QueueWorker/QueueWorkerSwapi.php
+0
-64
No files found.
app/composer.json
View file @
c5d0be44
...
@@ -40,6 +40,7 @@
...
@@ -40,6 +40,7 @@
"drupal/search_api"
:
"^1.23"
,
"drupal/search_api"
:
"^1.23"
,
"drupal/search_api_autocomplete"
:
"^1.6"
,
"drupal/search_api_autocomplete"
:
"^1.6"
,
"drupal/search_api_exclude"
:
"^2.0"
,
"drupal/search_api_exclude"
:
"^2.0"
,
"drupal/search_api_exclude_entity"
:
"^1.3"
,
"drupal/shariff"
:
"^1.7"
,
"drupal/shariff"
:
"^1.7"
,
"drupal/simple_sitemap"
:
"^4.1"
,
"drupal/simple_sitemap"
:
"^4.1"
,
"drupal/smtp"
:
"^1.0"
,
"drupal/smtp"
:
"^1.0"
,
...
...
app/composer.lock
View file @
c5d0be44
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
"This file is @generated automatically"
],
],
"content-hash": "
3df970584b1b9eb7ad06837036bba875
",
"content-hash": "
c7d3d0deb367b8080feafd1b3f5de48d
",
"packages": [
"packages": [
{
{
"name": "asm89/stack-cors",
"name": "asm89/stack-cors",
...
@@ -4250,6 +4250,51 @@
...
@@ -4250,6 +4250,51 @@
"issues": "https://www.drupal.org/project/issues/search_api_exclude"
"issues": "https://www.drupal.org/project/issues/search_api_exclude"
}
}
},
},
{
"name": "drupal/search_api_exclude_entity",
"version": "1.3.0",
"source": {
"type": "git",
"url": "https://git.drupalcode.org/project/search_api_exclude_entity.git",
"reference": "8.x-1.3"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/search_api_exclude_entity-8.x-1.3.zip",
"reference": "8.x-1.3",
"shasum": "a4b8fd96bceedf4f6cff382f531585613325a702"
},
"require": {
"drupal/core": "^8 || ^9",
"drupal/search_api": "*"
},
"type": "drupal-module",
"extra": {
"drupal": {
"version": "8.x-1.3",
"datestamp": "1603201534",
"security-coverage": {
"status": "covered",
"message": "Covered by Drupal's security advisory policy"
}
}
},
"notification-url": "https://packages.drupal.org/8/downloads",
"license": [
"GPL-2.0-or-later"
],
"authors": [
{
"name": "beltofte",
"homepage": "https://www.drupal.org/user/151799"
}
],
"description": "Exclude one or more entities from being indexed in Search API.",
"homepage": "https://www.drupal.org/project/search_api_exclude_entity",
"support": {
"source": "https://git.drupalcode.org/project/search_api_exclude_entity"
}
},
{
{
"name": "drupal/shariff",
"name": "drupal/shariff",
"version": "1.7.0",
"version": "1.7.0",
...
...
app/docroot/modules/custom/mymodule/mymodule.module
View file @
c5d0be44
...
@@ -9,14 +9,45 @@
...
@@ -9,14 +9,45 @@
*/
*/
function
mymodule_cron
()
{
function
mymodule_cron
()
{
$api
=
\Drupal
::
service
(
'mymodule.custom_services'
);
$api
=
\Drupal
::
service
(
'mymodule.custom_services'
);
$queue_api
=
\Drupal
::
queue
(
'mymodule_api'
);
$result_api
=
$api
->
getResponse
(
'https://swapi.dev/api'
);
$result_api
=
$api
->
getResponse
(
'https://swapi.dev/api'
);
$queue_api
=
\Drupal
::
queue
(
'mymodule_swapi'
);
foreach
(
$result_api
as
$item
)
{
$date
=
new
DateTime
();
$queue_api
->
createItem
(
$item
);
$date
=
$date
->
getTimestamp
(
);
}
\Drupal
::
state
()
->
set
(
'date_queue_swapi'
,
$date
);
\Drupal
::
state
()
->
set
(
'date_queue_swapi'
,
date
());
foreach
(
$result_api
as
$item
)
{
$bundle
=
$api
->
getTypeNode
(
$item
);
if
(
$api
->
checkBundle
(
$bundle
))
{
$uri
=
$item
;
while
(
!
empty
(
$uri
))
{
$result
=
$api
->
getResponse
(
$uri
);
foreach
(
$result
[
'results'
]
as
$value
)
{
$bundle
=
$api
->
getTypeNode
(
$value
[
'url'
]);
$swapi_id
=
$api
->
getSwapiId
(
$value
[
'url'
]);
$node
=
\Drupal
::
entityTypeManager
()
->
getStorage
(
'node'
)
->
loadByProperties
([
'type'
=>
$bundle
,
'field_swapi_id'
=>
$swapi_id
,
]);
foreach
(
$node
as
$val
)
{
$node_edited
=
$val
;
}
if
(
!
empty
(
$node
))
{
if
(
$node_edited
->
field_edited
->
value
!==
$value
[
'edited'
])
{
$queue_api
->
createItem
(
$value
);
}
}
else
{
$api
->
createNode
(
$value
);
}
}
$uri
=
$result
[
'next'
];
}
}
else
{
\Drupal
::
logger
(
'Queue mymodule_api'
)
->
notice
(
"Content type
$bundle
не создан!"
);
}
}
}
}
/**
/**
...
@@ -38,6 +69,9 @@ function mymodule_form_contact_message_feedback_form_alter(&$form, \Drupal\Core\
...
@@ -38,6 +69,9 @@ function mymodule_form_contact_message_feedback_form_alter(&$form, \Drupal\Core\
}
}
}
}
/**
* Implements hook_form_alter().
*/
function
mymodule_form_alter
(
&
$form
,
\Drupal\Core\Form\FormStateInterface
$form_state
,
$form_id
)
{
function
mymodule_form_alter
(
&
$form
,
\Drupal\Core\Form\FormStateInterface
$form_state
,
$form_id
)
{
if
(
$form_id
==
'views_exposed_form'
and
$form
[
'#id'
]
==
'views-exposed-form-index-films-page-1'
)
{
if
(
$form_id
==
'views_exposed_form'
and
$form
[
'#id'
]
==
'views-exposed-form-index-films-page-1'
)
{
$form
[
"actions"
][
"reset"
][
"#access"
]
=
true
;
$form
[
"actions"
][
"reset"
][
"#access"
]
=
true
;
...
...
app/docroot/modules/custom/mymodule/mymodule.services.yml
View file @
c5d0be44
services
:
services
:
mymodule.custom_services
:
mymodule.custom_services
:
class
:
Drupal\mymodule\API
class
:
Drupal\mymodule\API
arguments
:
[
'
@http_client'
]
app/docroot/modules/custom/mymodule/src/API.php
View file @
c5d0be44
...
@@ -3,13 +3,12 @@
...
@@ -3,13 +3,12 @@
namespace
Drupal\mymodule
;
namespace
Drupal\mymodule
;
use
GuzzleHttp\ClientInterface
;
use
GuzzleHttp\ClientInterface
;
use
GuzzleHttp\Client
;
class
API
{
class
API
{
pr
ivate
$httpClient
;
pr
otected
$httpClient
;
public
function
__construct
()
{
public
function
__construct
(
ClientInterface
$httpClient
)
{
$this
->
httpClient
=
\Drupal
::
httpClient
()
;
$this
->
httpClient
=
$httpClient
;
}
}
public
function
getResponse
(
$uri
)
{
public
function
getResponse
(
$uri
)
{
...
@@ -44,4 +43,21 @@ class API {
...
@@ -44,4 +43,21 @@ class API {
return
false
;
return
false
;
}
}
public
function
createNode
(
$item
)
{
$queue_api
=
\Drupal
::
queue
(
'mymodule_swapi'
);
$bundle
=
$this
->
getTypeNode
(
$item
[
'url'
]);
$swapi_id
=
(
int
)
$this
->
getSwapiId
(
$item
[
'url'
]);
$title
=
$item
[
array_keys
(
$item
)[
0
]];
$node
=
\Drupal
::
entityTypeManager
()
->
getStorage
(
'node'
)
->
create
([
'type'
=>
$bundle
,
'title'
=>
$title
,
'field_swapi_id'
=>
$swapi_id
]);
$node
->
save
();
$queue_api
->
createItem
(
$item
);
}
}
}
app/docroot/modules/custom/mymodule/src/Plugin/QueueWorker/Queue
WorkerUpdate
.php
→
app/docroot/modules/custom/mymodule/src/Plugin/QueueWorker/Queue
Swapi
.php
View file @
c5d0be44
...
@@ -8,27 +8,26 @@ use Drupal\Core\Queue\QueueWorkerBase;
...
@@ -8,27 +8,26 @@ use Drupal\Core\Queue\QueueWorkerBase;
* Comments
* Comments
*
*
* @QueueWorker (
* @QueueWorker (
* id = "mymodule_
update
",
* id = "mymodule_
swapi
",
* title = "Queue
update node
",
* title = "Queue
swapi
",
* cron = {"time" = 60}
* cron = {"time" = 60}
* )
* )
*/
*/
class
QueueWorkerUpdate
extends
QueueWorkerBase
{
class
QueueSwapi
extends
QueueWorkerBase
{
/**
* {@inheritdoc}
*/
public
function
processItem
(
$data
)
{
public
function
processItem
(
$data
)
{
$node
=
$this
->
getNodeByUrl
(
$data
[
'url'
]);
$node
=
$this
->
getNodeByUrl
(
$data
[
'url'
]);
if
(
$data
[
'edited'
]
!=
$node
->
field_edited
)
{
if
(
$data
[
'edited'
]
!=
$node
->
field_edited
)
{
$this
->
edited
(
$data
,
$node
);
$this
->
edited
(
$data
,
$node
);
}
}
}
}
private
function
edited
(
$data
,
$node
)
{
private
function
edited
(
$data
,
$node
)
{
foreach
(
$data
as
$key
=>
$value
)
{
foreach
(
$data
as
$key
=>
$value
)
{
$field_name
=
"field_"
.
$key
;
$field_name
=
"field_"
.
$key
;
$bool
=
(
bool
)(
$key
!=
'name'
and
$key
!=
'title'
and
$key
!=
'homeworld'
and
$key
!=
'url'
and
$key
!=
'created'
);
$bool
=
(
bool
)(
$key
!=
'name'
and
$key
!=
'title'
and
$key
!=
'homeworld'
and
$key
!=
'url'
and
$key
!=
'created'
and
$key
!=
'people_exclude'
);
if
(
$bool
and
!
is_array
(
$value
))
{
if
(
$bool
and
!
is_array
(
$value
))
{
!
empty
(
$value
)
?
$node
->
set
(
"field_"
.
strtolower
(
$key
),
$value
)
:
''
;
!
empty
(
$value
)
?
$node
->
set
(
"field_"
.
strtolower
(
$key
),
$value
)
:
''
;
}
}
...
...
app/docroot/modules/custom/mymodule/src/Plugin/QueueWorker/QueueWorkerNode.php
deleted
100644 → 0
View file @
f318f4b0
<?php
namespace
Drupal\mymodule\Plugin\QueueWorker
;
use
Drupal\Core\Queue\QueueWorkerBase
;
/**
* Comments
*
* @QueueWorker (
* id = "mymodule_node",
* title = "Queue create node",
* cron = {"time" = 60}
* )
*/
class
QueueWorkerNode
extends
QueueWorkerBase
{
/**
* {@inheritdoc}
*/
public
function
processItem
(
$data
)
{
$api
=
\Drupal
::
service
(
'mymodule.custom_services'
);
$queue_node_update
=
\Drupal
::
queue
(
'mymodule_update'
);
$bundle
=
$api
->
getTypeNode
(
$data
[
'url'
]);
$swapi_id
=
(
int
)
$api
->
getSwapiId
(
$data
[
'url'
]);
$title
=
$data
[
array_keys
(
$data
)[
0
]];
$node
=
\Drupal
::
entityTypeManager
()
->
getStorage
(
'node'
)
->
create
([
'type'
=>
$bundle
,
'title'
=>
$title
,
'field_swapi_id'
=>
$swapi_id
]);
$node
->
save
();
$queue_node_update
->
createItem
(
$data
);
}
}
app/docroot/modules/custom/mymodule/src/Plugin/QueueWorker/QueueWorkerSwapi.php
deleted
100644 → 0
View file @
f318f4b0
<?php
namespace
Drupal\mymodule\Plugin\QueueWorker
;
use
Drupal\Core\Queue\QueueWorkerBase
;
/**
* Comments
*
* @QueueWorker (
* id = "mymodule_api",
* title = "Queue api",
* cron = {"time" = 60}
* )
*/
class
QueueWorkerSwapi
extends
QueueWorkerBase
{
/**
* {@inheritdoc}
*/
// $data приходит в виде https://swapi.dev/api/string/
public
function
processItem
(
$data
)
{
$api
=
\Drupal
::
service
(
'mymodule.custom_services'
);
$queue_node_update
=
\Drupal
::
queue
(
'mymodule_update'
);
$queue_node
=
\Drupal
::
queue
(
'mymodule_node'
);
$type_node
=
$api
->
getTypeNode
(
$data
);
$result
=
$api
->
getResponse
(
$data
);
$uri
=
$data
;
if
(
!
empty
(
$result
[
'results'
]))
{
do
{
$result
=
$api
->
getResponse
(
$uri
);
foreach
(
$result
[
'results'
]
as
$item
)
{
$bundle
=
$api
->
getTypeNode
(
$item
[
'url'
]);
$swapi_id
=
$api
->
getSwapiId
(
$item
[
'url'
]);
if
(
$api
->
checkBundle
(
$bundle
))
{
$node
=
\Drupal
::
entityTypeManager
()
->
getStorage
(
'node'
)
->
loadByProperties
([
'type'
=>
$bundle
,
'field_swapi_id'
=>
$swapi_id
,
]);
foreach
(
$node
as
$val
)
{
$node_edited
=
$val
;
}
if
(
!
empty
(
$node
))
{
if
(
$node_edited
->
field_edited
->
value
!==
$item
[
'edited'
])
{
$queue_node_update
->
createItem
(
$item
);
}
}
else
{
$queue_node
->
createItem
(
$item
);
}
}
else
{
\Drupal
::
logger
(
'Queue mymodule_api'
)
->
notice
(
"Content type
$type_node
не создан!"
);
}
}
$uri
=
$result
[
'next'
];
}
while
(
!
empty
(
$uri
));
}
\Drupal
::
logger
(
'Queue mymodule_api'
)
->
notice
(
"Очередь по
$type_node
была выполнена"
);
}
}
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