25 foreach ($collection->
all() as $updateItem)
27 $codesByType[$updateItem->typeId][] = $updateItem->code;
29 $sqlHelper = Application::getConnection()->getSqlHelper();
31 foreach ($codesByType as $typeId => $allCodes)
33 $typeId = (int)$typeId;
34 $listId = (int)$listId;
37 foreach (SqlBatch::divide($allCodes) as $codes)
39 $codes = SqlBatch::getInString($codes);
41 $fields =
'(CONTACT_ID, LIST_ID) ';
42 $subSelect =
"SELECT ID AS CONTACT_ID, $listId as LIST_ID ";
43 $subSelect .=
"FROM $contactTableName ";
44 $subSelect .=
"WHERE TYPE_ID=$typeId AND CODE in ($codes)";
45 $sql = $sqlHelper->getInsertIgnore($contactListTableName,
$fields, $subSelect);
46 Application::getConnection()->query($sql);