<p>George Joseph <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/9839">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved
  George Joseph: Approved for Submit

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip: Fix mwi_subscribe_replaces_unsolicited type mismatch<br><br>ASTERISK-27988<br><br>Change-Id: Iccafdd0552ea8aaed647620fb14499f1bf341843<br>---<br>A contrib/ast-db-manage/config/versions/fe6592859b85_fix_mwi_subscribe_replaces_.py<br>M res/res_pjsip/pjsip_configuration.c<br>2 files changed, 62 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>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</span><br><span>new file mode 100644</span><br><span>index 0000000..4ecaaf7</span><br><span>--- /dev/null</span><br><span>+++ b/contrib/ast-db-manage/config/versions/fe6592859b85_fix_mwi_subscribe_replaces_.py</span><br><span>@@ -0,0 +1,61 @@</span><br><span style="color: hsl(120, 100%, 40%);">+"""Fix mwi_subscribe_replaces_unsolicited</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+Revision ID: fe6592859b85</span><br><span style="color: hsl(120, 100%, 40%);">+Revises: 19b00bc19b7b</span><br><span style="color: hsl(120, 100%, 40%);">+Create Date: 2018-08-06 15:50:44.405534</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+"""</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+# revision identifiers, used by Alembic.</span><br><span style="color: hsl(120, 100%, 40%);">+revision = 'fe6592859b85'</span><br><span style="color: hsl(120, 100%, 40%);">+down_revision = '1d3ed26d9978'</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+from alembic import op</span><br><span style="color: hsl(120, 100%, 40%);">+import sqlalchemy as sa</span><br><span style="color: hsl(120, 100%, 40%);">+from sqlalchemy.dialects.postgresql import ENUM</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+AST_BOOL_NAME = 'ast_bool_values'</span><br><span style="color: hsl(120, 100%, 40%);">+# We'll just ignore the n/y and f/t abbreviations as Asterisk does not write</span><br><span style="color: hsl(120, 100%, 40%);">+# those aliases.</span><br><span style="color: hsl(120, 100%, 40%);">+AST_BOOL_VALUES = [ '0', '1',</span><br><span style="color: hsl(120, 100%, 40%);">+                    'off', 'on',</span><br><span style="color: hsl(120, 100%, 40%);">+                    'false', 'true',</span><br><span style="color: hsl(120, 100%, 40%);">+                    'no', 'yes' ]</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+def upgrade():</span><br><span style="color: hsl(120, 100%, 40%);">+    # Create the new enum</span><br><span style="color: hsl(120, 100%, 40%);">+    ast_bool_values = ENUM(*AST_BOOL_VALUES, name=AST_BOOL_NAME, create_type=False)</span><br><span style="color: hsl(120, 100%, 40%);">+    if op.get_context().bind.dialect.name == 'postgresql':</span><br><span style="color: hsl(120, 100%, 40%);">+        ast_bool_values.create(op.get_bind(), checkfirst=False)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    # There is no direct way to convert from Integer to ENUM that is</span><br><span style="color: hsl(120, 100%, 40%);">+    # not database specific so we transition through a string type.</span><br><span style="color: hsl(120, 100%, 40%);">+    op.alter_column('ps_endpoints', 'mwi_subscribe_replaces_unsolicited',</span><br><span style="color: hsl(120, 100%, 40%);">+                    type_=sa.String(5))</span><br><span style="color: hsl(120, 100%, 40%);">+    op.alter_column('ps_endpoints', 'mwi_subscribe_replaces_unsolicited',</span><br><span style="color: hsl(120, 100%, 40%);">+                    type_=ast_bool_values)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+def downgrade():</span><br><span style="color: hsl(120, 100%, 40%);">+    # First we need to ensure the column is using only the 'numeric' bool enum values.</span><br><span style="color: hsl(120, 100%, 40%);">+    op.execute("UPDATE ps_endpoints SET mwi_subscribe_replaces_unsolicited='0'"</span><br><span style="color: hsl(120, 100%, 40%);">+               " WHERE mwi_subscribe_replaces_unsolicited='off'"</span><br><span style="color: hsl(120, 100%, 40%);">+               "  OR mwi_subscribe_replaces_unsolicited='false'"</span><br><span style="color: hsl(120, 100%, 40%);">+               "  OR mwi_subscribe_replaces_unsolicited='no'")</span><br><span style="color: hsl(120, 100%, 40%);">+    op.execute("UPDATE ps_endpoints SET mwi_subscribe_replaces_unsolicited='1'"</span><br><span style="color: hsl(120, 100%, 40%);">+               " WHERE mwi_subscribe_replaces_unsolicited='on'"</span><br><span style="color: hsl(120, 100%, 40%);">+               "  OR mwi_subscribe_replaces_unsolicited='true'"</span><br><span style="color: hsl(120, 100%, 40%);">+               "  OR mwi_subscribe_replaces_unsolicited='yes'")</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    # There is no direct way to convert from ENUM to Integer that is</span><br><span style="color: hsl(120, 100%, 40%);">+    # not database specific so we transition through a string type.</span><br><span style="color: hsl(120, 100%, 40%);">+    if op.get_context().bind.dialect.name == 'mssql':</span><br><span style="color: hsl(120, 100%, 40%);">+        op.drop_constraint('ck_ps_endpoints_mwi_subscribe_replaces_unsolicited_ast_bool_values', 'ps_endpoints')</span><br><span style="color: hsl(120, 100%, 40%);">+    op.alter_column('ps_endpoints', 'mwi_subscribe_replaces_unsolicited',</span><br><span style="color: hsl(120, 100%, 40%);">+                    type_=sa.String(5))</span><br><span style="color: hsl(120, 100%, 40%);">+    op.alter_column('ps_endpoints', 'mwi_subscribe_replaces_unsolicited',</span><br><span style="color: hsl(120, 100%, 40%);">+                    type_=sa.Integer)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    if op.get_context().bind.dialect.name == 'postgresql':</span><br><span style="color: hsl(120, 100%, 40%);">+        ENUM(name=AST_BOOL_NAME).drop(op.get_bind(), checkfirst=False)</span><br><span>diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c</span><br><span>index 5a25cb6..b0eb2d4 100644</span><br><span>--- a/res/res_pjsip/pjsip_configuration.c</span><br><span>+++ b/res/res_pjsip/pjsip_configuration.c</span><br><span>@@ -1784,7 +1784,7 @@</span><br><span>        ast_sorcery_object_field_register(sip_sorcery, "endpoint", "mailboxes", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_endpoint, subscription.mwi.mailboxes));</span><br><span>     ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "voicemail_extension", "", voicemail_extension_handler, voicemail_extension_to_str, NULL, 0, 0);</span><br><span>     ast_sorcery_object_field_register(sip_sorcery, "endpoint", "aggregate_mwi", "yes", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, subscription.mwi.aggregate));</span><br><span style="color: hsl(0, 100%, 40%);">-   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));</span><br><span style="color: hsl(120, 100%, 40%);">+        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));</span><br><span>      ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "media_encryption", "no", media_encryption_handler, media_encryption_to_str, NULL, 0, 0);</span><br><span>    ast_sorcery_object_field_register(sip_sorcery, "endpoint", "use_avpf", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, media.rtp.use_avpf));</span><br><span>      ast_sorcery_object_field_register(sip_sorcery, "endpoint", "force_avp", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, media.rtp.force_avp));</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/9839">change 9839</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/9839"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: Iccafdd0552ea8aaed647620fb14499f1bf341843 </div>
<div style="display:none"> Gerrit-Change-Number: 9839 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: Richard Mudgett <rmudgett@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Sean Bright <sean.bright@gmail.com> </div>