detail_template_factory = $detail_template_factory; $this->detail_template_repository = $detail_template_repository; } /** * Migrate the detail templates posts to taxonomy terms. * * @since 0.8 */ public function migrate() { $posts = get_posts(array( 'post_type' => 'detail_group', 'status' => 'publish' )); foreach ($posts as $post) { $fields = carbon_get_post_meta($post->ID, '_affilicious_detail_group_fields', 'complex'); if(!empty($fields)) { foreach ($fields as $field) { $name = isset($field['name']) ? $field['name'] : null; $type = isset($field['type']) ? $field['type'] : null; $unit = isset($field['unit']) ? $field['unit'] : null; if(empty($name) || empty($type)) { continue; } $detail_template = $this->detail_template_factory->create_from_name( new Name($name), new Type($type), !empty($unit) ? new Unit($unit) : null ); try { $this->detail_template_repository->store($detail_template); } catch (\Exception $e) { continue; } } } wp_delete_post($post->ID); } } }