function pmpapi_pull_check_valid_dates in Public Media Platform API Integration 7
Determines if the validity of a pulled doc has changed, and changes the corresponding node accordingly.
3 calls to pmpapi_pull_check_valid_dates()
- PMPAPIPullWebTestCase::testPmpAPIEmbargoedThenValid in pmpapi_pull/
tests/ pmpapi_pull.test - Checks that node is published when it becomes valid.
- PMPAPIPullWebTestCase::testPmpAPIValidThenExpired in pmpapi_pull/
tests/ pmpapi_pull.test - Checks that node is unpublished when it becomes expired.
- pmpapi_pull_cron in pmpapi_pull/
pmpapi_pull.module - Implements hook_cron().
File
- pmpapi_pull/
pmpapi_pull.module, line 93 - Allows admins to pull content from the PMP API, and turn PMP docs into (locally-stored, independent) drupal entities.
Code
function pmpapi_pull_check_valid_dates() {
$docs = db_query('SELECT * FROM {pmpapi_pull_pulled_docs}');
$timestamp = time();
// more expensive, but more accurate than REQUEST_TIME
foreach ($docs as $doc) {
$now = pmpapi_convert_timestamp($timestamp);
$guid = $doc->guid;
$from = pmpapi_convert_timestamp(strtotime($doc->valid_from));
$to = pmpapi_convert_timestamp(strtotime($doc->valid_to));
$last_check_timestamp = variable_get('pmpapi_pull_last_validity_check');
$last_check = pmpapi_convert_timestamp($last_check_timestamp);
if ($now >= $from && $now <= $to && $last_check <= $from) {
$entity = pmpapi_get_entity_from_guid($guid);
$type = pmpapi_get_entity_type_from_guid($guid);
if ($entity && $type != 'file' && empty($entity->status)) {
$entity->status = 1;
entity_save($type, $entity);
}
}
elseif ($now > $to && $last_check <= $to) {
$entity = pmpapi_get_entity_from_guid($guid);
$type = pmpapi_get_entity_type_from_guid($guid);
if ($entity && $type != 'file' && !empty($entity->status)) {
$entity->status = 0;
entity_save($type, $entity);
}
}
}
variable_set('pmpapi_pull_last_validity_check', $timestamp);
}