Fatal Error

When enabling webrtc in usermanager I get a sql fatal error.

FATAL ERROR

SQLSTATE[23000]: Integrity constraint violation: 1048 Column ‘flags’ cannot be null

error adding to SIP table

Trace Back

/var/www/html/admin/modules/core/Core.class.php:526 die_freepbx()
[0]: SQLSTATE[23000]: Integrity constraint violation: 1048 Column ‘flags’ cannot be null

error adding to SIP table

/var/www/html/admin/modules/webrtc/Webrtc.class.php:298 FreePBX\modules\Core->addDevice()
[0]: 9911
[1]: pjsip
[2]:

/var/www/html/admin/modules/webrtc/Webrtc.class.php:136 FreePBX\modules\Webrtc->createDevice()
[0]: 11
[1]: 1

/var/www/html/admin/modules/ucp/Ucp.class.php:181 FreePBX\modules\Webrtc->processUCPAdminDisplay()
[0]:

/var/www/html/admin/modules/ucp/Ucp.class.php:45 Ucp->processModuleConfigPages()
[0]:

: Ucp->usermanShowPage()

/var/www/html/admin/libraries/BMO/Hooks.class.php:141 call_user_func_array()
[0]:
[1]:

/var/www/html/admin/modules/userman/Userman.class.php:159 Hooks->processHooks()

/var/www/html/admin/modules/userman/page.userman.php:25 FreePBX\modules\Userman->myShowPage()

/var/www/html/admin/config.php:509 include()
[0]: /var/www/html/admin/modules/userman/page.userman.php

What extension are you trying to enable it against. Like what extension type?

pjsip with the extension 11

I can confirm that I’m also getting this same error.

Although…a reboot does help. So does not using “0” in front of the extension…why this logic?

This was fixed a very long time ago

What is the fix? I just started trying to use WebRTC and I’m seeing this issue.

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'flags' cannot be null

public function addDevice($id, $settings) {
	$sql = 'INSERT INTO sip (id, keyword, data, flags) values (?,?,?,?)';
	$sth = $this->database->prepare($sql);
	$settings = is_array($settings)?$settings:array();
	foreach($settings as $key => $setting) {
		$sth->execute(array($id,$key,$setting['value'],$setting['flag'])); << line indicated.
	}
	return true;

15. PDOStatement execute
/­var/­www/­html/­admin/­modules/­core/­functions.inc/­drivers/­PJSip.class.php50
14. FreePBX\modules\Core\Drivers\PJSip addDevice
/­var/­www/­html/­admin/­modules/­core/­Core.class.php1567
13. FreePBX\modules\Core addDevice
/­var/­www/­html/­admin/­modules/­webrtc/­Webrtc.class.php497
12. FreePBX\modules\Webrtc createDevice
/­var/­www/­html/­admin/­modules/­webrtc/­Webrtc.class.php233
11. FreePBX\modules\Webrtc ucpUpdateGroup
<#unknown>0
10. call_user_func_array
/­var/­www/­html/­admin/­libraries/­BMO/­Hooks.class.php261
9. FreePBX\Hooks processHooks
/­var/­www/­html/­admin/­modules/­ucp/­Ucp.class.php371
8. Ucp updateGroup
<#unknown>0
7. call_user_func_array
/­var/­www/­html/­admin/­libraries/­BMO/­Hooks.class.php188
6. FreePBX\Hooks processHooksByClassMethod
/­var/­www/­html/­admin/­modules/­userman/­functions.inc/­auth/­Auth.php46
5. FreePBX\modules\Userman\Auth\Auth updateGroupHook
/­var/­www/­html/­admin/­modules/­userman/­functions.inc/­auth/­modules/­Msad.php381
4. FreePBX\modules\Userman\Auth\Msad updateGroup
/­var/­www/­html/­admin/­modules/­userman/­Userman.class.php1224
3. FreePBX\modules\Userman updateGroup
/­var/­www/­html/­admin/­modules/­userman/­Userman.class.php249
2. FreePBX\modules\Userman doConfigPageInit
/­var/­www/­html/­admin/­libraries/­BMO/­GuiHooks.class.php290
1. FreePBX\GuiHooks doBMOConfigPage
/­var/­www/­html/­admin/­libraries/­BMO/­GuiHooks.class.php252
0. FreePBX\GuiHooks doConfigPageInits

It seems use_avpf is in $settings but doesn’t have a flag set. This is set in Webrtc.class.php around line 492.

I guess the behavior of mysql changed on how it sets defaults? I note the table looks like:

+---------+--------------+------+-----+---------+-------+
| Field   | Type         | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+-------+
| id      | varchar(20)  | NO   | PRI | -1      |       |
| keyword | varchar(30)  | NO   | PRI |         |       |
| data    | varchar(255) | NO   |     | NULL    |       |
| flags   | int(1)       | NO   |     | 0       |       |
+---------+--------------+------+-----+---------+-------+

I see two possible fixes. Building the query sent to mysql based on the settings object (ugly) or defaulting flags to 0 in the loop doing the insert. I got through my issue with the latter:

    public function addDevice($id, $settings) {
            $sql = 'INSERT INTO sip (id, keyword, data, flags) values (?,?,?,?)';
            $sth = $this->database->prepare($sql);
            $settings = is_array($settings)?$settings:array();
            foreach($settings as $key => $setting) {
                    if (!isset($setting['flag']))
                            $setting['flag'] = 0;
                    $sth->execute(array($id,$key,$setting['value'],$setting['flag']));
            }
            return true;
    }

Best,
Scott

The correct fix is change these lines:


From “use_avpf” to “avpf”

1 Like