@param $listUuid
@param ListElement $listElement

@throws ListElementNotConsistentException

@return mixed
349291
public function pushElement($listUuid, ListElement $listElement)
    {
        $elementUuid = $listElement->getUuid();
        $body = $listElement->getBody();

        if (!ListElementConsistencyChecker::isConsistent($listElement, $this->findListByUuid($listUuid))) {
            throw new ListElementNotConsistentException('Element '.(string) $listElement->getUuid().' is not consistent with list data.');
        }

        $numberOfChunks = $this->getNumberOfChunks($listUuid);
        $chunkSize = $this->getChunkSize($listUuid);

        $chunkNumber = $listUuid.self::SEPARATOR.self::CHUNK.'-'.$numberOfChunks;

        $options = [
            'cas' => true,
            'watch' => $this->getArrayChunksKeys($listUuid, $numberOfChunks),
            'retry' => 3,
        ];

        // persist in a transaction
        $this->client->transaction($options, function ($tx) use ($chunkNumber, $numberOfChunks, $chunkSize, $listUuid, $elementUuid, $body) {
            if (($chunkSize - count($tx->hgetall($chunkNumber))) === 0) {
                ++$numberOfChunks;
                $chunkNumber = $listUuid.self::SEPARATOR.self::CHUNK.'-'.$numberOfChunks;
            }

            $tx->hset(
                (string) $chunkNumber,
                (string) $elementUuid,
                (string) $body
            );

            // update list index
            $prevIndex = $this->getIndex($listUuid);
            $this->addOrUpdateListToIndex(
                $listUuid,
                ($prevIndex['size'] + 1),
                $numberOfChunks,
                $chunkSize,
                $this->getTtl($listUuid)
            );
        });
    }
401072
public function addWithIndex($index, $element)
    {
        if (!is_null($index)
            && is_scalar($index)
        ) {
            if (!$this->hasIndex($index)) {
                $this->set($index, $element);
            } else {
                // index already exist
                throw new ListException('Element could not be added to list. Index already exist.', E_NOTICE);
            }
        } else {
            // given index name is not valid
            throw new ListException('Element could not be added to list. Index is not valid.', E_NOTICE);
        }
    }
1077362
public function orderAt($uuid, $position, $userId, $webspaceKey, $locale)
    {
        $document = $this->documentManager->find($uuid, $locale);

        $parentDocument = $this->inspector->getParent($document);
        $siblingDocuments = $this->inspector->getChildren($parentDocument);

        $siblings = array_values($siblingDocuments->toArray()); // get indexed array
        $countSiblings = count($siblings);
        $currentPosition = array_search($document, $siblings) + 1;

        if ($countSiblings < $position || $position <= 0) {
            throw new InvalidOrderPositionException(
                sprintf(
                    'Cannot order node "%s" at out-of-range position "%s", must be >= 0 && < %d"',
                    $this->inspector->getPath($document),
                    $position,
                    $countSiblings
                )
            );
        }

        if ($position === $countSiblings) {
            // move to the end
            $this->documentManager->reorder($document, null);
        } else {
            if ($currentPosition < $position) {
                $targetSibling = $siblings[$position];
            } elseif ($currentPosition > $position) {
                $targetSibling = $siblings[$position - 1];
            }

            $this->documentManager->reorder($document, $targetSibling->getUuid());
        }

        $this->documentManager->flush();

        return $this->documentToStructure($document);
    }
722701
public function findListByUuid($listUuid)
    {
        $collection = $this->client->hgetall($listUuid.self::SEPARATOR.self::CHUNK.'-1');
        $number = $this->getNumberOfChunks($listUuid);

        for ($i = 2; $i <= $number; ++$i) {
            $collection = array_merge($collection, $this->client->hgetall($listUuid.self::SEPARATOR.self::CHUNK.'-'.$i));
        }

        return array_map('unserialize', $collection);
    }
5093
private function prepareListResponse(DoctrineListBuilder $listBuilder, $locale)
    {
        $listResponse = $listBuilder->execute();
        $listResponse = $this->addAvatars($listResponse, $locale);

        $ids = $listBuilder->getIds();
        if (null !== $ids) {
            $comparator = $this->getComparator();
            // the @ is necessary in case of a PHP bug https://bugs.php.net/bug.php?id=50688
            @usort(
                $listResponse,
                function($a, $b) use ($comparator, $ids) {
                    return $comparator->compare($a['id'], $b['id'], $ids);
                }
            );
        }

        return $listResponse;
    }
523476
private function createList($listId, $listParameters)
    {
        $providerServiceKey = $listParameters['subscriber_provider'];
        $provider = $this->providerFactory->create($providerServiceKey);
        $subscriberList = new SubscriberList($listId, $provider, $listParameters['merge_fields']);
        $subscriberList->setWebhookUrl($listParameters['webhook_url']);
        $subscriberList->setWebhookSecret($listParameters['webhook_secret']);

        return $subscriberList;
    }
583628
public function create(ListCollection $list, $ttl = null, $chunkSize = null)
    {
        $sql = 'INSERT INTO `'.self::LIST_COLLECTION_TABLE_NAME.'` (
                    `uuid`,
                    `headers`,
                    `created_at`
                  ) VALUES (
                    :uuid,
                    :headers,
                    :created_at
            ) ON DUPLICATE KEY UPDATE 
                `headers` = :headers,
                `created_at` = :created_at
            ';

        $data = [
            'uuid' => $list->getUuid(),
            'headers' => $list->getHeaders(),
            'created_at' => (new \DateTimeImmutable())->format('Y-m-d H:i:s.u'),
        ];

        $st[] = [
            'sql' => $sql,
            'data' => $data,
        ];

        foreach ($list->getElements() as $uuid => $element) {
            /** @var ListElement $element */
            $sql = 'INSERT INTO `'.self::LIST_ELEMENT_TABLE_NAME.'` (
                    `uuid`,
                    `list`,
                    `body`
                  ) VALUES (
                    :uuid,
                    :list,
                    :body
            ) ON DUPLICATE KEY UPDATE 
                `list` = :list,
                `body` = :body
            ';

            $data = [
                'uuid' => $uuid,
                'list' => $list->getUuid(),
                'body' => $element->getBody(),
            ];

            $st[] = [
                'sql' => $sql,
                'data' => $data,
            ];
        }

        $this->executeQueriesInATransaction($st);
    }
207461
public function memberInfo($email, $listID)
    {

        $mailchimpStatus = $this->mailChimp->call("/lists/member-info", [
            'id' => $listID,
            'emails' => [
                0 => [
                  'email' => $email
                ]
            ]
        ]);

        return $mailchimpStatus;
    }
862765
public function updateElement($listUuid, $elementUuid, $data)
    {
        $numberOfChunks = $this->getNumberOfChunks($listUuid);
        $ttl = ($this->getTtl($listUuid) > 0) ? $this->getTtl($listUuid) : null;

        for ($i = 1; $i <= $numberOfChunks; ++$i) {
            $chunkNumber = $listUuid.self::SEPARATOR.self::CHUNK.'-'.$i;
            $chunk = $this->memcached->get($chunkNumber);

            if (array_key_exists($elementUuid, $chunk)) {
                $listElement = $this->findElement(
                    (string) $listUuid,
                    (string) $elementUuid
                );

                $updatedElementBody = $this->updateListElementBody($listElement, $data);
                if (!ListElementConsistencyChecker::isConsistent($updatedElementBody, $this->findListByUuid($listUuid))) {
                    throw new ListElementNotConsistentException('Element '.(string) $elementUuid.' is not consistent with list data.');
                }

                $arrayOfElements = $this->memcached->get($listUuid);
                $updatedElement = new ListElement(
                    new ListElementUuid($elementUuid),
                    $updatedElementBody
                );
                $body = $updatedElement->getBody();
                $arrayOfElements[(string) $elementUuid] = $body;

                $this->memcached->replace(
                    (string) $chunkNumber,
                    $arrayOfElements,
                    $ttl
                );

                break;
            }
        }
    }
819098
public function pushElement($listUuid, $elementUuid, array $data = [])
    {
        $newElement = new ListElement(
            new ListElementUuid($elementUuid),
            $data
        );

        return $this->repository->pushElement($listUuid, $newElement);
    }
257408
public function updateElement($listUuid, $elementUuid, $data)
    {
        $listElement = $this->findElement(
            (string) $listUuid,
            (string) $elementUuid
        );

        $updatedElementBody = $this->updateListElementBody($listElement, $data);

        if (!ListElementConsistencyChecker::isConsistent($updatedElementBody, $this->findListByUuid($listUuid))) {
            throw new ListElementNotConsistentException('Element '.(string) $elementUuid.' is not consistent with list data.');
        }

        if (is_array($updatedElementBody) || is_object($updatedElementBody)) {
            $updatedElementBody = serialize($updatedElementBody);
        }

        $sql = 'UPDATE `'.self::LIST_ELEMENT_TABLE_NAME.'` 
                    SET `body` = :body
                    WHERE `uuid` = :uuid';

        $stmt = $this->pdo->prepare($sql);
        $stmt->bindParam(':uuid', $elementUuid);
        $stmt->bindParam(':body', $updatedElementBody);
        $stmt->execute();
    }
197057
public function setUUid($uuid = null)
    {
        $notAllowedNames = [
            ListRepositoryInterface::CHUNK,
            ListRepositoryInterface::HEADERS,
            ListRepositoryInterface::INDEX,
            ListRepositoryInterface::SEPARATOR,
            ListRepositoryInterface::STATISTICS,
        ];

        foreach ($notAllowedNames as $notAllowedName) {
            if (strpos($uuid, $notAllowedName) !== false) {
                throw new ListElementNotAllowedUuidException('You can\'t assign "'.$uuid.'" as element uuid.');
            }
        }

        $this->uuid = str_replace(' ', '-', $uuid) ?: Uuid::uuid4()->toString();
    }
212305
public function getListById($list_id)
		{
			$form_data = array(
				'list_id' => $list_id
			);
			$xml = $this->call('getlistbyid', $form_data);

			$list = new MailingList;
			$list
				->setListId((int)$xml->list_id)
				->setListName((string)$xml->list_name)
				->setDescription((string)$xml->description)
				->setTemplate((string)$xml->template)
				->setFromAddress((string)$xml->from)
				->setReplyToAddress((string)$xml->reply_to)
				->setBounceAddress((string)$xml->errors_to)
				->setTrackClicks((bool)$xml->track_clicks)
				->setTrackOpens((bool)$xml->track_opens)
				->setFolderId((int)$xml->folder_Id);

			return $list;
		}
665747
public function DumpList($options = array(), $listId = false) {
        $api = $this->url . 'list/';
        if (!$listId)
            $listId = $this->listId;
        $payload = array_merge(array('id' => $this->listId), $options);
        $data = $this->requestMonkey($api, $payload, true);
        if (empty($data) || !isset($data))
            return $data;
        $result = preg_split('/$\R?^/m', $data);

        $headerArray = json_decode($result[0]);
        unset($result[0]);

        $data = array();
        foreach ($result as $value) {
            $data[] = array_combine($headerArray, json_decode($value));
        }

        return $data;
    }
1202777
public function getCounter($listUuid)
    {
        $sql = 'SELECT `uuid` FROM `'.self::LIST_ELEMENT_TABLE_NAME.'` WHERE `list` = :list';
        $stmt = $this->pdo->prepare($sql);
        $stmt->bindParam(':list', $listUuid);
        $stmt->execute();

        return $stmt->rowCount();
    }
887353
public function findOrFailByUuid($uuid, $columns = ['*'])
    {
        $result = $this->findByUuid($uuid, $columns);

        if (is_array($uuid)) {
            if (count($result) == count(array_unique($uuid))) {
                return $result;
            }
        } elseif (! is_null($result)) {
            return $result;
        }

        throw new NotFoundHttpException('Resource \'' . class_basename(get_class($this->model)) . '\' with given UUID ' . $uuid . ' not found');
    }
1358647
@SuppressWarnings("unchecked")
    public <T> T getObjectByUuid(Class<T> clazz, UUID uuid) {
        final Query query = pm.newQuery(clazz, "uuid == :uuid");
        final List<T> result = (List<T>) query.execute(uuid);
        return Collections.isEmpty(result) ? null : result.get(0);
    }