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