Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions core/Updates/5.7.0-b1.php
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',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thing came to my mind after reading the requirements again. If that hasn't changed again the starring should be handled by website, but currently that happens by segment. This might need some clarification.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand this comment.
I understood the requirements that we should star a segment per Matomo instance and not per user, so a starred segment is visible by every users. That’s why we added a "starred by …" label.
Do you think we should store the segment per website entity?

'starred_by' => 'VARCHAR(100) NULL DEFAULT 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 @@ -22,7 +22,7 @@ final class Version
* The current Matomo version.
* @var string
*/
public const VERSION = '5.7.0-alpha';
public const VERSION = '5.7.0-b1';

public const MAJOR_VERSION = 5;

Expand Down
15 changes: 15 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@
"BrokenDownReportDocumentation": "It is broken down into various reports, which are displayed in sparklines at the bottom of the page. You can enlarge the graphs by clicking on the report you'd like to see.",
"Cancel": "Cancel",
"CannotUnzipFile": "Cannot unzip file %1$s: %2$s",
"CanNotEditGlobalSegment": "This is a global segment. Only super users can edit global segments.",
"CanNotStarGlobalSegment": "This is a global segment. Only super users can star global segments.",
"CanNotUnstarGlobalSegment": "This is a global segment. Only super users can unstar global segments.",
"CanEditGlobalSegment": "This is a global segment. Any changes will apply across all websites.",
"CanStarGlobalSegment": "This is a global segment. Adding to Starred will apply across all websites.",
"CanUnstarGlobalSegment": "This is a global segment. Removing from Starred will apply across all websites.",
"CanNotEditSiteSegment": "You can only edit the segments you created yourself.",
"CanNotStarSiteSegment": "You can only add to Starred the segments you created yourself.",
"CanNotUnstarSiteSegment": "You can only remove from Starred the segments you created yourself.",
"CanEditSiteSegment": "Edit the segment for this website.",
"CanStarSiteSegment": "Add to Starred segments for this website.",
"CanUnstarSiteSegment": "Remove from Starred segments for this website.",
"ChangeInX": "Change in %1$s",
"ChangePassword": "Change password",
"ChangeTagCloudView": "Please note, that you can view the report in other ways than as a tag cloud. Use the controls at the bottom of the report to do so.",
Expand Down Expand Up @@ -463,6 +475,9 @@
"SmtpServerAddress": "SMTP server address",
"SmtpUsername": "SMTP username",
"Source": "Source",
"Star": "Star",
"StarredBy": "Starred by",
"StarredByYou": "Starred by you",
"StatisticsAreNotRecorded": "Matomo Visitor Tracking is currently disabled! Re-enable tracking by setting record_statistics = 1 in your config/config.ini.php file.",
"Subtotal": "Subtotal",
"Summary": "Summary",
Expand Down
66 changes: 59 additions & 7 deletions plugins/SegmentEditor/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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.
Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand All @@ -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);
$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
*
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions plugins/SegmentEditor/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ public static function install()
`auto_archive` tinyint(4) NOT NULL default 0,
`ts_created` TIMESTAMP NULL,
`ts_last_edit` TIMESTAMP NULL,
`starred` tinyint(4) NOT NULL default 0,
`starred_by` VARCHAR(100) NULL default NULL,
`deleted` tinyint(4) NOT NULL default 0,
PRIMARY KEY (`idsegment`)";

Expand Down
15 changes: 15 additions & 0 deletions plugins/SegmentEditor/SegmentSelectorControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ private function wouldApplySegment($savedSegment)
private function getTranslations()
{
$translationKeys = array(
'General_CanNotEditGlobalSegment',
'General_CanNotStarGlobalSegment',
'General_CanNotUnstarGlobalSegment',
'General_CanEditGlobalSegment',
'General_CanStarGlobalSegment',
'General_CanUnstarGlobalSegment',
'General_CanNotEditSiteSegment',
'General_CanNotStarSiteSegment',
'General_CanNotUnstarSiteSegment',
'General_CanEditSiteSegment',
'General_CanStarSiteSegment',
'General_CanUnstarSiteSegment',
'General_OperationEquals',
'General_OperationNotEquals',
'General_OperationAtMost',
Expand All @@ -127,6 +139,9 @@ private function getTranslations()
'General_DefaultAppended',
'SegmentEditor_AddNewSegment',
'General_Edit',
'General_StarredBy',
'General_StarredByYou',
'General_Edit',
'General_Search',
'General_SearchNoResults',
);
Expand Down
Binary file removed plugins/SegmentEditor/images/edit_segment.png
Binary file not shown.
3 changes: 3 additions & 0 deletions plugins/SegmentEditor/images/edit_segment.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading