Created
July 21, 2018 14:04
-
-
Save davletyarov/d0b50381d65341e7f50532fd2444a209 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
use Bitrix\Main\Diag\Debug; | |
// не хватит памяти для обработки 586К сделок | |
ini_set('memory_limit', '1024M'); | |
// может быть очень долго будет работать | |
set_time_limit(0); | |
define('NO_KEEP_STATISTIC', true); | |
define('NOT_CHECK_PERMISSIONS', true); | |
define('BX_CAT_CRON', true); | |
define('NO_AGENT_CHECK', true); | |
$_SERVER['DOCUMENT_ROOT'] = '/home/bitrix/www'; | |
require_once($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_before.php'); | |
\Bitrix\Main\Loader::includeModule('crm'); | |
// получаем все сделки которые есть в портале | |
$dbDeal = \CCrmDeal::GetList([], ['CHECK_PERMISSIONS' => 'N']); | |
$arDeal = []; | |
while ($deal = $dbDeal->Fetch()) { | |
$arDeal[] = ['ID' => $deal['ID'], 'ASSIGNED_BY_ID' => $deal['ASSIGNED_BY_ID']]; | |
} | |
unset($dbDeal); | |
$count = count($arDeal); | |
/* @var \CCrmDeal $deal */ | |
$deal = new \CCrmDeal(false); | |
for ($i = 0; $i < $count; $i++) { | |
$obj = $arDeal[$i]; | |
$arFields = ['ASSIGNED_BY_ID' => $obj['ASSIGNED_BY_ID']]; | |
$DB->StartTransaction(); | |
// для быстроты лучше отключить индексацию для поиска и сравнение, разгрузка по памяти будет | |
if ($b = $deal->Update($obj['ID'], $arFields, false, false, | |
['DISABLE_USER_FIELD_CHECK' => true])) { | |
$DB->Commit(); | |
$arErrors = []; | |
// Обязательно нужно стартануть БП, иначе не обновяться права на доступ | |
CCrmBizProcHelper::AutoStartWorkflows( | |
CCrmOwnerType::Deal, | |
$obj['ID'], | |
CCrmBizProcEventType::Edit, | |
$arErrors | |
); | |
if ($arErrors) { | |
Debug::dumpToFile($arErrors); | |
} | |
} else { | |
$DB->Rollback(); | |
Debug::dumpToFile($DB->GetErrorMessage()); | |
} | |
} | |
require_once($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/epilog_after.php'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment