From: Richard Mudgett Date: Mon, 6 Aug 2018 20:37:05 +0000 (-0500) Subject: res_pjsip: Fix mwi_subscribe_replaces_unsolicited type mismatch X-Git-Tag: 13.24.0-rc1~122^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f2266602a1022e57ab3157942a1de426d393c51a;p=thirdparty%2Fasterisk.git res_pjsip: Fix mwi_subscribe_replaces_unsolicited type mismatch ASTERISK-27988 Change-Id: Iccafdd0552ea8aaed647620fb14499f1bf341843 --- diff --git a/contrib/ast-db-manage/config/versions/fe6592859b85_fix_mwi_subscribe_replaces_.py b/contrib/ast-db-manage/config/versions/fe6592859b85_fix_mwi_subscribe_replaces_.py new file mode 100644 index 0000000000..4ecaaf789f --- /dev/null +++ b/contrib/ast-db-manage/config/versions/fe6592859b85_fix_mwi_subscribe_replaces_.py @@ -0,0 +1,61 @@ +"""Fix mwi_subscribe_replaces_unsolicited + +Revision ID: fe6592859b85 +Revises: 19b00bc19b7b +Create Date: 2018-08-06 15:50:44.405534 + +""" + +# revision identifiers, used by Alembic. +revision = 'fe6592859b85' +down_revision = '1d3ed26d9978' + +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects.postgresql import ENUM + +AST_BOOL_NAME = 'ast_bool_values' +# We'll just ignore the n/y and f/t abbreviations as Asterisk does not write +# those aliases. +AST_BOOL_VALUES = [ '0', '1', + 'off', 'on', + 'false', 'true', + 'no', 'yes' ] + + +def upgrade(): + # Create the new enum + ast_bool_values = ENUM(*AST_BOOL_VALUES, name=AST_BOOL_NAME, create_type=False) + if op.get_context().bind.dialect.name == 'postgresql': + ast_bool_values.create(op.get_bind(), checkfirst=False) + + # There is no direct way to convert from Integer to ENUM that is + # not database specific so we transition through a string type. + op.alter_column('ps_endpoints', 'mwi_subscribe_replaces_unsolicited', + type_=sa.String(5)) + op.alter_column('ps_endpoints', 'mwi_subscribe_replaces_unsolicited', + type_=ast_bool_values) + + +def downgrade(): + # First we need to ensure the column is using only the 'numeric' bool enum values. + op.execute("UPDATE ps_endpoints SET mwi_subscribe_replaces_unsolicited='0'" + " WHERE mwi_subscribe_replaces_unsolicited='off'" + " OR mwi_subscribe_replaces_unsolicited='false'" + " OR mwi_subscribe_replaces_unsolicited='no'") + op.execute("UPDATE ps_endpoints SET mwi_subscribe_replaces_unsolicited='1'" + " WHERE mwi_subscribe_replaces_unsolicited='on'" + " OR mwi_subscribe_replaces_unsolicited='true'" + " OR mwi_subscribe_replaces_unsolicited='yes'") + + # There is no direct way to convert from ENUM to Integer that is + # not database specific so we transition through a string type. + if op.get_context().bind.dialect.name == 'mssql': + op.drop_constraint('ck_ps_endpoints_mwi_subscribe_replaces_unsolicited_ast_bool_values', 'ps_endpoints') + op.alter_column('ps_endpoints', 'mwi_subscribe_replaces_unsolicited', + type_=sa.String(5)) + op.alter_column('ps_endpoints', 'mwi_subscribe_replaces_unsolicited', + type_=sa.Integer) + + if op.get_context().bind.dialect.name == 'postgresql': + ENUM(name=AST_BOOL_NAME).drop(op.get_bind(), checkfirst=False) diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c index 5a25cb6d28..b0eb2d455a 100644 --- a/res/res_pjsip/pjsip_configuration.c +++ b/res/res_pjsip/pjsip_configuration.c @@ -1784,7 +1784,7 @@ int ast_res_pjsip_initialize_configuration(const struct ast_module_info *ast_mod ast_sorcery_object_field_register(sip_sorcery, "endpoint", "mailboxes", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_endpoint, subscription.mwi.mailboxes)); ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "voicemail_extension", "", voicemail_extension_handler, voicemail_extension_to_str, NULL, 0, 0); ast_sorcery_object_field_register(sip_sorcery, "endpoint", "aggregate_mwi", "yes", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, subscription.mwi.aggregate)); - ast_sorcery_object_field_register(sip_sorcery, "endpoint", "mwi_subscribe_replaces_unsolicited", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, subscription.mwi.subscribe_replaces_unsolicited)); + ast_sorcery_object_field_register(sip_sorcery, "endpoint", "mwi_subscribe_replaces_unsolicited", "no", OPT_YESNO_T, 1, FLDSET(struct ast_sip_endpoint, subscription.mwi.subscribe_replaces_unsolicited)); ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "media_encryption", "no", media_encryption_handler, media_encryption_to_str, NULL, 0, 0); ast_sorcery_object_field_register(sip_sorcery, "endpoint", "use_avpf", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, media.rtp.use_avpf)); ast_sorcery_object_field_register(sip_sorcery, "endpoint", "force_avp", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, media.rtp.force_avp));