![]() $query->leftJoin('node', 'n', "like.entity_id = n.nid AND like.entity_type = 'node' AND n.status = 1") We are also informing the migration system about the fields we will be returning from the query results. Here is the migration source plugin class, with the query override. We don't want to migrate any likes for news pages, comments, or users that are not published or active, so the query we create also removes this data from the migration source. We use left joins here to allow null values to be brought through in the query results. The likes in the old site were stored in a table called "like" and because it was possible to like both news pages and comments we need to link that table with the node and comment tables to get all of the data. To this end, we must create a migration source plugin and extend the \Drupal\migrate\Plugin\migrate\source\SqlBase class. In fact, the data was just stored in a table on the Drupal 7 site and logic was created to like or unlike content. Creating The Migration Sourceĭue to the fact that the likes on the old site are custom, the source for the like migration also needs to be a custom migration source. The session_id can remain null for the purposes of our setup here. In the above example we are creating a "like" on news page 1 for user 1. The value of "like_content" for the "flag_id" field informs the flag modules of name of the flag that we setup in the flag module. $flaggingStorage = \Drupal::service('entity_type.manager')->getStorage('flagging') Here is an example of how to create a flagging entity connected to an item of news content. The flagging entity has a few values that define what sort of flagging bundle it belongs to, and what sort of entity is being flagged. In our case, we are creating a non-session based flag that is linked to a content item and a user. This is the entity type that needs to be created to migrate the likes into the new site. Just a quick side note, the entity type used to link a user to a particular item of content through a flag is called a Flagging entity. With this in place we can now look at generating the entities that represent the flags users have attached to items of content. This is what the flag configuration looks like after settings things up. This might be used to create a bookmark system or to report an item of content to the site administrators for example. ![]() We must create "Personal" flags when configuring the module here in order to allow content to be flagged by more than one user.īy contrast, "Global" flags are used to allow users to add a single flag against an item of content. The Drupal 10 configuration consisted of two different types of flag one to flag content and one to flag comments. The flag module is well written (and well tested!) and allows for different types of flags to be added to different types of content. This won't be a detailed breakdown of each component so some prior knowledge of the migration system is expected. In this article I will go through each step of the migration process from source to destination, including the custom processing plugin created to aid the migration. In fact, the decision I took was to migrate the likes as a single process, which meant that I could run or re-run the migration with a single command. This was simple enough to do using two different types of flag entity one for nodes and one for comments.Īn added complication came from migrating from a single resource into what is essentially two different bundle types this needed a bit of logic to be written, but was certainly possible in a single migration step. To add further complication, it was possible to add likes to nodes and comments, which meant that the flags on the new side needed to be applied to two different types of entity. ![]() ![]() This meant that I needed to migrate the old custom structure into the entity structure provided by the Flag module. The likes in the old Drupal 7 site were built using a custom module, with the Flag module was selected to provide the new functionality on the new Drupal 10 site. I've been doing a bit of Drupal migration recently, and one of the tasks I have undertaken is to migrate "likes" from a Drupal 7 site to a Drupal 10 site.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |