Center-for-Digital-Narrative / elmcip

Electronic Literature as a Model of Creativity and Innovation in Practice (ELMCIP) is a collaborative research project funded by Humanities in the European Research Area (HERA) JRP for Creativity and Innovation built in Drupal
https://elmcip.net
4 stars 0 forks source link

Standardize date format to ISO #246

Closed steinmb closed 8 years ago

steinmb commented 8 years ago

In #234 did we check all date fields and two of the older fields was different then the rest. Would be a good idea that all our date field stored in the same format.

Suggested fix

Check and if not too much work. Change field type from datetime to date (ISO standard).

Scope

steinmb commented 8 years ago

Committed untested code 346ecdc Needs the helper module to pull this off. Does not change exiting data. They get changed on re-save.

steinmb commented 8 years ago

Clicked around on beta.elmcip.net and see no side effects to changing the field type. New event and re-saved/updated events get the new date format stored in the database. Still not clear if we have/should re-save the event to make sure they all get updated by magic. Wrote some code that do this:

    diff --git a/modules/elmcip_setup/elmcip_setup.install b/modules/elmcip_setup/elmcip_setup.install
    index 488b11c..4eb1b6c 100644
    --- a/modules/elmcip_setup/elmcip_setup.install
    +++ b/modules/elmcip_setup/elmcip_setup.install
    @@ -818,6 +818,34 @@ function elmcip_setup_update_7051() {
             $results[$name] = FieldChangeHelper::changeType($name, 'date');
           }
         }
    +
    +    /**
    +     * Update all event nodes to re-save new date format.
    +     */
    +    $query = new EntityFieldQuery();
    +    $query->entityCondition('entity_type', 'node')
    +      ->entityCondition('bundle', 'event');
    +
    +    $result = $query->execute();
    +    $event_items_nids = array_keys($result['node']);
    +
    +    foreach ($event_items_nids as $nid) {
    +      $dates = FALSE;
    +      print("Update event node ID: $nid" . PHP_EOL);
    +      $node = node_load($nid);
    +      $event = entity_metadata_wrapper('node', $node);
    +      $dates = $event->field_date->value();
    +      if ($dates) {
    +        $date = new DateTime($dates['value']);
    +        $date2 = new DateTime($dates['value2']);
    +        $event->field_date->set(array(
    +          'value' => $date->format('Y-m-d') . 'T' . $date->format('H:i:s'),
    +          'value2' => $date2->format('Y-m-d') . 'T' . $date2->format('H:i:s'),
    +        ));
    +        $event->save();
    +      }
    +    }
    +
         module_disable(array('helper'), FALSE);
         drupal_uninstall_modules(array('helper'), FALSE);
       }
steinmb commented 8 years ago

Talking to my self here. Decided after testing on beta to also update all event records containing date information to make sure consistent data. That will touch all the event last updated time in 424 event nodes.

committed to master

commit 6e3c7fa576619f0df7ca6730442f47ba4dcbffc6 Author: Stein Magne Bjorklund steinmb@smbjorklund.com Date: Tue Oct 18 00:21:09 2016 +0200

Issue 246 Update all event nodes.

commit a1bf127b78a1b32690b69f1e512c1a38b298e9e9 Author: Stein Magne Bjorklund steinmb@smbjorklund.com Date: Mon Oct 17 12:48:17 2016 +0200

Issue 246 Change from datefield to ISO standard type.
steinmb commented 8 years ago

Consider this OK. Pls. re-open if not.