From 122313370d4553eeffc670d0552d42f5472fa538 Mon Sep 17 00:00:00 2001 From: Siddharth Thevaril Date: Mon, 12 Feb 2024 15:33:58 +0530 Subject: [PATCH 01/20] add migration script for few features --- .../Features/AudioTranscriptsGeneration.php | 39 +++++++ .../Classifai/Features/Classification.php | 105 ++++++++++++++++++ .../Classifai/Features/ContentResizing.php | 51 +++++++++ .../Classifai/Features/ExcerptGeneration.php | 47 ++++++++ includes/Classifai/Features/TextToSpeech.php | 55 +++++++++ .../Classifai/Features/TitleGeneration.php | 47 ++++++++ 6 files changed, 344 insertions(+) diff --git a/includes/Classifai/Features/AudioTranscriptsGeneration.php b/includes/Classifai/Features/AudioTranscriptsGeneration.php index a37e723e0..13a4b6d54 100644 --- a/includes/Classifai/Features/AudioTranscriptsGeneration.php +++ b/includes/Classifai/Features/AudioTranscriptsGeneration.php @@ -347,4 +347,43 @@ public function add_transcription( string $text = '', int $attachment_id = 0 ) { return $text; } } + + /** + * 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_whisper', array() ); + $new_settings = $this->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 f26d161e8..1f288d896 100644 --- a/includes/Classifai/Features/Classification.php +++ b/includes/Classifai/Features/Classification.php @@ -154,4 +154,109 @@ public function run( ...$args ) { $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_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['users'] ) ) { + $new_settings['users'] = $old_settings['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['ibm_watson_nlu']['classification_mode'] = $old_settings['classification_mode']; + } + + if ( isset( $old_settings['classification_method'] ) ) { + $new_settings['ibm_watson_nlu']['classification_method'] = $old_settings['classification_method']; + } + + if ( isset( $old_settings['features'] ) ) { + foreach ( $old_settings['features'] as $feature => $value ) { + $new_settings['ibm_watson_nlu'][ $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']; + } + + if ( isset( $old_settings['content_classification_users'] ) ) { + $new_settings['users'] = $old_settings['content_classification_users']; + } + } + + return $new_settings; + } } diff --git a/includes/Classifai/Features/ContentResizing.php b/includes/Classifai/Features/ContentResizing.php index ed0e5303a..3eda55bfb 100644 --- a/includes/Classifai/Features/ContentResizing.php +++ b/includes/Classifai/Features/ContentResizing.php @@ -320,4 +320,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 = array(); + + 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['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/ExcerptGeneration.php b/includes/Classifai/Features/ExcerptGeneration.php index 2add6f960..57d0befa1 100644 --- a/includes/Classifai/Features/ExcerptGeneration.php +++ b/includes/Classifai/Features/ExcerptGeneration.php @@ -373,4 +373,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 = array(); + + 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/TextToSpeech.php b/includes/Classifai/Features/TextToSpeech.php index d0fdcf779..5dd5ab421 100644 --- a/includes/Classifai/Features/TextToSpeech.php +++ b/includes/Classifai/Features/TextToSpeech.php @@ -817,4 +817,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 = array(); + + 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 b43a3ccf8..6c1703054 100644 --- a/includes/Classifai/Features/TitleGeneration.php +++ b/includes/Classifai/Features/TitleGeneration.php @@ -379,4 +379,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 = array(); + + 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['number_of_titles'] = $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; + } } From 76bb7aa301e31aa3d9230e25607577cfc9a9f4a6 Mon Sep 17 00:00:00 2001 From: Siddharth Thevaril Date: Mon, 12 Feb 2024 18:12:55 +0530 Subject: [PATCH 02/20] add remaining migration code --- .../Features/DescriptiveTextGenerator.php | 54 +++++++++++++++++++ includes/Classifai/Features/ImageCropping.php | 43 +++++++++++++++ .../Classifai/Features/ImageGeneration.php | 47 ++++++++++++++++ .../Classifai/Features/ImageTagsGenerator.php | 51 ++++++++++++++++++ .../Features/ImageTextExtraction.php | 43 +++++++++++++++ .../Classifai/Features/PDFTextExtraction.php | 43 +++++++++++++++ 6 files changed, 281 insertions(+) diff --git a/includes/Classifai/Features/DescriptiveTextGenerator.php b/includes/Classifai/Features/DescriptiveTextGenerator.php index b21e04597..bdd12ec7e 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 = array(); + + $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/ImageCropping.php b/includes/Classifai/Features/ImageCropping.php index c50c3965e..55759ec1c 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 = array(); + + $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 a55f39870..f577ef534 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 = array(); + + $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..c13afdbc6 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 = array(); + + $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..0e59a421d 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 = array(); + + $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 066b974f2..682123514 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 = array(); + + $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['ocr_user_based_opt_out'] ) ) { + $new_settings['user_based_opt_out'] = $old_settings['ocr_user_based_opt_out']; + } + + return $new_settings; + } } From 7241b02395eeb781ba5066e360ba4c40b91b30be Mon Sep 17 00:00:00 2001 From: Siddharth Thevaril Date: Mon, 12 Feb 2024 18:54:41 +0530 Subject: [PATCH 03/20] add server-side logic to migrate settings --- includes/Classifai/Features/Feature.php | 45 +++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/includes/Classifai/Features/Feature.php b/includes/Classifai/Features/Feature.php index 74b3d76da..797117ce8 100644 --- a/includes/Classifai/Features/Feature.php +++ b/includes/Classifai/Features/Feature.php @@ -1207,4 +1207,49 @@ public function run( ...$args ) { $this ); } + + /** + * Migrates the settings from ClassifAI < 3.0.0 to higher versions of ClassifAI. + */ + public function migrate_settings_to_v3() { + $features = array( + // Language processing features. + Classification::class, + TitleGeneration::class, + ExcerptGeneration::class, + ContentResizing::class, + TextToSpeech::class, + AudioTranscriptsGeneration::class, + + // Image processing features. + DescriptiveTextGenerator::class, + ImageTagsGenerator::class, + ImageCropping::class, + ImageTextExtraction::class, + ImageGeneration::class, + PDFTextExtraction::class, + ); + + $records = get_option( 'classifai_migration_records', array() ); + + foreach ( $features as $feature ) { + $feature_instance = new $feature(); + $feature_id = $feature_instance->get_option_name(); + + if ( isset( $records[ $feature_id ] ) && $records[ $feature_id ] ) { + continue; + } + + if ( method_exists( $feature_instance, 'migrate_settings' ) ) { + $migrated_settings = $feature_instance->migrate_settings(); + $has_updated = update_option( $feature_id, $migrated_settings ); + + if ( $has_updated ) { + $records[ $feature_id ] = true; + } + } + } + + update_option( 'classifai_migration_records', $records ); + } } From e5f35cd5ec5b7a9ecd0ed2edde10e6c6a1a01904 Mon Sep 17 00:00:00 2001 From: Siddharth Thevaril Date: Mon, 19 Feb 2024 20:10:52 +0530 Subject: [PATCH 04/20] add migration routine --- includes/Classifai/Admin/Notifications.php | 82 ++++++++++++++++++++++ includes/Classifai/Features/Feature.php | 45 ------------ includes/Classifai/Plugin.php | 2 + src/js/admin.js | 48 +++++++++++++ 4 files changed, 132 insertions(+), 45 deletions(-) diff --git a/includes/Classifai/Admin/Notifications.php b/includes/Classifai/Admin/Notifications.php index 75a5292bf..b15526c82 100644 --- a/includes/Classifai/Admin/Notifications.php +++ b/includes/Classifai/Admin/Notifications.php @@ -27,8 +27,10 @@ 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_notice' ] ); add_action( 'admin_enqueue_scripts', [ $this, 'add_dismiss_script' ] ); add_action( 'wp_ajax_classifai_dismiss_notice', [ $this, 'ajax_maybe_dismiss_notice' ] ); + add_action( 'wp_ajax_v3_migration_script', [ $this, 'v3_migration_script' ] ); } /** @@ -212,4 +214,84 @@ public function thresholds_update_notice() { get_option_name(); + + if ( method_exists( $feature_instance, 'migrate_settings' ) ) { + $migrated_settings = $feature_instance->migrate_settings(); + update_option( $feature_id, $migrated_settings ); + } + } + + update_option( 'classifai-v3-migration-status', true ); + wp_send_json_success( esc_html__( 'V3 migration completed', 'classifai' ) ); + } + + /** + * Displays the migration notice for feature-first refactor + * of the settings. + */ + public function v3_migration_notice() { + $show_notice = get_option( 'classifai-v3-migration-status', false ); + + if ( ! $show_notice ) : + ?> +
+

+ +

+

+ +   + +

+
+ get_option_name(); - - if ( isset( $records[ $feature_id ] ) && $records[ $feature_id ] ) { - continue; - } - - if ( method_exists( $feature_instance, 'migrate_settings' ) ) { - $migrated_settings = $feature_instance->migrate_settings(); - $has_updated = update_option( $feature_id, $migrated_settings ); - - if ( $has_updated ) { - $records[ $feature_id ] = true; - } - } - } - - update_option( 'classifai_migration_records', $records ); - } } diff --git a/includes/Classifai/Plugin.php b/includes/Classifai/Plugin.php index 0615b60f7..e9431b2d1 100644 --- a/includes/Classifai/Plugin.php +++ b/includes/Classifai/Plugin.php @@ -185,6 +185,8 @@ public function enqueue_admin_assets() { 'ajax_nonce' => wp_create_nonce( 'classifai' ), 'opt_out_enabled_features' => array_keys( $allowed_features ), 'profile_url' => esc_url( get_edit_profile_url( get_current_user_id() ) . '#classifai-profile-features-section' ), + 'migrating_progress' => esc_html__( 'Migrating...', 'classifai' ), + 'migration_complete' => esc_html__( 'Migration complete.', 'classifai' ), ]; wp_localize_script( diff --git a/src/js/admin.js b/src/js/admin.js index 158af6ba0..ee2b3e362 100644 --- a/src/js/admin.js +++ b/src/js/admin.js @@ -368,3 +368,51 @@ document.addEventListener( 'DOMContentLoaded', function () { providerSelectEl.trigger( 'change' ); } ); } )( jQuery ); + + +/** + * Feature-first migration routine: + * @param {Object} $ jQuery object + */ +( function ( $ ) { + const noticeWrapper = $( '.classifai-migation-notice' ); + const migrateSettingsBtn = $( '#classifai-migrate-settings' ); + const skipMigrationBtn = $( '#classifai-skip-migration-settings' ); + + skipMigrationBtn.on( 'click', function ( e ) { + $.ajax( + ajaxurl, + { + type: 'POST', + data: { + action: 'v3_migration_script', + routine: 'skip', + nonce: ClassifAI.ajax_nonce, + }, + } + ).done( function () { + noticeWrapper.slideUp(); + } ); + } ); + + migrateSettingsBtn.on( 'click', function ( e ) { + const ogText = migrateSettingsBtn.text(); + skipMigrationBtn.hide(); + migrateSettingsBtn.text( ClassifAI.migrating_progress ); + + $.ajax( + ajaxurl, + { + type: 'POST', + data: { + action: 'v3_migration_script', + routine: 'migrate', + nonce: ClassifAI.ajax_nonce, + }, + } + ).done( function () { + migrateSettingsBtn.text( ogText ); + noticeWrapper.html( `

${ClassifAI.migration_complete}

` ); + } ); + } ); +} )( jQuery ); \ No newline at end of file From 210217927a29ca6c8c2e24808feb69c517e6ac5d Mon Sep 17 00:00:00 2001 From: Siddharth Thevaril Date: Mon, 19 Feb 2024 20:30:45 +0530 Subject: [PATCH 05/20] wrap up remaining Classification feature settings --- .../Classifai/Features/Classification.php | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/includes/Classifai/Features/Classification.php b/includes/Classifai/Features/Classification.php index 1f288d896..ed1a8f047 100644 --- a/includes/Classifai/Features/Classification.php +++ b/includes/Classifai/Features/Classification.php @@ -163,7 +163,7 @@ public function run( ...$args ) { */ public function migrate_settings() { $old_settings = get_option( 'classifai_watson_nlu', array() ); - $new_settings = $this->get_settings(); + $new_settings = array();; if ( isset( $old_settings['authenticated'] ) && $old_settings['authenticated'] ) { $new_settings['provider'] = 'ibm_watson_nlu'; @@ -255,6 +255,54 @@ public function migrate_settings() { if ( isset( $old_settings['content_classification_users'] ) ) { $new_settings['users'] = $old_settings['content_classification_users']; } + } else { + $old_settings = get_option( 'classifai_openai_whisper', 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['number'] ) ) { + $new_settings['openai_embeddings']['number_of_terms'] = $old_settings['number']; + } + + if ( isset( $old_settings['number'] ) ) { + $new_settings['openai_embeddings']['number_of_terms'] = $old_settings['number']; + } + + if ( isset( $old_settings['taxonomies'] ) ) { + $new_settings['openai_embeddings']['taxonomies'] = $old_settings['taxonomies']; + } + + 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; From 6885c569ef4c41ce0cf0424abd443957f4c6c5aa Mon Sep 17 00:00:00 2001 From: Siddharth Thevaril Date: Mon, 19 Feb 2024 21:25:32 +0530 Subject: [PATCH 06/20] disable migration button during migration --- src/js/admin.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/js/admin.js b/src/js/admin.js index ee2b3e362..7c7869178 100644 --- a/src/js/admin.js +++ b/src/js/admin.js @@ -399,6 +399,7 @@ document.addEventListener( 'DOMContentLoaded', function () { const ogText = migrateSettingsBtn.text(); skipMigrationBtn.hide(); migrateSettingsBtn.text( ClassifAI.migrating_progress ); + migrateSettingsBtn.prop( 'disabled', true ); $.ajax( ajaxurl, @@ -413,6 +414,7 @@ document.addEventListener( 'DOMContentLoaded', function () { ).done( function () { migrateSettingsBtn.text( ogText ); noticeWrapper.html( `

${ClassifAI.migration_complete}

` ); + window.location.reload(); } ); } ); } )( jQuery ); \ No newline at end of file From 8a9eeb68cbcb0215175f3e7aeb0d300c4fe77361 Mon Sep 17 00:00:00 2001 From: Siddharth Thevaril Date: Mon, 19 Feb 2024 21:27:49 +0530 Subject: [PATCH 07/20] js lint fixes --- src/js/admin.js | 47 ++++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/src/js/admin.js b/src/js/admin.js index 7c7869178..9dc275565 100644 --- a/src/js/admin.js +++ b/src/js/admin.js @@ -369,7 +369,6 @@ document.addEventListener( 'DOMContentLoaded', function () { } ); } )( jQuery ); - /** * Feature-first migration routine: * @param {Object} $ jQuery object @@ -379,42 +378,36 @@ document.addEventListener( 'DOMContentLoaded', function () { const migrateSettingsBtn = $( '#classifai-migrate-settings' ); const skipMigrationBtn = $( '#classifai-skip-migration-settings' ); - skipMigrationBtn.on( 'click', function ( e ) { - $.ajax( - ajaxurl, - { - type: 'POST', - data: { - action: 'v3_migration_script', - routine: 'skip', - nonce: ClassifAI.ajax_nonce, - }, - } - ).done( function () { + skipMigrationBtn.on( 'click', function () { + $.ajax( ajaxurl, { + type: 'POST', + data: { + action: 'v3_migration_script', + routine: 'skip', + nonce: ClassifAI.ajax_nonce, + }, + } ).done( function () { noticeWrapper.slideUp(); } ); } ); - migrateSettingsBtn.on( 'click', function ( e ) { + migrateSettingsBtn.on( 'click', function () { const ogText = migrateSettingsBtn.text(); skipMigrationBtn.hide(); migrateSettingsBtn.text( ClassifAI.migrating_progress ); migrateSettingsBtn.prop( 'disabled', true ); - $.ajax( - ajaxurl, - { - type: 'POST', - data: { - action: 'v3_migration_script', - routine: 'migrate', - nonce: ClassifAI.ajax_nonce, - }, - } - ).done( function () { + $.ajax( ajaxurl, { + type: 'POST', + data: { + action: 'v3_migration_script', + routine: 'migrate', + nonce: ClassifAI.ajax_nonce, + }, + } ).done( function () { migrateSettingsBtn.text( ogText ); - noticeWrapper.html( `

${ClassifAI.migration_complete}

` ); + noticeWrapper.html( `

${ ClassifAI.migration_complete }

` ); window.location.reload(); } ); } ); -} )( jQuery ); \ No newline at end of file +} )( jQuery ); From 6c26aeca43a14ea161a82746267ae47ee2b05742 Mon Sep 17 00:00:00 2001 From: Siddharth Thevaril Date: Mon, 19 Feb 2024 21:28:54 +0530 Subject: [PATCH 08/20] fix phpcs fixes --- includes/Classifai/Features/Classification.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Classifai/Features/Classification.php b/includes/Classifai/Features/Classification.php index ed1a8f047..b7b2b39cf 100644 --- a/includes/Classifai/Features/Classification.php +++ b/includes/Classifai/Features/Classification.php @@ -163,7 +163,7 @@ public function run( ...$args ) { */ public function migrate_settings() { $old_settings = get_option( 'classifai_watson_nlu', array() ); - $new_settings = array();; + $new_settings = array(); if ( isset( $old_settings['authenticated'] ) && $old_settings['authenticated'] ) { $new_settings['provider'] = 'ibm_watson_nlu'; From 3d9602c06c221eb7731d1ada1400fa7a7653de21 Mon Sep 17 00:00:00 2001 From: Siddharth Thevaril Date: Mon, 19 Feb 2024 23:15:46 +0530 Subject: [PATCH 09/20] add deletion logic --- includes/Classifai/Admin/Notifications.php | 26 +++++++++++++++-- .../Classifai/Features/Classification.php | 2 +- includes/Classifai/Plugin.php | 3 +- src/js/admin.js | 28 +++++++++++++++---- 4 files changed, 47 insertions(+), 12 deletions(-) diff --git a/includes/Classifai/Admin/Notifications.php b/includes/Classifai/Admin/Notifications.php index b15526c82..d1d1c01c6 100644 --- a/includes/Classifai/Admin/Notifications.php +++ b/includes/Classifai/Admin/Notifications.php @@ -231,6 +231,25 @@ public function v3_migration_script() { wp_send_json_error( esc_html__( 'Migration routine empty.', 'classifai' ) ); } + if ( 'delete_old' === $routine ) { + $old_settings = array( + 'classifai_watson_nlu', + 'classifai_openai_whisper', + 'classifai_openai_chatgpt', + 'classifai_openai_embeddings', + 'classifai_azure_text_to_speech', + 'classifai_openai_whisper', + 'classifai_computer_vision', + 'classifai_openai_dalle', + ); + + foreach ( $old_settings as $old_setting ) { + delete_option( $old_setting ); + } + + wp_send_json_success( esc_html__( 'Old settings deleted.', 'classifai' ) ); + } + if ( 'skip' === $routine ) { update_option( 'classifai-v3-migration-status', true ); wp_send_json_success( esc_html__( 'V3 migration skipped.', 'classifai' ) ); @@ -269,7 +288,7 @@ public function v3_migration_script() { } update_option( 'classifai-v3-migration-status', true ); - wp_send_json_success( esc_html__( 'V3 migration completed', 'classifai' ) ); + wp_send_json_success( esc_html__( 'Migration completed', 'classifai' ) ); } /** @@ -282,11 +301,12 @@ public function v3_migration_notice() { if ( ! $show_notice ) : ?>
-

- +

+

+  

diff --git a/includes/Classifai/Features/Classification.php b/includes/Classifai/Features/Classification.php index b7b2b39cf..d5ae3ddda 100644 --- a/includes/Classifai/Features/Classification.php +++ b/includes/Classifai/Features/Classification.php @@ -256,7 +256,7 @@ public function migrate_settings() { $new_settings['users'] = $old_settings['content_classification_users']; } } else { - $old_settings = get_option( 'classifai_openai_whisper', array() ); + $old_settings = get_option( 'classifai_openai_embeddings', array() ); if ( isset( $old_settings['enable_classification'] ) ) { $new_settings['status'] = $old_settings['enable_classification']; diff --git a/includes/Classifai/Plugin.php b/includes/Classifai/Plugin.php index e9431b2d1..09b84c5ae 100644 --- a/includes/Classifai/Plugin.php +++ b/includes/Classifai/Plugin.php @@ -185,8 +185,7 @@ public function enqueue_admin_assets() { 'ajax_nonce' => wp_create_nonce( 'classifai' ), 'opt_out_enabled_features' => array_keys( $allowed_features ), 'profile_url' => esc_url( get_edit_profile_url( get_current_user_id() ) . '#classifai-profile-features-section' ), - 'migrating_progress' => esc_html__( 'Migrating...', 'classifai' ), - 'migration_complete' => esc_html__( 'Migration complete.', 'classifai' ), + 'migration_progress' => esc_html__( 'Migrating...', 'classifai' ), ]; wp_localize_script( diff --git a/src/js/admin.js b/src/js/admin.js index 9dc275565..75fe8d5d2 100644 --- a/src/js/admin.js +++ b/src/js/admin.js @@ -376,6 +376,8 @@ document.addEventListener( 'DOMContentLoaded', function () { ( function ( $ ) { const noticeWrapper = $( '.classifai-migation-notice' ); const migrateSettingsBtn = $( '#classifai-migrate-settings' ); + const deleteOldSettings = $( '#classifai-delete-pre-v3-settings' ); + const interactiveTxt = $( '#classifai-migation-notice__interactive' ); const skipMigrationBtn = $( '#classifai-skip-migration-settings' ); skipMigrationBtn.on( 'click', function () { @@ -392,9 +394,8 @@ document.addEventListener( 'DOMContentLoaded', function () { } ); migrateSettingsBtn.on( 'click', function () { - const ogText = migrateSettingsBtn.text(); skipMigrationBtn.hide(); - migrateSettingsBtn.text( ClassifAI.migrating_progress ); + migrateSettingsBtn.text( ClassifAI.migration_progress ); migrateSettingsBtn.prop( 'disabled', true ); $.ajax( ajaxurl, { @@ -404,10 +405,25 @@ document.addEventListener( 'DOMContentLoaded', function () { routine: 'migrate', nonce: ClassifAI.ajax_nonce, }, - } ).done( function () { - migrateSettingsBtn.text( ogText ); - noticeWrapper.html( `

${ ClassifAI.migration_complete }

` ); - window.location.reload(); + } ).done( function ( response ) { + migrateSettingsBtn.hide(); + interactiveTxt.text( response.data ); + deleteOldSettings.show(); + } ); + } ); + + deleteOldSettings.on( 'click', function () { + deleteOldSettings.prop( 'disabled', true ); + + $.ajax( ajaxurl, { + type: 'POST', + data: { + action: 'v3_migration_script', + routine: 'delete_old', + nonce: ClassifAI.ajax_nonce, + }, + } ).done( function ( response ) { + noticeWrapper.html( `

${ response.data }

` ); } ); } ); } )( jQuery ); From b9def9dfce2a65c9f8faca39f354974787dfde7e Mon Sep 17 00:00:00 2001 From: Dharmesh Patel Date: Wed, 21 Feb 2024 16:02:41 +0530 Subject: [PATCH 10/20] Make migration routine run automatically. --- includes/Classifai/Plugin.php | 77 +++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/includes/Classifai/Plugin.php b/includes/Classifai/Plugin.php index 09b84c5ae..c784b8009 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' ) ); } @@ -233,4 +234,80 @@ 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', [] ); + + + // 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; + } + + // 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 ); + if ( $migration_needed ) { + // Display a notice to the users to inform them about the migration and new features. + update_option( 'classifai_display_v3_migration_notice', true ); + } + } } From 230a19538494398ef29c3e21dba882586e087794 Mon Sep 17 00:00:00 2001 From: Dharmesh Patel Date: Wed, 21 Feb 2024 16:35:09 +0530 Subject: [PATCH 11/20] Display migration completed notice. --- includes/Classifai/Admin/Notifications.php | 127 ++++++--------------- includes/Classifai/Plugin.php | 2 +- 2 files changed, 33 insertions(+), 96 deletions(-) diff --git a/includes/Classifai/Admin/Notifications.php b/includes/Classifai/Admin/Notifications.php index d1d1c01c6..b7a9a7daa 100644 --- a/includes/Classifai/Admin/Notifications.php +++ b/includes/Classifai/Admin/Notifications.php @@ -27,10 +27,9 @@ 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_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' ] ); - add_action( 'wp_ajax_v3_migration_script', [ $this, 'v3_migration_script' ] ); } /** @@ -216,102 +215,40 @@ public function thresholds_update_notice() { } /** - * Runs the feature-first migration routine. + * Displays the migration completed notice for feature-first refactor + * of the settings. + * + * @since 3.0.0 */ - public function v3_migration_script() { - $routine = sanitize_text_field( wp_unslash( $_POST['routine'] ?? '' ) ); - $nonce = sanitize_text_field( wp_unslash( $_POST['nonce'] ?? '' ) ); - - if ( ! wp_verify_nonce( $nonce, 'classifai' ) ) { - $error = new \WP_Error( 'classifai_nonce_error', __( 'Nonce could not be verified.', 'classifai' ) ); - wp_send_json_error( $error ); - } - - if ( empty( $routine ) ) { - wp_send_json_error( esc_html__( 'Migration routine empty.', 'classifai' ) ); - } - - if ( 'delete_old' === $routine ) { - $old_settings = array( - 'classifai_watson_nlu', - 'classifai_openai_whisper', - 'classifai_openai_chatgpt', - 'classifai_openai_embeddings', - 'classifai_azure_text_to_speech', - 'classifai_openai_whisper', - 'classifai_computer_vision', - 'classifai_openai_dalle', - ); - - foreach ( $old_settings as $old_setting ) { - delete_option( $old_setting ); - } - - wp_send_json_success( esc_html__( 'Old settings deleted.', 'classifai' ) ); - } - - if ( 'skip' === $routine ) { - update_option( 'classifai-v3-migration-status', true ); - wp_send_json_success( esc_html__( 'V3 migration skipped.', 'classifai' ) ); - } - - if ( 'migrate' !== $routine ) { - wp_send_json_error( esc_html__( 'Migration routine unrecognized.', 'classifai' ) ); + public function v3_migration_completed_notice() { + // Bail if no need to show the notice. + $display_notice = get_option( 'classifai_display_v3_migration_notice', false ); + if ( ! $display_notice ) { + return; } - $features = array( - // Language processing features. - \Classifai\Features\Classification::class, - \Classifai\Features\TitleGeneration::class, - \Classifai\Features\ExcerptGeneration::class, - \Classifai\Features\ContentResizing::class, - \Classifai\Features\TextToSpeech::class, - \Classifai\Features\AudioTranscriptsGeneration::class, - - // Image processing features. - \Classifai\Features\DescriptiveTextGenerator::class, - \Classifai\Features\ImageTagsGenerator::class, - \Classifai\Features\ImageCropping::class, - \Classifai\Features\ImageTextExtraction::class, - \Classifai\Features\ImageGeneration::class, - \Classifai\Features\PDFTextExtraction::class, - ); - - 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 ); - } + // Don't show the notice if the user has already dismissed it. + $key = 'v3_migration_completed'; + if ( get_user_meta( get_current_user_id(), "classifai_dismissed_{$key}", true ) ) { + return; } - - update_option( 'classifai-v3-migration-status', true ); - wp_send_json_success( esc_html__( 'Migration completed', 'classifai' ) ); - } - - /** - * Displays the migration notice for feature-first refactor - * of the settings. - */ - public function v3_migration_notice() { - $show_notice = get_option( 'classifai-v3-migration-status', false ); - - if ( ! $show_notice ) : - ?> -
-

- -

-

- - -   - -

-
- + + Date: Wed, 21 Feb 2024 16:37:00 +0530 Subject: [PATCH 12/20] Remove unwanted code. --- includes/Classifai/Plugin.php | 1 - src/js/admin.js | 59 ----------------------------------- 2 files changed, 60 deletions(-) diff --git a/includes/Classifai/Plugin.php b/includes/Classifai/Plugin.php index c4ca701fb..3c0b4ac22 100644 --- a/includes/Classifai/Plugin.php +++ b/includes/Classifai/Plugin.php @@ -186,7 +186,6 @@ public function enqueue_admin_assets() { 'ajax_nonce' => wp_create_nonce( 'classifai' ), 'opt_out_enabled_features' => array_keys( $allowed_features ), 'profile_url' => esc_url( get_edit_profile_url( get_current_user_id() ) . '#classifai-profile-features-section' ), - 'migration_progress' => esc_html__( 'Migrating...', 'classifai' ), ]; wp_localize_script( diff --git a/src/js/admin.js b/src/js/admin.js index 75fe8d5d2..158af6ba0 100644 --- a/src/js/admin.js +++ b/src/js/admin.js @@ -368,62 +368,3 @@ document.addEventListener( 'DOMContentLoaded', function () { providerSelectEl.trigger( 'change' ); } ); } )( jQuery ); - -/** - * Feature-first migration routine: - * @param {Object} $ jQuery object - */ -( function ( $ ) { - const noticeWrapper = $( '.classifai-migation-notice' ); - const migrateSettingsBtn = $( '#classifai-migrate-settings' ); - const deleteOldSettings = $( '#classifai-delete-pre-v3-settings' ); - const interactiveTxt = $( '#classifai-migation-notice__interactive' ); - const skipMigrationBtn = $( '#classifai-skip-migration-settings' ); - - skipMigrationBtn.on( 'click', function () { - $.ajax( ajaxurl, { - type: 'POST', - data: { - action: 'v3_migration_script', - routine: 'skip', - nonce: ClassifAI.ajax_nonce, - }, - } ).done( function () { - noticeWrapper.slideUp(); - } ); - } ); - - migrateSettingsBtn.on( 'click', function () { - skipMigrationBtn.hide(); - migrateSettingsBtn.text( ClassifAI.migration_progress ); - migrateSettingsBtn.prop( 'disabled', true ); - - $.ajax( ajaxurl, { - type: 'POST', - data: { - action: 'v3_migration_script', - routine: 'migrate', - nonce: ClassifAI.ajax_nonce, - }, - } ).done( function ( response ) { - migrateSettingsBtn.hide(); - interactiveTxt.text( response.data ); - deleteOldSettings.show(); - } ); - } ); - - deleteOldSettings.on( 'click', function () { - deleteOldSettings.prop( 'disabled', true ); - - $.ajax( ajaxurl, { - type: 'POST', - data: { - action: 'v3_migration_script', - routine: 'delete_old', - nonce: ClassifAI.ajax_nonce, - }, - } ).done( function ( response ) { - noticeWrapper.html( `

${ response.data }

` ); - } ); - } ); -} )( jQuery ); From 3738193c9e3af85c4dcb062824cd8194a96ad149 Mon Sep 17 00:00:00 2001 From: Dharmesh Patel Date: Wed, 21 Feb 2024 17:07:34 +0530 Subject: [PATCH 13/20] Fix nlu settings migration. --- includes/Classifai/Features/Classification.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/includes/Classifai/Features/Classification.php b/includes/Classifai/Features/Classification.php index 6f1431b45..370d5b6b1 100644 --- a/includes/Classifai/Features/Classification.php +++ b/includes/Classifai/Features/Classification.php @@ -1088,8 +1088,8 @@ public function migrate_settings() { } // Users - if ( isset( $old_settings['users'] ) ) { - $new_settings['users'] = $old_settings['users']; + if ( isset( $old_settings['content_classification_users'] ) ) { + $new_settings['users'] = $old_settings['content_classification_users']; } // Provider. @@ -1106,16 +1106,16 @@ public function migrate_settings() { } if ( isset( $old_settings['classification_mode'] ) ) { - $new_settings['ibm_watson_nlu']['classification_mode'] = $old_settings['classification_mode']; + $new_settings['classification_mode'] = $old_settings['classification_mode']; } if ( isset( $old_settings['classification_method'] ) ) { - $new_settings['ibm_watson_nlu']['classification_method'] = $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['ibm_watson_nlu'][ $feature ] = $value; + $new_settings[ $feature ] = $value; } } @@ -1126,10 +1126,6 @@ public function migrate_settings() { if ( isset( $old_settings['content_classification_user_based_opt_out'] ) ) { $new_settings['user_based_opt_out'] = $old_settings['content_classification_user_based_opt_out']; } - - if ( isset( $old_settings['content_classification_users'] ) ) { - $new_settings['users'] = $old_settings['content_classification_users']; - } } else { $old_settings = get_option( 'classifai_openai_embeddings', array() ); From 44ac289eaab1bc33c6f566c646c30437ded5e2c2 Mon Sep 17 00:00:00 2001 From: Dharmesh Patel Date: Wed, 21 Feb 2024 17:20:23 +0530 Subject: [PATCH 14/20] Fixed embeddings migration. --- includes/Classifai/Features/Classification.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/includes/Classifai/Features/Classification.php b/includes/Classifai/Features/Classification.php index 370d5b6b1..91391c135 100644 --- a/includes/Classifai/Features/Classification.php +++ b/includes/Classifai/Features/Classification.php @@ -1139,16 +1139,10 @@ public function migrate_settings() { $new_settings['openai_embeddings']['api_key'] = $old_settings['api_key']; } - if ( isset( $old_settings['number'] ) ) { - $new_settings['openai_embeddings']['number_of_terms'] = $old_settings['number']; - } - - if ( isset( $old_settings['number'] ) ) { - $new_settings['openai_embeddings']['number_of_terms'] = $old_settings['number']; - } - if ( isset( $old_settings['taxonomies'] ) ) { - $new_settings['openai_embeddings']['taxonomies'] = $old_settings['taxonomies']; + foreach ( $old_settings['taxonomies'] as $feature => $value ) { + $new_settings[ $feature ] = $value; + } } if ( isset( $old_settings['authenticated'] ) ) { From f25fc6e37e773d55c5c0c301e43680cba45d8fb4 Mon Sep 17 00:00:00 2001 From: Dharmesh Patel Date: Wed, 21 Feb 2024 17:58:32 +0530 Subject: [PATCH 15/20] Update to migration script. --- includes/Classifai/Features/Classification.php | 2 +- includes/Classifai/Features/ContentResizing.php | 4 ++-- includes/Classifai/Features/DescriptiveTextGenerator.php | 2 +- includes/Classifai/Features/ExcerptGeneration.php | 2 +- includes/Classifai/Features/ImageCropping.php | 2 +- includes/Classifai/Features/ImageGeneration.php | 2 +- includes/Classifai/Features/ImageTagsGenerator.php | 2 +- includes/Classifai/Features/ImageTextExtraction.php | 2 +- includes/Classifai/Features/PDFTextExtraction.php | 6 +++--- includes/Classifai/Features/TextToSpeech.php | 2 +- includes/Classifai/Features/TitleGeneration.php | 4 ++-- 11 files changed, 15 insertions(+), 15 deletions(-) diff --git a/includes/Classifai/Features/Classification.php b/includes/Classifai/Features/Classification.php index 91391c135..707da8bbc 100644 --- a/includes/Classifai/Features/Classification.php +++ b/includes/Classifai/Features/Classification.php @@ -1038,7 +1038,7 @@ public function get_supported_taxonomies( array $post_types = [] ): array { */ public function migrate_settings() { $old_settings = get_option( 'classifai_watson_nlu', array() ); - $new_settings = array(); + $new_settings = $this->get_default_settings(); if ( isset( $old_settings['authenticated'] ) && $old_settings['authenticated'] ) { $new_settings['provider'] = 'ibm_watson_nlu'; diff --git a/includes/Classifai/Features/ContentResizing.php b/includes/Classifai/Features/ContentResizing.php index 3b7a7de49..34836ade0 100644 --- a/includes/Classifai/Features/ContentResizing.php +++ b/includes/Classifai/Features/ContentResizing.php @@ -314,7 +314,7 @@ public function sanitize_default_feature_settings( array $new_settings ): array */ public function migrate_settings() { $old_settings = get_option( 'classifai_openai_chatgpt', array() ); - $new_settings = array(); + $new_settings = $this->get_default_settings(); if ( isset( $old_settings['enable_resize_content'] ) ) { $new_settings['status'] = $old_settings['enable_resize_content']; @@ -331,7 +331,7 @@ public function migrate_settings() { } if ( isset( $old_settings['number_resize_content'] ) ) { - $new_settings['number_of_suggestions'] = $old_settings['number_resize_content']; + $new_settings['openai_chatgpt']['number_of_suggestions'] = $old_settings['number_resize_content']; } if ( isset( $old_settings['shrink_content_prompt'] ) ) { diff --git a/includes/Classifai/Features/DescriptiveTextGenerator.php b/includes/Classifai/Features/DescriptiveTextGenerator.php index bdd12ec7e..2642c6b3c 100644 --- a/includes/Classifai/Features/DescriptiveTextGenerator.php +++ b/includes/Classifai/Features/DescriptiveTextGenerator.php @@ -401,7 +401,7 @@ public function sanitize_default_feature_settings( array $new_settings ): array */ public function migrate_settings() { $old_settings = get_option( 'classifai_computer_vision', array() ); - $new_settings = array(); + $new_settings = $this->get_default_settings(); $new_settings['provider'] = 'ms_computer_vision'; diff --git a/includes/Classifai/Features/ExcerptGeneration.php b/includes/Classifai/Features/ExcerptGeneration.php index 18063ab85..edabd3366 100644 --- a/includes/Classifai/Features/ExcerptGeneration.php +++ b/includes/Classifai/Features/ExcerptGeneration.php @@ -386,7 +386,7 @@ public function sanitize_default_feature_settings( array $new_settings ): array */ public function migrate_settings() { $old_settings = get_option( 'classifai_openai_chatgpt', array() ); - $new_settings = array(); + $new_settings = $this->get_default_settings(); if ( isset( $old_settings['enable_excerpt'] ) ) { $new_settings['status'] = $old_settings['enable_excerpt']; diff --git a/includes/Classifai/Features/ImageCropping.php b/includes/Classifai/Features/ImageCropping.php index 55759ec1c..997f13059 100644 --- a/includes/Classifai/Features/ImageCropping.php +++ b/includes/Classifai/Features/ImageCropping.php @@ -386,7 +386,7 @@ public function get_wp_filesystem() { */ public function migrate_settings() { $old_settings = get_option( 'classifai_computer_vision', array() ); - $new_settings = array(); + $new_settings = $this->get_default_settings(); $new_settings['provider'] = 'ms_computer_vision'; diff --git a/includes/Classifai/Features/ImageGeneration.php b/includes/Classifai/Features/ImageGeneration.php index f11242b27..8656c1202 100644 --- a/includes/Classifai/Features/ImageGeneration.php +++ b/includes/Classifai/Features/ImageGeneration.php @@ -396,7 +396,7 @@ public function get_feature_default_settings(): array { */ public function migrate_settings() { $old_settings = get_option( 'classifai_openai_dalle', array() ); - $new_settings = array(); + $new_settings = $this->get_default_settings(); $new_settings['provider'] = 'openai_dalle'; diff --git a/includes/Classifai/Features/ImageTagsGenerator.php b/includes/Classifai/Features/ImageTagsGenerator.php index c13afdbc6..eccca3fb1 100644 --- a/includes/Classifai/Features/ImageTagsGenerator.php +++ b/includes/Classifai/Features/ImageTagsGenerator.php @@ -363,7 +363,7 @@ public function sanitize_default_feature_settings( array $new_settings ): array */ public function migrate_settings() { $old_settings = get_option( 'classifai_computer_vision', array() ); - $new_settings = array(); + $new_settings = $this->get_default_settings(); $new_settings['provider'] = 'ms_computer_vision'; diff --git a/includes/Classifai/Features/ImageTextExtraction.php b/includes/Classifai/Features/ImageTextExtraction.php index 0e59a421d..7e0a40673 100644 --- a/includes/Classifai/Features/ImageTextExtraction.php +++ b/includes/Classifai/Features/ImageTextExtraction.php @@ -415,7 +415,7 @@ public function get_feature_default_settings(): array { */ public function migrate_settings() { $old_settings = get_option( 'classifai_computer_vision', array() ); - $new_settings = array(); + $new_settings = $this->get_default_settings(); $new_settings['provider'] = 'ms_computer_vision'; diff --git a/includes/Classifai/Features/PDFTextExtraction.php b/includes/Classifai/Features/PDFTextExtraction.php index ad6534d44..a4a6531a5 100644 --- a/includes/Classifai/Features/PDFTextExtraction.php +++ b/includes/Classifai/Features/PDFTextExtraction.php @@ -281,7 +281,7 @@ public function get_feature_default_settings(): array { */ public function migrate_settings() { $old_settings = get_option( 'classifai_computer_vision', array() ); - $new_settings = array(); + $new_settings = $this->get_default_settings(); $new_settings['provider'] = 'ms_computer_vision'; @@ -309,8 +309,8 @@ public function migrate_settings() { $new_settings['users'] = $old_settings['read_pdf_users']; } - if ( isset( $old_settings['ocr_user_based_opt_out'] ) ) { - $new_settings['user_based_opt_out'] = $old_settings['ocr_user_based_opt_out']; + 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/TextToSpeech.php b/includes/Classifai/Features/TextToSpeech.php index 497e0925f..bd530006c 100644 --- a/includes/Classifai/Features/TextToSpeech.php +++ b/includes/Classifai/Features/TextToSpeech.php @@ -808,7 +808,7 @@ public function get_audio_generation_subsequent_state( $post = null ): bool { */ public function migrate_settings() { $old_settings = get_option( 'classifai_azure_text_to_speech', array() ); - $new_settings = array(); + $new_settings = $this->get_default_settings(); if ( isset( $old_settings['enable_text_to_speech'] ) ) { $new_settings['status'] = $old_settings['enable_text_to_speech']; diff --git a/includes/Classifai/Features/TitleGeneration.php b/includes/Classifai/Features/TitleGeneration.php index 6fdf3ced2..be6646471 100644 --- a/includes/Classifai/Features/TitleGeneration.php +++ b/includes/Classifai/Features/TitleGeneration.php @@ -371,7 +371,7 @@ public function sanitize_default_feature_settings( array $new_settings ): array */ public function migrate_settings() { $old_settings = get_option( 'classifai_openai_chatgpt', array() ); - $new_settings = array(); + $new_settings = $this->get_default_settings(); if ( isset( $old_settings['enable_titles'] ) ) { $new_settings['status'] = $old_settings['enable_titles']; @@ -388,7 +388,7 @@ public function migrate_settings() { } if ( isset( $old_settings['number_titles'] ) ) { - $new_settings['number_of_titles'] = $old_settings['number_titles']; + $new_settings['openai_chatgpt']['number_of_suggestions'] = $old_settings['number_titles']; } if ( isset( $old_settings['generate_title_prompt'] ) ) { From 92eb54cde7631630f1d669a09c1c4110270b2f06 Mon Sep 17 00:00:00 2001 From: Dharmesh Patel Date: Wed, 21 Feb 2024 18:24:33 +0530 Subject: [PATCH 16/20] Add migration script for the Recommended Content. --- .../Classifai/Features/RecommendedContent.php | 43 +++++++++++++++++++ includes/Classifai/Plugin.php | 19 +++++--- 2 files changed, 55 insertions(+), 7 deletions(-) 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/Plugin.php b/includes/Classifai/Plugin.php index 3c0b4ac22..4fbea4cb7 100644 --- a/includes/Classifai/Plugin.php +++ b/includes/Classifai/Plugin.php @@ -250,13 +250,14 @@ public function maybe_migrate_to_v3() { $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', [] ); + $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. @@ -290,6 +291,10 @@ public function maybe_migrate_to_v3() { $features[] = \Classifai\Features\ImageGeneration::class; } + if ( ! empty( $personalizer_settings ) ) { + $features[] = \Classifai\Features\RecommendedContent::class; + } + // Migrate settings. $migration_needed = ! empty( $features ); foreach ( $features as $feature ) { From 487616ad15b9e2d5ed406b67f7f0065c3186a283 Mon Sep 17 00:00:00 2001 From: Dharmesh Patel Date: Wed, 21 Feb 2024 18:37:05 +0530 Subject: [PATCH 17/20] PHPCS fixes. --- includes/Classifai/Plugin.php | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/Classifai/Plugin.php b/includes/Classifai/Plugin.php index 4fbea4cb7..e4c774dc5 100644 --- a/includes/Classifai/Plugin.php +++ b/includes/Classifai/Plugin.php @@ -259,7 +259,6 @@ public function maybe_migrate_to_v3() { $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; From 16762bd4fe9912c69fbdb3831f9ae007fd48ba03 Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Tue, 27 Feb 2024 15:36:10 -0700 Subject: [PATCH 18/20] Ensure our dismiss code works properly if multiple notices are shown --- includes/Classifai/Admin/Notifications.php | 40 ++++++++++++---------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/includes/Classifai/Admin/Notifications.php b/includes/Classifai/Admin/Notifications.php index b7a9a7daa..9e94837bc 100644 --- a/includes/Classifai/Admin/Notifications.php +++ b/includes/Classifai/Admin/Notifications.php @@ -96,33 +96,35 @@ public function add_dismiss_script() { $script = << Date: Tue, 27 Feb 2024 15:38:20 -0700 Subject: [PATCH 19/20] Update notice message --- includes/Classifai/Admin/Notifications.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Classifai/Admin/Notifications.php b/includes/Classifai/Admin/Notifications.php index 9e94837bc..2fb07f466 100644 --- a/includes/Classifai/Admin/Notifications.php +++ b/includes/Classifai/Admin/Notifications.php @@ -241,7 +241,7 @@ public function v3_migration_completed_notice() { echo wp_kses_post( sprintf( // translators: %1$s: tag starting; %2$s: tag closing. - __( '%1$sClassifAI 3.0.0%2$s has changed how AI service providers are integrated with AI features which impacted how settings were handled. Those settings have been migrated automatically, and you can %3$sview them here%4$s.', 'classifai' ), + __( '%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' ), '', '', '', From 976b244d71b876ed6faeac4ab498fcd16e97b715 Mon Sep 17 00:00:00 2001 From: Darin Kotter Date: Tue, 27 Feb 2024 15:41:36 -0700 Subject: [PATCH 20/20] Set our migration options to not autoload --- includes/Classifai/Plugin.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/Classifai/Plugin.php b/includes/Classifai/Plugin.php index e4c774dc5..1cfd79caf 100644 --- a/includes/Classifai/Plugin.php +++ b/includes/Classifai/Plugin.php @@ -307,10 +307,10 @@ public function maybe_migrate_to_v3() { } // Mark the migration as completed. - update_option( 'classifai_v3_migration_completed', true ); + 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 ); + update_option( 'classifai_display_v3_migration_notice', true, false ); } } }