diff --git a/domain_entity.admin.inc b/domain_entity.admin.inc index 64e5e50..aef6fdb 100755 --- a/domain_entity.admin.inc +++ b/domain_entity.admin.inc @@ -32,12 +32,19 @@ function domain_entity_ui($form, &$form_state) { $form['header'] = array( '#markup' => t('Choose which entities are under Domain Access control, and choose domain entity widget behavior of bundles'), ); + $form['domain_entity_bypass_access_conditions_for_cron'] = array( + '#title' => t('Disable access rules during cron jobs.'), + '#type' => 'checkbox', + '#description' => t('Check this checkbox in order to make all your entities accessible on all domains for cron jobs.'), + '#default_value' => variable_get('domain_entity_bypass_access_conditions_for_cron', FALSE), + '#weight' => 3, + ); $form['domain_entity_bypass_access_conditions'] = array( '#title' => t('Disable access rules from this module. (You can use this settings to disable the query alter, for troubleshooting)'), '#type' => 'checkbox', '#description' => t('When this checkbox is checked, your entities must be accessible on all domains'), '#default_value' => variable_get('domain_entity_bypass_access_conditions', FALSE), - '#weight' => 3, + '#weight' => 4, ); $domain_entity_options = array( DOMAIN_ENTITY_BEHAVIOR_AUTO => t('Affiliate automatically created entity to a value (no widget on entity creation form, auto-assignation)'), @@ -199,6 +206,9 @@ function domain_entity_ui_submit($form, &$form_state) { // Save the disable access conditions value. variable_set('domain_entity_bypass_access_conditions', $values['domain_entity_bypass_access_conditions']); + // Save the disable access conditions for cron value. + variable_set('domain_entity_bypass_access_conditions_for_cron', $values['domain_entity_bypass_access_conditions_for_cron']); + // Do not allow domain access on entity that are actually bundle. $entities_info = entity_get_info(); foreach ($entities_info as $entity_type => $entity_info) { diff --git a/domain_entity.module b/domain_entity.module index e05b4c7..8c1a185 100755 --- a/domain_entity.module +++ b/domain_entity.module @@ -140,6 +140,18 @@ function domain_entity_query_alter(&$query) { return; } + // @see https://www.drupal.org/node/2664892 + // When the entity gets loaded during a cron-run, the active domain is + // considered to be the default one. This causes problems on some entities + // that need to be updated during the cron-run. For example, the + // commerce_license entities cannot get expired. + // @see https://www.drupal.org/project/commerce_license + // With the following workaround, the query alteration will be skipped + // during cron-runs. + if (php_sapi_name() == 'cli' && variable_get('domain_entity_bypass_access_conditions_for_cron', FALSE)) { + return; + } + // This is an enabled domain entity, // prepare our custom access conditions. // Get the accessible domain id's by the current user, in the current path.