0

I need a views display type that will not output content to the user.

Essentially, I've got a view that simply performs a query, and I get the results of the query with views_get_view_result() and then emails the results of the query to a user with a spreadsheet.

It's being run during cron, so I have to turn off access checks for access, or the query displays no results.

Though I could use an alternate access check that ensures the view is being run during cron. Any ideas, Drupalers?

1
  • If you call the view in code and the view does not have an associated page and the display is set to the master then I don't see much of a security concern. – J. Reynolds Sep 26 '14 at 5:48
0

Alright. So here's what I did. I installed Views Access Callback, then created a callback function that checks for the cron key.

The funny thing is, this disables the page URL access for me as user #1, even though I have "access all views" permission, and "Disable SQL rewriting" under Advanced -> Query Settings is turned on, which I would think bypassess access checks, but views_get_view_result() is getting results from the view even when my access function returns false. That's acceptable for me. I need to disable access via a URL.

Here's my implementation

/**
 * Implements hook_views_access_callbacks()
 */
function mycustommodule_rules_views_access_callbacks() {
  $callbacks['mycustommodule_rules_is_cron_view_access'] = t('Is function run from cron');
  return $callbacks;
}

function mycustommodule_rules_is_cron_view_access() {
  if (isset($_GET['cron_key']) && variable_get('cron_key', 'drupal') == $_GET['cron_key']) {
    return TRUE;
  }
  else {
    return FALSE;
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.