Beispiel #1
0
 public static function mergeRelationsFromTemporalTable($temporalTabName, $additinalFlds = array(), $fldMap = array())
 {
     $dbConnection = Main\HttpApplication::getConnection();
     $dbHelper = $dbConnection->getSqlHelper();
     $temporalTabName = Assert::expectStringNotNull($temporalTabName, false, 'Name of temporal table must be a non-zero length string');
     $temporalTabName = $dbHelper->forSql($temporalTabName);
     $entityTableName = static::getTableName();
     if (!is_array($additinalFlds)) {
         $additinalFlds = array();
     }
     $additinalFlds = array_merge(array('LEFT_MARGIN', 'RIGHT_MARGIN', 'DEPTH_LEVEL'), $additinalFlds);
     $fldReplace = array();
     foreach ($additinalFlds as &$fld) {
         $fld = $dbHelper->forSql($fld);
         $fldReplace[$fld] = is_array($fldMap) && isset($fldMap[$fld]) ? $dbHelper->forSql($fldMap[$fld]) : $fld;
     }
     $idReplace = is_array($fldMap) && isset($fldMap['ID']) ? $dbHelper->forSql($fldMap['ID']) : 'ID';
     if ($dbConnection->getType() == 'mysql') {
         $sql = 'update ' . $entityTableName . ', ' . $temporalTabName . ' set ';
         $additFldCnt = count($additinalFlds);
         for ($i = 0; $i < $additFldCnt; $i++) {
             $sql .= $entityTableName . '.' . $additinalFlds[$i] . ' = ' . $temporalTabName . '.' . $fldReplace[$additinalFlds[$i]] . ($i == count($additinalFlds) - 1 ? '' : ', ');
         }
         $sql .= ' where ' . $entityTableName . '.ID = ' . $temporalTabName . '.' . $idReplace;
     } elseif ($dbConnection->getType() == 'mssql') {
         $sql = 'update ' . $entityTableName . ' set ';
         $additFldCnt = count($additinalFlds);
         for ($i = 0; $i < $additFldCnt; $i++) {
             $sql .= $additinalFlds[$i] . ' = ' . $temporalTabName . '.' . $fldReplace[$additinalFlds[$i]] . ($i == count($additinalFlds) - 1 ? '' : ', ');
         }
         $sql .= ' from ' . $entityTableName . ' join ' . $temporalTabName . ' on ' . $entityTableName . '.ID = ' . $temporalTabName . '.' . $idReplace;
     } elseif ($dbConnection->getType() == 'oracle') {
         // update tab1 set (aa,bb) = (select aa,bb from tab2 where tab2.id = tab1.id)
         $sql = 'update ' . $entityTableName . ' set (' . implode(', ', $additinalFlds) . ') = (select ' . implode(', ', $fldReplace) . ' from ' . $temporalTabName . ' where ' . $entityTableName . '.ID = ' . $temporalTabName . '.' . $idReplace . ')';
     }
     $dbConnection->query($sql);
 }
Beispiel #2
0
 public static function checkNodeIsParentOfNode($primary, $childPrimary, $behaviour = array('ACCEPT_CODE' => false, 'CHECK_DIRECT' => false))
 {
     if (!$behaviour['ACCEPT_CODE']) {
         return static::checkNodeIsParentOfNodeById($primary, $childPrimary, $behaviour);
     }
     $primary = Assert::expectStringNotNull($primary, false, Loc::getMessage('SALE_LOCATION_LOCATION_ENTITY_BAD_ARGUMENT_CODE_UNSET_EXCEPTION'));
     $childPrimary = Assert::expectStringNotNull($childPrimary, false, Loc::getMessage('SALE_LOCATION_LOCATION_ENTITY_BAD_ARGUMENT_CODE_UNSET_EXCEPTION'));
     return static::checkNodeIsParentOfNodeByFilters(array('=CODE' => $primary), array('=CODE' => $childPrimary), $behaviour);
 }
Beispiel #3
0
 /**
  * Check if there is a link between entity and locations, optionally of a certain type (default: locations)
  *
  * @param mixed $entityPrimary primary key for an entity
  * @param string $linkType link type (G or L (default))
  *
  * @throws ArgumentNullException
  *
  * @return boolean
  */
 public static function checkLinkUsage($entityPrimary, $linkType = self::DB_LOCATION_FLAG)
 {
     $entityPrimary = Assert::expectStringNotNull($entityPrimary, Loc::getMessage('SALE_LOCATION_CONNECTOR_ENTITY_PRIMARY_FLD_NAME'));
     $linkType = Assert::expectEnumerationMember($linkType, array(self::DB_LOCATION_FLAG, self::DB_GROUP_FLAG), Loc::getMessage('SALE_LOCATION_CONNECTOR_ENTITY_PRIMARY_FLD_NAME'));
     if (!static::getUseLinkTracking()) {
         return true;
     }
     // force to true if link tracking is off
     $useGroups = static::getUseGroups();
     if (!$useGroups && $linkType == self::DB_GROUP_FLAG) {
         return false;
     }
     // we know we dont use groups
     $usageFlags = static::getLinkUsageOptionValue();
     if (isset($usageFlags[$entityPrimary][$linkType])) {
         return $usageFlags[$entityPrimary][$linkType];
     }
     $strictFilter = array(static::getLinkField() => $entityPrimary);
     if ($useGroups) {
         $strictFilter['LOCATION_TYPE'] = self::DB_LOCATION_FLAG;
     }
     $usageFlags[$entityPrimary][self::DB_LOCATION_FLAG] = !!static::getList(array('limit' => 1, 'filter' => $strictFilter))->fetch();
     if ($useGroups) {
         $usageFlags[$entityPrimary][self::DB_GROUP_FLAG] = !!static::getList(array('limit' => 1, 'filter' => array(static::getLinkField() => $entityPrimary, 'LOCATION_TYPE' => self::DB_GROUP_FLAG)))->fetch();
     }
     static::setLinkUsageOptionValue($usageFlags);
     return $usageFlags[$entityPrimary];
 }
 private static function checkSiteId($siteId)
 {
     $siteId = Assert::expectStringNotNull($siteId, Loc::getMessage('SALE_LOCATION_DEFAULTSITE_ENTITY_SITE_ID_NOT_SET_EXCEPTION'));
     $res = Main\SiteTable::getList(array('filter' => array('LID' => $siteId)))->fetch();
     if (!$res) {
         throw new Main\ArgumentOutOfRangeException(Loc::getMessage('SALE_LOCATION_DEFAULTSITE_ENTITY_SITE_ID_UNKNOWN_EXCEPTION'));
     }
     return $siteId;
 }