Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattab <matthieu.aubry@gmail.com>2013-11-04 04:16:45 +0400
committermattab <matthieu.aubry@gmail.com>2013-11-04 04:16:45 +0400
commitd16c46fa55ff72a61311a89a3a487535d79e0fae (patch)
tree02283239e1600a706c581970095427b0799b4474
parent3ea0878890958e8b329c40c89000e4ad56a22d5c (diff)
Refs #472 move getIdActionFromSegment to TableLogAction class
-rw-r--r--.gitignore1
-rw-r--r--core/Tracker/TableLogAction.php82
-rw-r--r--plugins/Actions/Actions.php71
-rw-r--r--plugins/Actions/ArchivingHelper.php63
-rw-r--r--plugins/Transitions/API.php9
5 files changed, 114 insertions, 112 deletions
diff --git a/.gitignore b/.gitignore
index 05529382ee..5ba1801a70 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,7 +19,6 @@ robots.txt
tmp
tmp/*
vendor/
-
.cache
.DS_Store
.externalToolBuilders
diff --git a/core/Tracker/TableLogAction.php b/core/Tracker/TableLogAction.php
index 59dc682cf0..b7ec978876 100644
--- a/core/Tracker/TableLogAction.php
+++ b/core/Tracker/TableLogAction.php
@@ -12,6 +12,7 @@
namespace Piwik\Tracker;
use Piwik\Common;
+use Piwik\SegmentExpression;
use Piwik\Tracker;
@@ -59,7 +60,7 @@ class TableLogAction
* @param $type
* @return string
*/
- public static function getIdActionMatchingNameAndType($name, $type)
+ private static function getIdActionMatchingNameAndType($name, $type)
{
$sql = TableLogAction::getSqlSelectActionId();
$bind = array($name, $name, $type);
@@ -73,7 +74,7 @@ class TableLogAction
* @return string
* @throws \Exception
*/
- public static function getSelectQueryWhereNameContains($matchType, $actionType)
+ private static function getSelectQueryWhereNameContains($matchType, $actionType)
{
// now, we handle the cases =@ (contains) and !@ (does not contain)
// build the expression based on the match type
@@ -94,7 +95,7 @@ class TableLogAction
return $sql;
}
- protected static function getSqlSelectActionId()
+ private static function getSqlSelectActionId()
{
$sql = "SELECT idaction, type, name
FROM " . Common::prefixTable('log_action')
@@ -103,7 +104,7 @@ class TableLogAction
return $sql;
}
- protected static function insertNewIdsAction($actionsNameAndType, $fieldNamesToInsert)
+ private static function insertNewIdsAction($actionsNameAndType, $fieldNamesToInsert)
{
$sql = "INSERT INTO " . Common::prefixTable('log_action') .
"( name, hash, type, url_prefix ) VALUES (?,CRC32(?),?,?)";
@@ -122,7 +123,7 @@ class TableLogAction
return $inserted;
}
- protected static function queryIdsAction($actionsNameAndType)
+ private static function queryIdsAction($actionsNameAndType)
{
$sql = TableLogAction::getSqlSelectActionId();
$bind = array();
@@ -148,7 +149,7 @@ class TableLogAction
return $actionIds;
}
- protected static function processIdsToInsert($actionsNameAndType, $actionIds)
+ private static function processIdsToInsert($actionsNameAndType, $actionIds)
{
// For the Actions found in the lookup table, add the idaction in the array,
// If not found in lookup table, queue for INSERT
@@ -177,5 +178,74 @@ class TableLogAction
}
return array($fieldNameToActionId, $fieldNamesToInsert);
}
+
+
+ /**
+ * Convert segment expression to an action ID or an SQL expression.
+ *
+ * This method is used as a sqlFilter-callback for the segments of this plugin.
+ * Usually, these callbacks only return a value that should be compared to the
+ * column in the database. In this case, that doesn't work since multiple IDs
+ * can match an expression (e.g. "pageUrl=@foo").
+ * @param string $valueToMatch
+ * @param string $sqlField
+ * @param string $matchType
+ * @param string $segmentName
+ * @throws \Exception
+ * @return array|int|string
+ */
+ public static function getIdActionFromSegment($valueToMatch, $sqlField, $matchType, $segmentName)
+ {
+ $actionType = self::guessActionTypeFromSegment($segmentName);
+
+ if ($actionType == Action::TYPE_PAGE_URL) {
+ // for urls trim protocol and www because it is not recorded in the db
+ $valueToMatch = preg_replace('@^http[s]?://(www\.)?@i', '', $valueToMatch);
+ }
+ $valueToMatch = Common::sanitizeInputValue(Common::unsanitizeInputValue($valueToMatch));
+
+ if ($matchType == SegmentExpression::MATCH_EQUAL
+ || $matchType == SegmentExpression::MATCH_NOT_EQUAL
+ ) {
+ $idAction = self::getIdActionMatchingNameAndType($valueToMatch, $actionType);
+ // if the action is not found, we hack -100 to ensure it tries to match against an integer
+ // otherwise binding idaction_name to "false" returns some rows for some reasons (in case &segment=pageTitle==Větrnásssssss)
+ if (empty($idAction)) {
+ $idAction = -100;
+ }
+ return $idAction;
+ }
+
+ // "name contains $string" match can match several idaction so we cannot return yet an idaction
+ // special case
+ $sql = TableLogAction::getSelectQueryWhereNameContains($matchType, $actionType);
+ return array(
+ // mark that the returned value is an sql-expression instead of a literal value
+ 'SQL' => $sql,
+ 'bind' => $valueToMatch,
+ );
+ }
+
+ /**
+ * @param $segmentName
+ * @return int
+ * @throws \Exception
+ */
+ private static function guessActionTypeFromSegment($segmentName)
+ {
+ if (stripos($segmentName, 'pageurl') !== false) {
+ $actionType = Action::TYPE_PAGE_URL;
+ return $actionType;
+ } elseif (stripos($segmentName, 'pagetitle') !== false) {
+ $actionType = Action::TYPE_PAGE_TITLE;
+ return $actionType;
+ } elseif (stripos($segmentName, 'sitesearch') !== false) {
+ $actionType = Action::TYPE_SITE_SEARCH;
+ return $actionType;
+ } else {
+ throw new \Exception(" The segment $segmentName has an unexpected value.");
+ }
+ }
+
}
diff --git a/plugins/Actions/Actions.php b/plugins/Actions/Actions.php
index 431f784c87..fa59748bb0 100644
--- a/plugins/Actions/Actions.php
+++ b/plugins/Actions/Actions.php
@@ -19,10 +19,7 @@ use Piwik\MetricsFormatter;
use Piwik\Piwik;
use Piwik\Plugin\ViewDataTable;
use Piwik\Plugins\CoreVisualizations\Visualizations\HtmlTable;
-use Piwik\SegmentExpression;
use Piwik\Site;
-use Piwik\Tracker\Action;
-use Piwik\Tracker\TableLogAction;
use Piwik\WidgetsList;
/**
@@ -67,7 +64,7 @@ class Actions extends \Piwik\Plugin
public function getSegmentsMetadata(&$segments)
{
- $sqlFilter = array($this, 'getIdActionFromSegment');
+ $sqlFilter = 'TableLogAction::getIdActionFromSegment';
// entry and exit pages of visit
$segments[] = array(
@@ -131,52 +128,6 @@ class Actions extends \Piwik\Plugin
);
}
- /**
- * Convert segment expression to an action ID or an SQL expression.
- *
- * This method is used as a sqlFilter-callback for the segments of this plugin.
- * Usually, these callbacks only return a value that should be compared to the
- * column in the database. In this case, that doesn't work since multiple IDs
- * can match an expression (e.g. "pageUrl=@foo").
- * @param string $valueToMatch
- * @param string $sqlField
- * @param string $matchType
- * @param string $segmentName
- * @throws \Exception
- * @return array|int|string
- */
- public function getIdActionFromSegment($valueToMatch, $sqlField, $matchType, $segmentName)
- {
- $actionType = $this->guessActionTypeFromSegment($segmentName);
-
- if ($actionType == Action::TYPE_PAGE_URL) {
- // for urls trim protocol and www because it is not recorded in the db
- $valueToMatch = preg_replace('@^http[s]?://(www\.)?@i', '', $valueToMatch);
- }
- $valueToMatch = Common::sanitizeInputValue(Common::unsanitizeInputValue($valueToMatch));
-
- if ($matchType == SegmentExpression::MATCH_EQUAL
- || $matchType == SegmentExpression::MATCH_NOT_EQUAL
- ) {
- $idAction = TableLogAction::getIdActionMatchingNameAndType($valueToMatch, $actionType);
- // if the action is not found, we hack -100 to ensure it tries to match against an integer
- // otherwise binding idaction_name to "false" returns some rows for some reasons (in case &segment=pageTitle==Větrnásssssss)
- if (empty($idAction)) {
- $idAction = -100;
- }
- return $idAction;
- }
-
- // "name contains $string" match can match several idaction so we cannot return yet an idaction
- // special case
- $sql = TableLogAction::getSelectQueryWhereNameContains($matchType, $actionType);
- return array(
- // mark that the returned value is an sql-expression instead of a literal value
- 'SQL' => $sql,
- 'bind' => $valueToMatch,
- );
- }
-
public function getReportMetadata(&$reports)
{
$reports[] = array(
@@ -589,26 +540,6 @@ class Actions extends \Piwik\Plugin
return \Piwik\Plugin\Manager::getInstance()->isPluginActivated('CustomVariables');
}
- /**
- * @param $segmentName
- * @return int
- * @throws \Exception
- */
- protected function guessActionTypeFromSegment($segmentName)
- {
- if (stripos($segmentName, 'pageurl') !== false) {
- $actionType = Action::TYPE_PAGE_URL;
- return $actionType;
- } elseif (stripos($segmentName, 'pagetitle') !== false) {
- $actionType = Action::TYPE_PAGE_TITLE;
- return $actionType;
- } elseif (stripos($segmentName, 'sitesearch') !== false) {
- $actionType = Action::TYPE_SITE_SEARCH;
- return $actionType;
- } else {
- throw new \Exception(" The segment $segmentName has an unexpected value.");
- }
- }
public function configureViewDataTable(ViewDataTable $view)
{
diff --git a/plugins/Actions/ArchivingHelper.php b/plugins/Actions/ArchivingHelper.php
index 6b05338e61..bd98942c28 100644
--- a/plugins/Actions/ArchivingHelper.php
+++ b/plugins/Actions/ArchivingHelper.php
@@ -350,7 +350,7 @@ class ArchivingHelper
* @param array $actionsTablesByType
* @return DataTable
*/
- protected static function getActionRow($actionName, $actionType, $urlPrefix = null, &$actionsTablesByType)
+ private static function getActionRow($actionName, $actionType, $urlPrefix = null, &$actionsTablesByType)
{
// we work on the root table of the given TYPE (either ACTION_URL or DOWNLOAD or OUTLINK etc.)
/* @var DataTable $currentTable */
@@ -378,6 +378,35 @@ class ArchivingHelper
}
/**
+ * Returns the configured sub-category level limit.
+ *
+ * @return int
+ */
+ public static function getSubCategoryLevelLimit()
+ {
+ return Config::getInstance()->General['action_category_level_limit'];
+ }
+
+ /**
+ * Returns default label for the action type
+ *
+ * @param $type
+ * @return string
+ */
+ static public function getUnknownActionName($type)
+ {
+ if (empty(self::$defaultActionNameWhenNotDefined)) {
+ self::$defaultActionNameWhenNotDefined = Piwik::translate('General_NotDefined', Piwik::translate('Actions_ColumnPageName'));
+ self::$defaultActionUrlWhenNotDefined = Piwik::translate('General_NotDefined', Piwik::translate('Actions_ColumnPageURL'));
+ }
+ if ($type == Action::TYPE_PAGE_TITLE) {
+ return self::$defaultActionNameWhenNotDefined;
+ }
+ return self::$defaultActionUrlWhenNotDefined;
+ }
+
+
+ /**
* Explodes action name into an array of elements.
*
* NOTE: before calling this function make sure ArchivingHelper::reloadConfig(); is called
@@ -449,34 +478,6 @@ class ArchivingHelper
}
/**
- * Returns the configured sub-category level limit.
- *
- * @return int
- */
- public static function getSubCategoryLevelLimit()
- {
- return Config::getInstance()->General['action_category_level_limit'];
- }
-
- /**
- * Returns default label for the action type
- *
- * @param $type
- * @return string
- */
- static public function getUnknownActionName($type)
- {
- if (empty(self::$defaultActionNameWhenNotDefined)) {
- self::$defaultActionNameWhenNotDefined = Piwik::translate('General_NotDefined', Piwik::translate('Actions_ColumnPageName'));
- self::$defaultActionUrlWhenNotDefined = Piwik::translate('General_NotDefined', Piwik::translate('Actions_ColumnPageURL'));
- }
- if ($type == Action::TYPE_PAGE_TITLE) {
- return self::$defaultActionNameWhenNotDefined;
- }
- return self::$defaultActionUrlWhenNotDefined;
- }
-
- /**
* Static cache to store Rows during processing
*/
static protected $cacheParsedAction = array();
@@ -547,7 +548,7 @@ class ArchivingHelper
));
}
- protected static function splitNameByDelimiter($name, $type)
+ private static function splitNameByDelimiter($name, $type)
{
if(is_array($name)) {
return $name;
@@ -574,7 +575,7 @@ class ArchivingHelper
return $split;
}
- protected static function parseNameFromPageUrl($name, $type, $urlPrefix)
+ private static function parseNameFromPageUrl($name, $type, $urlPrefix)
{
$urlRegexAfterDomain = '([^/]+)[/]?([^#]*)[#]?(.*)';
if ($urlPrefix === null) {
diff --git a/plugins/Transitions/API.php b/plugins/Transitions/API.php
index 4972c7dfad..933c59b27c 100644
--- a/plugins/Transitions/API.php
+++ b/plugins/Transitions/API.php
@@ -30,6 +30,7 @@ use Piwik\SegmentExpression;
use Piwik\Site;
use Piwik\Tracker\Action;
use Piwik\Tracker\PageUrl;
+use Piwik\Tracker\TableLogAction;
/**
* @package Transitions
@@ -134,23 +135,23 @@ class API extends \Piwik\Plugin\API
case 'url':
$originalActionName = $actionName;
$actionName = Common::unsanitizeInputValue($actionName);
- $id = $actionsPlugin->getIdActionFromSegment($actionName, 'idaction_url', SegmentExpression::MATCH_EQUAL, 'pageUrl');
+ $id = TableLogAction::getIdActionFromSegment($actionName, 'idaction_url', SegmentExpression::MATCH_EQUAL, 'pageUrl');
if ($id < 0) {
// an example where this is needed is urls containing < or >
$actionName = $originalActionName;
- $id = $actionsPlugin->getIdActionFromSegment($actionName, 'idaction_url', SegmentExpression::MATCH_EQUAL, 'pageUrl');
+ $id = TableLogAction::getIdActionFromSegment($actionName, 'idaction_url', SegmentExpression::MATCH_EQUAL, 'pageUrl');
}
return $id;
case 'title':
- $id = $actionsPlugin->getIdActionFromSegment($actionName, 'idaction_name', SegmentExpression::MATCH_EQUAL, 'pageTitle');
+ $id = TableLogAction::getIdActionFromSegment($actionName, 'idaction_name', SegmentExpression::MATCH_EQUAL, 'pageTitle');
if ($id < 0) {
$unknown = ArchivingHelper::getUnknownActionName(Action::TYPE_PAGE_TITLE);
if (trim($actionName) == trim($unknown)) {
- $id = $actionsPlugin->getIdActionFromSegment('', 'idaction_name', SegmentExpression::MATCH_EQUAL, 'pageTitle');
+ $id = TableLogAction::getIdActionFromSegment('', 'idaction_name', SegmentExpression::MATCH_EQUAL, 'pageTitle');
}
}