I have 2 core date fields. The date fields names are `start_date` and `end_date`. I was wondering if it's possible to import both fields into smart_date so the smart_date field will have both start and end times?

Thanks!

Comments

Sseto created an issue. See original summary.

mandclu’s picture

Category: Feature request » Support request

There is a drush command available designed with this use case in mind. You can find documentation for this drush command in the user guide.

That said, based on the discussion in #3262983: drush smart_date:migrate / The "" entity type does not exist. it seems as though there may be a fix needed for more recent versions of drush and/or PHP.

sseto’s picture

Amazing documentation!

Are you able to provide me an example of how I can use $source_end with my fields?

Will it be like this: `drush smart_date:migrate exhibition field_start_date field_end_date field_smart_date --langcode=und --clear`?

Thank you!

mandclu’s picture

The order of the arguments is a little bit wonky, because I left the (optional) source fields for the end, after the destination. So, assuming field_start_date and field_end_date are where you're migrating from, and field_smart_date is the destination, with a bundle of exhibition your command should look something like:

drush smart_date:migrate exhibition field_smart_date field_start_date field_end_date --langcode=und --clear

sseto’s picture

StatusFileSize
new41.92 KB

I installed the patch you created in #3262983. and used the example you gave me. The drush script ran with no issues, but it looks like my smart_date field didn't get imported.

Here's what the log shows when I used -vvv

drush smart_date:migrate exhibition field_date field_start_date field_end_date --langcode=und --clear -vvv
[preflight] Redispatch to site-local Drush: C:\wamp64\www\setomuseum/vendor/drush/drush/drush.
[preflight] Config paths: C:/wamp64/www/setomuseum/vendor/drush/drush/drush.yml,C:/wamp64/www/setomuseum/drush/drush.yml
[preflight] Alias paths: C:/wamp64/www/setomuseum/web/drush/sites,C:/wamp64/www/setomuseum/drush/sites,C:/wamp64/www/setomuseum/drush/sites
[preflight] Commandfile search paths: C:\wamp64\www\setomuseum\vendor\drush\drush\src,C:\wamp64\www\setomuseum/drush
[debug] Bootstrap further to find smart_date:migrate [0.37 sec, 8.71 MB]
[debug] Trying to bootstrap as far as we can [0.37 sec, 8.71 MB]
[debug] Drush bootstrap phase: bootstrapDrupalRoot() [0.37 sec, 8.71 MB]
[debug] Change working directory to C:\wamp64\www\setomuseum/web [0.37 sec, 8.71 MB]
[debug] Initialized Drupal 9.3.6 root directory at C:\wamp64\www\setomuseum/web [0.37 sec, 8.71 MB]
[debug] Drush bootstrap phase: bootstrapDrupalSite() [0.37 sec, 8.73 MB]
[debug] Initialized Drupal site default at sites/default [0.39 sec, 8.96 MB]
[debug] Drush bootstrap phase: bootstrapDrupalConfiguration() [0.39 sec, 8.96 MB]
[debug] Add service modifier [0.4 sec, 9.14 MB]
[debug] Drush bootstrap phase: bootstrapDrupalDatabase() [0.44 sec, 9.65 MB]
[debug] Successfully connected to the Drupal database. [0.44 sec, 9.65 MB]
[debug] Drush bootstrap phase: bootstrapDrupalFull() [0.44 sec, 9.65 MB]
[debug] Start bootstrap of the Drupal Kernel. [0.44 sec, 9.65 MB]
[debug] Finished bootstrap of the Drupal Kernel. [0.66 sec, 16.54 MB]
[debug] Add a command: twig-tweak:validate [0.91 sec, 21.68 MB]
[debug] Add a command: twig-tweak:debug [0.91 sec, 21.68 MB]
[debug] Add a commandfile class: Drush\Drupal\Commands\config\ConfigCommands [1.04 sec, 26.78 MB]
[debug] Add a commandfile class: Drush\Drupal\Commands\config\ConfigExportCommands [1.04 sec, 26.82 MB]
[debug] Add a commandfile class: Drush\Drupal\Commands\config\ConfigImportCommands [1.04 sec, 26.82 MB]
[debug] Add a commandfile class: Drush\Drupal\Commands\core\BatchCommands [1.05 sec, 26.83 MB]
[debug] Add a commandfile class: Drush\Drupal\Commands\core\CliCommands [1.05 sec, 26.83 MB]
[debug] Add a commandfile class: Drush\Drupal\Commands\core\DrupalCommands [1.05 sec, 26.84 MB]
[debug] Add a commandfile class: Drush\Drupal\Commands\core\DeployHookCommands [1.05 sec, 26.85 MB]
[debug] Add a commandfile class: Drush\Drupal\Commands\core\EntityCommands [1.05 sec, 26.87 MB]
[debug] Add a commandfile class: Drush\Drupal\Commands\core\ImageCommands [1.06 sec, 26.88 MB]
[debug] Add a commandfile class: Drush\Drupal\Commands\core\JsonapiCommands [1.06 sec, 26.89 MB]
[debug] Add a commandfile class: Drush\Drupal\Commands\core\LanguageCommands [1.06 sec, 26.89 MB]
[debug] Add a commandfile class: Drush\Drupal\Commands\core\LocaleCommands [1.06 sec, 26.9 MB]
[debug] Add a commandfile class: Drush\Drupal\Commands\core\MessengerCommands [1.06 sec, 26.93 MB]
[debug] Add a commandfile class: Drush\Drupal\Commands\core\MigrateRunnerCommands [1.07 sec, 26.93 MB]
[debug] Add a commandfile class: Drush\Drupal\Commands\core\QueueCommands [1.07 sec, 26.98 MB]
[debug] Add a commandfile class: Drush\Drupal\Commands\core\RoleCommands [1.07 sec, 26.99 MB]
[debug] Add a commandfile class: Drush\Drupal\Commands\core\StateCommands [1.07 sec, 27.02 MB]
[debug] Add a commandfile class: Drush\Drupal\Commands\core\TwigCommands [1.08 sec, 27.03 MB]
[debug] Add a commandfile class: Drush\Drupal\Commands\core\UserCommands [1.08 sec, 27.04 MB]
[debug] Add a commandfile class: Drush\Drupal\Commands\core\ViewsCommands [1.08 sec, 27.08 MB]
[debug] Add a commandfile class: Drush\Drupal\Commands\core\WatchdogCommands [1.09 sec, 27.11 MB]
[debug] Add a commandfile class: Drush\Drupal\Commands\pm\PmCommands [1.09 sec, 27.14 MB]
[debug] Add a commandfile class: Drush\Drupal\Commands\pm\ThemeCommands [1.09 sec, 27.16 MB]
[debug] Add a commandfile class: Drush\Drupal\Commands\sql\SanitizeCommands [1.09 sec, 27.16 MB]
[debug] Add a commandfile class: Drush\Drupal\Commands\sql\SanitizeCommentsCommands [1.1 sec, 27.17 MB]
[debug] Add a commandfile class: Drush\Drupal\Commands\sql\SanitizeSessionsCommands [1.1 sec, 27.17 MB]
[debug] Add a commandfile class: Drush\Drupal\Commands\sql\SanitizeUserFieldsCommands [1.1 sec, 27.17 MB]
[debug] Add a commandfile class: Drush\Drupal\Commands\sql\SanitizeUserTableCommands [1.1 sec, 27.18 MB]
[debug] Add a commandfile class: Drupal\audiofield\Commands\AudiofieldCommands [1.1 sec, 27.18 MB]
[debug] Add a commandfile class: Drupal\entity_reference_revisions\Commands\EntityReferenceRevisionsCommands [1.11 sec, 27.19 MB]
[debug] Add a commandfile class: Drupal\image_effects\Commands\ImageEffectsCommands [1.11 sec, 27.2 MB]
[debug] Add a commandfile class: Drupal\scheduler\Commands\SchedulerCommands [1.11 sec, 27.21 MB]
[debug] Add a commandfile class: Drupal\smart_date\Commands\SmartDateDrushCommands [1.11 sec, 27.21 MB]
[debug] Add a commandfile class: Drupal\token\Commands\TokenCommands [1.11 sec, 27.22 MB]
[debug] Add a commandfile class: Drupal\webform\Commands\WebformCommands [1.11 sec, 27.22 MB]
[debug] Add a commandfile class: Drupal\webform\Commands\WebformSanitizeSubmissionsCommands [1.12 sec, 27.3 MB]
[debug] Add a commandfile class: Drupal\pathauto\Commands\PathautoCommands [1.12 sec, 27.31 MB]
[debug] Done with bootstrap max in Application::bootstrapAndFind(): trying to find smart_date:migrate again. [1.12 sec, 27.32 MB]
[debug] Starting bootstrap to none [1.13 sec, 27.36 MB]
[debug] Drush bootstrap phase 0 [1.13 sec, 27.37 MB]
[debug] Try to validate bootstrap phase 0 [1.13 sec, 27.37 MB]
Clearing existing values.
Starting date migration.
Finished date migration, flushing caches.
[debug] audiofield commands loaded even though its constraint (^9) is incompatible with Drush 10.6.2. Broaden the constraint in modules/contrib/audiofield/composer.json (see 'extra\drush\services' section) to remove this message. [2.79 sec, 36.27 MB]
[info] entity_reference_revisions should have an extra.drush.services section in its composer.json. See http://docs.drush.org/en/10.x/commands/#specifying-the-services-file. [2.8 sec, 36.27 MB]
[info] image_effects should have an extra.drush.services section in its composer.json. See http://docs.drush.org/en/10.x/commands/#specifying-the-services-file. [2.8 sec, 36.27 MB]
[debug] Found drush.services.yml for scheduler Drush commands [2.8 sec, 36.27 MB]
[debug] smart_date commands loaded even though its constraint (^9) is incompatible with Drush 10.6.2. Broaden the constraint in modules/contrib/smart_date/composer.json (see 'extra\drush\services' section) to remove this message. [2.81 sec, 36.27 MB]
[debug] Found drush.services.yml for token Drush commands [2.81 sec, 36.27 MB]
[info] twig_tweak should have an extra.drush.services section in its composer.json. See http://docs.drush.org/en/10.x/commands/#specifying-the-services-file. [2.81 sec, 36.27 MB]
[debug] Found drush.services.yml for webform Drush commands [2.81 sec, 36.27 MB]
[debug] Found drush.services.yml for pathauto Drush commands [2.81 sec, 36.27 MB]
[debug] Get container builder [2.81 sec, 36.28 MB]
[debug] Service modifier alter. [2.82 sec, 36.38 MB]
[debug] process drush.console.services console.command [3.05 sec, 40.91 MB]
[debug] Found tagged service twig_tweak.validate [3.05 sec, 40.91 MB]
[debug] Found tagged service twig_tweak.debug [3.05 sec, 40.91 MB]
[debug] process drush.command.services drush.command [3.05 sec, 40.91 MB]
[debug] Found tagged service config.commands [3.05 sec, 40.91 MB]
[debug] Found tagged service config.export.commands [3.05 sec, 40.91 MB]
[debug] Found tagged service config.import.commands [3.05 sec, 40.92 MB]
[debug] Found tagged service batch.commands [3.05 sec, 40.92 MB]
[debug] Found tagged service cli.commands [3.05 sec, 40.92 MB]
[debug] Found tagged service drupal.commands [3.05 sec, 40.92 MB]
[debug] Found tagged service deploy_hook.commands [3.05 sec, 40.92 MB]
[debug] Found tagged service entity.commands [3.05 sec, 40.92 MB]
[debug] Found tagged service image.commands [3.05 sec, 40.92 MB]
[debug] Found tagged service jsonapi.commands [3.05 sec, 40.92 MB]
[debug] Found tagged service language.commands [3.05 sec, 40.92 MB]
[debug] Found tagged service locale.commands [3.05 sec, 40.92 MB]
[debug] Found tagged service messenger.commands [3.05 sec, 40.92 MB]
[debug] Found tagged service migrate_runner.commands [3.05 sec, 40.92 MB]
[debug] Found tagged service queue.commands [3.05 sec, 40.93 MB]
[debug] Found tagged service role.commands [3.05 sec, 40.93 MB]
[debug] Found tagged service state.commands [3.05 sec, 40.93 MB]
[debug] Found tagged service twig.commands [3.05 sec, 40.93 MB]
[debug] Found tagged service user.commands [3.05 sec, 40.93 MB]
[debug] Found tagged service views.commands [3.05 sec, 40.93 MB]
[debug] Found tagged service watchdog.commands [3.05 sec, 40.93 MB]
[debug] Found tagged service pm.commands [3.05 sec, 40.93 MB]
[debug] Found tagged service theme.commands [3.05 sec, 40.93 MB]
[debug] Found tagged service sanitize.commands [3.05 sec, 40.93 MB]
[debug] Found tagged service sanitize.comments.commands [3.05 sec, 40.93 MB]
[debug] Found tagged service sanitize.sessions.commands [3.05 sec, 40.93 MB]
[debug] Found tagged service sanitize.userfields.commands [3.05 sec, 40.94 MB]
[debug] Found tagged service sanitize.usertable.commands [3.05 sec, 40.94 MB]
[debug] Found tagged service audiofield.commands [3.05 sec, 40.94 MB]
[debug] Found tagged service entity_reference_revisions.commands [3.05 sec, 40.94 MB]
[debug] Found tagged service image_effects.commands [3.05 sec, 40.94 MB]
[debug] Found tagged service scheduler.commands [3.05 sec, 40.94 MB]
[debug] Found tagged service smart_date.commands [3.05 sec, 40.94 MB]
[debug] Found tagged service token.commands [3.05 sec, 40.94 MB]
[debug] Found tagged service webform.commands [3.05 sec, 40.94 MB]
[debug] Found tagged service webform.sanitize.submissions.commands [3.05 sec, 40.94 MB]
[debug] Found tagged service pathauto.commands [3.05 sec, 40.94 MB]
[debug] process drush.command_info_alterer.services drush.command_info_alterer [3.05 sec, 40.94 MB]
[debug] process drush.generator.services drush.generator [3.05 sec, 40.94 MB]

Any idea if I'm missing anything? Thanks!

mandclu’s picture

Based on your output, it doesn't seem as though you've quite followed the suggestion. My suggestion:
drush smart_date:migrate exhibition field_smart_date field_start_date field_end_date --langcode=und --clear

What your output indicates you ran:
drush smart_date:migrate exhibition field_date field_start_date field_end_date --langcode=und --clear -vvv

sseto’s picture

Sorry for the confusion! I realize my field name for smart_date is actually `field_date`

So this is my output: `drush smart_date:migrate exhibition field_date field_start_date field_end_date --langcode=und --clear`

Thanks!

sseto’s picture

Hey mandclu,

Could it be because of this?

[debug] smart_date commands loaded even though its constraint (^9) is incompatible with Drush 10.6.2. Broaden the constraint in modules/contrib/smart_date/composer.json (see 'extra\drush\services' section) to remove this message. [2.16 sec, 36.37 MB]

sseto’s picture

StatusFileSize
new39.64 KB

ohh! I reran the script without --langcode=und and it worked!

It imported a day behind though. I've attached a screenshot. Any idea what could be the issue now?

mandclu’s picture

If I had to guess, I would say it's probably something related to timezones. What timezone is your site?

sseto’s picture

StatusFileSize
new180.1 KB

I checked my timezone and it's set in the correct Canada/Vancouver time in /admin/config/regional/settings. Is there somewhere else I can edit the timezone?

Thank you!

sseto’s picture

Still working on it..Things I've tried:

1) Change the timezone on php.ini [Date] to `date.timezone ="America/Vancouver"`
2) Change regional settings to America/Vancouver
3) Played around with the start_date and end_date field settings.
4) Checked mysql time and it's using my current time
I) mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2022-02-23 15:01:59 |
+---------------------+

Very strange cause my DateTime displays the current time...what could I be missing?

sseto’s picture

I changed the timezone to Greenland (A country that's a day ahead of Canada) and the time migrated correctly. I switched back to Canada and it's back to a day behind. Any idea what could be the issue?

Thanks!

mandclu’s picture

Category: Support request » Bug report

Smart Date recently switched to always storing the timezone with all day events, so they can always be evaluated against the original timezone. I suspect the drush script needs to be updated to save the timezone when migrating dates/all day events.

sseto’s picture

I tested it on another website and it migrated perfectly, so I'm not sure if it's a drush script issue. If it is really a drush script issue, any idea what needs to be updated? Thanks!

mandclu’s picture

Title: Importing 2 core date fields to Smart_date » Import Drush command doesn't work with date-only values, or all day timezones
Status: Active » Needs review
StatusFileSize
new5.52 KB

I suspect it comes back to the timezones not being saved. While I was working on this, I realized that the code wasn't really set up to handle date-only events, so I also did some refactoring to improve that at the same time.

Here's a patch that should address these issue. Please note that this patch also includes the work from #3262983: drush smart_date:migrate / The "" entity type does not exist. so if you have that patch installed already, you'll probably need to uninstall it before you can apply this one. Let me know if this works for you, and I'll get it merged in.

sseto’s picture

hey hey! It worked!! Thank you so much Mandclu!!

sseto’s picture

StatusFileSize
new28.04 KB

  • mandclu committed 43d296b on 3.5.x
    Issue #3264802 by mandclu: Import Drush command doesn't work with date-...
mandclu’s picture

Status: Needs review » Fixed

Awesome! These are merged in, so closing this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.