Skip to content

Commit

Permalink
[#729] Handle languages in URLs when updating page view tracking summary
Browse files Browse the repository at this point in the history
Page view tracking was failing when a language was selected:

1. Put `ckan.tracking_enabled = true` in your ini file
2. Run CKAN, visit a page with a language e.g. `/en/dataset/annakarenina`
3. Run `paster tracking update`. If you look in your db, in the
   `tracking_summary` table there'll be a row with `package_id`
   `~~not~found~~`.
4. Run `paster tracking export tracking.csv`, the exported CSV file will
   say 0 views.

If you visit the page without the language in the URL e.g.
`/dataset/annakarenina` then run the export command again, the view does
get counted.

This commit fixes the SQL used by the `paster tracking update/export`
command to handle URLs with or without languages at the start.

Fixes #729
  • Loading branch information
Sean Hammond committed Apr 2, 2013
1 parent d242bb9 commit 55129db
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ckan/lib/cli.py
Expand Up @@ -1047,7 +1047,7 @@ def export_tracking(self, engine, output_filename):
for r in total_views])

def update_tracking(self, engine, summary_date):
PACKAGE_URL = '/dataset/'
PACKAGE_URL = '%/dataset/'
# clear out existing data before adding new
sql = '''DELETE FROM tracking_summary
WHERE tracking_date='%s'; ''' % summary_date
Expand All @@ -1073,7 +1073,7 @@ def update_tracking(self, engine, summary_date):
sql = '''UPDATE tracking_summary t
SET package_id = COALESCE(
(SELECT id FROM package p
WHERE t.url = %s || p.name)
WHERE t.url LIKE %s || p.name)
,'~~not~found~~')
WHERE t.package_id IS NULL
AND tracking_type = 'page';'''
Expand Down

0 comments on commit 55129db

Please sign in to comment.