-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpbs_media_manager_queue_unpublished.module
More file actions
69 lines (59 loc) · 2.49 KB
/
pbs_media_manager_queue_unpublished.module
File metadata and controls
69 lines (59 loc) · 2.49 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
<?php
/**
* Implements hook_help().
*
* Displays help and module information.
*
* @param path
* Which path of the site we're using to display help
* @param arg
* Array that holds the current path as returned from arg() function
*/
function pbs_media_manager_queue_unpublished_help($path, $arg) {
switch ($path) {
case "admin/help#pbs_media_manager_queue_unpublished":
return t("Registers a Drupal cron task that attempts to save video data from the Media Manager API for nodes saved with unpublished Media Manager assets");
break;
}
}
/**
* Implements hook_cron().
*
*/
function pbs_media_manager_queue_unpublished_cron() {
//get nodes that have valid MM video URLs/slugs but haven't received data from the MM API yet
$results = db_query("SELECT node.nid, field_data_field_pbs_mm_video.entity_id, field_data_field_pbs_mm_video.field_pbs_mm_video_asset_id, field_data_field_pbs_mm_video.field_pbs_mm_video_url
FROM node
INNER JOIN field_data_field_pbs_mm_video ON node.nid = field_data_field_pbs_mm_video.entity_id
WHERE field_data_field_pbs_mm_video.field_pbs_mm_video_asset_id IS NULL AND field_data_field_pbs_mm_video.field_pbs_mm_video_url != 'https://www.pbs.org/video/'");
foreach ($results as $record) {
$should_save_node = TRUE;
//prepare data that pbs_media_manager_player_field_presave expects
$entity = node_load($record->nid);
$items = array(
array(
'url' => $record->field_pbs_mm_video_url,
'original_url' => $record->field_pbs_mm_video_url
)
);
//clear Drupal messages since we'll be checking for new errors
drupal_get_messages('warning', TRUE);
//manually call PBS Media Manager Field presave hook to poll the MM API
pbs_media_manager_player_field_presave('node', $entity, null, array('label' => 'PBS Media Manager API Video'), 'und', $items);
$messages = drupal_get_messages('warning');
foreach ($messages as $message) {
foreach($message as $value) {
if (preg_match("/.+PBS Media Manager API Video.+$entity->title/", $value)) {
//PBS Media Manager Field set an API error, so skip saving this node
$should_save_node = FALSE;
}
}
};
if ($should_save_node) {
watchdog('PBS Media Manager Queue Unpublished', "Saving data from Media Manager API on node ID $record->nid");
node_save($entity);
return;
}
watchdog('PBS Media Manager Queue Unpublished', "The Media Manager API returned no data for node ID $record->nid");
}
}