-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmedia_telvue_connect_importer.module
142 lines (132 loc) · 4.97 KB
/
media_telvue_connect_importer.module
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
<?php
// Constants
define('MTCI_CONNECT_MRSS', variable_get('media_telvue_connect_importer_connect_mrss', FALSE));
define('MTCI_SYNC_MODE', variable_get('media_telvue_connect_importer_sync_mode', FALSE));
define('MTCI_CREATE_SERIES', variable_get('media_telvue_connect_importer_create_series', FALSE));
/**
* Implements hook_permission
*/
function media_telvue_connect_importer_permission() {
return array(
'administer media telvue connect importer' => array(
'title' => t('Media Telvue Connect Importer'),
'description' => t('Provides access to change Media Telvue Connect Importer Settings')
));
}
/**
* Implements hook_menu().
*/
function media_telvue_connect_importer_menu() {
$items = array();
$items['admin/config/media-telvue-connect-importer'] = array(
'title' => 'Media Telvue Connect Importer',
'description' => 'Configure Media Telvue Connect Importer',
'page callback' => 'drupal_get_form',
'page arguments' => array('media_telvue_connect_importer_settings_form'),
'access arguments' => array('administer media telvue connect importer'),
'file' => 'media_telvue_connect_importer.admin.inc',
);
return $items;
}
/**
* Implements hook_cron().
*/
function media_telvue_connect_importer_cron() {
// @todo this seems wrong, but works?
media_telvue_connect_importer_import();
}
/**
* Callback function for cron task.
*/
function media_telvue_connect_importer_import() {
// Load helpers
module_load_include('inc', 'media_telvue_connect_importer', 'media_telvue_connect_importer.helpers');
// Get parsed xml data
$data = media_telvue_connect_importer_parse_xml_source();
if (MTCI_SYNC_MODE == 'basic') {
foreach ($data as $item) {
// Check if show already exists
if (!$show_exists = media_telvue_connect_importer_show_exists($item['link'])) {
// Show doesn't exist, so create new show
if ($show = media_telvue_connect_importer_create_show($item)) {
// Log success to watchdog.
watchdog(
$type = 'media_telvue_connect_importer',
$message = 'Success! Created show for Telvue Connect GUID: %guid',
$variables = array('%guid' => $item['link']),
$severity = WATCHDOG_INFO
);
}
// Something went wrong, so log it.
else {
// Log failure to watchdog.
watchdog(
$type = 'media_telvue_connect_importer',
$message = 'Failure! Could not create show for Telvue Connect GUID: %guid',
$variables = array('%guid' => $item['link']),
$severity = WATCHDOG_ALERT
);
}
}
// Duplicate
else {
// Log duplicate to watchdog.
watchdog(
$type = 'media_telvue_connect_importer',
$message = 'Duplicate! Show already exists, skipping import for Telvue Connect GUID: %guid',
$variables = array('%guid' => $item['link']),
$severity = WATCHDOG_ALERT
);
}
}
}
else if (MTCI_SYNC_MODE == 'advanced') {
foreach ($data as $item) {
// Find matching show via field_expected_filename == [$item->{'title'}]
if ($show_nid = media_telvue_connect_importer_advanced_show_exists($item['field_expected_filename'])) {
// Load the show node
$show_node = node_load($show_nid);
// Check for field_show_vod
if (!isset($show_node->field_show_vod[LANGUAGE_NONE])) {
// Update show, populate field_show_vod only.
if ($show = media_telvue_connect_importer_update_show($show_node, $item)) {
// Log success to watchdog.
watchdog(
$type = 'media_telvue_connect_importer_advanced',
$message = 'Success! Updated show for Telvue Connect GUID: %guid',
$variables = array('%guid' => $item['link']),
$severity = WATCHDOG_INFO
);
}
else {
// Log failure to watchdog.
watchdog(
$type = 'media_telvue_connect_importer_advanced',
$message = 'Failure! Could not update show for Telvue Connect GUID: %guid',
$variables = array('%guid' => $item['link']),
$severity = WATCHDOG_ALERT
);
}
}
else {
// Log that show matches, but already has a field_show_vod value.
watchdog(
$type = 'media_telvue_connect_importer_advanced',
$message = 'Failure! Show already has a field_show_vod value for Telvue Connect GUID: %guid',
$variables = array('%guid' => $item['link']),
$severity = WATCHDOG_INFO
);
}
}
// Log that no matching show could be found.
else {
watchdog(
$type = 'media_telvue_connect_importer_advanced',
$message = 'No matching expected file name! Skipping show update for Telvue Connect GUID: %guid',
$variables = array('%guid' => $item['link']),
$severity = WATCHDOG_INFO
);
}
}
}
}