PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.0.7
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.0.7
5.12.0 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 / DataTable / Manager.php
matomo / app / core / DataTable Last commit date
Filter 2 years ago Renderer 2 years ago Row 2 years ago BaseFilter.php 2 years ago Bridges.php 2 years ago DataTableInterface.php 2 years ago Manager.php 2 years ago Map.php 2 years ago Renderer.php 2 years ago Row.php 2 years ago Simple.php 2 years ago TableNotFoundException.php 2 years ago
Manager.php
148 lines
1 <?php
2
3 /**
4 * Matomo - free/libre analytics platform
5 *
6 * @link https://matomo.org
7 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8 *
9 */
10 namespace Piwik\DataTable;
11
12 use Exception;
13 use Piwik\Common;
14 use Piwik\DataTable;
15 /**
16 * The DataTable_Manager registers all the instantiated DataTable and provides an
17 * easy way to access them. This is used to store all the DataTable during the archiving process.
18 * At the end of archiving, the ArchiveProcessor will read the stored datatable and record them in the DB.
19 */
20 class Manager extends \ArrayObject
21 {
22 /**
23 * Id of the next inserted table id in the Manager
24 * @var int
25 */
26 protected $nextTableId = 0;
27 private static $instance;
28 public static function getInstance()
29 {
30 if (!isset(self::$instance)) {
31 self::$instance = new \Piwik\DataTable\Manager();
32 }
33 return self::$instance;
34 }
35 /**
36 * Add a DataTable to the registry
37 *
38 * @param DataTable $table
39 * @return int Index of the table in the manager array
40 */
41 public function addTable($table)
42 {
43 $this->nextTableId++;
44 $this[$this->nextTableId] = $table;
45 return $this->nextTableId;
46 }
47 /**
48 * Returns the DataTable associated to the ID $idTable.
49 * NB: The datatable has to have been instantiated before!
50 * This method will not fetch the DataTable from the DB.
51 *
52 * @param int $idTable
53 * @throws Exception If the table can't be found
54 * @return DataTable The table
55 */
56 public function getTable($idTable)
57 {
58 if (!isset($this[$idTable])) {
59 throw new \Piwik\DataTable\TableNotFoundException(sprintf("Error: table id %s not found in memory. (If this error is causing you problems in production, please report it in Matomo issue tracker.)", $idTable));
60 }
61 return $this[$idTable];
62 }
63 /**
64 * Returns the latest used table ID
65 *
66 * @return int
67 */
68 public function getMostRecentTableId()
69 {
70 return $this->nextTableId;
71 }
72 /**
73 * Delete all the registered DataTables from the manager
74 *
75 * @param int $deleteWhenIdTableGreaterThan if supplied, only deletes tables whose id is greater than this value.
76 * @param null|int $deleteUntil if not null, only deletes tables that are <= this value.
77 */
78 public function deleteAll($deleteWhenIdTableGreaterThan = 0, $deleteUntil = null)
79 {
80 foreach ($this as $id => $table) {
81 if ($id > $deleteWhenIdTableGreaterThan && ($deleteUntil === null || $id <= $deleteUntil)) {
82 $this->deleteTable($id);
83 }
84 }
85 if ($deleteWhenIdTableGreaterThan == 0) {
86 $this->exchangeArray(array());
87 $this->nextTableId = 0;
88 }
89 }
90 /**
91 * Deletes (unsets) the datatable given its id and removes it from the manager
92 * Subsequent get for this table will fail
93 *
94 * @param int $id
95 */
96 public function deleteTable($id)
97 {
98 if (isset($this[$id])) {
99 Common::destroy($this[$id]);
100 $this->setTableDeleted($id);
101 }
102 }
103 /**
104 * Deletes all tables starting from the $firstTableId to the most recent table id except the ones that are
105 * supposed to be ignored.
106 *
107 * @param int[] $idsToBeIgnored
108 * @param int $firstTableId
109 */
110 public function deleteTablesExceptIgnored($idsToBeIgnored, $firstTableId = 0)
111 {
112 $lastTableId = $this->getMostRecentTableId();
113 for ($index = $firstTableId; $index <= $lastTableId; $index++) {
114 if (!in_array($index, $idsToBeIgnored)) {
115 $this->deleteTable($index);
116 }
117 }
118 }
119 /**
120 * Remove the table from the manager (table has already been unset)
121 *
122 * @param int $id
123 */
124 public function setTableDeleted($id)
125 {
126 $this[$id] = null;
127 }
128 /**
129 * Debug only. Dumps all tables currently registered in the Manager
130 */
131 public function dumpAllTables()
132 {
133 echo "<hr />Manager->dumpAllTables()<br />";
134 foreach ($this as $id => $table) {
135 if (!$table instanceof DataTable) {
136 echo "Error table {$id} is not instance of datatable<br />";
137 var_export($table);
138 } else {
139 echo "<hr />";
140 echo "Table (index={$id}) TableId = " . $table->getId() . "<br />";
141 echo $table;
142 echo "<br />";
143 }
144 }
145 echo "<br />-- End Manager->dumpAllTables()<hr />";
146 }
147 }
148