PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / trunk
Matomo Analytics – Powerful, Privacy-First Insights for WordPress vtrunk
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / Plugin / Dimension / DimensionMetadataProvider.php
matomo / app / core / Plugin / Dimension Last commit date
ActionDimension.php 1 month ago ConversionDimension.php 1 month ago DimensionMetadataProvider.php 1 year ago VisitDimension.php 3 months ago
DimensionMetadataProvider.php
94 lines
1 <?php
2
3 /**
4 * Matomo - free/libre analytics platform
5 *
6 * @link https://matomo.org
7 * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8 */
9 namespace Piwik\Plugin\Dimension;
10
11 use Piwik\Piwik;
12 /**
13 * Provides metadata about dimensions for the LogDataPurger class.
14 */
15 class DimensionMetadataProvider
16 {
17 /**
18 * Overrids for the result of the getActionReferenceColumnsByTable() method. Exists so Piwik
19 * instances can be monkey patched, in case there are idaction columns that this class does not
20 * naturally discover.
21 *
22 * @var array
23 */
24 private $actionReferenceColumnsOverride;
25 public function __construct(array $actionReferenceColumnsOverride = array())
26 {
27 $this->actionReferenceColumnsOverride = $actionReferenceColumnsOverride;
28 }
29 /**
30 * Returns a list of idaction column names organized by table name. Uses dimension metadata
31 * to find idaction columns dynamically.
32 *
33 * Note: It is not currently possible to use the Piwik platform to add idaction columns to tables
34 * other than log_link_visit_action (w/o doing something unsupported), so idaction columns in
35 * other tables are hard coded.
36 *
37 * @return array[]
38 */
39 public function getActionReferenceColumnsByTable()
40 {
41 $result = array('log_link_visit_action' => array('idaction_url', 'idaction_url_ref', 'idaction_name_ref'), 'log_conversion' => array('idaction_url'), 'log_visit' => array('visit_exit_idaction_url', 'visit_exit_idaction_name', 'visit_entry_idaction_url', 'visit_entry_idaction_name'), 'log_conversion_item' => array('idaction_sku', 'idaction_name', 'idaction_category', 'idaction_category2', 'idaction_category3', 'idaction_category4', 'idaction_category5'));
42 $dimensionIdActionColumns = $this->getVisitActionTableActionReferences();
43 $result['log_link_visit_action'] = array_unique(array_merge($result['log_link_visit_action'], $dimensionIdActionColumns));
44 foreach ($this->actionReferenceColumnsOverride as $table => $columns) {
45 if (empty($result[$table])) {
46 $result[$table] = $columns;
47 } else {
48 $result[$table] = array_unique(array_merge($result[$table], $columns));
49 }
50 }
51 /**
52 * Triggered when detecting which log_action entries to keep. Any log tables that use the log_action
53 * table to reference text via an ID should add their table info so no actions that are still in use
54 * will be accidentally deleted.
55 *
56 * **Example**
57 *
58 * Piwik::addAction('Db.getActionReferenceColumnsByTable', function(&$result) {
59 * $tableNameUnprefixed = 'log_example';
60 * $columnNameThatReferencesIdActionInLogActionTable = 'idaction_example';
61 * $result[$tableNameUnprefixed] = array($columnNameThatReferencesIdActionInLogActionTable);
62 * });
63 * @param array $result
64 */
65 Piwik::postEvent('Db.getActionReferenceColumnsByTable', array(&$result));
66 return $result;
67 }
68 private function getVisitActionTableActionReferences()
69 {
70 $idactionColumns = array();
71 foreach (\Piwik\Plugin\Dimension\ActionDimension::getAllDimensions() as $actionDimension) {
72 if ($this->isActionReference($actionDimension)) {
73 $idactionColumns[] = $actionDimension->getColumnName();
74 }
75 }
76 return $idactionColumns;
77 }
78 /**
79 * Returns `true` if the column for this dimension is a reference to the `log_action` table (ie, an "idaction column"),
80 * `false` if otherwise.
81 *
82 * @return bool
83 */
84 private function isActionReference(\Piwik\Plugin\Dimension\ActionDimension $dimension)
85 {
86 try {
87 $dimension->getActionId();
88 return \true;
89 } catch (\Exception $ex) {
90 return \false;
91 }
92 }
93 }
94