Digitalist-Open-Cloud / Matomo-Plugin-ExtraTools

ExtraTools is a plugin for Matomo, which provides some console commands.
https://digitalist.cloud/
GNU General Public License v3.0
26 stars 12 forks source link

site:add only supports one URL #10

Closed chriscroome closed 5 years ago

chriscroome commented 5 years ago

The help for site:add suggests that one than one URL can be added at a time:

php console site:add --no-ansi -n
Adding a new site

  [Exception]                       
  The website name can't be empty.  

site:add [--name[="..."]] [--urls[="..."]] [--ecommerce] [--no-site-search] [--search-keyword-parameters[="..."]] [--search-category-parameters[="..."]] [--exclude-ips[="..."]] [--exclude-query-parameters[="..."]] [--timezone[="..."]] [--currency[="..."]] [--group[="..."]] [--start-date[="..."]] [--exclude-user-agents] [--keep-url-fragments] [--type[="..."]] [--settings-value[="..."]] [--exclude-unknown-urls]

However if you add more than one URL, space separated:

php console site:add --no-ansi -n --name='foo' --urls='https://foo.example.com/ https://bar.example.com/ https://baz.example.com/'
Adding a new site
Site added

It results in:

mysql stats -e 'SELECT idsite,name,main_url FROM site WHERE name="foo"'
+--------+------+---------------------------------------------------------------------------+
| idsite | name | main_url                                                                  |
+--------+------+---------------------------------------------------------------------------+
|      2 | foo  | https://foo.example.com/ https://bar.example.com/ https://baz.example.com |
+--------+------+---------------------------------------------------------------------------+

If comers are used:

php console site:add --no-ansi -n --name='bar' --urls='https://foo.example.com/,https://bar.example.com/,https://baz.example.com/'
Adding a new site
Site added

It results in:

mysql stats -e 'SELECT idsite,name,main_url FROM site WHERE name="bar"'
+--------+------+---------------------------------------------------------------------------+
| idsite | name | main_url                                                                  |
+--------+------+---------------------------------------------------------------------------+
|      3 | bar  | https://foo.example.com/,https://bar.example.com/,https://baz.example.com |
+--------+------+---------------------------------------------------------------------------+

This is what is needed, the main_url column should just contain the main URL for the site and other URL's should be in the site_url table cross referenced via the idsite column.

So either the urls argument needs to be a bit cleverer in the manner in which it handles input, for example splitting the first URL from subsequent ones and then correctly inserting them into the database or perhaps it would make sense to have two command line options, one for the main_url column in the site table and another option to update the site_url table?

MariaDB [stats]> describe matomo_site_url;
+--------+------------------+------+-----+---------+-------+
| Field  | Type             | Null | Key | Default | Extra |
+--------+------------------+------+-----+---------+-------+
| idsite | int(10) unsigned | NO   | PRI | NULL    |       |
| url    | varchar(255)     | NO   | PRI | NULL    |       |
+--------+------------------+------+-----+---------+-------+

Another thing to consider is the possible need for a site:update command to update things like the list of url's in the site_url table?

I'm sorry that I'm not a Python programmer so I'm not in a position to help with suggested enhancements like this other than by suggesting features and testing them.

For consistency with the database perhaps the command line options could be:

php console site:add --name='foo' --main_url='https://foo.example.com' --urls='https://bar.example.com
https://baz.example.com'

With urls requiring one URL per line?

mikkeschiren commented 5 years ago

Will look into this! (btw it's PHP not Phython :) )

mikkeschiren commented 5 years ago

Hi, this should be a typo in the code, so this:

php console site:add --name='foo' --urls=https://bar.example.com, https://baz.example.com

Should work in next release - there the first url is the primary url.

mikkeschiren commented 5 years ago

Fixed in 0.1.0-alpha10