Support from Acquia helps fund testing for Drupal Acquia logo

Comments

chr.fritsch created an issue. See original summary.

marcoscano’s picture

I may not have a good picture of what sites out there are using, but from my (likely biased) perspective, I'm not sure media_entity is the best place for this. I have the feeling that most sites that want to use media in core at this point are already using Media in core + VEF 2.x. So I'd say this would either need to be in core (unlikely), or maybe a new branch of VEF that only served to perform the upgrade, and then be disabled?

Berdir’s picture

Agreed, this belongs into VEF and can't be done here.

seanB’s picture

I agree with marcos en berdir. If video embed field wants people to move over it should provide an upgrade path. It is basically a migration from 1 media source to another. Since it supports a whole lot of providers migration could be a bit tricky.

Sam152’s picture

Project: Media entity » Video Embed Field
Component: Code » Video Embed Media

It’d be great if we had a mechanism to move all VEF media entities over to core oembed.
Couple of caveats: I believe there are providers out there that have no oembed support, VEF itself has a stand-alone field type and direct WYSWIYG integration.
So for sites built on those things, the module will probably stick around.
But there should be a big disclaimer at the top with instructions on how to use the core oembed feature I think
So I think a reasonable approach would be a feature in the video_embed_media sub-module that can essentially swap the bundle of the media entity and make itself redundant, then give users the option to uninstall it.
Then uninstalling the base module is an “at your own risk” kind of thing, provided you haven’t made use of the other features.

Quoting from slack. I think this would be a great idea.

chr.fritsch’s picture

Status: Active » Needs review
FileSize
4.43 KB

I started working on this on my way to DrupalEurope. Hopefully, we can finish it there.

Sam152’s picture

Looking like a great start. It would be good to have some tests for this as well.

+++ b/modules/video_embed_media/modules/vem_migrate_oembed/vem_migrate_oembed.drush.inc
@@ -0,0 +1,108 @@
+    $field_storage->set('type', 'string');
+    $field_storage->set('module', 'core');
+    $field_storage->set('settings.max_length', 255);

I didn't realise you could do this. I thought once a field schema was installed, changing the type or storage settings was impossible. After running this, does "drush entity-updates" complain about pending schema updates?

chr.fritsch’s picture

Status: Needs review » Needs work

You are right. drush entup is complaining Drupal\Core\Entity\Exception\FieldStorageDefinitionUpdateForbiddenException: The SQL storage cannot change the schema for an existing field (field_media_video_embed_field in media entity) with data.

So looks like we have to do something else to change the field definition.

Sam152’s picture

There are ways to hack the repository to change the field type, given both VEF and string use the 'value' column, but overall I imagine it's probably easiest to create a new field and copy the data from the old one to the new one.

chr.fritsch’s picture

Discussed this with @webflo and @alexpott and we think it's best to change the field schema on a very low level.

Sam152’s picture

This is really nice work, only thing I picked up was below. If possible a test would be useful, otherwise I'm happy to get this in and iterate from there.

+++ b/modules/video_embed_media/modules/vem_migrate_oembed/vem_migrate_oembed.drush.inc
@@ -0,0 +1,138 @@
+    \Drupal::database()->query(
+      "ALTER TABLE media__$field_name MODIFY ${field_name}_value varchar(255);"
+    );
+    \Drupal::database()->query(
+      "ALTER TABLE media_revision__$field_name MODIFY ${field_name}_value varchar(255);"
+    );

We could use \Drupal\Core\Entity\Sql\DefaultTableMapping::getFieldTableName for this, although the hardcoded table name is probably reliable.

Berdir’s picture

No, it's actually not because if someone has a long field name, it gets hashed.

Hardcoded Alter Table statements are also MySQL specific, why isn't this using the schema API?

jibran’s picture

I wish we can write D8 -> D8 migration but @Berdir is right we should be using schema API.

Sam152’s picture

No, it's actually not because if someone has a long field name, it gets hashed.

I believe VEF used to create the field for you automatically when adding a new media entity bundle, with a fixed name, but you're correct it would be more reliable to lookup the table name.

EntityDefinitionUpdateManager doesn't support changing a field type, so I think the only alternative would be #9, unless there is a general field schema api?

Berdir’s picture

You can use \Drupal::database()->schema() also on field tables, it doesn't care what kind of table it is. You just tell it which field on which table to change and what the new definition is.

Sam152’s picture

Gotcha, that sounds preferable. Thanks for clarifying.

chr.fritsch’s picture

Nick Hope’s picture

Not sure if I'm a typical VEF user, but oEmbed would need Colorbox support (the same as VEF) for me to migrate to it, unless I can get oEmbeds to display in modals some other way. Others might need one of the the other display formats such as "Video (lazy load)" perhaps?:

Video Embed Field display formats

Also, I still have 3 issues with oEmbed in 8.6.1, although the lack of response makes me wonder if some of them may be unique to my situation:

  1. oEmbed Remote Video iFrame contains my site, not a video
  2. Remote Video (oEmbed) - Cannot map URL of the author/owner to field
  3. Remote Video (oEmbed) - Default thumbnails location is invalid

Also I guess some may need the field mapping that VEF provides:

Video Embed Field field mapping

Unfortunately I'm not a coder, or I would try and fix/implement this stuff myself. Just raising some considerations that someone working on this might overlook.

chr.fritsch’s picture

It's true, oEmbed currently doesn't support colorbox. But IMHO that should not block this issue. This is only an optional upgrade path. If you need colorbox or lazy video you can still use this module. That's totally fine.

seanB’s picture

chr.fritsch’s picture

A new patch that fixes wrong dependencies in the config files after the migration.

chr.fritsch’s picture

Ooups, the previous patch was empty

daniel.bosen’s picture

Status: Needs review » Reviewed & tested by the community

I tested this patch and the migration went very smooth.

chr.fritsch’s picture

Can we get that committed?

chr.fritsch’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
11.91 KB

I added drush 9 support

Sam152’s picture

I'm kind of hesitant to commit this without a test, especially given that it would be great to have proof this works as D9 compatibility approaches. Bumping the major version of core is probably a good time to evaluate all of these dependencies that may be outdated.

chr.fritsch’s picture

Ok, so here we go.

It's the first test to check that the source and the field type was changed.

Sam152’s picture

Status: Needs review » Reviewed & tested by the community

Cool, based on this having a test, being completely optional and in a sub-module I think this is safe to go in.

RTBC, will commit tomorrow if nobody has any further feedback.

Thanks!

chr.fritsch’s picture

Uploading a new patch that fixes a wrong dependency on the media type.

m.abdulqader’s picture

+1

  • Sam152 committed 1e1f195 on 8.x-2.x authored by chr.fritsch
    Issue #2997799 by chr.fritsch, Nick Hope: Include upgrade path from...
Sam152’s picture

Status: Reviewed & tested by the community » Fixed
chr.fritsch’s picture

Thanks for committing this. Could we get a new VEF release?

Sam152’s picture

Done. 2.2 tagged.

ThomWilhelm’s picture

Will this migrate video_embed_fields added to nodes? I'm looking at an upgrade to core media at the moment from media_entity 1.x and found this interesting. However from an early test this only covers migrating video_embed_fields added to media entities, but doesn't migrate those added to nodes.

Sam152’s picture

I don't believe that kind of migration was in scope for this issue, no.

Status: Fixed » Closed (fixed)

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

bryanbuchs’s picture

Is there a usage example for this? I've got a media entity using the video_embed_field, but when I enable this sub-module, clear caches, & run drush venmo I get a "command could not be found" message. Tried against my project install running 8.7.6 and the 2.2 release version of video_embed_field

Sam152’s picture

I have added a documentation page for "Migrating to core media
": https://www.drupal.org/docs/8/modules/video-embed-field/migrating-to-cor....

If anyone has capacity, it would be great if details on how to use the upgrade path committed here was added to this docs page.

rjzaar’s picture

i found drush vem:migrate_oembed worked (D8.8). drush venmo or drush vemmo didn't work for me. I found it using drush list, even though in the vem_migrate_oembed module the alias is vemmo.

Robert DeArmond’s picture

On Drupal 8.8.6.

When I run drush vemmo
I get the following error:

No hook functions were found for vem_migrate_oembed. The primary hook    [error]
function is drush_vem_migrate_oembed(). Please implement this
function. Run with --show-invoke to see all available hooks.

When I run drush vem:migrate_oembed
I get the following error:

The drush command 'vem:migrate_oembed' could not be found.  Run          [error]
`drush cache-clear drush` to clear the commandfile cache if you have
installed new extensions.

Any advice?

jonathanshaw’s picture

I fleshed out the docs.

drupalbrax’s picture

I get the same error as described in #41

Rob230’s picture

The documentation is wrong. There is no such drush command as vem:migrate_oembed in the code that I can see. It's called video-embed-media-migrate-oembed or vemmo.

But when I run this I get the error:

LogicException: Missing bundle entity, entity type media_type, entity id video. in www/core/lib/Drupal/Core/Entity/EntityType.php:914
Stack trace:
#0 www/core/lib/Drupal/Core/Field/FieldConfigBase.php(249):
Drupal\Core\Entity\EntityType->getBundleConfigDependency('video')
#1 www/core/modules/field/src/Entity/FieldConfig.php(189):
Drupal\Core\Field\FieldConfigBase->calculateDependencies()
#2
www/modules/contrib/video_embed_field/modules/video_embed_media/modules/vem_migrate_oembed/src/VemMigrate.php(144):
Drupal\field\Entity\FieldConfig->calculateDependencies()

I don't know if this means some other part of the upgrade process has gone wrong. To me it is not clear what order things need to be done in. I have already upgraded media_entity and all media providers to 2.x and run database updates.

Edit: vem_migrate_oembed is the name of the command in 2.4. I'm having to use 2.2 because later versions require 8.8 which I obviously can't upgrade to yet, given that I'm still doing media updates.

Edit2: The error I got was from badly applied update to media_entity (it didn't complete).

marcoka’s picture

I am not sure but that migration command will not migrate simple video_embed fields?
At least it did not do anything fpr me using a simple embed field with a youtube url.

gbyte’s picture

This is not fixed, please reopen the issue.

The following did not work:

  • drush vem:migrate_oembed
  • drush vem_migrate_oembed
  • drush video-embed-media-migrate-oembed
  • drush vemmo

To migrate the videos, I executed drush php-eval '\Drupal::service("vem_migrate_oembed.migrate")->migrate();' isntead.

SKAUGHT’s picture

#46.
drush version could be the problem. @drush9+ commands

rattusrattus’s picture

If anyone is looking for an upgrade path from video_embed_field fields attached to nodes etc. then you can check out https://www.drupal.org/project/video_embed_field_migrate