32 new Main\Entity\IntegerField(
'ID'),
33 new Main\Entity\IntegerField(
'SRC_ENTITY_TYPE_ID', [
'primary' =>
true ]),
34 new Main\Entity\IntegerField(
'SRC_ENTITY_ID', [
'primary' =>
true ]),
35 new Main\Entity\IntegerField(
'DST_ENTITY_TYPE_ID', [
'primary' =>
true ]),
36 new Main\Entity\IntegerField(
'DST_ENTITY_ID', [
'primary' =>
true ]),
37 new Main\Entity\DatetimeField(
'CREATED_TIME'),
38 new Main\Entity\DatetimeField(
'LAST_UPDATED_TIME')
42 public static function upsert(array $data)
44 $result =
new Main\Entity\AddResult();
46 $srcEntityTypeID = isset($data[
'SRC_ENTITY_TYPE_ID']) ? (int)$data[
'SRC_ENTITY_TYPE_ID'] : \CCrmOwnerType::Undefined;
47 $srcEntityID = isset($data[
'SRC_ENTITY_ID']) ? (int)$data[
'SRC_ENTITY_ID'] : 0;
49 $dstEntityTypeID = isset($data[
'DST_ENTITY_TYPE_ID']) ? (int)$data[
'DST_ENTITY_TYPE_ID'] : \CCrmOwnerType::Undefined;
50 $dstEntityID = isset($data[
'DST_ENTITY_ID']) ? (int)$data[
'DST_ENTITY_ID'] : 0;
52 $now = Main\Type\DateTime::createFromTimestamp(time() + \CTimeZone::GetOffset());
55 'SRC_ENTITY_TYPE_ID' => $srcEntityTypeID,
56 'SRC_ENTITY_ID' => $srcEntityID,
57 'DST_ENTITY_TYPE_ID' => $dstEntityTypeID,
58 'DST_ENTITY_ID' => $dstEntityID,
59 'CREATED_TIME' => $now,
60 'LAST_UPDATED_TIME' => $now
64 'LAST_UPDATED_TIME' => $now,
65 'SRC_ENTITY_TYPE_ID' => $srcEntityTypeID,
66 'SRC_ENTITY_ID' => $srcEntityID,
67 'DST_ENTITY_TYPE_ID' => $dstEntityTypeID,
68 'DST_ENTITY_ID' => $dstEntityID
71 $connection = Main\Application::getConnection();
72 $queries = $connection->getSqlHelper()->prepareMerge(
73 static::getTableName(),
84 foreach($queries as $query)
86 $connection->queryExecute($query);
90 $connection->getInsertedId());