Refresh all batch from MailChimp API
@param array $batchesResult
@return array
541313
private function refreshBatchesResult($batchesResult)
    {
        $refreshedBatchsResults = [];
        $mailchimp = $this->getContainer()->get('welp_mailchimp.mailchimp_master');
        foreach ($batchesResult as $key => $batch) {
            $batch = $mailchimp->get("batches/".$batch['id']);
            array_push($refreshedBatchsResults, $batch);
        }
        return $refreshedBatchsResults;
    }
706297
public static function updateBatch($data, $where = null): IResult
    {
        $class = static::__getRealClassName();
        if(Update::hasUpdateRelation($class))
        {
            $query = Db::query()->table(ModelManager::getTable($class));
            $query = static::parseWhere($query, $where);

            $list = $query->select()->getArray();
            
            foreach($list as $row)
            {
                $model = static::newInstance($row);
                $model->set($data);
                $model->update();
            }
        }
        else
        {
            $query = static::query();
            $query = static::parseWhere($query, $where);

            $updateData = static::parseSaveData($data);

            // 更新前
            Event::trigger(static::__getRealClassName() . ':' . ModelEvents::BEFORE_BATCH_UPDATE, [
                'data'  => $updateData,
                'query' => $query,
            ], null, \Imi\Model\Event\Param\BeforeBatchUpdateEventParam::class);
            
            $result = $query->update($updateData);
    
            // 更新后
            Event::trigger(static::__getRealClassName() . ':' . ModelEvents::AFTER_BATCH_UPDATE, [
                'data'  => $updateData,
                'result'=> $result,
            ], null, \Imi\Model\Event\Param\BeforeBatchUpdateEventParam::class);
    
            return $result;
        }
    }
773113
private function pushEventBatch($batch) {
        $eventBatch = [];
        foreach ($batch as $collection => $events) {
            $eventBatch[$collection] = array_map(function ($eventDetails) {
                $event = new Event($eventDetails);
                return $event->getDetails();
            }, $events);
        }
        return $this->client->pushEventBatch($eventBatch);
    }
1345497
public function dispatch($rawResult)
    {
        $this->arrayResult = json_decode($rawResult, true);
        $result = parent::dispatch($this->arrayResult);
        $this->rawResult = $rawResult;

        return $result;
    }
112759
private function iteratorFromResults(array $results)
    {
        $values = [];

        foreach ($results as $pair) {
            $entry = new IndexEntry();

            $entry->indexKey  = $pair->key;
            $entry->objectKey = $pair->value;

            $values[] = $entry;
        }

        return new ArrayIterator($values);
    }
1359851
public function getInputsFromSearchResult($searchResult)
    {
        $input_array = [];

        if (!isset($searchResult['hits'])) {
            throw new \Exception('Hits Not Found');
        }

        foreach ($searchResult['hits'] as $hit) {
            if (!isset($hit['input'])) {
                throw new \Exception('Inputs Not Found');
            }
            $input = new Input($hit['input']);
            $input_array[] = $input;
        }

        return $input_array;
    }
716114
public function fetchRecipientDeliveryReport($batchId, $recipient)
    {
        $path = '/delivery_report/' . urlencode($recipient);
        $result = $this->_get($this->_batchUrl($batchId, $path));
        return Deserialize::batchRecipientDeliveryReport($result);
    }
786059
public function buildResult($result)
    {
        $updates = [];

        foreach ($result as $updateData) {
            $update = new Update($updateData);
            $updates[] = $update;
            $this->lastUpdateId = max($this->lastUpdateId, $update->updateId);
        }

        return $updates;
    }
388237
public function send_batch_requests($requests){
		$client = new \GuzzleHttp\Client();

		$response = $client->post($this->api_endpoint.'batch', array(
		    'headers' =>  array('Authorization' => 'Token token="'.$this->getAPIKey().'"'),
		    'json' => array( "ops" => $requests, "sequential" => true )
		));

		$result = json_decode($response->getBody());

		return $result;
	}
751640
private static function _batchUpdateHelper(Api\MtBatchSmsUpdate $batch)
    {
        $fields = [];

        if (!empty($batch->getRecipientInsertions())) {
            $fields['to_add'] = $batch->getRecipientInsertions();
        }

        if (!empty($batch->getRecipientRemovals())) {
            $fields['to_remove'] = $batch->getRecipientRemovals();
        }

        if (null != $batch->getSender()) {
            $fields['from'] = $batch->getSender();
        }

        if (null != $batch->getDeliveryReport()) {
            if ($batch->getDeliveryReport() === Api\Reset::reset()) {
                $fields['delivery_report'] = null;
            } else {
                $fields['delivery_report'] = $batch->getDeliveryReport();
            }
        }

        if (null != $batch->getSendAt()) {
            if ($batch->getSendAt() === Api\Reset::reset()) {
                $fields['send_at'] = null;
            } else {
                $fields['send_at'] = Serialize::_dateTime($batch->getSendAt());
            }
        }

        if (null != $batch->getExpireAt()) {
            if ($batch->getExpireAt() === Api\Reset::reset()) {
                $fields['expire_at'] = null;
            } else {
                $fields['expire_at']
                    = Serialize::_dateTime($batch->getExpireAt());
            }
        }

        if (null != $batch->getCallbackUrl()) {
            if ($batch->getCallbackUrl() === Api\Reset::reset()) {
                $fields['callback_url'] = null;
            } else {
                $fields['callback_url'] = $batch->getCallbackUrl();
            }
        }

        return $fields;
    }
1286720
protected function restoreVerbatimBlocks($result)
    {
        $result = preg_replace_callback(
            '/' . preg_quote($this->verbatimPlaceholder) . '/',
            function () {
                return array_shift($this->verbatimBlocks);
            },
            $result
        );

        $this->verbatimBlocks = [];

        return $result;
    }
546276
public function batch() {
		$success = array();
		$action = $this->request->query('batch_action');

		if (!in_array($action, $this->batchActions, true)) {
			throw new ForbiddenException("Method '$action' not allowed");
		}
		
		if ($this->request->query('batch_conditions')) {
			$ids = array_values($this->TaskClient->find('list', array(
						'conditions' => $this->_paginationFilter()
			)));
		} else {
			$ids = array_filter((array)$this->request->query('ids'));
		}
		
		if ($ids) {
			foreach ($ids as $id) {
				$success[$id] = $this->TaskClient->{$action}($id);
			}
		}

		if (empty($success)) {
			$this->Session->setFlash("No ids specified", 'alert/simple', array(
				'class' => 'alert-warning', 'title' => 'Warning!'
			));
		} elseif (array_filter($success) == $success) {
			$this->Session->setFlash("Batch $action successfully applied to " . count($success) . " task(s)", 'alert/simple', array(
				'class' => 'alert-success', 'title' => 'Ok!'
			));
		} else {
			$failIds = array_keys(
					array_filter($success, function($a) {
						return !$a;
					})
			);
			$this->Session->setFlash(count($failIds) . " of " . count($success) . " operations was errored (with ids: " . implode(', ', $failIds) . ")", 'alert/simple', array(
				'class' => 'alert-error', 'title' => 'Error!'
			));
		}

		$this->redirect($this->referer());
	}
381452
private function iteratorFromResults(array $results)
    {
        $values = [];

        foreach ($results as $item) {
            $entry = new IndexEntry();

            $entry->indexKey  = key($item);
            $entry->objectKey = reset($item);

            $values[] = $entry;
        }

        return new ArrayIterator($values);
    }
956369
public Result[] batch(List<? extends Row> actions) throws IOException {
    try {
      Object[] resultsOrErrors = new Object[actions.size()];
      batchCallback(actions, resultsOrErrors, null);
      // At this point we are guaranteed that the array only contains results,
      // if it had any errors, batch would've thrown an exception
      Result[] results = new Result[resultsOrErrors.length];
      System.arraycopy(resultsOrErrors, 0, results, 0, results.length);
      return results;
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
      LOG.error("Encountered exception in batch(List<>).", e);
      throw new IOException("Batch error", e);
    }
  }
145151
public static int getBatchUpdateCount(int[] batchExecuteResult){
		int result = 0;
		for (int c: batchExecuteResult){
			if (c >= 0){
				// real count
				result += c;
			}else if (c == -2){
				// unknown
				return -2;
			}else{
				// error or others
				// do nothing
			}
		}
		return result;
	}
235827
public function batchSubscribe($listId, array $subscribers)
    {
        $batchResults = [];
        // as suggested in MailChimp API docs, we send multiple smaller requests instead of a bigger one
        $subscriberChunks = array_chunk($subscribers, self::SUBSCRIBER_BATCH_SIZE);
        foreach ($subscriberChunks as $subscriberChunk) {
            $Batch = $this->mailchimp->new_batch();
            foreach ($subscriberChunk as $index => $newsubscribers) {
                $subscriberHash = $this->mailchimp->subscriberHash($newsubscribers->getEmail());
                $Batch->put("op$index", "lists/$listId/members/$subscriberHash", array_merge(
                    $newsubscribers->formatMailChimp(),
                    ['status' => 'subscribed']
                ));
            }
            $Batch->execute();
            $currentBatch = $Batch->check_status();
            array_push($batchResults, $currentBatch);
        }
        return $batchResults;
    }
1304648
public function updateTextBatch(
        $batchId, Api\MtBatchTextSmsUpdate $batch
    ) {
        $json = Serialize::textBatchUpdate($batch);
        $result = $this->_post($this->_batchUrl($batchId), $json);
        return Deserialize::batchResponse($result);
    }