Skip to content

Commit 9a1f9e6

Browse files
authored
Merge pull request #17 from MITLibraries/update-plugins
Update plugins to match Matomo v5.x
2 parents 7a957a0 + c65074a commit 9a1f9e6

File tree

116 files changed

+4037
-30
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+4037
-30
lines changed

Dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
FROM matomo:5.0.1
1+
FROM matomo:5.0.3
22

33
# Add the EnvironmentVariables plugin
4-
COPY ./files/plugin-EnvironmentVariables-4.0.1/ /var/www/html/plugins/EnvironmentVariables
5-
COPY ./files/plugin-CustomVariables-4.1.1/ /var/www/html/plugins/CustomVariables
4+
COPY ./files/plugin-EnvironmentVariables-5.0.0/ /var/www/html/plugins/EnvironmentVariables
5+
6+
# Add the CustomVariables plugin
7+
COPY ./files/plugin-CustomVariables-5.0.2/ /var/www/html/plugins/CustomVariables
68

79
# Preconfigure settings
810
COPY ./files/config.ini.php /var/www/html/config/config.ini.php

docs/HowTos/HOWTO-matomo-upgrade.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ The database engine is managed by [mitlib-tf-workloads-matomo](https://github.co
88

99
## Update Matomo version
1010

11-
These instructions assume you are working in the **dev** environment. Change to the appropriate <env> tag if you are working in a different environment.
11+
These instructions assume you are working in the **dev** environment. Change to the appropriate `<env>` tag if you are working in a different environment.
1212

1313
1. Ensure that a backup of the current `config/config.ini.php` exists in the EFS mount.
1414
* SSH (via AWSCLI + Session Manager) to the container(see the [Troubleshooting](./HOWTO-miscellaneous.md) section for the AWS CLI connection command).
1515
* Run the **backup-data.sh** script `/usr/local/bin/backup-data.sh`
1616
1. Make any necessary changes to the repo.
1717
* For version upgrades, change line 1 in **Dockerfile** to the new version.
18+
* Verify plugin versions for compatibility with new version of Matomo. See **Update Matomo Plugins** below for more details.
1819
1. Publish the updated container to ECR.
1920
* Run `make dist-dev` to create the updated container.
2021
* Run `make publish-dev` to push the new container to ECR and tag it as 'latest'.
@@ -39,3 +40,15 @@ These instructions assume you are working in the **dev** environment. Change to
3940
1. Verify that there were no changes to the `config.ini.php` file that need to be captured back in this repo.
4041
* See [compare-ini-files](./HOWTO-compare-ini-files.md)
4142
1. Log back in to the webUI to verify that everything is working. Ask someone in DEP to assist with this step.
43+
44+
## Update Matomo Plugins
45+
46+
Often, an update to the version of Matomo will require an update to a plugin version. See below for an overview of the plugin update process.
47+
48+
1. Ensure that a backup of the current `config/config.ini.php` exists in the EFS mount.
49+
* SSH (via AWSCLI + Session Manager) to the container(see the [Troubleshooting](./HOWTO-miscellaneous.md) section for the AWS CLI connection command).
50+
* Run the **backup-data.sh** script `/usr/local/bin/backup-data.sh`
51+
1. Visit [Matomo plugins](https://plugins.matomo.org), select the correct version of Matomo, and then search for the plugins that are currently in use in our instance of Matomo.
52+
* If there is a newer version, download it from the site, unzip it, and store the unzipped folder in the [files/](../../files/) directory, following the naming convention in place (e.g., `plugin-<plugin_name>-<version>`)
53+
1. Update the [Dockerfile](../../Dockerfile) to reference the newer version of the plugin stored in the [files/](../../files/) directory.
54+
1. Proceed with the publishing process as outlined in the **Update Matomo Version** instructions above.
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
<?php
2+
/**
3+
* Matomo - free/libre analytics platform
4+
*
5+
* @link https://matomo.org
6+
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7+
*
8+
*/
9+
namespace Piwik\Plugins\CustomVariables;
10+
11+
use Piwik\API\Request;
12+
use Piwik\Archive;
13+
use Piwik\Container\StaticContainer;
14+
use Piwik\DataTable;
15+
use Piwik\Date;
16+
use Piwik\Metrics;
17+
use Piwik\Piwik;
18+
19+
/**
20+
* The Custom Variables API lets you access reports for your <a href='http://matomo.org/docs/custom-variables/' rel='noreferrer' target='_blank'>Custom Variables</a> names and values.
21+
*
22+
* @method static \Piwik\Plugins\CustomVariables\API getInstance()
23+
*/
24+
class API extends \Piwik\Plugin\API
25+
{
26+
/**
27+
* @param int $idSite
28+
* @param string $period
29+
* @param Date $date
30+
* @param string $segment
31+
* @param bool $expanded
32+
* @param int $idSubtable
33+
*
34+
* @return DataTable|DataTable\Map
35+
*/
36+
protected function getDataTable($idSite, $period, $date, $segment, $expanded, $flat, $idSubtable)
37+
{
38+
$dataTable = Archive::createDataTableFromArchive(Archiver::CUSTOM_VARIABLE_RECORD_NAME, $idSite, $period, $date, $segment, $expanded, $flat, $idSubtable);
39+
$dataTable->queueFilter('ColumnDelete', 'nb_uniq_visitors');
40+
41+
if ($flat) {
42+
$dataTable->filterSubtables('Sort', array(Metrics::INDEX_NB_ACTIONS, 'desc', $naturalSort = false, $expanded));
43+
$dataTable->queueFilterSubtables('ColumnDelete', 'nb_uniq_visitors');
44+
}
45+
46+
return $dataTable;
47+
}
48+
49+
/**
50+
* @param int $idSite
51+
* @param string $period
52+
* @param Date $date
53+
* @param string|bool $segment
54+
* @param bool $expanded
55+
* @param bool $_leavePiwikCoreVariables
56+
* @param bool $flat
57+
*
58+
* @return DataTable|DataTable\Map
59+
*/
60+
public function getCustomVariables($idSite, $period, $date, $segment = false, $expanded = false, $_leavePiwikCoreVariables = false, $flat = false)
61+
{
62+
Piwik::checkUserHasViewAccess($idSite);
63+
64+
$dataTable = $this->getDataTable($idSite, $period, $date, $segment, $expanded, $flat, $idSubtable = null);
65+
66+
if ($dataTable instanceof DataTable
67+
&& !$_leavePiwikCoreVariables
68+
) {
69+
$mapping = self::getReservedCustomVariableKeys();
70+
foreach ($mapping as $name) {
71+
$row = $dataTable->getRowFromLabel($name);
72+
if ($row) {
73+
$dataTable->deleteRow($dataTable->getRowIdFromLabel($name));
74+
}
75+
}
76+
}
77+
78+
79+
if ($flat) {
80+
$dataTable->filterSubtables('Piwik\Plugins\CustomVariables\DataTable\Filter\CustomVariablesValuesFromNameId');
81+
} else {
82+
$dataTable->filter('AddSegmentByLabel', array('customVariableName'));
83+
}
84+
85+
return $dataTable;
86+
}
87+
88+
/**
89+
* @ignore
90+
* @return array
91+
*/
92+
public static function getReservedCustomVariableKeys()
93+
{
94+
// Note: _pk_scat and _pk_scount has been used for site search, but aren't in use anymore
95+
return array('_pks', '_pkn', '_pkc', '_pkp', '_pk_scat', '_pk_scount');
96+
}
97+
98+
/**
99+
* @param int $idSite
100+
* @param string $period
101+
* @param Date $date
102+
* @param int $idSubtable
103+
* @param string|bool $segment
104+
* @param bool $_leavePriceViewedColumn
105+
*
106+
* @return DataTable|DataTable\Map
107+
*/
108+
public function getCustomVariablesValuesFromNameId($idSite, $period, $date, $idSubtable, $segment = false, $_leavePriceViewedColumn = false)
109+
{
110+
Piwik::checkUserHasViewAccess($idSite);
111+
112+
$dataTable = $this->getDataTable($idSite, $period, $date, $segment, $expanded = false, $flat = false, $idSubtable);
113+
114+
if (!$_leavePriceViewedColumn) {
115+
$dataTable->deleteColumn('price_viewed');
116+
} else {
117+
// Hack Ecommerce product price tracking to display correctly
118+
$dataTable->renameColumn('price_viewed', 'price');
119+
}
120+
121+
$dataTable->filter('Piwik\Plugins\CustomVariables\DataTable\Filter\CustomVariablesValuesFromNameId');
122+
123+
return $dataTable;
124+
}
125+
126+
/**
127+
* Get a list of all available custom variable slots (scope + index) and which names have been used so far in
128+
* each slot since the beginning of the website.
129+
*
130+
* @param int $idSite
131+
* @return array
132+
*/
133+
public function getUsagesOfSlots($idSite)
134+
{
135+
Piwik::checkUserHasAdminAccess($idSite);
136+
137+
$numVars = CustomVariables::getNumUsableCustomVariables();
138+
139+
$usedCustomVariables = array(
140+
'visit' => array_fill(1, $numVars, array()),
141+
'page' => array_fill(1, $numVars, array()),
142+
);
143+
144+
/** @var DataTable $customVarUsages */
145+
$today = StaticContainer::get('CustomVariables.today');
146+
$date = '2008-12-12,' . $today;
147+
$customVarUsages = Request::processRequest('CustomVariables.getCustomVariables',
148+
array('idSite' => $idSite, 'period' => 'range', 'date' => $date,
149+
'format' => 'original')
150+
);
151+
152+
foreach ($customVarUsages->getRows() as $row) {
153+
$slots = $row->getMetadata('slots');
154+
155+
if (!empty($slots)) {
156+
foreach ($slots as $slot) {
157+
$usedCustomVariables[$slot['scope']][$slot['index']][] = array(
158+
'name' => $row->getColumn('label'),
159+
'nb_visits' => $row->getColumn('nb_visits'),
160+
'nb_actions' => $row->getColumn('nb_actions'),
161+
);
162+
}
163+
}
164+
}
165+
166+
$grouped = array();
167+
foreach ($usedCustomVariables as $scope => $scopes) {
168+
foreach ($scopes as $index => $cvars) {
169+
$grouped[] = array(
170+
'scope' => $scope,
171+
'index' => $index,
172+
'usages' => $cvars
173+
);
174+
}
175+
}
176+
177+
return $grouped;
178+
}
179+
}
180+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* Matomo - free/libre analytics platform
4+
*
5+
* @link https://matomo.org
6+
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7+
*
8+
*/
9+
namespace Piwik\Plugins\CustomVariables;
10+
11+
class Archiver extends \Piwik\Plugin\Archiver
12+
{
13+
const LABEL_CUSTOM_VALUE_NOT_DEFINED = "Value not defined";
14+
const CUSTOM_VARIABLE_RECORD_NAME = 'CustomVariables_valueByName';
15+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# CHANGELOG
2+
3+
5.0.2
4+
- Archiving: Ensure parameter is provided in correct type
5+
6+
5.0.1
7+
- Compatibility with Matomo 5.0.0-b4
8+
9+
5.0.0
10+
- Compatibility with Matomo 5
11+
12+
4.1.3
13+
- Update documentation
14+
15+
4.1.2
16+
- Update documentation
17+
- Translation updates
18+
19+
4.1.1
20+
- Translation updates
21+
22+
4.1.0
23+
- migrate from AngularJS to Vue.
24+
- Replaced substr() with mb_substr() to correctly cut utf8 values.
25+
- Fixed warnings and depreciation for PHP8.1
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/**
3+
* Matomo - free/libre analytics platform
4+
*
5+
* @link https://matomo.org
6+
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7+
*
8+
*/
9+
namespace Piwik\Plugins\CustomVariables\Categories;
10+
11+
use Piwik\Category\Category;
12+
13+
class CustomVariablesCategory extends Category
14+
{
15+
protected $id = 'CustomVariables_CustomVariables';
16+
protected $order = 8;
17+
18+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* Matomo - free/libre analytics platform
4+
*
5+
* @link https://matomo.org
6+
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7+
*
8+
*/
9+
namespace Piwik\Plugins\CustomVariables\Categories;
10+
11+
use Piwik\Category\Subcategory;
12+
use Piwik\Piwik;
13+
14+
class CustomVariablesSubcategory extends Subcategory
15+
{
16+
protected $categoryId = 'General_Visitors';
17+
protected $id = 'CustomVariables_CustomVariables';
18+
protected $order = 45;
19+
20+
public function getHelp()
21+
{
22+
return '<p>' . Piwik::translate('CustomVariables_CustomVariablesSubcategoryHelp1') . '</p>'
23+
. '<p><a href="https://matomo.org/docs/custom-variables/" rel="noreferrer noopener" target="_blank">' . Piwik::translate('CustomVariables_CustomVariablesSubcategoryHelp2') . '</a></p>'
24+
;
25+
}
26+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
/**
3+
* Matomo - free/libre analytics platform
4+
*
5+
* @link https://matomo.org
6+
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7+
*/
8+
9+
namespace Piwik\Plugins\CustomVariables\Columns;
10+
11+
use Piwik\Columns\DimensionSegmentFactory;
12+
use Piwik\Piwik;
13+
use Piwik\Plugin\Dimension\VisitDimension;
14+
use Piwik\Plugins\CustomVariables\Segment;
15+
use Piwik\Plugins\CustomVariables\CustomVariables;
16+
use Piwik\Segment\SegmentsList;
17+
18+
abstract class Base extends VisitDimension
19+
{
20+
protected function configureSegmentsFor($segmentNameSuffix, SegmentsList $segmentsList, DimensionSegmentFactory $dimensionSegmentFactory)
21+
{
22+
$numCustomVariables = CustomVariables::getNumUsableCustomVariables();
23+
24+
$segmentSuffix = 'v';
25+
if (strtolower($segmentNameSuffix) === 'name') {
26+
$segmentSuffix = 'k';
27+
}
28+
29+
for ($i = 1; $i <= $numCustomVariables; $i++) {
30+
$segment = new Segment();
31+
$segment->setSegment('customVariable' . $segmentNameSuffix . $i);
32+
$segment->setSqlSegment('log_visit.custom_var_' . $segmentSuffix . $i);
33+
$segment->setName(Piwik::translate('CustomVariables_ColumnCustomVariable' . $segmentNameSuffix) . ' ' . $i
34+
. ' (' . Piwik::translate('CustomVariables_ScopeVisit') . ')');
35+
$segmentsList->addSegment($dimensionSegmentFactory->createSegment($segment));
36+
37+
$segment = new Segment();
38+
$segment->setSegment('customVariablePage' . $segmentNameSuffix . $i);
39+
$segment->setSqlSegment('log_link_visit_action.custom_var_' . $segmentSuffix . $i);
40+
$segment->setName(Piwik::translate('CustomVariables_ColumnCustomVariable' . $segmentNameSuffix) . ' ' . $i
41+
. ' (' . Piwik::translate('CustomVariables_ScopePage') . ')');
42+
$segmentsList->addSegment($dimensionSegmentFactory->createSegment($segment));
43+
}
44+
45+
$segment = new Segment();
46+
$segment->setType('dimension');
47+
$segment->setSegment('customVariable' . $segmentNameSuffix);
48+
$segment->setName($this->getName() . ' (' . Piwik::translate('CustomVariables_ScopeVisit') . ')');
49+
$segment->setUnionOfSegments($this->getSegmentColumns('customVariable' . $segmentNameSuffix, $numCustomVariables));
50+
$segmentsList->addSegment($dimensionSegmentFactory->createSegment($segment));
51+
52+
$segment = new Segment();
53+
$segment->setType('dimension');
54+
$segment->setSegment('customVariablePage' . $segmentNameSuffix);
55+
$segment->setName($this->getName() . ' (' . Piwik::translate('CustomVariables_ScopePage') . ')');
56+
$segment->setUnionOfSegments($this->getSegmentColumns('customVariablePage' . $segmentNameSuffix, $numCustomVariables));
57+
$segmentsList->addSegment($dimensionSegmentFactory->createSegment($segment));
58+
}
59+
60+
private function getSegmentColumns($column, $numCustomVariables)
61+
{
62+
$columns = array();
63+
for ($i = 1; $i <= $numCustomVariables; ++$i) {
64+
$columns[] = $column . $i;
65+
}
66+
return $columns;
67+
}
68+
}

0 commit comments

Comments
 (0)