1

I have a Rules Component that I want to run every week, using cron.

The component's elements:

  • set a variable (emailbodytext)
  • viewsloop 1 to fill the emailbodytext with titles of all recent nodes
  • viewsloop 2 to send emails to selected users

When I (as admin) execute the component, it works fine: all selected users receive a mail with the recent node-titles. When I execute thru cron (after planning it) viewsloop 1 always gives zero results, which results in sending empty mails to all selected users in viewsloop 2.

Question:

Why does one view seem to give results and the other does not? Both views have the same access setting (role: adm) in the "Rules setting"-part.

I add the view from viewsloop 1 here:

$view = new view();
$view->name = 'nieuwigheden';
$view->description = 'nieuwe items van de laatste x dagen: blokken om in overzicht op te nemen';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Nieuwigheden';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Nieuwigheden';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['use_more_text'] = 'meer';
$handler->display->display_options['access']['type'] = 'role';
$handler->display->display_options['access']['role'] = array(
  2 => '2',
);
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['exposed_form']['options']['submit_button'] = 'Toepassen';
$handler->display->display_options['exposed_form']['options']['reset_button_label'] = 'Opnieuw instellen';
$handler->display->display_options['exposed_form']['options']['exposed_sorts_label'] = 'Sorteer op';
$handler->display->display_options['exposed_form']['options']['sort_asc_label'] = 'Oplopend';
$handler->display->display_options['exposed_form']['options']['sort_desc_label'] = 'Aflopend';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['pager']['options']['expose']['items_per_page_label'] = 'Items per pagina';
$handler->display->display_options['pager']['options']['expose']['items_per_page_options_all_label'] = '- Alle -';
$handler->display->display_options['pager']['options']['tags']['first'] = '« eerste';
$handler->display->display_options['pager']['options']['tags']['previous'] = '‹ vorige';
$handler->display->display_options['pager']['options']['tags']['next'] = 'volgende ›';
$handler->display->display_options['pager']['options']['tags']['last'] = 'laatste »';
$handler->display->display_options['style_plugin'] = 'table';
/* Relatie: Inhoud: Auteur */
$handler->display->display_options['relationships']['uid']['id'] = 'uid';
$handler->display->display_options['relationships']['uid']['table'] = 'node';
$handler->display->display_options['relationships']['uid']['field'] = 'uid';
$handler->display->display_options['relationships']['uid']['required'] = TRUE;
/* Veld: Gebruiker: Naam */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'users';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['relationship'] = 'uid';
/* Veld: Inhoud: Titel */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
/* Veld: Inhoud: Body */
$handler->display->display_options['fields']['body']['id'] = 'body';
$handler->display->display_options['fields']['body']['table'] = 'field_data_body';
$handler->display->display_options['fields']['body']['field'] = 'body';
$handler->display->display_options['fields']['body']['label'] = 'Berichttekst';
/* Veld: Inhoud: Datum van inzending */
$handler->display->display_options['fields']['created']['id'] = 'created';
$handler->display->display_options['fields']['created']['table'] = 'node';
$handler->display->display_options['fields']['created']['field'] = 'created';
$handler->display->display_options['fields']['created']['label'] = 'Datum';
$handler->display->display_options['fields']['created']['date_format'] = 'datum_zndr_tijd';
$handler->display->display_options['fields']['created']['second_date_format'] = 'long';
/* Veld: Gebruiker: E-mailadres */
$handler->display->display_options['fields']['mail']['id'] = 'mail';
$handler->display->display_options['fields']['mail']['table'] = 'users';
$handler->display->display_options['fields']['mail']['field'] = 'mail';
$handler->display->display_options['fields']['mail']['relationship'] = 'uid';
/* Sorteercriterium: Inhoud: Datum van inzending */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Filtercriterium: Inhoud: Gepubliceerd */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filtercriterium: Inhoud: Datum van inzending */
$handler->display->display_options['filters']['created']['id'] = 'created';
$handler->display->display_options['filters']['created']['table'] = 'node';
$handler->display->display_options['filters']['created']['field'] = 'created';
$handler->display->display_options['filters']['created']['operator'] = '>=';
$handler->display->display_options['filters']['created']['value']['value'] = '2017-09-01';
$handler->display->display_options['filters']['created']['group'] = 1;

/* Display: Rules VAB last 7 days */
$handler = $view->new_display('views_rules', 'Rules VAB last 7 days', 'views_rules_1');
$handler->display->display_options['defaults']['access'] = FALSE;
$handler->display->display_options['access']['type'] = 'role';
$handler->display->display_options['access']['role'] = array(
  1 => '1',
);
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['pager']['options']['items_per_page'] = '50';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['defaults']['fields'] = FALSE;
/* Veld: Inhoud: Nid */
$handler->display->display_options['fields']['nid']['id'] = 'nid';
$handler->display->display_options['fields']['nid']['table'] = 'node';
$handler->display->display_options['fields']['nid']['field'] = 'nid';
/* Veld: Inhoud: V/A/B */
$handler->display->display_options['fields']['field_v_a_b']['id'] = 'field_v_a_b';
$handler->display->display_options['fields']['field_v_a_b']['table'] = 'field_data_field_v_a_b';
$handler->display->display_options['fields']['field_v_a_b']['field'] = 'field_v_a_b';
$handler->display->display_options['fields']['field_v_a_b']['type'] = 'taxonomy_term_reference_plain';
/* Veld: Inhoud: Titel */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
/* Veld: Inhoud: Body */
$handler->display->display_options['fields']['body']['id'] = 'body';
$handler->display->display_options['fields']['body']['table'] = 'field_data_body';
$handler->display->display_options['fields']['body']['field'] = 'body';
$handler->display->display_options['fields']['body']['label'] = 'Berichttekst';
/* Veld: Inhoud: Datum van inzending */
$handler->display->display_options['fields']['created']['id'] = 'created';
$handler->display->display_options['fields']['created']['table'] = 'node';
$handler->display->display_options['fields']['created']['field'] = 'created';
$handler->display->display_options['fields']['created']['label'] = 'Datum';
$handler->display->display_options['fields']['created']['date_format'] = 'datum_zndr_tijd';
$handler->display->display_options['fields']['created']['second_date_format'] = 'long';
/* Veld: Gebruiker: Naam */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'users';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['relationship'] = 'uid';
/* Veld: Gebruiker: E-mailadres */
$handler->display->display_options['fields']['mail']['id'] = 'mail';
$handler->display->display_options['fields']['mail']['table'] = 'users';
$handler->display->display_options['fields']['mail']['field'] = 'mail';
$handler->display->display_options['fields']['mail']['relationship'] = 'uid';
/* Veld: Gebruiker: Gemeente */
$handler->display->display_options['fields']['field_p_gemeente']['id'] = 'field_p_gemeente';
$handler->display->display_options['fields']['field_p_gemeente']['table'] = 'field_data_field_p_gemeente';
$handler->display->display_options['fields']['field_p_gemeente']['field'] = 'field_p_gemeente';
$handler->display->display_options['fields']['field_p_gemeente']['relationship'] = 'uid';
$handler->display->display_options['fields']['field_p_gemeente']['type'] = 'text_plain';
$handler->display->display_options['defaults']['filter_groups'] = FALSE;
$handler->display->display_options['defaults']['filters'] = FALSE;
/* Filtercriterium: Inhoud: Gepubliceerd */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filtercriterium: Inhoud: Datum van inzending */
$handler->display->display_options['filters']['created']['id'] = 'created';
$handler->display->display_options['filters']['created']['table'] = 'node';
$handler->display->display_options['filters']['created']['field'] = 'created';
$handler->display->display_options['filters']['created']['operator'] = '>=';
$handler->display->display_options['filters']['created']['value']['value'] = '-8 days';
$handler->display->display_options['filters']['created']['value']['type'] = 'offset';
$handler->display->display_options['filters']['created']['group'] = 1;
/* Filtercriterium: Inhoud: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
  'vraag_of_aanbod' => 'vraag_of_aanbod',
);
$handler->display->display_options['rules_variables'] = array(
  'nid' => array(
    'enabled' => 1,
    'rendered' => 0,
    'type' => 'integer',
    'label' => 'Nid',
    'name' => 'nid',
  ),
  'field_v_a_b' => array(
    'enabled' => 1,
    'rendered' => 1,
    'type' => 'text',
    'label' => 'V/A/B',
    'name' => 'field_v_a_b',
  ),
  'title' => array(
    'enabled' => 1,
    'rendered' => 0,
    'type' => 'text',
    'label' => 'Titel',
    'name' => 'title',
  ),
  'body' => array(
    'enabled' => 1,
    'rendered' => 1,
    'type' => 'text',
    'label' => 'Berichttekst',
    'name' => 'body',
  ),
  'created' => array(
    'enabled' => 1,
    'rendered' => 0,
    'type' => 'date',
    'label' => 'Datum',
    'name' => 'created',
  ),
  'name' => array(
    'enabled' => 1,
    'rendered' => 0,
    'type' => 'text',
    'label' => '(auteur) Naam',
    'name' => 'name',
  ),
  'mail' => array(
    'enabled' => 1,
    'rendered' => 0,
    'type' => 'text',
    'label' => '(auteur) E-mailadres',
    'name' => 'mail',
  ),
  'field_p_gemeente' => array(
    'enabled' => 1,
    'rendered' => 1,
    'type' => 'text',
    'label' => '(auteur) Gemeente',
    'name' => 'field_p_gemeente',
  ),
);
$translatables['nieuwigheden'] = array(
  t('Master'),
  t('Nieuwigheden'),
  t('meer'),
  t('Toepassen'),
  t('Opnieuw instellen'),
  t('Sorteer op'),
  t('Oplopend'),
  t('Aflopend'),
  t('Items per pagina'),
  t('- Alle -'),
  t('Offset'),
  t('« eerste'),
  t('‹ vorige'),
  t('volgende ›'),
  t('laatste »'),
  t('auteur'),
  t('Naam'),
  t('Titel'),
  t('Berichttekst'),
  t('Datum'),
  t('E-mailadres'),
  t('Rules VAB last 7 days'),
  t('Nid'),
  t('V/A/B'),
  t('Gemeente'),
);

And the rules itself: a duplicate where I replaced viewsloop2 with only 1 emailaddress:

{ "rules_weekoverzicht_per_mail_gedupliceerd_" : {
    "LABEL" : "Weekoverzicht per mail (gedupliceerd)",
    "PLUGIN" : "action set",
    "OWNER" : "rules",
    "TAGS" : [ "mail" ],
    "REQUIRES" : [ "rules" ],
    "ACTION SET" : [
      { "variable_add" : {
          "USING" : {
            "type" : "text",
            "value" : "\u003Ch2\u003E[site:name] weekoverzicht op [site:current-date]\u003C\/h2\u003E\r\n"
          },
          "PROVIDE" : { "variable_added" : { "variable_samengesteld" : "Samengestelde inhoud" } }
        }
      },
      { "drupal_message" : { "message" : "[mail-from-view:value]" } },
      { "data_set" : {
          "data" : [ "variable-samengesteld" ],
          "value" : "\u003Cp\u003EDag\u003C\/p\u003E\r\n\u003Cp\u003ETer herinnering: Om de \u0022mail alle leden - nieuwe stijl\u0022 te ontvangen moet je in \u0022Mijn account: Adres etc bewerken\u0022 aanduiden tot welke interessegroep je behoort. Pas daarna ontvang je direct een email wanneer een nieuwe V\/A gepost wordt in jouw interesse. \u003C\/p\u003E\r\n\u003Cp\u003EHet volautomatische weekoverzicht woensdagnacht was niet echt een succes. Volgende keer beter.\r\n\u003C\/p\u003E\r\n\r\n[variable-samengesteld:value]"
        }
      },
      { "mail" : {
          "to" : "ingrid@letsleie.be",
          "subject" : "[[site:name]] Weekoverzicht test",
          "message" : [ "variable-samengesteld" ],
          "language" : [ "" ]
        }
      },
      { "VIEW LOOP" : {
          "VIEW" : "nieuwigheden",
          "DISPLAY" : "views_rules_1",
          "ROW VARIABLES" : {
            "nid" : { "fiche_nid" : "Nid van VAB fiche" },
            "field_v_a_b" : { "fiche_field_v_a_b" : "V\/A\/B uit view" },
            "title" : { "fiche_title" : "Titel uit view" },
            "body" : { "fiche_body" : "Body uit view" },
            "created" : { "fiche_created" : "Datum creatie" },
            "name" : { "fiche_van_name" : "(auteur) Naam" },
            "mail" : { "fiche_van_mail" : "(auteur) E-mailadres" },
            "field_p_gemeente" : { "fiche_field_p_gemeente" : "(auteur) Gemeente" }
          },
          "DO" : [
            { "data_set" : {
                "data" : [ "variable-samengesteld" ],
                "value" : "[variable-samengesteld:value]\r\n\u003Chr\u003E\r\n\u003Ch3\u003E\u003Ca href=\u0022[site:url]\/node\/[fiche-nid:value]\u0022\u003E [fiche-title:value]\u003C\/a\u003E\u003C\/h3\u003E\r\n\u003Cp\u003E\u003Cstrong\u003E[fiche-field-v-a-b:value] van [fiche-van-name:value] ([fiche-field-p-gemeente:value]) dd. [fiche-created:value]\u003C\/strong\u003E\u003C\/p\u003E\r\n\u003Cp\u003E[fiche-body:value]\u003C\/p\u003E\r\n\u003Cp\u003E Antwoorden via \u003Ca href=\u0022mailto:[fiche-van-mail:value]\u0022\u003E[fiche-van-mail:value]\u003C\/a\u003E\u003C\/p\u003E\r\n\r\n"
              }
            }
          ]
        }
      },
      { "data_set" : {
          "data" : [ "variable-samengesteld" ],
          "value" : "[variable-samengesteld:value]\r\n\u003Chr\u003E\r\n\u003Cp\u003EDe Letsleie Robot\u003C\/p\u003E\r\n\u003Cp\u003EJe krijgt deze mail omdat je lid bent van Letsleie. Via \u0022Mijn account: Adres etc. bewerken\u0022 kun je aanduiden of je wel of niet een wekelijks overzicht per email wenst.\u003C\/p\u003E "
        }
      },
      { "drupal_message" : { "message" : "[variable-samengesteld:value]" } },
      { "mail" : {
          "to" : "me@mysite.be",
          "subject" : "weekoverzicht test",
          "message" : [ "variable-samengesteld" ],
          "language" : [ "" ]
        }
      }
    ]
  }
}

When executed from UI I receive a mail with the introduction text and the node-info. When exectuded thru cron the mail only has the introduction text.

1

Quote from Configuring cron jobs using the cron command:

... Note that as of Drupal 7, cron always runs as an anonymous user ...

So if your views have "access settings to limit them to role adm" (as in your question), then that explains why via cron you don't get any results (assuming your question is about D7 or above).

  • yes, it is drupal 7. But how can this explain be that loop2 does give results and loop1 does not? i have carefully set access in both views equal. if I would make the rules-view accessible to anonymous, will this lead to security risk of unauthorised users executing the view and seeing the emailadresses or other info? – sigridt Nov 5 '17 at 16:45
  • I have set access in Rules view to "anonymous user". But still cron gives empty mail. – sigridt Nov 5 '17 at 17:10
  • @sigridt Please edit your question to include an export of your Rule. Depending on how it looks like, that might be sufficient to pinpoint your issue. If it isn't, then you might have to also include an export of both of your Views. Without such extra info, I'd only be guessing about various possibilities. PS about your 2nd comment: if you access the view as anonymous, do you get any view results (in this scenario there is no rule involved, a matter of step by step debugging)? – Pierre.Vriens Nov 5 '17 at 17:11
  • I am not sure what you mean with "if you access the view as anonymous"? The preview gives a result, but I am not anonymous. Also, when executed from the UI, it is not anonymous. idea: I have drupal.org/project/content_access running on this site, saying this content type is for authenticated users only. Could this be the reason? maybe I should enable "Content Access Rules Integrations" ? – sigridt Nov 5 '17 at 18:12
  • @sigridt dank je wel for the update (zullen we naar NL switchen???). About access view as anonymous: can you (temporary) create an extra PAGE display that produces the same set of rows as your views_rules display, and give that some path. Save it, and then try to browse that path without being logged in. This way there is "no" rules involved (just temporary, to do debugging). Also, that content access "might" be a related issue (though I'm not sure about that). Can you try to temporary allow access to 1 node (or create a new one) and re-test if that node then would show up for anonymous. – Pierre.Vriens Nov 5 '17 at 18:43
0

conclusion: content_access-permissions show different behaviour than core permissions

viewsloop 1: content of a content type that has a setting “not to be displayed to anonymous” by module content_access (because core permission “display published content” is not on a per content type basis).

Apparently the view evaluates this as an extra filter on the content: “may the user running the view see this node” . Anonymous cron executing the view receives no protected content.

Viewsloop 2: users, where user profiles are set “not to be displayed to anonymous”, by core role permissions (no content_access involved here)

Apparently when the view is executed the view does not evaluate this permission, so anonymous cron receives all the email addresses needed.

I see no effect of the access setting $handler->display->display_options['access']['type'] = 'role'; in the view when the view is called by a viewsloop-action in a Rules Component.

Solution found!

I solved my problem following the suggestions in the answer to a similar question: switch to and back to a specific user with just enough permissions to see what I want to have in the view.

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.