-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy_extra.core.inc
More file actions
151 lines (127 loc) · 4.36 KB
/
Copy pathdeploy_extra.core.inc
File metadata and controls
151 lines (127 loc) · 4.36 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
<?php
/**
* @file
* Describe core functions provided by the Deploy Extra module.
*/
/**
* The entry point for the import process.
*
* @param $entity_type
* @param $uuid
* @param $entity
* @param $config
* @return mixed
*/
function deploy_extra_import_entity($entity_type, $uuid, $entity, $config) {
// Settings preparation.
deploy_extra_import_settings_preparation($config);
// Add ability to change entity before executing save/update operation.
drupal_alter('deploy_extra_import_entity', $entity_type, $uuid, $entity, $config);
// Is the entity exists?
$id = entity_get_id_by_uuid($entity_type, array($uuid));
$config['entity_exists'] = !empty($id[$uuid]);
// Add default import callback.
$callbacks[] = DEPLOY_EXTRA_IMPORT_DEFAULT_CALLBACK;
// Get all callbacks for the import process.
foreach (module_implements('deploy_extra_import_callbacks') as $module) {
$function = $module . '_deploy_extra_import_callbacks';
// Modules can change the $config and add their own callback functions.
$function($callbacks, $config, $uuid, $entity_type, $entity);
}
$status = DEPLOY_EXTRA_IMPORT_STATUS_PROCESSED;
try {
$controller = entity_get_controller($entity_type);
if ($controller instanceof EntityAPIControllerInterface) {
$entity = $controller->create($entity);
}
else {
$entity = (object) $entity;
}
// Calling all modules import callbacks.
foreach ($callbacks as $callback) {
$status = $callback($entity_type, $entity, $uuid, $config);
}
} catch (Exception $exception) {
watchdog_exception('deploy_extra', $exception);
$status = DEPLOY_EXTRA_IMPORT_STATUS_FAILED;
}
// Allow modules to do something after the deploy process has been finished.
module_invoke_all('deploy_extra_import_complete', $entity_type, $entity, $uuid, $config, $status);
// Return error if deploy has been failed.
if ($status == DEPLOY_EXTRA_IMPORT_STATUS_FAILED) {
return services_error($status['error'], 406, $entity);
}
}
/**
* Implements hook_deploy_extra_import_callbacks().
*/
function deploy_extra_deploy_extra_import_callbacks(&$callbacks, &$config, $uuid, $entity_type) {
// If enabled mode to skip updates and entity already exists or enabled tmode.
if ($config['tmode'] || ($config['skip'] && !empty($config['entity_exists']))) {
// Remove default (save) callback for the test mode.
foreach ($callbacks as $id => $callback) {
if ($callback == DEPLOY_EXTRA_IMPORT_DEFAULT_CALLBACK) {
// Remove save callback.
unset($callbacks[$id]);
return ($config['skip']) ? DEPLOY_EXTRA_IMPORT_STATUS_SKIPPED : DEPLOY_EXTRA_IMPORT_STATUS_TEST_MODE;
}
}
}
}
/**
* Check, save, enable entity.
* @TODO add right description.
*
* @param $entity_type
* @param $entity
* @param $uuid
* @param $config
* @return mixed|object
*/
function deploy_extra_import_entity_save($entity_type, $entity, $uuid, $config) {
// Perform the save/update operation.
entity_uuid_save($entity_type, $entity);
$status = ($config['entity_exists']) ? DEPLOY_EXTRA_IMPORT_STATUS_UPDATED : DEPLOY_EXTRA_IMPORT_STATUS_SAVED;
return $status;
}
/**
* Helper function.
* Import settings array preparations.
*
* @param $config
*/
function deploy_extra_import_settings_preparation(&$config) {
$config['adv_log'] = !empty($config['adv_log']) ? TRUE : FALSE;
$config['deployment_key'] = !empty($config['deployment_key']) ? $config['deployment_key'] : FALSE;
$config['tmode'] = !empty($config['tmode']) ? TRUE : FALSE;
$config['skip'] = !empty($config['skip']) ? TRUE : FALSE;
}
/**
* Helper debug function.
* Save variables in to watchdog.
*
* @param $data
*/
function deploy_extra_debug($data, $func = '') {
$prefix = '';
if (!empty($func)) {
$prefix = 'Function:' . $func . '<br> ';
}
watchdog('deploy_extra:debug', $prefix . 'Debug vars: <pre>@info</pre>', array('@info' => print_r($data, 1)), WATCHDOG_DEBUG);
}
/*
* Helper function.
* Return vuuid from entity.
*/
function deploy_extra_get_vuuid_from_entity($entity, $entity_type) {
$info = entity_get_info($entity_type);
if (!empty($info['entity keys']['revision uuid'])) {
// Get the keys for revision UUID.
$vuuid_key = $info['entity keys']['revision uuid'];
// Fetch the local revision ID by its UUID.
if (isset($entity->{$vuuid_key})) {
return $entity->{$vuuid_key};
}
}
return FALSE;
}