Example #1
1
 public static function deleteMultipleForOwner($primaryOwner)
 {
     $primaryOwner = Assert::expectIntegerPositive($primaryOwner, false, Loc::getMessage('SALE_LOCATION_EXTERNAL_ENTITY_OWNER_NOT_SET_EXCEPTION'));
     $listRes = self::getList(array('filter' => array('LOCATION_ID' => $primaryOwner), 'select' => array('ID')));
     while ($item = $listRes->fetch()) {
         $res = self::delete($item['ID']);
         if (!$res->isSuccess()) {
             throw new Main\SystemException(Loc::getMessage('SALE_LOCATION_EXTERNAL_ENTITY_CANNOT_DELETE_DATA_EXCEPTION'));
         }
     }
 }
Example #2
0
 public static function delete($primary)
 {
     $primary = Assert::expectIntegerPositive($primary, Loc::getMessage('SALE_LOCATION_TYPE_ENTITY_PRIMARY_FIELD'));
     $delResult = parent::delete($primary);
     // delete connected data
     if ($delResult->isSuccess()) {
         Name\TypeTable::deleteMultipleForOwner($primary);
     }
     return $delResult;
 }
Example #3
0
 public static function delete($primary)
 {
     $primary = Assert::expectIntegerPositive($primary, Loc::getMessage('SALE_LOCATION_GROUP_ENTITY_PRIMARY_FIELD'));
     $delResult = parent::delete($primary);
     // delete connected data
     if ($delResult->isSuccess()) {
         Name\GroupTable::deleteMultipleForOwner($primary);
         // set flag that indicates whether project still uses groups or not
         self::checkGroupUsage();
     }
     return $delResult;
 }
 public static function deleteMultipleForOwner($primaryOwner)
 {
     $primaryOwner = Assert::expectIntegerPositive($primaryOwner, false, Loc::getMessage('SALE_LOCATION_NAME_NAME_ENTITY_OWNER_NOT_SET_EXCEPTION'));
     // hunt existed
     $listRes = static::getList(array('filter' => array(static::getReferenceFieldName() => $primaryOwner), 'select' => array('ID')));
     // kill existed
     while ($item = $listRes->fetch()) {
         $res = static::delete($item['ID']);
         if (!$res->isSuccess()) {
             throw new Main\SystemException(Loc::getMessage('SALE_LOCATION_NAME_NAME_ENTITY_CANNOT_DELETE_NAMES_EXCEPTION'));
         }
     }
 }
Example #5
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);
 }
Example #6
0
 private static function checkUpdateLinks($links)
 {
     $useCodes = static::getUseCodes();
     $useGroups = static::getUseGroups();
     if (is_array($links[self::DB_LOCATION_FLAG])) {
         if ($useCodes) {
             $links[self::DB_LOCATION_FLAG] = Assert::expectArrayOfUniqueStringNotNull($links[self::DB_LOCATION_FLAG], Loc::getMessage('SALE_LOCATION_CONNECTOR_ENTITY_LINKS_FLD_NAME'));
         } else {
             $links[self::DB_LOCATION_FLAG] = Assert::expectArrayOfUniqueIntegerNotNull($links[self::DB_LOCATION_FLAG], Loc::getMessage('SALE_LOCATION_CONNECTOR_ENTITY_LINKS_FLD_NAME'));
         }
     }
     if (is_array($links[self::DB_GROUP_FLAG])) {
         if (!$useGroups) {
             Assert::announceNotSupported(Loc::getMessage('SALE_LOCATION_CONNECTOR_ENTITY_DOESNT_SUPPORT_GROUPS'));
         }
         if ($useCodes) {
             $links[self::DB_GROUP_FLAG] = Assert::expectArrayOfUniqueStringNotNull($links[self::DB_GROUP_FLAG], Loc::getMessage('SALE_LOCATION_CONNECTOR_ENTITY_LINKS_FLD_NAME'));
         } else {
             $links[self::DB_GROUP_FLAG] = Assert::expectArrayOfUniqueIntegerNotNull($links[self::DB_GROUP_FLAG], Loc::getMessage('SALE_LOCATION_CONNECTOR_ENTITY_LINKS_FLD_NAME'));
         }
     }
     return $links;
 }
Example #7
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);
 }
 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;
 }