Skip to content

Commit

Permalink
Remember user who created a site. (matomo-org#13362)
Browse files Browse the repository at this point in the history
* Remember user who created a site.

* Bump version & change column name to creator_login.

* Rename Site::getCreationUserFor

* Process sites like other methods in getPatternMatchSites().

* Update expected test files.

* update test again
  • Loading branch information
diosmosis authored and InfinityVoid committed Oct 11, 2018
1 parent e2bedb0 commit 2d1facb
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 1 deletion.
1 change: 1 addition & 0 deletions core/Db/Schema/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public function getTablesCreateSql()
`group` VARCHAR(250) NOT NULL,
`type` VARCHAR(255) NOT NULL,
keep_url_fragment TINYINT NOT NULL DEFAULT 0,
creator_login VARCHAR(100) NULL,
PRIMARY KEY(idsite)
) ENGINE=$engine DEFAULT CHARSET=utf8
",
Expand Down
11 changes: 11 additions & 0 deletions core/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -646,4 +646,15 @@ public static function getExcludedQueryParametersFor($idsite)
{
return self::getFor($idsite, 'excluded_parameters');
}

/**
* Returns the user that created this site.
*
* @param int $idsite The site ID.
* @return string|null If null, the site was created before the creation user was tracked.
*/
public static function getCreatorLoginFor($idsite)
{
return self::getFor($idsite, 'creator_login');
}
}
43 changes: 43 additions & 0 deletions core/Updates/3.6.1-b2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/

namespace Piwik\Updates;

use Piwik\Common;
use Piwik\Updater\Migration\Factory as MigrationFactory;
use Piwik\Updates;
use Piwik\Updater;

/**
* Update for version 3.6.1-b2.
*/
class Updates_3_6_1_b2 extends Updates
{
/**
* @var MigrationFactory
*/
private $migration;

public function __construct(MigrationFactory $factory)
{
$this->migration = $factory;
}

public function getMigrations(Updater $updater)
{
return array(
$this->migration->db->addColumn('site', 'creator_login', ' VARCHAR(100) NULL'),
);
}

public function doUpdate(Updater $updater)
{
$updater->executeMigrations(__FILE__, $this->getMigrations($updater));
}
}
2 changes: 1 addition & 1 deletion core/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class Version
* The current Matomo version.
* @var string
*/
const VERSION = '3.6.1-b1';
const VERSION = '3.6.1-b2';

public function isStableVersion($version)
{
Expand Down
Binary file not shown.
12 changes: 12 additions & 0 deletions plugins/SitesManager/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,11 @@ private function enrichSite(&$site)
$name = Piwik::translate($key);

$site['currency_name'] = ($key === $name) ? $site['currency'] : $name;

// don't want to expose other user logins here
if (!Piwik::hasUserSuperUserAccess()) {
unset($site['creator_login']);
}
}

/**
Expand Down Expand Up @@ -648,6 +653,8 @@ public function addSite($siteName,
$bind['group'] = "";
}

$bind['creator_login'] = Piwik::getCurrentUserLogin();

$allSettings = $this->setAndValidateMeasurableSettings(0, 'website', $coreProperties);

// any setting specified in setting values will overwrite other setting
Expand Down Expand Up @@ -1622,7 +1629,12 @@ public function getPatternMatchSites($pattern, $limit = false)

$sites = $this->getModel()->getPatternMatchSites($ids, $pattern, $limit);

foreach ($sites as &$site) {
$this->enrichSite($site);
}

$sites = Site::setSitesFromArray($sites);

return $sites;
}

Expand Down
2 changes: 2 additions & 0 deletions plugins/SitesManager/tests/Integration/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ private function addSiteTest($expectedWebsiteType, $settingValues = null)
$this->assertTrue(Site::isSiteSearchEnabledFor($idsite));
$this->assertEquals($expectedWebsiteType, $siteInfo['type']);
$this->assertEquals($expectedWebsiteType, Site::getTypeFor($idsite));
$this->assertEquals('superUserLogin', $siteInfo['creator_login']);
$this->assertEquals('superUserLogin', Site::getCreatorLoginFor($idsite));

$this->assertEquals($searchKeywordParameters, $siteInfo['sitesearch_keyword_parameters']);
$this->assertEquals($searchCategoryParameters, $siteInfo['sitesearch_category_parameters']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<group />
<type>website</type>
<keep_url_fragment>0</keep_url_fragment>
<creator_login>superUserLogin</creator_login>
<timezone_name>UTC</timezone_name>
<currency_name>US Dollar</currency_name>
</row>
<row>
<idsite>10</idsite>
Expand All @@ -37,6 +40,9 @@
<group />
<type>website</type>
<keep_url_fragment>0</keep_url_fragment>
<creator_login>superUserLogin</creator_login>
<timezone_name>UTC</timezone_name>
<currency_name>US Dollar</currency_name>
</row>
<row>
<idsite>11</idsite>
Expand All @@ -56,6 +62,9 @@
<group />
<type>website</type>
<keep_url_fragment>0</keep_url_fragment>
<creator_login>superUserLogin</creator_login>
<timezone_name>UTC</timezone_name>
<currency_name>US Dollar</currency_name>
</row>
<row>
<idsite>12</idsite>
Expand All @@ -75,6 +84,9 @@
<group />
<type>website</type>
<keep_url_fragment>0</keep_url_fragment>
<creator_login>superUserLogin</creator_login>
<timezone_name>UTC</timezone_name>
<currency_name>US Dollar</currency_name>
</row>
<row>
<idsite>13</idsite>
Expand All @@ -94,6 +106,9 @@
<group />
<type>website</type>
<keep_url_fragment>0</keep_url_fragment>
<creator_login>superUserLogin</creator_login>
<timezone_name>UTC</timezone_name>
<currency_name>US Dollar</currency_name>
</row>
<row>
<idsite>14</idsite>
Expand All @@ -113,6 +128,9 @@
<group />
<type>website</type>
<keep_url_fragment>0</keep_url_fragment>
<creator_login>superUserLogin</creator_login>
<timezone_name>UTC</timezone_name>
<currency_name>US Dollar</currency_name>
</row>
<row>
<idsite>15</idsite>
Expand All @@ -132,6 +150,9 @@
<group />
<type>website</type>
<keep_url_fragment>0</keep_url_fragment>
<creator_login>superUserLogin</creator_login>
<timezone_name>UTC</timezone_name>
<currency_name>US Dollar</currency_name>
</row>
<row>
<idsite>16</idsite>
Expand All @@ -151,6 +172,9 @@
<group />
<type>website</type>
<keep_url_fragment>0</keep_url_fragment>
<creator_login>superUserLogin</creator_login>
<timezone_name>UTC</timezone_name>
<currency_name>US Dollar</currency_name>
</row>
<row>
<idsite>17</idsite>
Expand All @@ -170,6 +194,9 @@
<group />
<type>website</type>
<keep_url_fragment>0</keep_url_fragment>
<creator_login>superUserLogin</creator_login>
<timezone_name>UTC</timezone_name>
<currency_name>US Dollar</currency_name>
</row>
<row>
<idsite>18</idsite>
Expand All @@ -189,6 +216,9 @@
<group />
<type>website</type>
<keep_url_fragment>0</keep_url_fragment>
<creator_login>superUserLogin</creator_login>
<timezone_name>UTC</timezone_name>
<currency_name>US Dollar</currency_name>
</row>
<row>
<idsite>19</idsite>
Expand All @@ -208,5 +238,8 @@
<group />
<type>website</type>
<keep_url_fragment>0</keep_url_fragment>
<creator_login>superUserLogin</creator_login>
<timezone_name>UTC</timezone_name>
<currency_name>US Dollar</currency_name>
</row>
</result>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<group />
<type>website</type>
<keep_url_fragment>0</keep_url_fragment>
<creator_login>superUserLogin</creator_login>
<timezone_name>UTC</timezone_name>
<currency_name>US Dollar</currency_name>
</row>
<row>
<idsite>10</idsite>
Expand All @@ -37,5 +40,8 @@
<group />
<type>website</type>
<keep_url_fragment>0</keep_url_fragment>
<creator_login>superUserLogin</creator_login>
<timezone_name>UTC</timezone_name>
<currency_name>US Dollar</currency_name>
</row>
</result>

0 comments on commit 2d1facb

Please sign in to comment.