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/rospirotorg.ru/bitrix/modules/socialnetwork/lib/update/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/socialnetwork/lib/update/grouptypeconverter.php
<?php

declare(strict_types=1);

namespace Bitrix\Socialnetwork\Update;

use Bitrix\Main\Update\Stepper;
use Bitrix\Socialnetwork\Internals\Group\GroupEntity;
use Bitrix\Socialnetwork\Internals\Group\GroupEntityCollection;
use Bitrix\Socialnetwork\Item\Workgroup\Type;
use Bitrix\Socialnetwork\WorkgroupTable;

final class GroupTypeConverter extends Stepper
{
	private const LIMIT = 500;

	protected static $moduleId = 'socialnetwork';

	private GroupEntityCollection $groups;

	/** @var GroupEntityCollection[] */
	private array $storage = [];

	private array $option;

	public function execute(array &$option): bool
	{
		$this->option = &$option;

		$this->fetchGroups();

		if ($this->groups->isEmpty())
		{
			return self::FINISH_EXECUTION;
		}

		$this->setLastId();
		$this->convert();
		$this->save();

		return self::CONTINUE_EXECUTION;
	}

	private function fetchGroups(): void
	{
		$query = WorkgroupTable::query()
			->setSelect(['ID', 'PROJECT', 'SCRUM_MASTER_ID', 'TYPE'])
			// ->whereNull('TYPE') // recalc for all
			->where('ID', '>', $this->getLastId())
			->setOrder(['ID' => 'ASC'])
			->setLimit(self::LIMIT);

		$this->groups = $query->exec()->fetchCollection();
	}

	private function convert(): void
	{
		foreach ($this->groups as $group)
		{
			$this->setType($group);
		}
	}

	private function save(): void
	{
		foreach ($this->storage as $collection)
		{
			$collection->save(true);
		}
	}

	private function setType(GroupEntity $group): void
	{
		$typeBefore = $group->getType();

		if ($typeBefore === Type::Collab->value)
		{
			return;
		}

		if ($group->getScrumMasterId() > 0 && $group->getProject())
		{
			$group->setType(Type::Scrum->value);
		}
		elseif ($group->getProject())
		{
			$group->setType(Type::Project->value);
		}
		else
		{
			$group->setType(Type::getDefault()->value);
		}

		if ($typeBefore !== $group->getType())
		{
			$this->store($group);
		}
	}

	private function store(GroupEntity $group): void
	{
		if (!isset($this->storage[$group->getType()]))
		{
			$this->storage[$group->getType()] = new GroupEntityCollection();
		}

		$this->storage[$group->getType()]->add($group);
	}

	private function getLastId(): int
	{
		return (int)($this->option['lastId'] ?? 0);
	}

	private function setLastId(): void
	{
		$this->option['lastId'] = max($this->groups->getIdList());
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit