On this page
Migrating Data From Core Date Fields
As of version 3.2, Smart Date includes a smart_date:migrate drush script to facilitate the process of moving date from core date fields into Smart Date fields.
The structure looks like:
drush smart_date:migrate workshop field_when field_core_daterange
In the above example, "workshop" is the content type, "field_when" is the destination Smart Date field, and "field_core_daterange" is where the data will be drawn from. If you had separate fields for the start and end you could just pass them in as two parameters.
Parameters
string $bundle: The content type or other bundle whose data will be used.
string $dest: The Smart Date field that will receive the data.
string $source_start: The core date field that will provide the start date and time. If no end date parameter is provided, this field will be checked for an end value. If that doesn't exist, the end will be calculated using a provided default_duration value (if it exists), or the end date will match the start.
string $source_end (optional): The core date field that will provide the end date and time. Provide NULL if you don't need a value here (for example, if migrating a core date range field) but want to specify an all day field.
string $source_all_day (optional): A field whose values will determine whether or not the value should be interpreted as all day. Note that the field's value should evaluate to empty ("" or 0 but not "0") in order to not be interpreted as all day.
Options
--clear: Remove any existing data in the destination field. Unless this option is specified, existing data will not be removed.
--entity=ENTITYID: The machine name of the entity type to use for the migration. Defaults to node.
--default_duration=MINUTES: A number of minutes (will be cast to an integer) to be used as the duration to calculate the end time if one isn't available.
--langcode=CODE: a language code that will be used for the database insert of the new data.
Running in a post-update hook
It may be useful to run this command in a post-update hook in order to automate the process.
In my_module.post_update.php:
use Drush\Drush;
...
/**
* Migrate from core date field to smart date field.
*/
function my_module_post_update_smart_date_migrate(&$sandbox)
{
return Drush::processManager()->drush(
Drush::service('site.alias.manager')->getSelf(),
'smart_date:migrate',
['workshop', 'field_when', 'field_core_daterange'])
->run();
}Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion