I had the following functionality programmed. I will provide a patch in the next comment. I hope this can get into the main release, since I'm sure others would love this functionality.

Basically, for an event type system, I needed to create a form of a Holiday date on a node, that would auto repeat forever into the future.

However, choosing "Stop repeating - After: 99999 occurrences" wasn't optimal because it creates all the dates at once, and due to performance implications doesn't work when multiple users are doing this same action at the same time. So instead, the following patch provides a new option "Never" with a "PHP strtotime formatted" field.

If I were to add "1 month" into the field, after hitting save, it would add 1 month of occurrences. Every additional site cron run will pull the offset and keep the "1 month" value always current. So if a week has passed, it will pull any occurrences for that passed week that would be valid within that "1 month".

When testing out the patch, be sure to turn on Date caching.

Also, please note, that I am not very PHP savvy, which is why I had this programmed, so I would love any alterations to the patch.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

NWOM’s picture

Status: Active » Needs review
FileSize
14.49 KB

Here is the patch based on the current dev shown on the project page (7.x-2.6+2-dev).

Status: Needs review » Needs work

The last submitted patch, date.stop_repeating_never.patch, failed testing.

Anonymous’s picture

Issue summary: View changes

Spelling and typos corrected.

shortspoken’s picture

Any news? Has anyone tested the patch?

cameron prince’s picture

Here's a re-roll of the patch against the current version of date, but sadly it doesn't work. There are no errors, but when you create a date and then come back and edit it, the values that were entered don't appear to have been saved.

For now I'm going to just go with a high repeat count.

Road Kill’s picture

I am also looking for a feature like this it would be awesome if it makes into the next release.

vtcore’s picture

Priority: Normal » Major
Status: Needs work » Needs review
FileSize
12.57 KB

Here is an updated patch. It's not tested thoroughly, but it seems to work.

laurelstreng’s picture

Applied the updated patch, and the 'Never' option appears, but I don't think it's working any more? Using the calendar module as well the node only appears once in the calendar even though it's been set to repeat & never stop repeating.

Using the latest Drupal 7.50

DamienMcKenna’s picture

Status: Needs review » Needs work

This needs minor improvements to adhere to the Drupal coding standards, specifically whitespace around brackets, comments before new functions, etc.

jmuzz’s picture

Cleaned it up, tweaked the help text, and added a default value that should have it working for most use cases.

Status: Needs review » Needs work

The last submitted patch, 9: date-stop_repeating_never-2076639-9.patch, failed testing.

DamienMcKenna’s picture

Status: Needs work » Needs review
FileSize
12.52 KB

@jmuzz: When you create patches please make sure they are created correctly otherwise the testbot can't test them.

Here's #9 fixed up so it should apply cleanly.

Status: Needs review » Needs work

The last submitted patch, 11: date-n2076639-11.patch, failed testing.

jmuzz’s picture

Status: Needs work » Needs review
FileSize
12.91 KB
572 bytes

My bad.

Not sure this will fix the test failure but it does fix my migration problem.

Status: Needs review » Needs work

The last submitted patch, 13: date-stop_repeating_never-2076639-13.patch, failed testing.

dsouza_rohan’s picture

dsouza_rohan’s picture

Status: Needs work » Needs review
dsouza_rohan’s picture

Adding credit comments

Aracon’s picture

Will this patch be added to the module? The function is really helpful for endless repeating events.

NWOM’s picture

@Aracon: The status is "Needs Review".

If you have tested #15, and it applies cleanly to "7.x-2.x-dev" HEAD of the module, you can mark it as "Reviewed by the Community". Only then will it have a chance of being committed.

aitala’s picture

Installed and tested. It seems to do the job.

Chris Matthews’s picture

The patch in #15 works great for me. Would be awesome to get this in 7.x-2.11.

DamienMcKenna’s picture

Status: Needs review » Needs work

This needs a bit of work.

  • date_repeat_cron() should use the field API instead of a query.
  • Instead of using array_key_exists() just use isset().
  • Please don't hardcode 'und' anywhere, either use the constant LANGUAGE_NONE or actually use the entity's language.
  • I really don't like the queries in date_repeat_process_repeat_date_entity_never_field(), they seem really brittle and there might be problems with entity.
  • There are lots of small coding standards problems with the code.

It'd also be nice to have tests to confirm the functionality works as intended.

pyrello’s picture

@DamienMcKenna - As far as I can tell, the usage of array_key_exists in the patch in #15 is consistent with similar lines of code. While I agree with you that isset is the better option for checking whether the key exists, wouldn't it make sense to package code cleanup unrelated to this issue as a separate patch?

DamienMcKenna’s picture

The major issue with #15 is that the queries need work.

DamienMcKenna’s picture

Issue tags: +Needs tests

I also think it'd be useful to add at least *some* test coverage, to make sure this doesn't break again.

Neo13’s picture

Hi guys,

The proposed cron solution didn't work for me at all. So I removed it and also all the helper functions. Other parts work good (e.g. field widget, etc.).

I ended up doing a custom cron function:

function date_repeat_cron() {
  module_load_include('inc', 'date_api', 'date_api_ical');
  $node_array = array();

  $query = db_query("SELECT field_config_instance.field_name, field_config_instance.entity_type, field_config_instance.bundle, field_config.type, field_config.data from {field_config_instance} field_config_instance left join {field_config} field_config on field_config.field_name=field_config_instance.field_name where field_config.module='date' and field_config.type in ('datetime', 'date', 'datestamp')");
  foreach ($query as $row) {
    $data = unserialize($row->data);
    if (isset($data['settings']['repeat']) && $data['settings']['repeat'] == 1 && $row->entity_type == 'node') {
      $node_array[$row->field_name] = node_load_multiple(array(), array('type' => $row->bundle));
    }
  }

  if (!empty($node_array)) {
    foreach ($node_array as $field_name => $nodes) {
      $field = field_info_field($field_name);
      foreach ($nodes as $node) {

        if (isset($node->{$field_name}[LANGUAGE_NONE][0]['rrule'])) {
          $rruletext = $node->{$field_name}[LANGUAGE_NONE][0]['rrule'];
          $parts = explode("\n", $rruletext);
          if (count($parts)) {
            $rruletext = $parts[0];
          }

          // Get the parsed array of rule values.
          $rrule = date_ical_parse_rrule('RRULE:', $rruletext);

          if (isset($rrule['NEVER']) && $rrule['NEVER'] && strtotime($rrule['NEVER'])) {
            $node->{$field_name}[LANGUAGE_NONE] = date_repeat_build_dates($rruletext, $rrule, $field, $node->{$field_name}[LANGUAGE_NONE][0]);
            node_save($node);
          }
        }
      }
    }
  }
}

It works for me. There is only one ugly select left and that's easy to correct. Downsides are that this updates nodes on each cron run which could have high performance consequences especially with higher node count. Also node changed timestamp is updated every time.

On my site I am using Elysia cron to run this only once daily and my node count is in low double digits so that's not an issue for me.