You are here

function pmpapi_pull_entity_update in Public Media Platform API Integration 7

Implements hook_entity_update().

File

pmpapi_pull/pmpapi_pull.module, line 222
Allows admins to pull content from the PMP API, and turn PMP docs into (locally-stored, independent) drupal entities.

Code

function pmpapi_pull_entity_update($entity, $type) {
  if (!empty($entity->pmpapi_guid) && pmpapi_pull_doc_has_been_pulled($entity->pmpapi_guid)) {
    $update = db_update('pmpapi_pull_pulled_docs')
      ->condition('guid', $entity->pmpapi_guid);
    $fields = array(
      'changed' => REQUEST_TIME,
    );

    // Only update valid_from and valid_to if fields are defined on the entity
    if (!empty($entity->pmpapi_valid_from)) {
      $fields['valid_from'] = $entity->pmpapi_valid_from;
    }
    if (!empty($entity->pmpapi_valid_to)) {
      $fields['valid_to'] = $entity->pmpapi_valid_to;
    }
    $update
      ->fields($fields);
    $update
      ->execute();

    // Other modules might try to remove the doc from API on update (e.g., if
    // status set to 0). This property will prevent that.
    $entity->pmpapi_do_not_remove = TRUE;
  }
}