403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /home/bitrix/ext_www/ilovecveti.ru/bitrix/modules/calendar/lib/sync/managers/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/ilovecveti.ru/bitrix/modules/calendar/lib/sync/managers/importeventmanager.php
<?php

namespace Bitrix\Calendar\Sync\Managers;

use Bitrix\Calendar\Core;
use Bitrix\Calendar\Sync;
use Bitrix\Main\ArgumentException;
use Bitrix\Main\DI\ServiceLocator;
use Bitrix\Main\ObjectNotFoundException;

class ImportEventManager
{
	private Sync\Entities\SyncEventMap $externalEventMap;
	private Core\Base\Map $syncSectionCollection;
	private IncomingEventManagerInterface $importManager;
	/**
	 * @var Core\Mappers\Factory
	 */
	private $mapperFactory;

	/**
	 * @param Sync\Factories\FactoryBase $factory
	 * @param Core\Base\Map $syncSectionCollection
	 *
	 * @throws ObjectNotFoundException
	 */
	public function __construct(Sync\Factories\FactoryBase $factory, Core\Base\Map $syncSectionCollection)
	{
		$this->importManager = $factory->getIncomingEventManager();
		$this->syncSectionCollection = $syncSectionCollection;
		$this->externalEventMap = new Sync\Entities\SyncEventMap();
		$this->mapperFactory = ServiceLocator::getInstance()->get('calendar.service.mappers.factory');
	}

	/**
	 * @return $this
	 *
	 * @throws Core\Base\BaseException
	 * @throws ArgumentException
	 */
	public function import(): ImportEventManager
	{
		/** @var Sync\Entities\SyncSection $syncSection */
		foreach ($this->syncSectionCollection as $syncSection)
		{
			if (
				$syncSection->getSectionConnection() === null
				|| !$syncSection->getSectionConnection()->isActive()
			)
			{
				continue;
			}

			try
			{
				$result = $this->importManager->getEvents($syncSection);

				if ($result->isSuccess())
				{
					$this->handleCalendarChange(($result->getData()['externalSyncEventMap'])->getCollection());
					$this->externalEventMap->addItems(($result->getData()['externalSyncEventMap'])->getCollection());
					$syncSection
						->getSectionConnection()
						->setLastSyncDate(new Core\Base\Date())
						->setSyncToken($this->importManager->getSyncToken())
						->setPageToken($this->importManager->getPageToken())
						->setLastSyncStatus($this->importManager->getStatus())
						->setVersionId($this->importManager->getEtag())
					;
					$syncSection->setSectionConnection(
						$this->saveSectionConnection($syncSection->getSectionConnection())
					);
				}
			}
			catch (Sync\Exceptions\NotFoundException $e)
			{
				$syncSection->getSectionConnection()
					->setActive(false)
					->setLastSyncStatus(Sync\Dictionary::SYNC_STATUS['deleted']);
				$syncSection->setSectionConnection(
					$this->saveSectionConnection($syncSection->getSectionConnection())
				);
			}
			catch (Sync\Exceptions\AuthException | Sync\Exceptions\RemoteAccountException $e)
			{
				$syncSection->getSectionConnection()
					->setLastSyncStatus(Sync\Dictionary::SYNC_STATUS['failed']);
				$syncSection->setSectionConnection(
					$this->saveSectionConnection($syncSection->getSectionConnection())
				);
			}
		}

		return $this;
	}

	/**
	 * @param Sync\Connection\SectionConnection $link
	 *
	 * @return Sync\Connection\SectionConnection
	 *
	 * @throws ArgumentException
	 * @throws Core\Base\BaseException
	 */
	private function saveSectionConnection(Sync\Connection\SectionConnection $link): Sync\Connection\SectionConnection
	{
		$mapper = $this->mapperFactory->getSectionConnection();
		return $link->getId()
			? $mapper->update($link)
			: $mapper->create($link)
			;
	}

	/**
	 * @return Sync\Entities\SyncEventMap
	 */
	public function getEvents(): Sync\Entities\SyncEventMap
	{
		return $this->externalEventMap;
	}

	/**
	 * @throws ArgumentException
	 */
	private function handleCalendarChange(array $collection)
	{
		$handledCollection = $this->externalEventMap->getCollection();

		/**
		 * @var string $key
		 * @var Sync\Entities\SyncEvent $value
		 */
		foreach ($collection as $key => $value)
		{
			if (
				array_key_exists($key, $handledCollection)
				&& $value->getAction() === 'save'
			)
			{
				$this->externalEventMap->remove($key);
				$this->externalEventMap->add($value, $key);
			}
		}
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit