diff options
author | Stefan Giehl <stefan@matomo.org> | 2020-04-23 10:43:30 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-23 10:43:30 +0300 |
commit | a8d917778e75346eab9509ac9707f7e6e2e6c58d (patch) | |
tree | 8259898ab33eb882e631f1f5475cd1482f70e402 /plugins | |
parent | 0cdeb6da6e4679c56aa351c004cbd6afe7843c56 (diff) |
Refactores the way segments are configured in dimensions (#15836)
* Improve naming of methods for segments to rescrict access for anonymous user
* Introduce new classes SegmentsList nad DimensionSegmentFactory
* removes SegmentEditor\SegmentList and adds some tests
* submodule updates
Diffstat (limited to 'plugins')
20 files changed, 70 insertions, 183 deletions
diff --git a/plugins/API/SegmentMetadata.php b/plugins/API/SegmentMetadata.php index ca6cf0e470..28a05b06de 100644 --- a/plugins/API/SegmentMetadata.php +++ b/plugins/API/SegmentMetadata.php @@ -12,6 +12,7 @@ use Piwik\Category\CategoryList; use Piwik\Columns\Dimension; use Piwik\Piwik; use Piwik\Plugin\Segment; +use Piwik\Segment\SegmentsList; class SegmentMetadata { @@ -21,48 +22,21 @@ class SegmentMetadata */ private $categoryOrder = array(); - public function getSegmentsMetadata($idSites = array(), $_hideImplementationData = true, $isAuthenticatedWithViewAccess, $_showAllSegments = false) + public function getSegmentsMetadata($idSites, $_hideImplementationData, $isRegisteredUser, $_showAllSegments = false) { - $segments = array(); - - /** - * Triggered to add custom segment definitions. - * - * **Example** - * - * public function addSegments(&$segments) - * { - * $segment = new Segment(); - * $segment->setSegment('my_segment_name'); - * $segment->setType(Segment::TYPE_DIMENSION); - * $segment->setName('My Segment Name'); - * $segment->setSqlSegment('log_table.my_segment_name'); - * $segments[] = $segment; - * } - * - * @param array &$segments An array containing a list of segment entries. - */ - Piwik::postEvent('Segment.addSegments', array(&$segments)); - - foreach (Dimension::getAllDimensions() as $dimension) { - foreach ($dimension->getSegments() as $segment) { - if (!$_showAllSegments - && $segment->isInternal() - ) { - continue; - } - - $segments[] = $segment; - } - } - /** @var Segment[] $dimensionSegments */ - $dimensionSegments = $segments; + $dimensionSegments = SegmentsList::get()->getSegments(); $segments = array(); foreach ($dimensionSegments as $segment) { - if ($segment->isRequiresAtLeastViewAccess()) { - $segment->setPermission($isAuthenticatedWithViewAccess); + if (!$_showAllSegments + && $segment->isInternal() + ) { + continue; + } + + if ($segment->isRequiresRegisteredUser()) { + $segment->setPermission($isRegisteredUser); } $segments[] = $segment->toArray(); diff --git a/plugins/Actions/Columns/ActionUrl.php b/plugins/Actions/Columns/ActionUrl.php index df6705be23..9a591bbbfa 100644 --- a/plugins/Actions/Columns/ActionUrl.php +++ b/plugins/Actions/Columns/ActionUrl.php @@ -8,22 +8,23 @@ */ namespace Piwik\Plugins\Actions\Columns; -use Piwik\Piwik; +use Piwik\Columns\DimensionSegmentFactory; use Piwik\Plugin\Dimension\ActionDimension; use Piwik\Plugins\Actions\Segment; +use Piwik\Segment\SegmentsList; class ActionUrl extends ActionDimension { protected $nameSingular = 'Actions_ColumnActionURL'; - protected function configureSegments() + public function configureSegments(SegmentsList $segmentsList, DimensionSegmentFactory $dimensionSegmentFactory) { $segment = new Segment(); $segment->setSegment('actionUrl'); $segment->setName('Actions_ColumnActionURL'); $segment->setUnionOfSegments(array('pageUrl', 'downloadUrl', 'outlinkUrl', 'eventUrl')); - $this->addSegment($segment); + $segmentsList->addSegment($dimensionSegmentFactory->createSegment($segment)); } } diff --git a/plugins/Bandwidth b/plugins/Bandwidth -Subproject 7565711c862896ddfdde766aa5fce3080294dbf +Subproject 7d2d569d6f7b1411ba7bbd8a2df28b897f832ea diff --git a/plugins/CoreHome/Columns/LinkVisitActionIdPages.php b/plugins/CoreHome/Columns/LinkVisitActionIdPages.php index fe8355f2f8..c218ce7090 100644 --- a/plugins/CoreHome/Columns/LinkVisitActionIdPages.php +++ b/plugins/CoreHome/Columns/LinkVisitActionIdPages.php @@ -9,11 +9,13 @@ namespace Piwik\Plugins\CoreHome\Columns; use Piwik\Columns\DimensionMetricFactory; +use Piwik\Columns\DimensionSegmentFactory; use Piwik\Columns\Discriminator; use Piwik\Columns\MetricsList; use Piwik\Piwik; use Piwik\Plugin\ArchivedMetric; use Piwik\Plugin\Dimension\ActionDimension; +use Piwik\Segment\SegmentsList; use Piwik\Tracker\Action; class LinkVisitActionIdPages extends ActionDimension @@ -23,7 +25,7 @@ class LinkVisitActionIdPages extends ActionDimension protected $nameSingular = 'General_Actions'; protected $type = self::TYPE_NUMBER; - public function configureSegments() + public function configureSegments(SegmentsList $segmentsList, DimensionSegmentFactory $dimensionSegmentFactory) { // empty so we don't auto-generate a segment } diff --git a/plugins/CoreHome/Columns/VisitId.php b/plugins/CoreHome/Columns/VisitId.php index b55501a9f2..cea3a1f1cf 100644 --- a/plugins/CoreHome/Columns/VisitId.php +++ b/plugins/CoreHome/Columns/VisitId.php @@ -9,11 +9,13 @@ namespace Piwik\Plugins\CoreHome\Columns; use Piwik\Columns\DimensionMetricFactory; +use Piwik\Columns\DimensionSegmentFactory; use Piwik\Columns\MetricsList; use Piwik\Piwik; use Piwik\Plugin\ArchivedMetric; use Piwik\Plugin\Dimension\VisitDimension; use Piwik\Plugin\Segment; +use Piwik\Segment\SegmentsList; /** * Dimension for the log_visit.idvisit column. This column is added in the CREATE TABLE @@ -30,11 +32,11 @@ class VisitId extends VisitDimension protected $metricId = 'visits'; protected $type = self::TYPE_TEXT; - protected function configureSegments() + public function configureSegments(SegmentsList $segmentsList, DimensionSegmentFactory $dimensionSegmentFactory) { $segment = new Segment(); $segment->setName('General_VisitId'); - $this->addSegment($segment); + $segmentsList->addSegment($dimensionSegmentFactory->createSegment($segment)); } public function configureMetrics(MetricsList $metricsList, DimensionMetricFactory $dimensionMetricFactory) diff --git a/plugins/CoreHome/Columns/VisitIp.php b/plugins/CoreHome/Columns/VisitIp.php index f7f09e56f4..9a75b5856f 100644 --- a/plugins/CoreHome/Columns/VisitIp.php +++ b/plugins/CoreHome/Columns/VisitIp.php @@ -8,11 +8,13 @@ namespace Piwik\Plugins\CoreHome\Columns; +use Piwik\Columns\DimensionSegmentFactory; use Piwik\Common; use Piwik\Metrics\Formatter; use Matomo\Network\IPUtils; use Piwik\Plugin\Dimension\VisitDimension; use Piwik\Plugin\Segment; +use Piwik\Segment\SegmentsList; /** * Dimension for the log_visit.location_ip column. This column is added in the CREATE TABLE @@ -36,10 +38,10 @@ class VisitIp extends VisitDimension return $value; } - protected function configureSegments() + public function configureSegments(SegmentsList $segmentsList, DimensionSegmentFactory $dimensionSegmentFactory) { $segment = new Segment(); $segment->setType(Segment::TYPE_METRIC); // we cannot remove this for now as it would assign dimension based on text type - $this->addSegment($segment); + $segmentsList->addSegment($dimensionSegmentFactory->createSegment($segment)); } } diff --git a/plugins/CustomDimensions b/plugins/CustomDimensions -Subproject e86b861b843491384be107f5d474af87fe10b41 +Subproject 3e8dad6798e272e6e38de421d7fa2f49cfd2170 diff --git a/plugins/CustomVariables/Columns/Base.php b/plugins/CustomVariables/Columns/Base.php index 070aaeed98..928de6f91e 100644 --- a/plugins/CustomVariables/Columns/Base.php +++ b/plugins/CustomVariables/Columns/Base.php @@ -8,14 +8,16 @@ namespace Piwik\Plugins\CustomVariables\Columns; +use Piwik\Columns\DimensionSegmentFactory; use Piwik\Piwik; use Piwik\Plugin\Dimension\VisitDimension; use Piwik\Plugins\CustomVariables\Segment; use Piwik\Plugins\CustomVariables\CustomVariables; +use Piwik\Segment\SegmentsList; class Base extends VisitDimension { - protected function configureSegmentsFor($segmentNameSuffix) + protected function configureSegmentsFor($segmentNameSuffix, SegmentsList $segmentsList, DimensionSegmentFactory $dimensionSegmentFactory) { $numCustomVariables = CustomVariables::getNumUsableCustomVariables(); @@ -24,14 +26,14 @@ class Base extends VisitDimension $segment->setSegment('customVariable' . $segmentNameSuffix); $segment->setName($this->getName() . ' (' . Piwik::translate('CustomVariables_ScopeVisit') . ')'); $segment->setUnionOfSegments($this->getSegmentColumns('customVariable' . $segmentNameSuffix, $numCustomVariables)); - $this->addSegment($segment); + $segmentsList->addSegment($dimensionSegmentFactory->createSegment($segment)); $segment = new Segment(); $segment->setType('dimension'); $segment->setSegment('customVariablePage' . $segmentNameSuffix); $segment->setName($this->getName() . ' (' . Piwik::translate('CustomVariables_ScopePage') . ')'); $segment->setUnionOfSegments($this->getSegmentColumns('customVariablePage' . $segmentNameSuffix, $numCustomVariables)); - $this->addSegment($segment); + $segmentsList->addSegment($dimensionSegmentFactory->createSegment($segment)); $segmentSuffix = 'v'; if (strtolower($segmentNameSuffix) === 'name') { @@ -44,14 +46,14 @@ class Base extends VisitDimension $segment->setSqlSegment('log_visit.custom_var_' . $segmentSuffix . $i); $segment->setName(Piwik::translate('CustomVariables_ColumnCustomVariable' . $segmentNameSuffix) . ' ' . $i . ' (' . Piwik::translate('CustomVariables_ScopeVisit') . ')'); - $this->addSegment($segment); + $segmentsList->addSegment($dimensionSegmentFactory->createSegment($segment)); $segment = new Segment(); $segment->setSegment('customVariablePage' . $segmentNameSuffix . $i); $segment->setSqlSegment('log_link_visit_action.custom_var_' . $segmentSuffix . $i); $segment->setName(Piwik::translate('CustomVariables_ColumnCustomVariable' . $segmentNameSuffix) . ' ' . $i . ' (' . Piwik::translate('CustomVariables_ScopePage') . ')'); - $this->addSegment($segment); + $segmentsList->addSegment($dimensionSegmentFactory->createSegment($segment)); } } diff --git a/plugins/CustomVariables/Columns/CustomVariableName.php b/plugins/CustomVariables/Columns/CustomVariableName.php index d094bd0588..8e03352f94 100644 --- a/plugins/CustomVariables/Columns/CustomVariableName.php +++ b/plugins/CustomVariables/Columns/CustomVariableName.php @@ -8,13 +8,15 @@ */ namespace Piwik\Plugins\CustomVariables\Columns; +use Piwik\Columns\DimensionSegmentFactory; use Piwik\Piwik; +use Piwik\Segment\SegmentsList; class CustomVariableName extends Base { - protected function configureSegments() + public function configureSegments(SegmentsList $segmentsList, DimensionSegmentFactory $dimensionSegmentFactory) { - $this->configureSegmentsFor('Name'); + $this->configureSegmentsFor('Name', $segmentsList, $dimensionSegmentFactory); } public function getName() diff --git a/plugins/CustomVariables/Columns/CustomVariableValue.php b/plugins/CustomVariables/Columns/CustomVariableValue.php index dafd3c87ba..74d44f35d4 100644 --- a/plugins/CustomVariables/Columns/CustomVariableValue.php +++ b/plugins/CustomVariables/Columns/CustomVariableValue.php @@ -8,13 +8,15 @@ */ namespace Piwik\Plugins\CustomVariables\Columns; +use Piwik\Columns\DimensionSegmentFactory; use Piwik\Piwik; +use Piwik\Segment\SegmentsList; class CustomVariableValue extends Base { - protected function configureSegments() + public function configureSegments(SegmentsList $segmentsList, DimensionSegmentFactory $dimensionSegmentFactory) { - $this->configureSegmentsFor('Value'); + $this->configureSegmentsFor('Value', $segmentsList, $dimensionSegmentFactory); } public function getName() diff --git a/plugins/DevicesDetection/Columns/BrowserName.php b/plugins/DevicesDetection/Columns/BrowserName.php index 9a1e59ee23..58df84ba6f 100644 --- a/plugins/DevicesDetection/Columns/BrowserName.php +++ b/plugins/DevicesDetection/Columns/BrowserName.php @@ -9,9 +9,11 @@ namespace Piwik\Plugins\DevicesDetection\Columns; use DeviceDetector\Parser\Client\Browser; +use Piwik\Columns\DimensionSegmentFactory; use Piwik\Common; use Piwik\Metrics\Formatter; use Piwik\Plugin\Segment; +use Piwik\Segment\SegmentsList; use Piwik\Tracker\Request; use Piwik\Tracker\Visitor; use Piwik\Tracker\Action; @@ -26,11 +28,11 @@ class BrowserName extends Base protected $acceptValues = 'FF, IE, CH, SF, OP etc.'; protected $type = self::TYPE_TEXT; - protected function configureSegments() + public function configureSegments(SegmentsList $segmentsList, DimensionSegmentFactory $dimensionSegmentFactory) { $segment = new Segment(); $segment->setName('DevicesDetection_BrowserCode'); - $this->addSegment($segment); + $segmentsList->addSegment($dimensionSegmentFactory->createSegment($segment)); $segment = new Segment(); $segment->setSegment('browserName'); @@ -52,7 +54,7 @@ class BrowserName extends Base $segment->setSuggestedValuesCallback(function ($idSite, $maxValuesToReturn) { return array_values(Browser::getAvailableBrowsers() + ['Unknown']); }); - $this->addSegment($segment); + $segmentsList->addSegment($dimensionSegmentFactory->createSegment($segment)); } public function formatValue($value, $idSite, Formatter $formatter) diff --git a/plugins/DevicesDetection/Columns/Os.php b/plugins/DevicesDetection/Columns/Os.php index 947a35490c..200f93b055 100644 --- a/plugins/DevicesDetection/Columns/Os.php +++ b/plugins/DevicesDetection/Columns/Os.php @@ -9,10 +9,12 @@ namespace Piwik\Plugins\DevicesDetection\Columns; use DeviceDetector\Parser\OperatingSystem; +use Piwik\Columns\DimensionSegmentFactory; use Piwik\Common; use Piwik\Metrics\Formatter; use Piwik\Piwik; use Piwik\Plugin\Segment; +use Piwik\Segment\SegmentsList; use Piwik\Tracker\Request; use Piwik\Tracker\Settings; use Piwik\Tracker\Visitor; @@ -28,11 +30,11 @@ class Os extends Base protected $acceptValues = 'WIN, LIN, MAX, AND, IOS etc.'; protected $type = self::TYPE_TEXT; - protected function configureSegments() + public function configureSegments(SegmentsList $segmentsList, DimensionSegmentFactory $dimensionSegmentFactory) { $segment = new Segment(); $segment->setName('DevicesDetection_OperatingSystemCode'); - $this->addSegment($segment); + $segmentsList->addSegment($dimensionSegmentFactory->createSegment($segment)); $segment = new Segment(); $segment->setSegment('operatingSystemName'); @@ -54,7 +56,7 @@ class Os extends Base $segment->setSuggestedValuesCallback(function ($idSite, $maxValuesToReturn) { return array_values(OperatingSystem::getAvailableOperatingSystems() + ['Unknown']); }); - $this->addSegment($segment); + $segmentsList->addSegment($dimensionSegmentFactory->createSegment($segment)); } public function formatValue($value, $idSite, Formatter $formatter) diff --git a/plugins/Ecommerce/Columns/ProductCategory.php b/plugins/Ecommerce/Columns/ProductCategory.php index 6ec80b649e..bd4c0d07a6 100644 --- a/plugins/Ecommerce/Columns/ProductCategory.php +++ b/plugins/Ecommerce/Columns/ProductCategory.php @@ -9,8 +9,10 @@ namespace Piwik\Plugins\Ecommerce\Columns; use Piwik\Columns\Dimension; +use Piwik\Columns\DimensionSegmentFactory; use Piwik\Piwik; use Piwik\Plugin\Segment; +use Piwik\Segment\SegmentsList; class ProductCategory extends Dimension { @@ -20,7 +22,7 @@ class ProductCategory extends Dimension protected $category = 'Goals_Ecommerce'; protected $nameSingular = 'Goals_ProductCategory'; - protected function configureSegments() + public function configureSegments(SegmentsList $segmentsList, DimensionSegmentFactory $dimensionSegmentFactory) { $individualProductCategorySegments = $this->getProductCategorySegments(self::PRODUCT_CATEGORY_COUNT); @@ -39,7 +41,7 @@ class ProductCategory extends Dimension $segment->setSqlFilter('\\Piwik\\Tracker\\TableLogAction::getIdActionFromSegment'); $segment->setSqlSegment('log_conversion_item.' . $productCategoryColumnName); $segment->setIsInternal(true); - $this->addSegment($segment); + $segmentsList->addSegment($dimensionSegmentFactory->createSegment($segment)); } // add a union of these individual columns as productCategory @@ -49,7 +51,7 @@ class ProductCategory extends Dimension $segment->setSegment('productCategory'); $segment->setName($this->getName()); $segment->setUnionOfSegments($individualProductCategorySegments); - $this->addSegment($segment); + $segmentsList->addSegment($dimensionSegmentFactory->createSegment($segment)); } private function getProductCategorySegments($categoryCount) diff --git a/plugins/MarketingCampaignsReporting b/plugins/MarketingCampaignsReporting -Subproject 9cddfd243873665a88b7b68deaa700af38988b2 +Subproject 49d063b0869fa3440be9b34b07079a7ef3bb2c9 diff --git a/plugins/QueuedTracking b/plugins/QueuedTracking -Subproject 8fa9104c2899a83ace185864c02d942b8f9e359 +Subproject 6f334d26951db3fdac572aa79247e1ce133290b diff --git a/plugins/SegmentEditor/SegmentFormatter.php b/plugins/SegmentEditor/SegmentFormatter.php index 15de12372c..2825efb738 100644 --- a/plugins/SegmentEditor/SegmentFormatter.php +++ b/plugins/SegmentEditor/SegmentFormatter.php @@ -10,8 +10,6 @@ namespace Piwik\Plugins\SegmentEditor; use Exception; use Piwik\Common; -use Piwik\Config; -use Piwik\Db; use Piwik\Piwik; use Piwik\Segment; use Piwik\Segment\SegmentExpression; @@ -21,7 +19,7 @@ use Piwik\Segment\SegmentExpression; class SegmentFormatter { /** - * @var SegmentList + * @var Segment\SegmentsList */ private $segmentList; @@ -49,7 +47,7 @@ class SegmentFormatter SegmentExpression::BOOL_OPERATOR_END => '', ); - public function __construct(SegmentList $segmentList) + public function __construct(Segment\SegmentsList $segmentList) { $this->segmentList = $segmentList; } @@ -74,14 +72,14 @@ class SegmentFormatter $operand = $expression[SegmentExpression::INDEX_OPERAND]; $name = $operand[SegmentExpression::INDEX_OPERAND_NAME]; - $segment = $this->segmentList->findSegment($name, $idSite); + $segment = $this->segmentList->getSegment($name); if (empty($segment)) { throw new Exception(sprintf("The segment '%s' does not exist.", $name)); } - $readable .= $segment['name'] . ' '; - $readable .= $this->getTranslationForComparison($operand, $segment['type']) . ' '; + $readable .= Piwik::translate($segment->getName()) . ' '; + $readable .= $this->getTranslationForComparison($operand, $segment->getType()) . ' '; $readable .= $this->getFormattedValue($operand); $readable .= $this->getTranslationForBoolOperator($operator) . ' '; } diff --git a/plugins/SegmentEditor/SegmentList.php b/plugins/SegmentEditor/SegmentList.php deleted file mode 100644 index 32bbaf5375..0000000000 --- a/plugins/SegmentEditor/SegmentList.php +++ /dev/null @@ -1,33 +0,0 @@ -<?php -/** - * Piwik - free/libre analytics platform - * - * @link https://matomo.org - * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - * - */ -namespace Piwik\Plugins\SegmentEditor; - -use Piwik\API\Request; -use Piwik\Config; -use Piwik\Db; - -/** - */ -class SegmentList -{ - public function findSegment($segmentName, $idSite) - { - $segments = Request::processRequest('API.getSegmentsMetadata', array( - 'idSites' => array($idSite), - 'filter_limit' => '-1' - )); - - foreach ($segments as $segment) { - if ($segment['segment'] == $segmentName && !empty($segmentName)) { - return $segment; - } - } - } - -} diff --git a/plugins/SegmentEditor/tests/Integration/SegmentFormatterTest.php b/plugins/SegmentEditor/tests/Integration/SegmentFormatterTest.php index a7db9f6666..0e0f250351 100644 --- a/plugins/SegmentEditor/tests/Integration/SegmentFormatterTest.php +++ b/plugins/SegmentEditor/tests/Integration/SegmentFormatterTest.php @@ -9,7 +9,7 @@ namespace Piwik\Plugins\SegmentEditor\tests\Integration; use Piwik\Plugins\SegmentEditor\SegmentFormatter; -use Piwik\Plugins\SegmentEditor\SegmentList; +use Piwik\Segment\SegmentsList; use Piwik\Tests\Framework\Fixture; use Piwik\Tests\Framework\TestCase\IntegrationTestCase; @@ -32,10 +32,10 @@ class SegmentFormatterTest extends IntegrationTestCase { parent::setUp(); - $this->idSite = Fixture::createWebsite('2012-01-01 00:00:00'); - $this->formatter = new SegmentFormatter(new SegmentList()); - Fixture::loadAllTranslations(); + + $this->idSite = Fixture::createWebsite('2012-01-01 00:00:00'); + $this->formatter = new SegmentFormatter(SegmentsList::get()); } public function tearDown(): void diff --git a/plugins/SegmentEditor/tests/Integration/SegmentListTest.php b/plugins/SegmentEditor/tests/Integration/SegmentListTest.php deleted file mode 100644 index 3a66a4bd4e..0000000000 --- a/plugins/SegmentEditor/tests/Integration/SegmentListTest.php +++ /dev/null @@ -1,73 +0,0 @@ -<?php -/** - * Piwik - free/libre analytics platform - * - * @link https://matomo.org - * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - */ - -namespace Piwik\Plugins\SegmentEditor\tests\Integration; - -use Piwik\Plugins\SegmentEditor\SegmentList; -use Piwik\Tests\Framework\Fixture; -use Piwik\Tests\Framework\Mock\FakeAccess; -use Piwik\Tests\Framework\TestCase\IntegrationTestCase; -use Exception; - -/** - * @group SegmentListTest - * @group SegmentList - * @group SegmentEditor - * @group Plugins - */ -class SegmentListTest extends IntegrationTestCase -{ - /** - * @var SegmentList - */ - private $list; - - private $idSite; - - public function setUp(): void - { - parent::setUp(); - - $this->idSite = Fixture::createWebsite('2012-01-01 00:00:00'); - $this->list = new SegmentList(); - } - - public function test_findSegment_shouldFindSegmentByName_IfNameExists() - { - $segmentName = 'pageUrl'; - - $segment = $this->list->findSegment($segmentName, $this->idSite); - self::assertIsArray($segment); - $this->assertSame($segmentName, $segment['segment']); - } - - public function test_findSegment_shouldNotFindSegmentByName_IfNameDoesNotExist() - { - $segment = $this->list->findSegment('aNyNotExisTinGSegmEnt', $this->idSite); - $this->assertNull($segment); - } - - public function test_findSegment_ShouldThrowException_IfNotEnoughPermission() - { - $this->expectException(\Exception::class); - $this->expectExceptionMessage('checkUserHasViewAccess'); - - FakeAccess::clearAccess($superUser = false, array(1)); - - $segment = $this->list->findSegment('pageUrl', 999); - $this->assertNull($segment); - } - - public function provideContainerConfig() - { - return array( - 'Piwik\Access' => new FakeAccess() - ); - } - -} diff --git a/plugins/UserCountry/Columns/Country.php b/plugins/UserCountry/Columns/Country.php index 139e987746..f61151a1ae 100644 --- a/plugins/UserCountry/Columns/Country.php +++ b/plugins/UserCountry/Columns/Country.php @@ -8,6 +8,7 @@ */ namespace Piwik\Plugins\UserCountry\Columns; +use Piwik\Columns\DimensionSegmentFactory; use Piwik\Common; use Piwik\Config; use Piwik\Container\StaticContainer; @@ -19,6 +20,7 @@ use Piwik\Plugin\Manager; use Piwik\Plugin\Segment; use Piwik\Plugins\Provider\Provider as ProviderProvider; use Piwik\Plugins\UserCountry\LocationProvider; +use Piwik\Segment\SegmentsList; use Piwik\Tracker\Visit; use Piwik\Tracker\Visitor; use Piwik\Tracker\Action; @@ -38,11 +40,11 @@ class Country extends Base protected $segmentName = 'countryCode'; protected $acceptValues = 'ISO 3166-1 alpha-2 country codes (de, us, fr, in, es, etc.)'; - protected function configureSegments() + public function configureSegments(SegmentsList $segmentsList, DimensionSegmentFactory $dimensionSegmentFactory) { $segment = new Segment(); $segment->setName('UserCountry_CountryCode'); - $this->addSegment($segment); + $segmentsList->addSegment($dimensionSegmentFactory->createSegment($segment)); $segment = new Segment(); $segment->setSegment('countryName'); @@ -64,7 +66,7 @@ class Country extends Base $segment->setSuggestedValuesCallback(function ($idSite, $maxValuesToReturn) use ($countryList) { return array_values($countryList + ['Unknown']); }); - $this->addSegment($segment); + $segmentsList->addSegment($dimensionSegmentFactory->createSegment($segment)); } |