To help sort user agents and expose data about the user agent to Drupal it would be useful to separate the data into database columns. This allows data to be queried in groups, sort data based on any value and filter results more quickly.

It would also be required to implement a feature in Mobile Tools where by we expose user agent data through CTools contextual data.

Context is CTools way of saying, my plugin (read, block) shouldn't be dumb. If it requires a node or a user to extract data from, then it should let others know about it.

I'll attempt a patch to Browscap with the adjustment in-place. The change shouldn't change any of the existing functionality, the existing columns would be retained.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

minorOffense’s picture

Status: Active » Needs review
FileSize
10.58 KB

Here's my first attempt at a patch to add this feature. We may need to add some indexes and ensure all the data is being imported properly.

webadpro’s picture

Has this been pushed yet?

minorOffense’s picture

Not that I know of.

dgreenyc’s picture

I've tried applying this patch but am running into problems - new to patching, so any instructions that you may be able to provide would be appreciated.

taonac’s picture

Hi,

I tried patching but im getting Hunk #1 FAILED at 20.

hebbar10’s picture

Patch #1 worked for me. Thanks.

drupalok’s picture

please add this to a release! all those folks out there (like me) that are not too much into patching can't use mobile tools with browscap at all if this is only usable by patchin...
thanks a lot!

miahon’s picture

Should this #1 patch working with Browscap 7.x-2.0 (dated 2012-Nov-22 ) ?

imoreno’s picture

Hi,
Based on my knowledge end experiments. this patch didn't make it to the nov-22 version. i had to apply it in order to make mobile tools 7.3.x to work.

Please correct me if i'm wrong

BR
Itzhak

dominikb1888’s picture

Using drush to enable browscap I received the following error. Apparently false instead of 0 is submitted to alpha, which is a tinyint column. Apart from this the patch seems to work as expected. The table is generated nonetheless.

WD php: PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'false' for column 'alpha' at row 1: INSERT INTO {browscap} (useragent, data, comment, browser, version, majorver, minorver, platform,         [error]
platform_version, alpha, beta, win16, win32, win64, frames, iframes, tables, cookies, backgroundsounds, javascript, vbscript, javaapplets, activexcontrols, ismobiledevice, issyndicationreader, crawler, cssversion, aolversion)
VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7,
:db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11, :db_insert_placeholder_12, :db_insert_placeholder_13, :db_insert_placeholder_14, :db_insert_placeholder_15,
:db_insert_placeholder_16, :db_insert_placeholder_17, :db_insert_placeholder_18, :db_insert_placeholder_19, :db_insert_placeholder_20, :db_insert_placeholder_21, :db_insert_placeholder_22, :db_insert_placeholder_23,
:db_insert_placeholder_24, :db_insert_placeholder_25, :db_insert_placeholder_26, :db_insert_placeholder_27); Array
(
    [:db_insert_placeholder_0] => DefaultProperties
    [:db_insert_placeholder_1] =>
a:26:{s:7:"comment";s:17:"DefaultProperties";s:7:"browser";s:17:"DefaultProperties";s:7:"version";s:3:"0.0";s:8:"majorver";s:1:"0";s:8:"minorver";s:1:"0";s:8:"platform";s:7:"unknown";s:16:"platform_version";s:7:"unknown";s:5:"alpha";s:5:"false";s:4:"beta";s:5:"false";s:5:"win16";s:5:"false";s:5:"win32";s:5:"false";s:5:"win64";s:5:"false";s:6:"frames";s:5:"false";s:7:"iframes";s:5:"false";s:6:"tables";s:5:"false";s:7:"cookies";s:5:"false";s:16:"backgroundsounds";s:5:"false";s:10:"javascript";s:5:"false";s:8:"vbscript";s:5:"false";s:11:"javaapplets";s:5:"false";s:15:"activexcontrols";s:5:"false";s:14:"ismobiledevice";s:5:"false";s:19:"issyndicationreader";s:5:"false";s:7:"crawler";s:5:"false";s:10:"cssversion";s:1:"0";s:10:"aolversion";s:1:"0";}
    [:db_insert_placeholder_2] => DefaultProperties
    [:db_insert_placeholder_3] => DefaultProperties
    [:db_insert_placeholder_4] => 0.0
    [:db_insert_placeholder_5] => 0
    [:db_insert_placeholder_6] => 0
    [:db_insert_placeholder_7] => unknown
    [:db_insert_placeholder_8] => unknown
    [:db_insert_placeholder_9] => false
    [:db_insert_placeholder_10] => false
    [:db_insert_placeholder_11] => false
    [:db_insert_placeholder_12] => false
    [:db_insert_placeholder_13] => false
    [:db_insert_placeholder_14] => false
    [:db_insert_placeholder_15] => false
    [:db_insert_placeholder_16] => false
    [:db_insert_placeholder_17] => false
    [:db_insert_placeholder_18] => false
    [:db_insert_placeholder_19] => false
    [:db_insert_placeholder_20] => false
    [:db_insert_placeholder_21] => false
    [:db_insert_placeholder_22] => false
    [:db_insert_placeholder_23] => false
    [:db_insert_placeholder_24] => false
    [:db_insert_placeholder_25] => false
    [:db_insert_placeholder_26] => 0
    [:db_insert_placeholder_27] => 0
)
 in _browscap_import() (line 137 of /mysite.dev/sites/all/modules/browscap/import.inc).
jlea9378’s picture

I also received this error in my log after enabling Browscap (after patching):
PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'false' for column 'alpha' at row 1...).

jlea9378’s picture

Status: Needs review » Needs work

Clicking "Refresh browscap data" on the Browscap admin UI causes the error to throw again:

PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'false' for column 'alpha' at row 1: INSERT INTO {browscap} (useragent, data, comment, browser, version, majorver, minorver, platform, platform_version, alpha, beta, win16, win32, win64, frames, iframes, tables, cookies, backgroundsounds, javascript, vbscript, javaapplets, activexcontrols, ismobiledevice, issyndicationreader, crawler, cssversion, aolversion) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11, :db_insert_placeholder_12, :db_insert_placeholder_13, :db_insert_placeholder_14, :db_insert_placeholder_15, :db_insert_placeholder_16, :db_insert_placeholder_17, :db_insert_placeholder_18, :db_insert_placeholder_19, :db_insert_placeholder_20, :db_insert_placeholder_21, :db_insert_placeholder_22, :db_insert_placeholder_23, :db_insert_placeholder_24, :db_insert_placeholder_25, :db_insert_placeholder_26, :db_insert_placeholder_27); Array ( [:db_insert_placeholder_0] => DefaultProperties [:db_insert_placeholder_1] => a:26:{s:7:"comment";s:17:"DefaultProperties";s:7:"browser";s:17:"DefaultProperties";s:7:"version";s:3:"0.0";s:8:"majorver";s:1:"0";s:8:"minorver";s:1:"0";s:8:"platform";s:7:"unknown";s:16:"platform_version";s:7:"unknown";s:5:"alpha";s:5:"false";s:4:"beta";s:5:"false";s:5:"win16";s:5:"false";s:5:"win32";s:5:"false";s:5:"win64";s:5:"false";s:6:"frames";s:5:"false";s:7:"iframes";s:5:"false";s:6:"tables";s:5:"false";s:7:"cookies";s:5:"false";s:16:"backgroundsounds";s:5:"false";s:10:"javascript";s:5:"false";s:8:"vbscript";s:5:"false";s:11:"javaapplets";s:5:"false";s:15:"activexcontrols";s:5:"false";s:14:"ismobiledevice";s:5:"false";s:19:"issyndicationreader";s:5:"false";s:7:"crawler";s:5:"false";s:10:"cssversion";s:1:"0";s:10:"aolversion";s:1:"0";} [:db_insert_placeholder_2] => DefaultProperties [:db_insert_placeholder_3] => DefaultProperties [:db_insert_placeholder_4] => 0.0 [:db_insert_placeholder_5] => 0 [:db_insert_placeholder_6] => 0 [:db_insert_placeholder_7] => unknown [:db_insert_placeholder_8] => unknown [:db_insert_placeholder_9] => false [:db_insert_placeholder_10] => false [:db_insert_placeholder_11] => false [:db_insert_placeholder_12] => false [:db_insert_placeholder_13] => false [:db_insert_placeholder_14] => false [:db_insert_placeholder_15] => false [:db_insert_placeholder_16] => false [:db_insert_placeholder_17] => false [:db_insert_placeholder_18] => false [:db_insert_placeholder_19] => false [:db_insert_placeholder_20] => false [:db_insert_placeholder_21] => false [:db_insert_placeholder_22] => false [:db_insert_placeholder_23] => false [:db_insert_placeholder_24] => false [:db_insert_placeholder_25] => false [:db_insert_placeholder_26] => 0 [:db_insert_placeholder_27] => 0 ) in _browscap_import() (line 137 of /var/www/html/drupal_test/sites/all/modules/browscap/import.inc).
dark_kz’s picture

have the same problem

Iztok’s picture

Same problem when I want to update. The default mobile group is also missing parent browser agents list.

drupalok’s picture

i ended up using some javascript for browser detection.

don't get me wrong. i really appreciate the hard work every developer does for drupal, but longterm issues like this, which make the use of some standard-functionality (come on, mobile sites have to work out of the box in drupal now!) make me think about where drupal is going...

is it really just us 14 followers that use drupal with browscap and mobile tools and want this to work without patching and painful try-and-error?

or are we just to stupid to get this done?

mondrake’s picture

For comments #10 to #14, issue #1868808: False/true not converted to 0/1 during browscap.ini import seems to be related.

jlea9378’s picture

Thanks mondrake, that second patch you pointed me to worked. No more errors!

benchesters’s picture

I have now spent 2 hours trying to patch this file with no luck. Can someone please send me the finished file? Seems strange how no one ever posts the actual patched file yet talks about it endlessly!! Please help a novice out. Cheers!

benchesters’s picture

I am definitely too stupid - I have wasted 3 hours just trying to patch this file. I beg anyone to send me the completed file!

mondrake’s picture

@benchesters,

welcome to patching :)

in fact you should apply the patch to a local copy of the latest code, available in the development branch of the project - then, copy the resulting patched files to the folder where browscap is installed, clear caches, and you should be done.

If you are totally new to git, Drupal's version control system, where the code is stored, I would suggest you take a look at Git documentation. If you can't wait :), more direct instructions are available at Applying patches with Git.

benchesters’s picture

Hello there. I have tried and tried to do this but cannot. I even posted the job on a freelancer site. I am happy to pay someone to so this for me as it's infuriating! Appreciate your feedback mondrake but this one is out of my depth and seriously slowing me down.

DaveHS’s picture

The attached patch applies the same changes as minorOffense made in comment #1 to the 7.x-2.x code.

The zip file is the full plugin - use at your own discretion, and be careful about applying any future updates...

This version has been used successfully with:

  • Mobile Tools 7.x-3.x-dev
  • Persistent URL 7.x-1.0-beta1+11-dev
  • ThemeKey 7.x-2.3

to handle mobile devices.

benchesters’s picture

Thank you very much for your help, I really appreciate it.

steven.wichers’s picture

Not sure what's with the attached patch in #22. Here's a patch from the zip he included.

benchesters’s picture

The error seems to have stopped now that I used the version in #22. Next problem is the URL which has a word added to it when a mobile visits. The URL Modifier? Anyone know how to get rid of this, I want the same URL to be served for all devices.

alibama’s picture

Ditto - in fact I can now add the word mobile to my url eg test.com/mobile and get the same functionality regardless of whether the user agent has changed. This is not working as I had expected when I added the browscapped user agents to the mobile group.... this may be a question for mobile tools instead of browscap though... any help appreciated

xturgorex’s picture

Version: 7.x-1.x-dev » 7.x-2.0

After trying a few different patches without any luck, I finally upgraded my server from PHP 5.2 to 5.3 and used patch #24. That worked for me. I could not get this module working with 5.2. Not that my project requires 5.2, I just didn't realize this would be the issue.

dsnopek’s picture

Version: 7.x-2.0 » 7.x-2.x-dev
Status: Needs work » Reviewed & tested by the community

Patch in #24 works for me! I think the issues in #25 and #26 are with mobile_tools, not browscap. Unfortunately, I don't have a PHP 5.2 environment to verify #27.

decibel.places’s picture

I came here via directions in mobile_tools_browscap/README.txt

[Apply this patch](http://drupal.org/node/1713570) to "Browscap"

but the patch in #24 fails:

browscap$ patch -p1 < browscap-schemafix-1713570-24.patch
patching file README.txt
patching file browscap.admin.inc
Hunk #1 FAILED at 1.
1 out of 1 hunk FAILED -- saving rejects to file browscap.admin.inc.rej
patching file browscap.info
Hunk #1 FAILED at 1.
1 out of 1 hunk FAILED -- saving rejects to file browscap.info.rej
patching file browscap.install
patching file browscap.module
Hunk #1 FAILED at 1.
1 out of 1 hunk FAILED -- saving rejects to file browscap.module.rej
patching file import.inc

also it appears that the second optional patch for the Chosen module is already in the latest version

- Enable the [Chosen module](http://drupal.org/project/chosen)

- Apply the following patch

- [Add hook_library support](http://drupal.org/node/1713584)

And when I try to add a Mobile Tools device group, I get this error:

PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'b.parent' in 'field list': SELECT b.parent AS parent FROM {browscap} b GROUP BY parent ORDER BY parent ASC; Array ( ) in mobile_tools_browscap_get_browscap_parents() (line 139 of /sites/all/modules/mobile_tools/mobile_tools_browscap/mobile_tools_browscap.module).

[EDIT]

BUT...

When I replace the Browscap module with the browscap-7.x-2.x-patch.zip from #22, run db updates, and restore the official version of Browscap the error does not appear, but neither do the parent browser agents... tried the patched version form #22, still no parents...

OK, maybe because in local dev I have PHP 5.4.9-4ubuntu2.3 ?

Well on CentOS server with PHP 5.3.3 still no dice...

greggles’s picture

Status: Reviewed & tested by the community » Needs work

The patch no longer applies, so "needs work" status for that.

It would be great if someone could benchmark the code with and without this change.

jlea9378’s picture

I tried using this module (latest version) with the patch in #24 (I applied it manually) with the most recent 7.x-3.x dev release of Mobile Tools but got this error: #2117253: PDOException Data too long for column 'detection_settings'

I figured I would mention it here in case anyone else tries using this module with the patch with Mobile Tools.

danharper’s picture

Issue summary: View changes

I can't get browscap to work with latest version of mobile_tools, when I try to edit a device group I get a PDO error.

PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'b.parent' in 'field list': SELECT b.parent AS parent FROM {browscap} b GROUP BY parent ORDER BY parent ASC; Array ( ) in mobile_tools_browscap_get_browscap_parents() (line 139 of /srv/drupal/sites/all/modules/mobile_tools/mobile_tools_browscap/mobile_tools_browscap.module).

When I turn off browscap I can edit the device groups again.

The patches in the thread don't seem to work against the latest dev version.

I'm using the latest mobile tools dev version.

Cheers Dan

Damien Laguerre’s picture

Hi,

This is the patch for Browscap 7.x-2.2.

Damien Laguerre’s picture

FileSize
13.68 KB

New one,

Some fields have changed in the latest version.

greggles’s picture

  1. +++ b/browscap.install
    @@ -1,27 +1,215 @@
    + * Implements hook_install().
    

    Original was right. This is hook_schema.

  2. +++ b/browscap.install
    @@ -1,27 +1,215 @@
    +    'indexes'     => array(
    

    Did anyone benchmark this change? It will make imports even slower but should improve some lookups. So...what's the tradeoff :)

  3. +++ b/import.inc
    @@ -77,9 +78,9 @@
    +//  if (function_exists('gzdecode')) {
    

    This change looks unrelated. Can you clarify why it's needed or add it back?

  4. +++ b/import.inc
    @@ -90,8 +91,8 @@
    +        "/=\"true\"\n/",
    

    This seems like an unrelated change. Can you clarify why it was necessary?

  5. +++ b/import.inc
    @@ -144,17 +145,23 @@
    +        ->fields($fields)
    

    This change is likely to conflict with the work in #2305223: Optimize database access in _browscap_import() which seems to be closer to ready to go.

Damien Laguerre’s picture

1. From #24

2. Idem

3. I have this error with gzdecode :
Warning : gzdecode(): data error

4. Previous regex doesn't work :
Part of ini file :

[NikiBot]
Parent="DefaultProperties"
Comment="NikiBot"
Browser="NikiBot"
Frames="true"
IFrames="true"
Tables="true"
Crawler="true"

5. From #24

greggles’s picture

OK. If there are problems with the patch in #24 they should be removed, not referenced ;)

Items 3 and 4 should be split into unique issues so the merits can be discussed more directly with an issue title that focuses on that problem.

Damien Laguerre’s picture

I've just port the #24 on Browscap 7.x-2.2

This patch is requested by mobile_tools(README in mobile_tools_browscap).

I do not know why they want to blow up the table into several fields.

danharper’s picture

Hi Thanks for the updated patch, it adds the new schema correctly but it breaks the import.

When I click refresh data the page just refreshes, it doesn't display any error nor does it report to the log file.

Also as you mention a lot of work has been done to optimise the database access on the other thread but this patch which is now in dev doesn't cope with new schema required for mobilt_tools either.

I can't seem to get this to work with any combination either 7.x-2.2 or 7.x-dev patched.

It would be great to get a patch against the latest dev that would solve all the issues with slow db writes and having the correct schema.

Cheers Dan

danharper’s picture

I've created a patch which does work against the current dev version in terms of writing the correct records to the db but one caveat is that I could only get the import to work through drush as when it tries to write the records to the database it timesout.

Also although I can see the records in the db the actual mobile tools UI seems to be broken which I will log as a separate issue on that issue queue.

Dan

AohRveTPV’s picture

danharper, looks like you may have uploaded the wrong patch?

danharper’s picture

FileSize
9.91 KB

Updated patch and this seems to work but mobile tools still needs patching as the mobile tools UI seems to fail querying the parent, Patch #40 needs removing but not sure how to do it.

After reinstalling the module it doesn't bring all the fields in.

Cheers Dan

AohRveTPV’s picture

Might it be better to not hardcode the specific fields? The properties in the Browscap data may change over time. If Browscap data version x adds a property, this may break for a user whose site automatically updates from version x-1? I am wondering if it is possible and would be better to create the database columns dynamically upon import.

vishalgala’s picture

Status: Needs work » Needs review
Issue tags: +Browscap
FileSize
9.05 KB

I received the same below issue and tried to applied attached patch which worked also resolved the issue mentioned in #12 in the above mail thread..

PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'b.parent' in 'field list': SELECT b.parent AS parent FROM {browscap} b GROUP BY parent ORDER BY parent ASC; Array ( ) in mobile_tools_browscap_get_browscap_parents() (line 139 of /Users/alfredonevarez/Sites/tresplace/sites/all/modules/contrib/mobile_tools/mobile_tools_browscap/mobile_tools_browscap.module).

This is the patch for Browscap 7.x-2.2.

sidharthap’s picture

Thank you for the patch @vishalgala

I applied the patch and it shows trailing whitespace at line 191, 389,391
warning: 3 lines add whitespace errors.

Here is the new patch with correcting the whitespace errors.