PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 1.3.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v1.3.1
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 6 years ago ConversionDimension.php 6 years ago DimensionMetadataProvider.php 6 years ago VisitDimension.php 6 years ago
DimensionMetadataProvider.php
125 lines
1 <?php
2 /**
3 * Piwik - free/libre analytics platform
4 *
5 * @link https://matomo.org
6 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7 */
8
9 namespace Piwik\Plugin\Dimension;
10 use Piwik\Piwik;
11
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
26 public function __construct(array $actionReferenceColumnsOverride = array())
27 {
28 $this->actionReferenceColumnsOverride = $actionReferenceColumnsOverride;
29 }
30
31 /**
32 * Returns a list of idaction column names organized by table name. Uses dimension metadata
33 * to find idaction columns dynamically.
34 *
35 * Note: It is not currently possible to use the Piwik platform to add idaction columns to tables
36 * other than log_link_visit_action (w/o doing something unsupported), so idaction columns in
37 * other tables are hard coded.
38 *
39 * @return array[]
40 */
41 public function getActionReferenceColumnsByTable()
42 {
43 $result = array(
44 'log_link_visit_action' => array('idaction_url',
45 'idaction_url_ref',
46 'idaction_name_ref'
47 ),
48
49 'log_conversion' => array('idaction_url'),
50
51 'log_visit' => array('visit_exit_idaction_url',
52 'visit_exit_idaction_name',
53 'visit_entry_idaction_url',
54 'visit_entry_idaction_name'),
55
56 'log_conversion_item' => array('idaction_sku',
57 'idaction_name',
58 'idaction_category',
59 'idaction_category2',
60 'idaction_category3',
61 'idaction_category4',
62 'idaction_category5')
63 );
64
65 $dimensionIdActionColumns = $this->getVisitActionTableActionReferences();
66 $result['log_link_visit_action'] = array_unique(
67 array_merge($result['log_link_visit_action'], $dimensionIdActionColumns));
68
69 foreach ($this->actionReferenceColumnsOverride as $table => $columns) {
70 if (empty($result[$table])) {
71 $result[$table] = $columns;
72 } else {
73 $result[$table] = array_unique(array_merge($result[$table], $columns));
74 }
75 }
76
77 /**
78 * Triggered when detecting which log_action entries to keep. Any log tables that use the log_action
79 * table to reference text via an ID should add their table info so no actions that are still in use
80 * will be accidentally deleted.
81 *
82 * **Example**
83 *
84 * Piwik::addAction('Db.getActionReferenceColumnsByTable', function(&$result) {
85 * $tableNameUnprefixed = 'log_example';
86 * $columnNameThatReferencesIdActionInLogActionTable = 'idaction_example';
87 * $result[$tableNameUnprefixed] = array($columnNameThatReferencesIdActionInLogActionTable);
88 * });
89 * @param array $result
90 */
91 Piwik::postEvent('Db.getActionReferenceColumnsByTable', array(&$result));
92
93 return $result;
94 }
95
96 private function getVisitActionTableActionReferences()
97 {
98 $idactionColumns = array();
99 foreach (ActionDimension::getAllDimensions() as $actionDimension) {
100 if ($this->isActionReference($actionDimension)) {
101 $idactionColumns[] = $actionDimension->getColumnName();
102 }
103 }
104 return $idactionColumns;
105 }
106
107
108 /**
109 * Returns `true` if the column for this dimension is a reference to the `log_action` table (ie, an "idaction column"),
110 * `false` if otherwise.
111 *
112 * @return bool
113 */
114 private function isActionReference(ActionDimension $dimension)
115 {
116 try {
117 $dimension->getActionId();
118
119 return true;
120 } catch (\Exception $ex) {
121 return false;
122 }
123 }
124 }
125