-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsync.install
More file actions
134 lines (127 loc) · 3.25 KB
/
sync.install
File metadata and controls
134 lines (127 loc) · 3.25 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
<?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',
],
],
'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();
}