This repository has been archived by the owner on Nov 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
indieweb.drush.inc
152 lines (140 loc) · 4.18 KB
/
indieweb.drush.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
/**
* @file
* Drush legacy commands.
*/
/**
* Implements hook_drush_command().
*
* @return array
*/
function indieweb_drush_command() {
return [
'indieweb-send-webmentions' => [
'description' => 'Send webmentions',
'aliases' => ['isw'],
],
'indieweb-replace-avatar' => [
'description' => 'Replace avatar',
'aliases' => ['ira', 'indieweb-replace-avatar'],
'required-arguments' => 2,
'arguments' => [
'search' => 'The avatar to search',
'replace' => 'The avatar to replace',
'field_name' => 'The condition field'
],
],
'indieweb-process-webmentions' => [
'description' => 'Process webmentions',
'aliases' => ['ipw'],
],
'indieweb-fetch-post-contexts' => [
'description' => 'Fetch post contexts',
'aliases' => ['ifpr'],
],
'indieweb-microsub-fetch-items' => [
'description' => 'Microsub fetch new items',
'aliases' => ['imfi'],
],
'indieweb-externalauth-map-account' => [
'description' => 'Maps an existing account with a domain.',
'aliases' => ['iema'],
'required-arguments' => 2,
'arguments' => [
'uid' => 'The uid of the account.',
'domain' => 'The domain to map.'
],
],
'indieweb-websub-publish' => [
'description' => 'WebSub publish',
],
'indieweb-websub-resubscribe' => [
'description' => 'WebSub resubscribe',
],
];
}
/**
* Handles WebSub publish.
*/
function drush_indieweb_websub_publish() {
if (\Drupal::config('indieweb_websub.settings')->get('send_pub_handler') == 'drush') {
\Drupal::service('indieweb.websub.client')->handleQueue();
}
}
/**
* Handles WebSub resubscribe.
*
* @param $debug
*/
function drush_indieweb_websub_resubscribe($debug = FALSE) {
if (\Drupal::config('indieweb_websub.settings')->get('resubscribe_handler') == 'drush') {
\Drupal::service('indieweb.websub.client')->resubscribe($debug);
}
}
/**
* Send webmentions in queue.
*/
function drush_indieweb_send_webmentions() {
if (\Drupal::config('indieweb_webmention.settings')->get('send_webmention_handler') == 'drush') {
\Drupal::service('indieweb.webmention.client')->handleQueue();
}
}
/**
* Process webmentions.
*/
function drush_indieweb_process_webmentions() {
if (\Drupal::config('indieweb_webmention.settings')->get('webmention_internal_handler') == 'drush') {
\Drupal::service('indieweb.webmention.client')->processWebmentions();
}
}
/**
* Fetch post contexts in queue.
*/
function drush_indieweb_fetch_post_contexts() {
if (\Drupal::config('indieweb_context.settings')->get('handler') == 'drush') {
\Drupal::service('indieweb.post_context.client')->handleQueue();
}
}
/**
* Microsub fetch items.
*/
function drush_indieweb_microsub_fetch_items() {
if (\Drupal::config('indieweb_microsub.settings')->get('microsub_internal') &&
\Drupal::config('indieweb_microsub.settings')->get('microsub_internal_handler') == 'drush') {
\Drupal::service('indieweb.microsub.client')->fetchItems();
}
}
/**
* Maps a domain to an existing account.
*
* @param int $uid
* @param string $domain
*/
function drush_indieweb_externalauth_map_account($uid = 0, $domain = '') {
\Drupal::service('indieweb.indieauth.client')->externalauthMapAccount($uid, $domain, TRUE);
}
/**
* Replace avatar.
*
* @param string $search
* @param string $replace
* @param string $field_name
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
* @throws \Drupal\Core\Entity\EntityStorageException
*/
function drush_indieweb_replace_avatar($search = '', $replace = '', $field_name = 'author_photo') {
$ids = \Drupal::entityQuery('indieweb_webmention')
->condition($field_name, $search)
->execute();
if (!empty($ids)) {
/** @var \Drupal\indieweb_webmention\Entity\WebmentionInterface[] $webmentions */
$webmentions = \Drupal::entityTypeManager()->getStorage('indieweb_webmention')->loadMultiple($ids);
foreach ($webmentions as $webmention) {
$webmention->set('author_photo', $replace);
$webmention->save();
}
}
drush_print('Replaced avatars: ' . count($ids));
}