prefix.'r360_claims'; $new_claims=$wpdb->prefix . NET360RECLAMACIONES_LEGACY_DB_PREFIX . '_peru_claims'; $old_history=$wpdb->prefix.'r360_claim_history'; $new_history=$wpdb->prefix . NET360RECLAMACIONES_LEGACY_DB_PREFIX . '_peru_claim_history'; $claims_exists=$wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s',$old_claims)); $new_claims_exists=$wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s',$new_claims)); if ($claims_exists && !$new_claims_exists) { // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table names are generated from the WordPress prefix and plugin constants. $wpdb->query( $wpdb->prepare( 'RENAME TABLE %i TO %i', $old_claims, $new_claims ) ); } $history_exists=$wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s',$old_history)); $new_history_exists=$wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s',$new_history)); if ($history_exists && !$new_history_exists) { // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table names are generated from the WordPress prefix and plugin constants. $wpdb->query( $wpdb->prepare( 'RENAME TABLE %i TO %i', $old_history, $new_history ) ); } $legacy_public_prefix = NET360RECLAMACIONES_LEGACY_DB_PREFIX; $legacy_settings=get_option($legacy_public_prefix . '_settings',null); if($legacy_settings!==null && get_option(NET360RECLAMACIONES_PUBLIC_PREFIX . '_settings',null)===null){ update_option(NET360RECLAMACIONES_PUBLIC_PREFIX . '_settings',$legacy_settings); } $legacy_db=get_option($legacy_public_prefix . '_db_version',null); if($legacy_db!==null && get_option(NET360RECLAMACIONES_PUBLIC_PREFIX . '_db_version',null)===null){ update_option(NET360RECLAMACIONES_PUBLIC_PREFIX . '_db_version',$legacy_db); } $old_settings=get_option('r360_settings',null); if($old_settings!==null && get_option(NET360RECLAMACIONES_PUBLIC_PREFIX . '_settings',null)===null){ update_option(NET360RECLAMACIONES_PUBLIC_PREFIX . '_settings',$old_settings); } $old_db=get_option('r360_db_version',null); if($old_db!==null && get_option(NET360RECLAMACIONES_PUBLIC_PREFIX . '_db_version',null)===null){ update_option(NET360RECLAMACIONES_PUBLIC_PREFIX . '_db_version',$old_db); } } public static function install(){ global $wpdb; $charset=$wpdb->get_charset_collate(); $table=$wpdb->prefix . NET360RECLAMACIONES_LEGACY_DB_PREFIX . '_peru_claims'; $history=$wpdb->prefix . NET360RECLAMACIONES_LEGACY_DB_PREFIX . '_peru_claim_history'; $sql="CREATE TABLE `$table` (id bigint(20) unsigned NOT NULL AUTO_INCREMENT,claim_code varchar(40) NOT NULL,created_at datetime NOT NULL,updated_at datetime NULL,status varchar(30) NOT NULL DEFAULT 'new',full_name varchar(190) NOT NULL,is_minor tinyint(1) NOT NULL DEFAULT 0,guardian_name varchar(190) NULL,guardian_document_type varchar(50) NULL,guardian_document_number varchar(100) NULL,document_type varchar(50) NOT NULL,document_number varchar(100) NOT NULL,email varchar(190) NOT NULL,phone varchar(100) NULL,address text NULL,goods_type varchar(50) NOT NULL,goods_description longtext NOT NULL,claim_amount_enabled tinyint(1) NOT NULL DEFAULT 0,currency varchar(10) NULL,amount decimal(14,2) NULL,claim_type varchar(20) NOT NULL,claim_description longtext NOT NULL,request_description longtext NOT NULL,admin_notes longtext NULL,PRIMARY KEY (id),UNIQUE KEY claim_code (claim_code),KEY status (status),KEY created_at (created_at),KEY email (email),KEY claim_type (claim_type)) $charset;"; $sql2="CREATE TABLE `$history` (id bigint(20) unsigned NOT NULL AUTO_INCREMENT,claim_id bigint(20) unsigned NOT NULL,event_type varchar(40) NOT NULL,message longtext NULL,user_id bigint(20) unsigned NULL,created_at datetime NOT NULL,PRIMARY KEY (id),KEY claim_id (claim_id),KEY created_at (created_at)) $charset;"; require_once ABSPATH.'wp-admin/includes/upgrade.php'; dbDelta($sql); dbDelta($sql2); $defaults=['primary_color'=>'#2f6fd3','card_radius'=>'20','responsible_name'=>get_bloginfo('name'),'privacy_responsible'=>'','privacy_purpose'=>'Registrar y gestionar su reclamo conforme al reglamento del libro de reclamaciones.','privacy_rights'=>'','privacy_retention'=>'Mínimo 2 años desde el registro, según normativa aplicable.','privacy_transfer'=>'','privacy_more_url'=>'','legal_notice'=>'La formulación de la queja o reclamo no impide acudir a otras vías de solución de controversias si es requisito previo para interponer una denuncia ante el INDECOPI.\n\nEl proveedor debe dar respuesta al reclamo o queja en un plazo no mayor a quince (15) días hábiles, conforme a la normativa aplicable.','admin_email'=>get_option('admin_email'),'admin_cc'=>'','admin_bcc'=>'','from_name'=>get_bloginfo('name'),'from_email'=>get_option('admin_email'),'admin_subject'=>'Nueva reclamación {claim_code}','customer_subject'=>'Hemos recibido su reclamación {claim_code}','customer_message'=>'Estimado/a {full_name},\n\nHemos recibido correctamente su reclamación.\nCódigo: {claim_code}\n\nNos comunicaremos con usted dentro del plazo correspondiente.']; update_option(NET360RECLAMACIONES_PUBLIC_PREFIX . '_settings',wp_parse_args(get_option(NET360RECLAMACIONES_PUBLIC_PREFIX . '_settings',[]),$defaults)); update_option(NET360RECLAMACIONES_PUBLIC_PREFIX . '_db_version','1.4.6'); } }