diff options
author | diosmosis <benaka@piwik.pro> | 2015-09-23 11:08:30 +0300 |
---|---|---|
committer | diosmosis <benaka@piwik.pro> | 2015-09-23 11:13:10 +0300 |
commit | 055481dcacd6dd106c3aba9a9cec49124e771e02 (patch) | |
tree | 01aa8ec3730b8d5d5295ea5e0686db5e3fb80faa /plugins/SegmentEditor | |
parent | 960e635d134bd6725e927df466c501b789e2fcf7 (diff) |
Do not use doAsSuperUser in order to use API in SegmentQueryDecorator. Instead use new service-layer class that is not accessible from API and does not do access checking.
Diffstat (limited to 'plugins/SegmentEditor')
-rw-r--r-- | plugins/SegmentEditor/API.php | 33 | ||||
-rw-r--r-- | plugins/SegmentEditor/SegmentQueryDecorator.php | 15 | ||||
-rw-r--r-- | plugins/SegmentEditor/Services/StoredSegmentService.php | 56 |
3 files changed, 63 insertions, 41 deletions
diff --git a/plugins/SegmentEditor/API.php b/plugins/SegmentEditor/API.php index b9c88bbf48..e69a86bb98 100644 --- a/plugins/SegmentEditor/API.php +++ b/plugins/SegmentEditor/API.php @@ -29,15 +29,9 @@ class API extends \Piwik\Plugin\API */ private $model; - /** - * @var TransientCache - */ - private $transientCache; - - public function __construct(Model $model, TransientCache $transientCache) + public function __construct(Model $model) { $this->model = $model; - $this->transientCache = $transientCache; } protected function checkSegmentValue($definition, $idSite) @@ -368,31 +362,6 @@ class API extends \Piwik\Plugin\API } /** - * Returns stored segments that are set to be archived during cron archiving. - * - * @param int|bool $idSite - * @return array - */ - public function getSegmentsToAutoArchive($idSite = false) - { - if (!empty($idSite)) { - Piwik::checkUserHasAdminAccess($idSite); - } else { - Piwik::checkUserHasSuperUserAccess(); - } - - $idSite = (int)$idSite; - - $cacheKey = 'SegmentEditor.getSegmentsToAutoArchive_' . (!empty($idSite) ? $idSite : 'enabled_all'); - if (!$this->transientCache->contains($cacheKey)) { - $result = $this->model->getSegmentsToAutoArchive($idSite); - - $this->transientCache->save($cacheKey, $result); - } - return $this->transientCache->fetch($cacheKey); - } - - /** * @return string */ private function getMessageCannotEditSegmentCreatedBySuperUser() diff --git a/plugins/SegmentEditor/SegmentQueryDecorator.php b/plugins/SegmentEditor/SegmentQueryDecorator.php index a8f30393c0..609599eb8d 100644 --- a/plugins/SegmentEditor/SegmentQueryDecorator.php +++ b/plugins/SegmentEditor/SegmentQueryDecorator.php @@ -8,8 +8,8 @@ namespace Piwik\Plugins\SegmentEditor; -use Piwik\Access; use Piwik\DataAccess\LogQueryBuilder; +use Piwik\Plugins\SegmentEditor\Services\StoredSegmentService; use Piwik\Segment\SegmentExpression; /** @@ -21,13 +21,13 @@ use Piwik\Segment\SegmentExpression; class SegmentQueryDecorator extends LogQueryBuilder { /** - * @var API + * @var StoredSegmentService */ - private $segmentEditorApi; + private $storedSegmentService; - public function __construct(API $segmentEditorApi) + public function __construct(StoredSegmentService $storedSegmentService) { - $this->segmentEditorApi = $segmentEditorApi; + $this->storedSegmentService = $storedSegmentService; } public function getSelectQueryString(SegmentExpression $segmentExpression, $select, $from, $where, $bind, $groupBy, @@ -46,10 +46,7 @@ class SegmentQueryDecorator extends LogQueryBuilder private function getSegmentIdOfExpression(SegmentExpression $segmentExpression) { - $segmentEditorApi = $this->segmentEditorApi; - $allSegments = Access::doAsSuperUser(function () use ($segmentEditorApi) { - return $segmentEditorApi->getSegmentsToAutoArchive('all'); - }); + $allSegments = $this->storedSegmentService->getSegmentsToAutoArchive('all'); $idSegments = array(); foreach ($allSegments as $segment) { diff --git a/plugins/SegmentEditor/Services/StoredSegmentService.php b/plugins/SegmentEditor/Services/StoredSegmentService.php new file mode 100644 index 0000000000..89e3129dfc --- /dev/null +++ b/plugins/SegmentEditor/Services/StoredSegmentService.php @@ -0,0 +1,56 @@ +<?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\Plugins\SegmentEditor\Services; + +use Piwik\Plugins\SegmentEditor\Model; +use Piwik\Cache\Transient as TransientCache; + + +/** + * Service layer class for stored segments. + */ +class StoredSegmentService +{ + /** + * @var Model + */ + private $model; + + /** + * @var TransientCache + */ + private $transientCache; + + public function __construct(Model $model, TransientCache $transientCache) + { + $this->model = $model; + $this->transientCache = $transientCache; + } + + /** + * Returns stored segments that are set to be archived during cron archiving. + * + * @param int|bool $idSite + * @return array + */ + public function getSegmentsToAutoArchive($idSite = false) + { + if ($idSite != 'all') { + $idSite = (int)$idSite; + } + + $cacheKey = 'SegmentEditor.getSegmentsToAutoArchive_' . (!empty($idSite) ? $idSite : 'enabled_all'); + if (!$this->transientCache->contains($cacheKey)) { + $result = $this->model->getSegmentsToAutoArchive($idSite); + + $this->transientCache->save($cacheKey, $result); + } + return $this->transientCache->fetch($cacheKey); + } +} |