-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsync.install
More file actions
190 lines (180 loc) · 5.21 KB
/
Copy pathsync.install
File metadata and controls
190 lines (180 loc) · 5.21 KB
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
/**
* @file
* Contains install and update functions for sync.
*/
use Drupal\Core\Database\Database;
/**
* Implements hook_schema().
*
* Defines the database tables used by this module.
*
* @see hook_schema()
*
* @ingroup sync
*/
function sync_schema() {
$schema['sync'] = [
'description' => 'Stores synced entities.',
'fields' => [
'id' => [
'type' => 'varchar_ascii',
'length' => 255,
'not null' => TRUE,
'default' => 0,
'description' => "The sync id.",
],
'entity_type' => [
'type' => 'varchar_ascii',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'The entity type.',
],
'entity_id' => [
'type' => 'varchar_ascii',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => "The entity id.",
],
'locked' => [
'description' => 'Boolean indicating whether the entity is locked and should not be synced.',
'type' => 'int',
'not null' => FALSE,
'default' => 0,
'size' => 'tiny',
],
],
'primary key' => ['id', 'entity_type'],
'indexes' => [
'entity_type' => ['entity_type'],
'entity_id' => ['entity_id'],
],
];
$schema['sync_data'] = [
'description' => 'Stores sync data.',
'fields' => [
'id' => [
'type' => 'varchar_ascii',
'length' => 255,
'not null' => TRUE,
'default' => 0,
'description' => "The sync id.",
],
'segment' => [
'type' => 'varchar_ascii',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'The sync group',
],
'changed' => [
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Unix timestamp of when the entity was last updated',
],
'hash' => [
'type' => 'varchar_ascii',
'length' => 64,
'not null' => FALSE,
'default' => NULL,
'description' => 'Fingerprint of the source record at the last successful sync. NULL means unknown, which always processes the record.',
],
],
'primary key' => ['id', 'segment'],
];
return $schema;
}
/**
* Convert entity_id column to varchar to support config entity ids.
*/
function sync_update_8001() {
$schema = Database::getConnection()->schema();
$schema->changeField('sync', 'entity_id', 'entity_id', [
'type' => 'varchar_ascii',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => "The entity id.",
]);
}
/**
* Rename group field to segment if necessary.
*/
function sync_update_8002() {
$database = Database::getConnection();
$sql = "SHOW COLUMNS FROM `sync_data` LIKE 'group';";
if ($database->query($sql)->fetchAssoc()) {
$database->schema()->changeField('sync_data', 'group', 'segment', [
'type' => 'varchar_ascii',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'The sync group',
], []);
}
}
/**
* Set the default queue cron time on existing sites.
*/
function sync_update_8003() {
// Do nothing. The default value for queue_cron_time is now hardcoded to 30
// seconds, so there is no need to set it on existing sites.
}
/**
* Remove the queue_cron_time setting now that the value is hardcoded.
*/
function sync_update_8004() {
\Drupal::configFactory()->getEditable('sync.settings')
->clear('queue_cron_time')
->save();
}
/**
* Add the change-detection hash column to sync_data.
*/
function sync_update_8005() {
$schema = Database::getConnection()->schema();
if (!$schema->fieldExists('sync_data', 'hash')) {
$schema->addField('sync_data', 'hash', [
'type' => 'varchar_ascii',
'length' => 64,
'not null' => FALSE,
'default' => NULL,
'description' => 'Fingerprint of the source record at the last successful sync. NULL means unknown, which always processes the record.',
]);
}
}
/**
* Add the settings that control what cron does with syncs.
*/
function sync_update_8006() {
$config = \Drupal::configFactory()->getEditable('sync.settings');
// Seed with the values that reproduce the previously hardcoded behavior.
foreach (['cron_build' => TRUE, 'cron_queue' => TRUE, 'cron_queue_time' => 30] as $key => $value) {
if ($config->get($key) === NULL) {
$config->set($key, $value);
}
}
// An earlier iteration of this update used queue_cron/queue_cron_time. Carry
// those values over and drop them so both namings cannot drift apart.
foreach (['queue_cron' => 'cron_queue', 'queue_cron_time' => 'cron_queue_time'] as $old => $new) {
if ($config->get($old) !== NULL) {
$config->set($new, $config->get($old))->clear($old);
}
}
$config->save();
\Drupal::service('plugin.manager.queue_worker')->clearCachedDefinitions();
}
/**
* Add the setting that switches entity locking.
*/
function sync_update_8007() {
$config = \Drupal::configFactory()->getEditable('sync.settings');
if ($config->get('lock_enabled') === NULL) {
// Off by default. Existing sites see no new UI until they opt in.
$config->set('lock_enabled', FALSE)->save();
}
}