Sync

@return int
345880
public function sync()
    {
        $limit = $this->scopeConfig->getValue(
            \Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_TRANSACTIONAL_DATA_SYNC_LIMIT
        );
        $stores = $this->helper->getStores();
        $products = [];

        foreach ($stores as $store) {
            $enabled = $this->helper->isEnabled($store->getWebsiteId());
            $catalogSyncEnabled = $this->helper->isCatalogSyncEnabled($store->getWebsiteId());

            if (!$enabled || !$catalogSyncEnabled) {
                continue;
            }

            $storeId = $store->getId();
            $this->appEmulation->startEnvironmentEmulation($storeId);

            $importType = 'Catalog_' . $store->getWebsite()->getCode() . '_' . $store->getCode();
            $products += $this->storeCatalogSyncer->syncByStore(
                $storeId,
                $store->getWebsiteId(),
                $limit,
                $importType
            );

            $this->appEmulation->stopEnvironmentEmulation();
        }

        /*
         * Sits outside of syncByStore by intention.
         * We grab products for sync from each store and put them all into an array, then we mark them all as imported.
         * This is to prevent products that need to be synced with multiple stores being marked as imported before they have been synced.
         */
        $this->catalogResource->setImportedByIds(array_keys($products));

        return count($products);
    }
1360550
private function getTotalCount(): int
    {
        if ($this->totalCount === -1) {
            $this->setTotalCount($this->getLastResponse()->getTotal());
        }

        return $this->totalCount;
    }
1157984
private function syncCheck()
    {
        $this->goodPools = [];

        foreach ($this->pools as $pool => $weight) {
            try {
                $poolInstance = getInstance()->getAsynPool($pool);
                if (!$poolInstance) {
                    $poolInstance = new RedisAsynPool(getInstance()->config, $pool);
                    getInstance()->addAsynPool($pool, $poolInstance, true);
                }

                if ($poolInstance->getSync()->set('msf_active_cluster_check_' . gethostname(), 1, 5)) {
                    $this->goodPools[$pool] = $weight;
                } else {
                    $host = getInstance()->getAsynPool($pool)->getSync()->getHost();
                    $port = getInstance()->getAsynPool($pool)->getSync()->getPort();
                    getInstance()->getAsynPool($pool)->getSync()->connect($host, $port, 0.05);
                }
            } catch (\Exception $e) {
                writeln('Redis Proxy' . $e->getMessage() . "\t {$pool}");
            }
        }
    }
291902
def sync(self):
        ''
        log.info("syncing %r" % self.path)
        self.folder = self.jfs.get(self.path)
        self.synced = True
1149432
public function current()
    {
        $offset = 0;

        foreach ($this->observer as $observer) {
            if ($offset === $this->position) {
                return $observer;
            }
            ++$offset;
        }
    }
771964
public function next():int
    {
        $timestamp = $this->milliTime();
        if ($timestamp < $this->_lastTimestamp) {
            throw new Exception(sprintf("Clock moved backwards.  Refusing to generate id for %d milliseconds", $this->_lastTimestamp - $timestamp));
        }
        if ($this->_lastTimestamp == $timestamp) {
            $this->_sequence = ($this->_sequence + 1) & self::SEQUENCE_MASK;
            if ($this->_sequence == 0) {
                $timestamp = $this->waitNextMilli($this->_lastTimestamp);
            }
        } else {
            $this->_sequence = 0;
        }
        $this->_lastTimestamp = $timestamp;
        return (($timestamp - $this->epoch) << self::TIMESTAMP_LEFT_SHIFT)
            | ($this->dataCenterId << self::DATA_CENTER_ID_SHIFT)
            | ($this->workerId << self::WORKER_ID_SHIFT)
            | $this->_sequence;
    }
318696
def sync(self):
        
        if self._sync is None:
            self._sync = Sync(self)
        return self._sync
1241020
protected function getSyncStreams() {
        if (!$this->_syncStreams) {
            $this->_syncStreams = new SyncStreamList($this->version, $this->solution['sid']);
        }

        return $this->_syncStreams;
    }
288867
public function sync()
    {
        $this->checkStatusForPendingContacts();
        $this->setupAutomationTypes();

        //send the campaign by each types
        foreach ($this->automationTypes as $type => $config) {
            $contacts = $this->buildFirstDimensionOfContactsArray($type, $config);
            //get collection from type
            $automationCollection = $this->automationFactory->create()
                ->getCollectionByType($type, $this->limit);

            foreach ($automationCollection as $automation) {
                $type = $automation->getAutomationType();
                $email = $automation->getEmail();
                $this->typeId = $automation->getTypeId();
                $websiteId = $automation->getWebsiteId();
                $this->storeName = $automation->getStoreName();
                $typeDouble = $type;
                //Set type to generic automation status if type contains constant value
                if (strpos($typeDouble, self::ORDER_STATUS_AUTOMATION) !== false) {
                    $typeDouble = self::ORDER_STATUS_AUTOMATION;
                }
                $contact = $this->helper->getContact($email, $websiteId);
                //contact id is valid, can update datafields
                if ($contact && isset($contact->id)) {
                    if ($contact->status === self::CONTACT_STATUS_PENDING) {
                        $automation->setEnrolmentStatus(self::CONTACT_STATUS_PENDING);
                        $this->automationResource->save($automation);
                        continue;
                    }

                    //need to update datafields
                    $this->updateDatafieldsByType(
                        $typeDouble,
                        $email,
                        $websiteId
                    );
                    $contacts[$automation->getWebsiteId()]['contacts'][$automation->getId()] = $contact->id;
                } else {
                    // the contact is suppressed or the request failed
                    $automation->setEnrolmentStatus('Suppressed');
                    $this->automationResource->save($automation);
                }
            }
            $this->sendAutomationEnrolements($contacts, $type);
        }
    }
211321
public function getTimestamp() : ?int 
    {
        if ( ! $this->hasTimestamp()) {
            $this->setTimestamp($this->getDefaultTimestamp());
        }
        return $this->timestamp;
    }
111265
public function committedVersion(): ?int
    {
        if ($this->committedVersion === null) {
            $this->committedVersion = $this->eventCollection()->committedSequence();
        }

        return $this->committedVersion;
    }
292220
public function sync()
    {
        $response = ['success' => true, 'message' => 'Done.'];
        $websites = $this->helper->getWebsites();
        foreach ($websites as $website) {
            $wishlistEnabled = $this->helper->getWebsiteConfig(
                \Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_SYNC_WISHLIST_ENABLED,
                $website
            );
            $apiEnabled      = $this->helper->isEnabled($website);
            $storeIds        = $website->getStoreIds();

            if ($wishlistEnabled && $apiEnabled && ! empty($storeIds)) {
                //using bulk api
                $this->start = microtime(true);
                $this->exportWishlistForWebsite($website);
                //send wishlist as transactional data
                if (isset($this->wishlists[$website->getId()])) {
                    $websiteWishlists = $this->wishlists[$website->getId()];
                    //register in queue with importer
                    $this->importerFactory->create()
                                          ->registerQueue(
                                              Importer::IMPORT_TYPE_WISHLIST,
                                              $websiteWishlists,
                                              Importer::MODE_BULK,
                                              $website->getId()
                                          );
                    //mark connector wishlist as  imported
                    $this->setImported($this->wishlistIds);
                }
                if (! empty($this->wishlists)) {
                    $message = '----------- Wishlist bulk sync ----------- : ' .
                               gmdate('H:i:s', microtime(true) - $this->start) .
                               ', Total synced = ' . $this->countWishlists;

                    $this->helper->log($message);
                }

                //using single api
                $this->exportWishlistForWebsiteInSingle($website);
            }
        }
        $response['message'] = 'wishlists updated: ' . $this->countWishlists;

        return $response;
    }
827829
public function count(): int
    {
        $this->flags['count'] = true;
        $pdoStatement = $this->provideStatement();
        $pdoStatement = $this->execute($pdoStatement);
        return $pdoStatement->fetchColumn();
    }
105602
public function syncCatalog()
    {
        try {
            //remove product with product id set and no product
            $this->catalogResourceFactory->create()
                ->removeOrphanProducts();

            return $this->catalogSyncFactory->create()->sync();

        } catch (\Exception $e) {
            $this->helper->debug((string)$e, []);
        }
    }
21354
public function sync($collection)
    {
        foreach ($collection as $item) {
            $result = true;
            $websiteId = $item->getWebsiteId();
            if ($this->helper->isEnabled($websiteId)) {
                $this->client = $this->helper->getWebsiteApiClient($websiteId);
                $importData = $this->serializer->unserialize($item->getImportData());

                if ($this->client) {
                    $key = $importData[0];
                    $collectionName = $item->getImportType();
                    $this->client->deleteContactsTransactionalData($key, $collectionName);
                    $this->_handleSingleItemAfterSync($item, $result);
                }
            }
        }
    }
458587
protected function synchronize()
    {
        $conversions = $this->getConversions();
        if (!empty($conversions)) {
            foreach ($conversions as $currency => $monthlyAverageConversions) {
                // Map keys to month number and modify dates to be month specific.
                $monthlyAverageConversions = array_reduce($monthlyAverageConversions, function ($monthlyAverageConversions, MonthlyAverageConversion $monthlyAverageConversion) use ($currency) {
                    $monthlyAverageConversion->setCurrency($currency);
                    $monthlyAverageConversion->setDate($this->getDate() ?: $monthlyAverageConversion->getDate());

                    // Sometimes this method is called before a date has been injected via the serializer.
                    // Modify the date to be month specific once it has been injected.
                    if (!empty($monthlyAverageConversion->getDate())) {
                        $date = clone $monthlyAverageConversion->getDate();
                        $date->setDate($date->format('Y'), $monthlyAverageConversion->getMonth(), $date->format('d'));
                        $monthlyAverageConversion->setDate($date);
                    }

                    $monthlyAverageConversions[$monthlyAverageConversion->getMonth()] = $monthlyAverageConversion;

                    return $monthlyAverageConversions;
                }, []);

                $conversions[$currency] = $monthlyAverageConversions;
            }

            $this->setConversions($conversions);
        }
    }
585976
public static function syncAllGroups()
	{
		// @TODO: chunk this to 1000 groups at a time

		$db = \App::get('db');

		$query = "SELECT gidNumber FROM `#__xgroups`;";

		$db->setQuery($query);

		$result = $db->loadColumn();

		if ($result === false)
		{
			return false;
		}

		foreach ($result as $row)
		{
			self::syncGroup($row);

			if (is_array(self::$errors['fatal']) && !empty(self::$errors['fatal'][0]))
			{
				// If there's a fatal error, go ahead and stop
				return self::$errors;
			}
		}

		if (!empty(self::$errors['fatal'][0]) || !empty(self::$errors['warning'][0]))
		{
			return self::$errors;
		}
		else
		{
			return self::$success;
		}
	}