{"id":14360,"date":"2024-02-29T17:21:35","date_gmt":"2024-02-29T11:21:35","guid":{"rendered":"https:\/\/shra.ru\/?p=14360"},"modified":"2024-03-01T17:39:38","modified_gmt":"2024-03-01T11:39:38","slug":"migraciya-terminov-taksonomii","status":"publish","type":"post","link":"https:\/\/shra.ru\/2024\/02\/migraciya-terminov-taksonomii\/","title":{"rendered":"\u041c\u0438\u0433\u0440\u0430\u0446\u0438\u044f \u0442\u0435\u0440\u043c\u0438\u043d\u043e\u0432 \u0442\u0430\u043a\u0441\u043e\u043d\u043e\u043c\u0438\u0438"},"content":{"rendered":"\n
\u0422\u0435\u0440\u043c\u0438\u043d\u044b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u044e\u0442\u0441\u044f \u043a \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0439 entity \u0432 \u0432\u0438\u0434\u0435 term reference<\/strong>. \u041f\u043e\u0442\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 — \u044d\u0442\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0430\u044f \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u044f \u0442\u0435\u0440\u043c\u0438\u043d\u043e\u0432, \u0430 \u043f\u043e\u0442\u043e\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0438\u0445, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f migration_lookup<\/strong> \u043f\u043b\u0430\u0433\u0438\u043d.<\/p>\n\n\n\n \u041d\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435, \u0432\u044b \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0442\u0435\u0440\u043c\u0438\u043d\u044b \u0432 \u0432\u0438\u0434\u0435 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0445 \u043c\u0435\u0442\u043e\u043a. \u0418 \u0432\u0430\u043c \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0438\u0445 «\u043d\u0430 \u043b\u0435\u0442\u0443», \u0431\u0435\u0437 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438. <\/p>\n\n\n\n \u0418\u043c\u0435\u043d\u043d\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u044f \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u0443\u044e \u043c\u0435\u0442\u043a\u0443 \u0432 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0442\u0435\u0440\u043c\u0438\u043d (\u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0438\u043b\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439).<\/p>\n\n\n\n\n\n\n\n \u0412\u043e\u0442 \u043a\u043e\u0434 \u044d\u0442\u043e\u0433\u043e process plugin:<\/p>\n\n\n\n \u041e\u043d \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 $value (\u043c\u0435\u0442\u043a\u0443 \u0442\u0435\u0440\u043c\u0438\u043d\u0430) \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 [‘target_id’ => TERMID]. <\/p>\n\n\n\n \u0412 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u0445 \u043c\u043e\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0432 \u043a\u0430\u043a\u043e\u0439 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u043f\u0430\u0434\u0430\u0442\u044c \u0442\u0435\u0440\u043c\u0438\u043d (destination_bundle<\/em>).<\/p>\n\n\n\n \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438:<\/p>\n\n\n\n \u0412 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 (field_blog_category<\/em>) \u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043e\u0434\u0438\u043d\u043e\u0447\u043d\u044b\u0439 \u0442\u0435\u0440\u043c\u0438\u043d \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 (category). \u0412\u043e \u0432\u0442\u043e\u0440\u043e\u043c — (field_blog_tag<\/em>) \u0441\u043f\u0438\u0441\u043e\u043a \u0442\u0435\u0433\u043e\u0432, \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0437\u0430\u043f\u044f\u0442\u044b\u043c\u0438. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0442.\u043d. pipeline<\/em>, \u0433\u0434\u0435 \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u043c \u0448\u0430\u0433\u0435 \u0441\u0442\u0440\u043e\u043a\u0430 \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u043f\u043b\u0430\u0433\u0438\u043d\u043e\u043c explode<\/em>, \u0430 \u0434\u0430\u043b\u044c\u0448\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u0442\u0435\u0440\u043c\u0438\u043d \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u0432 \u043d\u0430\u0448 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440 term_generate<\/strong>.<\/p>\n\n\n\n \u0420\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u0442\u0435 \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u043b\u0430\u0433\u0438\u043d \u0432 \u0432\u0430\u0448\u0435\u043c \u043c\u043e\u0434\u0443\u043b\u0435 (\/src\/Plugin\/migrate\/process), \u0438 \u0441\u0431\u0440\u043e\u0441\u044c\u0442\u0435 \u043a\u0435\u0448, \u0447\u0442\u043e\u0431\u044b Drupal \u0435\u0433\u043e \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043b.<\/p>\n","protected":false},"excerpt":{"rendered":" \u0422\u0435\u0440\u043c\u0438\u043d\u044b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u044e\u0442\u0441\u044f \u043a \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0439 entity \u0432 \u0432\u0438\u0434\u0435 term reference. \u041f\u043e\u0442\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 — \u044d\u0442\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0430\u044f \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u044f \u0442\u0435\u0440\u043c\u0438\u043d\u043e\u0432, \u0430 \u043f\u043e\u0442\u043e\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0438\u0445, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f migration_lookup \u043f\u043b\u0430\u0433\u0438\u043d. \u041d\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435, \u0432\u044b \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0442\u0435\u0440\u043c\u0438\u043d\u044b \u0432 \u0432\u0438\u0434\u0435 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0445 \u043c\u0435\u0442\u043e\u043a. \u0418 \u0432\u0430\u043c \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0438\u0445 «\u043d\u0430 \u043b\u0435\u0442\u0443», \u0431\u0435\u0437 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[178],"acf":[],"yoast_head":"\n<?php\n\n\/\/ \u0443 \u043c\u0435\u043d\u044f \u043e\u043d \u0431\u044b\u043b \u0432 \u0441\u043e\u0441\u0442\u0430\u0432\u0435 \u043c\u043e\u0435\u0433\u043e \n\/\/ \u043c\u043e\u0434\u0443\u043b\u044f \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 custom_migration\nnamespace Drupal\\custom_migration\\Plugin\\migrate\\process;\n\nuse Drupal\\migrate\\MigrateException;\nuse Drupal\\migrate\\MigrateExecutableInterface;\nuse Drupal\\migrate\\ProcessPluginBase;\nuse Drupal\\migrate\\Row;\nuse Drupal\\taxonomy\\Entity\\Term;\n\n\/**\n * Generates a term entity from a Term Name and returns the term id.\n *\n * @MigrateProcessPlugin(\n * id = \"term_generate\"\n * )\n *\n * To generate the entity it is best to this in a subprocess:\n *\n * @code\n * process:\n * field_blog_category\/target_id:\n * source: category_name\n * plugin: term_generate\n * destination_bundle: content_tags\n * @endcode\n *\/\nclass TermGenerate extends ProcessPluginBase {\n\n \/**\n * {@inheritdoc}\n *\/\n public function transform(\n $value,\n MigrateExecutableInterface $migrate_executable,\n Row $row, \n $destination_property) \n {\n if (!isset($this->configuration['destination_bundle'])) {\n throw new MigrateException('Destination bundle must be set.');\n }\n $vid = $this->configuration['destination_bundle'];\n\n $value = trim($value ?? '');\n $result = NULL;\n\n if (!empty($value)) {\n\n \/\/ Prepare TERM.\n $query = \\Drupal::entityTypeManager()\n ->getStorage('taxonomy_term')\n ->getQuery();\n $query->condition('status', 1)\n ->condition('name', $value)\n ->condition('vid', $vid)\n ->accessCheck(FALSE);\n $tids = $query->execute();\n $tid = reset($tids) ?: NULL;\n\n if ($tid === NULL) {\n $term = Term::create([\n 'vid' => $vid,\n 'status' => '1',\n 'name' => $value,\n ]);\n $term->save();\n $result = $term->id();\n }\n else {\n $result = $tid;\n }\n }\n return ['target_id' => $result];\n }\n}\n<\/code><\/pre>\n\n\n\n
process:\n field_blog_category:\n source: category\n plugin: term_generate\n destination_bundle: blog_category\n field_blog_tag:\n -\n plugin: explode\n source: tags\n delimiter: ','\n -\n plugin: term_generate\n destination_bundle: blog_tags<\/code><\/pre>\n\n\n\n