diff --git a/includes/Classifai/Admin/Notifications.php b/includes/Classifai/Admin/Notifications.php index 75a5292bf..2fb07f466 100644 --- a/includes/Classifai/Admin/Notifications.php +++ b/includes/Classifai/Admin/Notifications.php @@ -27,6 +27,7 @@ public function register() { add_action( 'classifai_activation_hook', [ $this, 'add_activation_notice' ] ); add_action( 'admin_notices', [ $this, 'maybe_render_notices' ], 0 ); add_action( 'admin_notices', [ $this, 'thresholds_update_notice' ] ); + add_action( 'admin_notices', [ $this, 'v3_migration_completed_notice' ] ); add_action( 'admin_enqueue_scripts', [ $this, 'add_dismiss_script' ] ); add_action( 'wp_ajax_classifai_dismiss_notice', [ $this, 'ajax_maybe_dismiss_notice' ] ); } @@ -95,33 +96,35 @@ public function add_dismiss_script() { $script = << +
+

+ tag starting; %2$s: tag closing. + __( '%1$sClassifAI 3.0.0%2$s has changed how AI providers are integrated with individual features. This changes how settings are stored and requires that existing settings be migrated. This migration has happened automatically and you can %3$sverify your settings here%4$s.', 'classifai' ), + '', + '', + '', + '' + ) + ); + ?> +

+
+ get_settings(); + + if ( isset( $old_settings['enable_transcripts'] ) ) { + $new_settings['status'] = $old_settings['enable_transcripts']; + } + + $new_settings['provider'] = 'openai_whisper'; + + if ( isset( $old_settings['api_key'] ) ) { + $new_settings['openai_whisper']['api_key'] = $old_settings['api_key']; + } + + if ( isset( $old_settings['authenticated'] ) ) { + $new_settings['openai_whisper']['authenticated'] = $old_settings['authenticated']; + } + + if ( isset( $old_settings['speech_to_text_users'] ) ) { + $new_settings['users'] = $old_settings['speech_to_text_users']; + } + + if ( isset( $old_settings['speech_to_text_roles'] ) ) { + $new_settings['roles'] = $old_settings['speech_to_text_roles']; + } + + if ( isset( $old_settings['speech_to_text_user_based_opt_out'] ) ) { + $new_settings['user_based_opt_out'] = $old_settings['speech_to_text_user_based_opt_out']; + } + + return $new_settings; + } } diff --git a/includes/Classifai/Features/Classification.php b/includes/Classifai/Features/Classification.php index e02449db9..707da8bbc 100644 --- a/includes/Classifai/Features/Classification.php +++ b/includes/Classifai/Features/Classification.php @@ -1029,4 +1029,147 @@ public function get_supported_taxonomies( array $post_types = [] ): array { */ return apply_filters( 'classifai_' . static::ID . '_setting_taxonomies', $supported, $this ); } + + /** + * Generates feature setting data required for migration from + * ClassifAI < 3.0.0 to 3.0.0 + * + * @return array + */ + public function migrate_settings() { + $old_settings = get_option( 'classifai_watson_nlu', array() ); + $new_settings = $this->get_default_settings(); + + if ( isset( $old_settings['authenticated'] ) && $old_settings['authenticated'] ) { + $new_settings['provider'] = 'ibm_watson_nlu'; + + // Status + if ( isset( $old_settings['enable_content_classification'] ) ) { + $new_settings['status'] = $old_settings['enable_content_classification']; + } + + // Post types + if ( isset( $old_settings['post_types'] ) ) { + if ( is_array( $old_settings['post_types'] ) ) { + foreach ( $old_settings['post_types'] as $post_type => $value ) { + if ( 1 === $value ) { + $new_settings['post_types'][ $post_type ] = $post_type; + continue; + } elseif ( is_null( $value ) ) { + $new_settings['post_types'][ $post_type ] = '0'; + continue; + } + $new_settings['post_types'][ $post_type ] = $value; + } + } + + unset( $new_settings['post_types']['attachment'] ); + } + + // Post statuses + if ( isset( $old_settings['post_statuses'] ) ) { + if ( is_array( $old_settings['post_statuses'] ) ) { + foreach ( $old_settings['post_statuses'] as $post_status => $value ) { + if ( 1 === $value ) { + $new_settings['post_statuses'][ $post_status ] = $post_status; + continue; + } elseif ( is_null( $value ) ) { + $new_settings['post_statuses'][ $post_status ] = '0'; + continue; + } + $new_settings['post_statuses'][ $post_status ] = $value; + } + } + } + + // Roles + if ( isset( $old_settings['content_classification_roles'] ) ) { + $new_settings['roles'] = $old_settings['content_classification_roles']; + } + + // Users + if ( isset( $old_settings['content_classification_users'] ) ) { + $new_settings['users'] = $old_settings['content_classification_users']; + } + + // Provider. + if ( isset( $old_settings['credentials'] ) && isset( $old_settings['credentials']['watson_url'] ) ) { + $new_settings['ibm_watson_nlu']['endpoint_url'] = $old_settings['credentials']['watson_url']; + } + + if ( isset( $old_settings['credentials'] ) && isset( $old_settings['credentials']['watson_username'] ) ) { + $new_settings['ibm_watson_nlu']['username'] = $old_settings['credentials']['watson_username']; + } + + if ( isset( $old_settings['credentials'] ) && isset( $old_settings['credentials']['watson_password'] ) ) { + $new_settings['ibm_watson_nlu']['password'] = $old_settings['credentials']['watson_password']; + } + + if ( isset( $old_settings['classification_mode'] ) ) { + $new_settings['classification_mode'] = $old_settings['classification_mode']; + } + + if ( isset( $old_settings['classification_method'] ) ) { + $new_settings['classification_method'] = $old_settings['classification_method']; + } + + if ( isset( $old_settings['features'] ) ) { + foreach ( $old_settings['features'] as $feature => $value ) { + $new_settings[ $feature ] = $value; + } + } + + if ( isset( $old_settings['authenticated'] ) ) { + $new_settings['ibm_watson_nlu']['authenticated'] = $old_settings['authenticated']; + } + + if ( isset( $old_settings['content_classification_user_based_opt_out'] ) ) { + $new_settings['user_based_opt_out'] = $old_settings['content_classification_user_based_opt_out']; + } + } else { + $old_settings = get_option( 'classifai_openai_embeddings', array() ); + + if ( isset( $old_settings['enable_classification'] ) ) { + $new_settings['status'] = $old_settings['enable_classification']; + } + + $new_settings['provider'] = 'openai_embeddings'; + + if ( isset( $old_settings['api_key'] ) ) { + $new_settings['openai_embeddings']['api_key'] = $old_settings['api_key']; + } + + if ( isset( $old_settings['taxonomies'] ) ) { + foreach ( $old_settings['taxonomies'] as $feature => $value ) { + $new_settings[ $feature ] = $value; + } + } + + if ( isset( $old_settings['authenticated'] ) ) { + $new_settings['openai_embeddings']['authenticated'] = $old_settings['authenticated']; + } + + if ( isset( $old_settings['post_statuses'] ) ) { + $new_settings['post_statuses'] = $old_settings['post_statuses']; + } + + if ( isset( $old_settings['post_types'] ) ) { + $new_settings['post_types'] = $old_settings['post_types']; + } + + if ( isset( $old_settings['classification_roles'] ) ) { + $new_settings['roles'] = $old_settings['classification_roles']; + } + + if ( isset( $old_settings['classification_users'] ) ) { + $new_settings['users'] = $old_settings['classification_users']; + } + + if ( isset( $old_settings['classification_user_based_opt_out'] ) ) { + $new_settings['user_based_opt_out'] = $old_settings['classification_user_based_opt_out']; + } + } + + return $new_settings; + } } diff --git a/includes/Classifai/Features/ContentResizing.php b/includes/Classifai/Features/ContentResizing.php index 6a6f9da73..34836ade0 100644 --- a/includes/Classifai/Features/ContentResizing.php +++ b/includes/Classifai/Features/ContentResizing.php @@ -305,4 +305,55 @@ public function sanitize_default_feature_settings( array $new_settings ): array return $new_settings; } + + /** + * Generates feature setting data required for migration from + * ClassifAI < 3.0.0 to 3.0.0 + * + * @return array + */ + public function migrate_settings() { + $old_settings = get_option( 'classifai_openai_chatgpt', array() ); + $new_settings = $this->get_default_settings(); + + if ( isset( $old_settings['enable_resize_content'] ) ) { + $new_settings['status'] = $old_settings['enable_resize_content']; + } + + $new_settings['provider'] = 'openai_chatgpt'; + + if ( isset( $old_settings['api_key'] ) ) { + $new_settings['openai_chatgpt']['api_key'] = $old_settings['api_key']; + } + + if ( isset( $old_settings['authenticated'] ) ) { + $new_settings['openai_chatgpt']['authenticated'] = $old_settings['authenticated']; + } + + if ( isset( $old_settings['number_resize_content'] ) ) { + $new_settings['openai_chatgpt']['number_of_suggestions'] = $old_settings['number_resize_content']; + } + + if ( isset( $old_settings['shrink_content_prompt'] ) ) { + $new_settings['condense_text_prompt'] = $old_settings['shrink_content_prompt']; + } + + if ( isset( $old_settings['grow_content_prompt'] ) ) { + $new_settings['expand_text_prompt'] = $old_settings['grow_content_prompt']; + } + + if ( isset( $old_settings['resize_content_roles'] ) ) { + $new_settings['roles'] = $old_settings['resize_content_roles']; + } + + if ( isset( $old_settings['resize_content_users'] ) ) { + $new_settings['users'] = $old_settings['resize_content_users']; + } + + if ( isset( $old_settings['resize_content_user_based_opt_out'] ) ) { + $new_settings['user_based_opt_out'] = $old_settings['resize_content_user_based_opt_out']; + } + + return $new_settings; + } } diff --git a/includes/Classifai/Features/DescriptiveTextGenerator.php b/includes/Classifai/Features/DescriptiveTextGenerator.php index b21e04597..2642c6b3c 100644 --- a/includes/Classifai/Features/DescriptiveTextGenerator.php +++ b/includes/Classifai/Features/DescriptiveTextGenerator.php @@ -392,4 +392,58 @@ public function sanitize_default_feature_settings( array $new_settings ): array return $new_settings; } + + /** + * Generates feature setting data required for migration from + * ClassifAI < 3.0.0 to 3.0.0 + * + * @return array + */ + public function migrate_settings() { + $old_settings = get_option( 'classifai_computer_vision', array() ); + $new_settings = $this->get_default_settings(); + + $new_settings['provider'] = 'ms_computer_vision'; + + if ( isset( $old_settings['url'] ) ) { + $new_settings['ms_computer_vision']['endpoint_url'] = $old_settings['url']; + } + + if ( isset( $old_settings['api_key'] ) ) { + $new_settings['ms_computer_vision']['api_key'] = $old_settings['api_key']; + } + + if ( isset( $old_settings['caption_threshold'] ) ) { + $new_settings['ms_computer_vision']['descriptive_confidence_threshold'] = $old_settings['caption_threshold']; + } + + if ( isset( $old_settings['authenticated'] ) ) { + $new_settings['ms_computer_vision']['authenticated'] = $old_settings['authenticated']; + } + + if ( isset( $old_settings['enable_image_captions'] ) ) { + $new_settings['descriptive_text_fields'] = $old_settings['enable_image_captions']; + + foreach ( $new_settings['descriptive_text_fields'] as $key => $value ) { + if ( '0' !== $value ) { + $new_settings['status'] = '1'; + break; + } + } + } + + if ( isset( $old_settings['image_captions_roles'] ) ) { + $new_settings['roles'] = $old_settings['image_captions_roles']; + } + + if ( isset( $old_settings['image_captions_users'] ) ) { + $new_settings['users'] = $old_settings['image_captions_users']; + } + + if ( isset( $old_settings['image_captions_user_based_opt_out'] ) ) { + $new_settings['user_based_opt_out'] = $old_settings['image_captions_user_based_opt_out']; + } + + return $new_settings; + } } diff --git a/includes/Classifai/Features/ExcerptGeneration.php b/includes/Classifai/Features/ExcerptGeneration.php index 2a33db41b..edabd3366 100644 --- a/includes/Classifai/Features/ExcerptGeneration.php +++ b/includes/Classifai/Features/ExcerptGeneration.php @@ -377,4 +377,51 @@ public function sanitize_default_feature_settings( array $new_settings ): array return $new_settings; } + + /** + * Generates feature setting data required for migration from + * ClassifAI < 3.0.0 to 3.0.0 + * + * @return array + */ + public function migrate_settings() { + $old_settings = get_option( 'classifai_openai_chatgpt', array() ); + $new_settings = $this->get_default_settings(); + + if ( isset( $old_settings['enable_excerpt'] ) ) { + $new_settings['status'] = $old_settings['enable_excerpt']; + } + + if ( isset( $old_settings['length'] ) ) { + $new_settings['length'] = $old_settings['length']; + } + + $new_settings['provider'] = 'openai_chatgpt'; + + if ( isset( $old_settings['api_key'] ) ) { + $new_settings['openai_chatgpt']['api_key'] = $old_settings['api_key']; + } + + if ( isset( $old_settings['authenticated'] ) ) { + $new_settings['openai_chatgpt']['authenticated'] = $old_settings['authenticated']; + } + + if ( isset( $old_settings['generate_excerpt_prompt'] ) ) { + $new_settings['generate_excerpt_prompt'] = $old_settings['generate_excerpt_prompt']; + } + + if ( isset( $old_settings['excerpt_generation_roles'] ) ) { + $new_settings['roles'] = $old_settings['excerpt_generation_roles']; + } + + if ( isset( $old_settings['excerpt_generation_users'] ) ) { + $new_settings['users'] = $old_settings['excerpt_generation_users']; + } + + if ( isset( $old_settings['excerpt_generation_user_based_opt_out'] ) ) { + $new_settings['user_based_opt_out'] = $old_settings['excerpt_generation_user_based_opt_out']; + } + + return $new_settings; + } } diff --git a/includes/Classifai/Features/ImageCropping.php b/includes/Classifai/Features/ImageCropping.php index c50c3965e..997f13059 100644 --- a/includes/Classifai/Features/ImageCropping.php +++ b/includes/Classifai/Features/ImageCropping.php @@ -377,4 +377,47 @@ public function get_wp_filesystem() { */ return apply_filters( 'classifai_smart_crop_wp_filesystem', $this->wp_filesystem ); } + + /** + * Generates feature setting data required for migration from + * ClassifAI < 3.0.0 to 3.0.0 + * + * @return array + */ + public function migrate_settings() { + $old_settings = get_option( 'classifai_computer_vision', array() ); + $new_settings = $this->get_default_settings(); + + $new_settings['provider'] = 'ms_computer_vision'; + + if ( isset( $old_settings['enable_smart_cropping'] ) ) { + $new_settings['status'] = $old_settings['enable_smart_cropping']; + } + + if ( isset( $old_settings['url'] ) ) { + $new_settings['ms_computer_vision']['endpoint_url'] = $old_settings['url']; + } + + if ( isset( $old_settings['api_key'] ) ) { + $new_settings['ms_computer_vision']['api_key'] = $old_settings['api_key']; + } + + if ( isset( $old_settings['authenticated'] ) ) { + $new_settings['ms_computer_vision']['authenticated'] = $old_settings['authenticated']; + } + + if ( isset( $old_settings['smart_cropping_roles'] ) ) { + $new_settings['roles'] = $old_settings['smart_cropping_roles']; + } + + if ( isset( $old_settings['smart_cropping_users'] ) ) { + $new_settings['users'] = $old_settings['smart_cropping_users']; + } + + if ( isset( $old_settings['smart_cropping_user_based_opt_out'] ) ) { + $new_settings['user_based_opt_out'] = $old_settings['smart_cropping_user_based_opt_out']; + } + + return $new_settings; + } } diff --git a/includes/Classifai/Features/ImageGeneration.php b/includes/Classifai/Features/ImageGeneration.php index b617dc596..8656c1202 100644 --- a/includes/Classifai/Features/ImageGeneration.php +++ b/includes/Classifai/Features/ImageGeneration.php @@ -387,4 +387,51 @@ public function get_feature_default_settings(): array { 'provider' => DallE::ID, ]; } + + /** + * Generates feature setting data required for migration from + * ClassifAI < 3.0.0 to 3.0.0 + * + * @return array + */ + public function migrate_settings() { + $old_settings = get_option( 'classifai_openai_dalle', array() ); + $new_settings = $this->get_default_settings(); + + $new_settings['provider'] = 'openai_dalle'; + + if ( isset( $old_settings['enable_image_gen'] ) ) { + $new_settings['status'] = $old_settings['enable_image_gen']; + } + + if ( isset( $old_settings['number'] ) ) { + $new_settings['openai_dalle']['number_of_images'] = $old_settings['number']; + } + + if ( isset( $old_settings['size'] ) ) { + $new_settings['openai_dalle']['image_size'] = $old_settings['size']; + } + + if ( isset( $old_settings['api_key'] ) ) { + $new_settings['openai_dalle']['api_key'] = $old_settings['api_key']; + } + + if ( isset( $old_settings['authenticated'] ) ) { + $new_settings['openai_dalle']['authenticated'] = $old_settings['authenticated']; + } + + if ( isset( $old_settings['image_generation_roles'] ) ) { + $new_settings['roles'] = $old_settings['image_generation_roles']; + } + + if ( isset( $old_settings['image_generation_users'] ) ) { + $new_settings['users'] = $old_settings['image_generation_users']; + } + + if ( isset( $old_settings['image_generation_user_based_opt_out'] ) ) { + $new_settings['user_based_opt_out'] = $old_settings['image_generation_user_based_opt_out']; + } + + return $new_settings; + } } diff --git a/includes/Classifai/Features/ImageTagsGenerator.php b/includes/Classifai/Features/ImageTagsGenerator.php index 6a6e02ea0..eccca3fb1 100644 --- a/includes/Classifai/Features/ImageTagsGenerator.php +++ b/includes/Classifai/Features/ImageTagsGenerator.php @@ -354,4 +354,55 @@ public function sanitize_default_feature_settings( array $new_settings ): array return $new_settings; } + + /** + * Generates feature setting data required for migration from + * ClassifAI < 3.0.0 to 3.0.0 + * + * @return array + */ + public function migrate_settings() { + $old_settings = get_option( 'classifai_computer_vision', array() ); + $new_settings = $this->get_default_settings(); + + $new_settings['provider'] = 'ms_computer_vision'; + + if ( isset( $old_settings['enable_image_tagging'] ) ) { + $new_settings['status'] = $old_settings['enable_image_tagging']; + } + + if ( isset( $old_settings['url'] ) ) { + $new_settings['ms_computer_vision']['endpoint_url'] = $old_settings['url']; + } + + if ( isset( $old_settings['api_key'] ) ) { + $new_settings['ms_computer_vision']['api_key'] = $old_settings['api_key']; + } + + if ( isset( $old_settings['tag_threshold'] ) ) { + $new_settings['ms_computer_vision']['tag_confidence_threshold'] = $old_settings['tag_threshold']; + } + + if ( isset( $old_settings['authenticated'] ) ) { + $new_settings['ms_computer_vision']['authenticated'] = $old_settings['authenticated']; + } + + if ( isset( $old_settings['image_tag_taxonomy'] ) ) { + $new_settings['tag_taxonomy'] = $old_settings['image_tag_taxonomy']; + } + + if ( isset( $old_settings['image_tagging_roles'] ) ) { + $new_settings['roles'] = $old_settings['image_tagging_roles']; + } + + if ( isset( $old_settings['image_tagging_users'] ) ) { + $new_settings['users'] = $old_settings['image_tagging_users']; + } + + if ( isset( $old_settings['image_tagging_user_based_opt_out'] ) ) { + $new_settings['user_based_opt_out'] = $old_settings['image_tagging_user_based_opt_out']; + } + + return $new_settings; + } } diff --git a/includes/Classifai/Features/ImageTextExtraction.php b/includes/Classifai/Features/ImageTextExtraction.php index d8dafd3cd..7e0a40673 100644 --- a/includes/Classifai/Features/ImageTextExtraction.php +++ b/includes/Classifai/Features/ImageTextExtraction.php @@ -406,4 +406,47 @@ public function get_feature_default_settings(): array { 'provider' => ComputerVision::ID, ]; } + + /** + * Generates feature setting data required for migration from + * ClassifAI < 3.0.0 to 3.0.0 + * + * @return array + */ + public function migrate_settings() { + $old_settings = get_option( 'classifai_computer_vision', array() ); + $new_settings = $this->get_default_settings(); + + $new_settings['provider'] = 'ms_computer_vision'; + + if ( isset( $old_settings['enable_smart_cropping'] ) ) { + $new_settings['status'] = $old_settings['enable_smart_cropping']; + } + + if ( isset( $old_settings['url'] ) ) { + $new_settings['ms_computer_vision']['endpoint_url'] = $old_settings['url']; + } + + if ( isset( $old_settings['api_key'] ) ) { + $new_settings['ms_computer_vision']['api_key'] = $old_settings['api_key']; + } + + if ( isset( $old_settings['authenticated'] ) ) { + $new_settings['ms_computer_vision']['authenticated'] = $old_settings['authenticated']; + } + + if ( isset( $old_settings['ocr_roles'] ) ) { + $new_settings['roles'] = $old_settings['ocr_roles']; + } + + if ( isset( $old_settings['ocr_users'] ) ) { + $new_settings['users'] = $old_settings['ocr_users']; + } + + if ( isset( $old_settings['ocr_user_based_opt_out'] ) ) { + $new_settings['user_based_opt_out'] = $old_settings['ocr_user_based_opt_out']; + } + + return $new_settings; + } } diff --git a/includes/Classifai/Features/PDFTextExtraction.php b/includes/Classifai/Features/PDFTextExtraction.php index d3637c410..a4a6531a5 100644 --- a/includes/Classifai/Features/PDFTextExtraction.php +++ b/includes/Classifai/Features/PDFTextExtraction.php @@ -272,4 +272,47 @@ public function get_feature_default_settings(): array { 'provider' => ComputerVision::ID, ]; } + + /** + * Generates feature setting data required for migration from + * ClassifAI < 3.0.0 to 3.0.0 + * + * @return array + */ + public function migrate_settings() { + $old_settings = get_option( 'classifai_computer_vision', array() ); + $new_settings = $this->get_default_settings(); + + $new_settings['provider'] = 'ms_computer_vision'; + + if ( isset( $old_settings['enable_read_pdf'] ) ) { + $new_settings['status'] = $old_settings['enable_read_pdf']; + } + + if ( isset( $old_settings['url'] ) ) { + $new_settings['ms_computer_vision']['endpoint_url'] = $old_settings['url']; + } + + if ( isset( $old_settings['api_key'] ) ) { + $new_settings['ms_computer_vision']['api_key'] = $old_settings['api_key']; + } + + if ( isset( $old_settings['authenticated'] ) ) { + $new_settings['ms_computer_vision']['authenticated'] = $old_settings['authenticated']; + } + + if ( isset( $old_settings['read_pdf_roles'] ) ) { + $new_settings['roles'] = $old_settings['read_pdf_roles']; + } + + if ( isset( $old_settings['read_pdf_users'] ) ) { + $new_settings['users'] = $old_settings['read_pdf_users']; + } + + if ( isset( $old_settings['read_pdf_user_based_opt_out'] ) ) { + $new_settings['user_based_opt_out'] = $old_settings['read_pdf_user_based_opt_out']; + } + + return $new_settings; + } } diff --git a/includes/Classifai/Features/RecommendedContent.php b/includes/Classifai/Features/RecommendedContent.php index 9cb123f0f..f582ba650 100644 --- a/includes/Classifai/Features/RecommendedContent.php +++ b/includes/Classifai/Features/RecommendedContent.php @@ -71,4 +71,47 @@ public function run( ...$args ) { ); } } + + /** + * Generates feature setting data required for migration from + * ClassifAI < 3.0.0 to 3.0.0 + * + * @return array + */ + public function migrate_settings() { + $old_settings = get_option( 'classifai_personalizer', array() ); + $new_settings = $this->get_default_settings(); + + if ( isset( $old_settings['enable_recommended_content'] ) ) { + $new_settings['status'] = $old_settings['enable_recommended_content']; + } + + $new_settings['provider'] = PersonalizerProvider::ID; + + if ( isset( $old_settings['url'] ) ) { + $new_settings[ PersonalizerProvider::ID ]['endpoint_url'] = $old_settings['url']; + } + + if ( isset( $old_settings['api_key'] ) ) { + $new_settings[ PersonalizerProvider::ID ]['api_key'] = $old_settings['api_key']; + } + + if ( isset( $old_settings['authenticated'] ) ) { + $new_settings[ PersonalizerProvider::ID ]['authenticated'] = $old_settings['authenticated']; + } + + if ( isset( $old_settings['recommended_content_roles'] ) ) { + $new_settings['roles'] = $old_settings['recommended_content_roles']; + } + + if ( isset( $old_settings['recommended_content_users'] ) ) { + $new_settings['users'] = $old_settings['recommended_content_users']; + } + + if ( isset( $old_settings['recommended_content_user_based_opt_out'] ) ) { + $new_settings['user_based_opt_out'] = $old_settings['recommended_content_user_based_opt_out']; + } + + return $new_settings; + } } diff --git a/includes/Classifai/Features/TextToSpeech.php b/includes/Classifai/Features/TextToSpeech.php index 8deda3892..bd530006c 100644 --- a/includes/Classifai/Features/TextToSpeech.php +++ b/includes/Classifai/Features/TextToSpeech.php @@ -799,4 +799,59 @@ public function get_audio_generation_subsequent_state( $post = null ): bool { */ return apply_filters( 'classifai_audio_generation_subsequent_state', false, get_post( $post ) ); } + + /** + * Generates feature setting data required for migration from + * ClassifAI < 3.0.0 to 3.0.0 + * + * @return array + */ + public function migrate_settings() { + $old_settings = get_option( 'classifai_azure_text_to_speech', array() ); + $new_settings = $this->get_default_settings(); + + if ( isset( $old_settings['enable_text_to_speech'] ) ) { + $new_settings['status'] = $old_settings['enable_text_to_speech']; + } + + $new_settings['provider'] = 'ms_azure_text_to_speech'; + + if ( isset( $old_settings['credentials']['url'] ) ) { + $new_settings['ms_azure_text_to_speech']['endpoint_url'] = $old_settings['credentials']['url']; + } + + if ( isset( $old_settings['credentials']['api_key'] ) ) { + $new_settings['ms_azure_text_to_speech']['api_key'] = $old_settings['credentials']['api_key']; + } + + if ( isset( $old_settings['authenticated'] ) ) { + $new_settings['ms_azure_text_to_speech']['authenticated'] = $old_settings['authenticated']; + } + + if ( isset( $old_settings['voices'] ) ) { + $new_settings['ms_azure_text_to_speech']['voices'] = $old_settings['voices']; + } + + if ( isset( $old_settings['voice'] ) ) { + $new_settings['ms_azure_text_to_speech']['voice'] = $old_settings['voice']; + } + + if ( isset( $old_settings['text_to_speech_users'] ) ) { + $new_settings['users'] = $old_settings['text_to_speech_users']; + } + + if ( isset( $old_settings['text_to_speech_roles'] ) ) { + $new_settings['roles'] = $old_settings['text_to_speech_roles']; + } + + if ( isset( $old_settings['text_to_speech_user_based_opt_out'] ) ) { + $new_settings['user_based_opt_out'] = $old_settings['text_to_speech_user_based_opt_out']; + } + + if ( isset( $old_settings['post_types'] ) ) { + $new_settings['post_types'] = $old_settings['post_types']; + } + + return $new_settings; + } } diff --git a/includes/Classifai/Features/TitleGeneration.php b/includes/Classifai/Features/TitleGeneration.php index 3ceb9a1a7..be6646471 100644 --- a/includes/Classifai/Features/TitleGeneration.php +++ b/includes/Classifai/Features/TitleGeneration.php @@ -362,4 +362,51 @@ public function sanitize_default_feature_settings( array $new_settings ): array return $new_settings; } + + /** + * Generates feature setting data required for migration from + * ClassifAI < 3.0.0 to 3.0.0 + * + * @return array + */ + public function migrate_settings() { + $old_settings = get_option( 'classifai_openai_chatgpt', array() ); + $new_settings = $this->get_default_settings(); + + if ( isset( $old_settings['enable_titles'] ) ) { + $new_settings['status'] = $old_settings['enable_titles']; + } + + $new_settings['provider'] = 'openai_chatgpt'; + + if ( isset( $old_settings['api_key'] ) ) { + $new_settings['openai_chatgpt']['api_key'] = $old_settings['api_key']; + } + + if ( isset( $old_settings['authenticated'] ) ) { + $new_settings['openai_chatgpt']['authenticated'] = $old_settings['authenticated']; + } + + if ( isset( $old_settings['number_titles'] ) ) { + $new_settings['openai_chatgpt']['number_of_suggestions'] = $old_settings['number_titles']; + } + + if ( isset( $old_settings['generate_title_prompt'] ) ) { + $new_settings['generate_title_prompt'] = $old_settings['generate_title_prompt']; + } + + if ( isset( $old_settings['title_generation_roles'] ) ) { + $new_settings['roles'] = $old_settings['title_generation_roles']; + } + + if ( isset( $old_settings['title_generation_users'] ) ) { + $new_settings['users'] = $old_settings['title_generation_users']; + } + + if ( isset( $old_settings['title_generation_user_based_opt_out'] ) ) { + $new_settings['user_based_opt_out'] = $old_settings['title_generation_user_based_opt_out']; + } + + return $new_settings; + } } diff --git a/includes/Classifai/Plugin.php b/includes/Classifai/Plugin.php index 0615b60f7..1cfd79caf 100644 --- a/includes/Classifai/Plugin.php +++ b/includes/Classifai/Plugin.php @@ -37,6 +37,7 @@ public function enable() { add_action( 'init', [ $this, 'i18n' ] ); add_action( 'admin_init', [ $this, 'init_admin_helpers' ] ); add_action( 'admin_init', [ $this, 'add_privacy_policy_content' ] ); + add_action( 'admin_init', [ $this, 'maybe_migrate_to_v3' ] ); add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_assets' ] ); add_filter( 'plugin_action_links_' . CLASSIFAI_PLUGIN_BASENAME, array( $this, 'filter_plugin_action_links' ) ); } @@ -232,4 +233,84 @@ public function filter_plugin_action_links( $links ): array { $links ); } + + /** + * Migrate the existing settings to v3 if necessary. + * + * @since 3.0.0 + */ + public function maybe_migrate_to_v3() { + $is_migrated = get_option( 'classifai_v3_migration_completed', false ); + + if ( false !== $is_migrated ) { + // Already migrated. + return; + } + + $features = array(); + + // Get the existing settings. + $nlu_settings = get_option( 'classifai_watson_nlu', [] ); + $embeddings_settings = get_option( 'classifai_openai_embeddings', [] ); + $whisper_settings = get_option( 'classifai_openai_whisper', [] ); + $chatgpt_settings = get_option( 'classifai_openai_chatgpt', [] ); + $tts_settings = get_option( 'classifai_azure_text_to_speech', [] ); + $vision_settings = get_option( 'classifai_computer_vision', [] ); + $dalle_settings = get_option( 'classifai_openai_dalle', [] ); + $personalizer_settings = get_option( 'classifai_personalizer', [] ); + + // If settings are there, migrate them. + if ( ! empty( $nlu_settings ) || ! empty( $embeddings_settings ) ) { + $features[] = \Classifai\Features\Classification::class; + } + + if ( ! empty( $whisper_settings ) ) { + $features[] = \Classifai\Features\AudioTranscriptsGeneration::class; + } + + if ( ! empty( $chatgpt_settings ) ) { + $features[] = \Classifai\Features\TitleGeneration::class; + $features[] = \Classifai\Features\ExcerptGeneration::class; + $features[] = \Classifai\Features\ContentResizing::class; + } + + if ( ! empty( $tts_settings ) ) { + $features[] = \Classifai\Features\TextToSpeech::class; + } + + if ( ! empty( $vision_settings ) ) { + $features[] = \Classifai\Features\DescriptiveTextGenerator::class; + $features[] = \Classifai\Features\ImageTagsGenerator::class; + $features[] = \Classifai\Features\ImageCropping::class; + $features[] = \Classifai\Features\ImageTextExtraction::class; + $features[] = \Classifai\Features\PDFTextExtraction::class; + } + + if ( ! empty( $dalle_settings ) ) { + $features[] = \Classifai\Features\ImageGeneration::class; + } + + if ( ! empty( $personalizer_settings ) ) { + $features[] = \Classifai\Features\RecommendedContent::class; + } + + // Migrate settings. + $migration_needed = ! empty( $features ); + foreach ( $features as $feature ) { + $feature_instance = new $feature(); + $feature_id = $feature_instance->get_option_name(); + + if ( method_exists( $feature_instance, 'migrate_settings' ) ) { + $migrated_settings = $feature_instance->migrate_settings(); + update_option( $feature_id, $migrated_settings ); + } + } + + // Mark the migration as completed. + update_option( 'classifai_v3_migration_completed', true, false ); + if ( $migration_needed ) { + // This option will be used to display a notice only to users who have completed the migration process. This will help to avoid showing the notice to new users. + update_option( 'classifai_display_v3_migration_notice', true, false ); + } + } }