-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathargo.install
82 lines (74 loc) · 1.69 KB
/
argo.install
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
<?php
/**
* @file
* Installs Argo module.
*/
use Drupal\user\Entity\Role;
use Drupal\user\Entity\User;
/**
* Implements hook_schema().
*/
function argo_schema() {
$schema = [];
$schema['argo_entity_deletion'] = [
'description' => 'Argo Entity deletion log.',
'fields' => [
'uuid' => [
'description' => 'Deleted entity uuid',
'type' => 'varchar',
'length' => 36,
'not null' => TRUE,
],
'entityType' => [
'description' => 'Deleted entity type',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
],
'bundle' => [
'description' => 'Deleted entity bundle',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
],
],
'primary key' => ['uuid'],
];
return $schema;
}
/**
* Add Argo service account, permission, and role.
*/
function argo_update_8001() {
// Create Argo role.
$roleId = 'argo_service';
$role = Role::load($roleId);
if ($role === NULL) {
$role = Role::create([
'id' => $roleId,
'label' => 'Argo service',
]);
}
// Grant permission to role.
$permission = 'translate content using argo';
if (!$role->hasPermission($permission)) {
$role->grantPermission($permission);
}
$role->save();
// Create Argo user.
$userName = 'argo.service';
$user = user_load_by_name($userName);
if ($user === FALSE) {
/** @var \Drupal\user\Entity\User $user */
$user = User::create([
'name' => $userName,
'mail' => 'support@spartansoftwareinc.com',
'status' => 1,
]);
}
// Add Argo role to user.
if (!$user->hasRole($roleId)) {
$user->addRole($roleId);
}
$user->save();
}