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:
authordiosmosis <benaka@piwik.pro>2015-03-06 04:42:10 +0300
committerdiosmosis <benaka@piwik.pro>2015-03-06 04:42:10 +0300
commit1479c500f04cc921ee93f0ea89d9f8b1505f6fee (patch)
tree3822b09e05fe99892d5d75faf272d87bab00048f /core/Concurrency/DistributedList.php
parent7c3c4057d2d540025e4da19ee4c82b06f163d07e (diff)
Refs #7181, add tests for DistributedList base type and add removeByIndex method to list for future use.
Diffstat (limited to 'core/Concurrency/DistributedList.php')
-rw-r--r--core/Concurrency/DistributedList.php30
1 files changed, 27 insertions, 3 deletions
diff --git a/core/Concurrency/DistributedList.php b/core/Concurrency/DistributedList.php
index 3823b4b47f..eecfab6a55 100644
--- a/core/Concurrency/DistributedList.php
+++ b/core/Concurrency/DistributedList.php
@@ -16,7 +16,6 @@ use Piwik\Option;
*
* The list of items is serialized and stored in an Option. Items are converted to string
* before being persisted, so it is not expected to unserialize objects.
- * TODO: light integration tests
*/
class DistributedList
{
@@ -88,7 +87,9 @@ class DistributedList
}
/**
- * Removes one or more items by value from the list in the optiontable.
+ * Removes one or more items by value from the list in the option table.
+ *
+ * Does not preserve array keys.
*
* @param string|array $items
*/
@@ -109,6 +110,29 @@ class DistributedList
unset($allItems[$existingIndex]);
}
- $this->setAll($allItems);
+ $this->setAll(array_values($allItems));
+ }
+
+ /**
+ * Removes one or more items by index from the list in the option table.
+ *
+ * Does not preserve array keys.
+ *
+ * @param int[]|int $indices
+ */
+ public function removeByIndex($indices)
+ {
+ if (!is_array($indices)) {
+ $indices = array($indices);
+ }
+
+ $indices = array_unique($indices);
+
+ $allItems = $this->getAll();
+ foreach ($indices as $index) {
+ unset($allItems[$index]);
+ }
+
+ $this->setAll(array_values($allItems));
}
} \ No newline at end of file