-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Allow to star and unstar stored segment #23771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6d80b16
a3a209c
6e670b7
0678ffe
9a0667c
9cf8de5
27c6d09
3cdc0e7
43dcc8f
da0eb63
80c0f52
d149101
912a775
c8ff8d3
f1630eb
754051c
57caa8e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Matomo - free/libre analytics platform | ||
| * | ||
| * @link https://matomo.org | ||
| * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
| */ | ||
|
|
||
| namespace Piwik\Updates; | ||
|
|
||
| use Piwik\Updater; | ||
| use Piwik\Updater\Migration\Factory as MigrationFactory; | ||
| use Piwik\Updates; | ||
|
|
||
| class Updates_5_7_0_b1 extends Updates | ||
| { | ||
| /** | ||
| * @var MigrationFactory | ||
| */ | ||
| private $migration; | ||
|
|
||
| public function __construct(MigrationFactory $factory) | ||
| { | ||
| $this->migration = $factory; | ||
| } | ||
|
|
||
| public function getMigrations(Updater $updater) | ||
| { | ||
| return [ | ||
| $this->migration->db->addColumns('segment', [ | ||
| 'starred' => 'TINYINT(1) NOT NULL DEFAULT 0', | ||
| 'starred_by' => 'VARCHAR(100) NULL DEFAULT NULL', | ||
| ]), | ||
| ]; | ||
| } | ||
|
|
||
| public function doUpdate(Updater $updater) | ||
| { | ||
| $updater->executeMigrations(__FILE__, $this->getMigrations($updater)); | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -192,7 +192,7 @@ protected function checkUserCanEditOrDeleteSegment(array $segment): void | |
| throw new Exception($this->getMessageCannotEditSegmentCreatedBySuperUser()); | ||
| } | ||
|
|
||
| if ((int) $segment['enable_only_idsite'] === 0 && !Piwik::hasUserSuperUserAccess()) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ℹ️ Already tested few lines before
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix a PHPStan error in the same time |
||
| if ((int) $segment['enable_only_idsite'] === 0) { | ||
| throw new Exception(Piwik::translate('SegmentEditor_UpdatingAllSitesSegmentPermittedToSuperUser')); | ||
| } | ||
| } | ||
|
|
@@ -215,7 +215,7 @@ public function delete(int $idSegment): void | |
| * | ||
| * @param int $idSegment The ID of the segment being deleted. | ||
| */ | ||
| Piwik::postEvent('SegmentEditor.deactivate', array($idSegment)); | ||
| Piwik::postEvent('SegmentEditor.deactivate', [$idSegment]); | ||
|
|
||
| $this->getModel()->deleteSegment($idSegment); | ||
|
|
||
|
|
@@ -263,14 +263,14 @@ public function update( | |
|
|
||
| $autoArchive = $this->checkAutoArchive($autoArchive, $idSite); | ||
|
|
||
| $bind = array( | ||
| $bind = [ | ||
| 'name' => $name, | ||
| 'definition' => $definition, | ||
| 'enable_all_users' => (int) $enabledAllUsers, | ||
| 'enable_only_idsite' => (int) $idSite, | ||
| 'auto_archive' => (int) $autoArchive, | ||
| 'ts_last_edit' => Date::now()->getDatetime(), | ||
| ); | ||
| ]; | ||
|
|
||
| /** | ||
| * Triggered before a segment is modified. | ||
|
|
@@ -280,7 +280,7 @@ public function update( | |
| * | ||
| * @param int $idSegment The ID of the segment which visibility is reduced. | ||
| */ | ||
| Piwik::postEvent('SegmentEditor.update', array($idSegment, $bind)); | ||
| Piwik::postEvent('SegmentEditor.update', [$idSegment, $bind]); | ||
|
|
||
| $this->getModel()->updateSegment($idSegment, $bind); | ||
|
|
||
|
|
@@ -321,16 +321,18 @@ public function add( | |
| $enabledAllUsers = $this->checkEnabledAllUsers($enabledAllUsers); | ||
| $autoArchive = $this->checkAutoArchive($autoArchive, $idSite); | ||
|
|
||
| $bind = array( | ||
| $bind = [ | ||
| 'name' => $name, | ||
| 'definition' => $definition, | ||
| 'login' => Piwik::getCurrentUserLogin(), | ||
| 'enable_all_users' => (int) $enabledAllUsers, | ||
| 'enable_only_idsite' => (int) $idSite, | ||
| 'auto_archive' => (int) $autoArchive, | ||
| 'ts_created' => Date::now()->getDatetime(), | ||
| 'starred' => 0, | ||
| 'starred_by' => null, | ||
| 'deleted' => 0, | ||
| ); | ||
| ]; | ||
|
|
||
| $id = $this->getModel()->createSegment($bind); | ||
|
|
||
|
|
@@ -348,6 +350,56 @@ public function add( | |
| return $id; | ||
| } | ||
|
|
||
| /** | ||
| * Stars a stored segment. | ||
| * | ||
| * @param int $idSegment | ||
| * @return array{result: boolean, starred_by: string} | ||
| * @throws Exception if the user is not logged in or does not have the required permissions. | ||
| */ | ||
| public function star(int $idSegment): array | ||
| { | ||
| Piwik::checkUserHasSomeViewAccess(); | ||
| $segment = $this->getSegmentOrFail($idSegment); | ||
|
tzi marked this conversation as resolved.
|
||
| $this->checkUserCanEditOrDeleteSegment($segment); | ||
| $login = Piwik::getCurrentUserLogin(); | ||
| $bind = [ | ||
| 'starred' => 1, | ||
| 'starred_by' => $login, | ||
| ]; | ||
|
|
||
| $result = $this->getModel()->updateSegment($idSegment, $bind); | ||
|
|
||
| return [ | ||
| 'result' => $result, | ||
| 'starred_by' => $login, | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * Unstars a stored segment. | ||
| * | ||
| * @param int $idSegment | ||
| * @return array{result: boolean} | ||
| * @throws Exception if the user is not logged in or does not have the required permissions. | ||
| */ | ||
| public function unstar(int $idSegment): array | ||
| { | ||
| Piwik::checkUserHasSomeViewAccess(); | ||
| $segment = $this->getSegmentOrFail($idSegment); | ||
| $this->checkUserCanEditOrDeleteSegment($segment); | ||
| $bind = [ | ||
| 'starred' => 0, | ||
| 'starred_by' => null, | ||
| ]; | ||
|
|
||
| $result = $this->getModel()->updateSegment($idSegment, $bind); | ||
|
|
||
| return [ | ||
| 'result' => $result, | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * Returns a stored segment by ID | ||
| * | ||
|
|
@@ -444,7 +496,7 @@ private function filterSegmentsWithDisabledElements(array $segments, $idSite = n | |
| */ | ||
| private function sortSegmentsCreatedByUserFirst(array $segments): array | ||
| { | ||
| $orderedSegments = array(); | ||
| $orderedSegments = []; | ||
| foreach ($segments as $id => &$segment) { | ||
| if ($segment['login'] == Piwik::getCurrentUserLogin()) { | ||
| $orderedSegments[] = $segment; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.