Example #1
0
 public static function delete($primary)
 {
     $primary = Assert::expectIntegerPositive($primary, '$primary');
     $delResult = parent::delete($primary);
     // delete connected data
     if ($delResult->isSuccess()) {
         Name\TypeTable::deleteMultipleForOwner($primary);
     }
     return $delResult;
 }
Example #2
0
 public static function deleteMultipleForOwner($primaryOwner)
 {
     $primaryOwner = Assert::expectIntegerPositive($primaryOwner, '$primaryOwner');
     $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 #3
0
 public static function delete($primary)
 {
     $primary = Assert::expectIntegerPositive($primary, '$primary');
     $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;
 }
Example #4
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, '$primary');
     $childPrimary = Assert::expectStringNotNull($childPrimary, '$childPrimary');
     return static::checkNodeIsParentOfNodeByFilters(array('=CODE' => $primary), array('=CODE' => $childPrimary), $behaviour);
 }
Example #5
0
 private static function checkSiteId($siteId)
 {
     $siteId = Assert::expectStringNotNull($siteId, '$siteId');
     $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;
 }
Example #6
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 #7
0
 /**
  * Get existed translations for $primaryOwner and add only non-existed ones from $names
  * @param mixed $primaryOwner Primary key of the item
  * @param string[] $names A set of translations for the item
  * 
  * @return void
  */
 public static function addAbsentForOwner($primaryOwner, $names, $behaviour = array('TREAT_EMPTY_AS_ABSENT' => true))
 {
     $primaryOwner = Assert::expectIntegerPositive($primaryOwner, '$primaryOwner');
     if (!is_array($names)) {
         $names = array();
     }
     if (!is_array($behaviour)) {
         $behaviour = array();
     }
     if (!isset($behaviour['TREAT_EMPTY_AS_ABSENT'])) {
         $behaviour['TREAT_EMPTY_AS_ABSENT'] = true;
     }
     if (empty($names)) {
         return;
     }
     $namesLC = array();
     foreach ($names as $lid => $data) {
         $namesLC[Assert::castTrimLC($lid)] = $data;
     }
     $names = $namesLC;
     $langField = static::getLanguageFieldName();
     $refField = static::getReferenceFieldName();
     $names2Update = array();
     $res = static::getList(array('filter' => array('=' . $refField => $primaryOwner)));
     while ($item = $res->fetch()) {
         $isEmpty = static::checkEmpty($item);
         if ($isEmpty && $behaviour['TREAT_EMPTY_AS_ABSENT']) {
             $names2Update[$item['ID']] = $names[$item[$langField]];
         }
         unset($names[$item[$langField]]);
     }
     foreach ($names as $lid => $data) {
         $data[$langField] = $lid;
         $data[$refField] = $primaryOwner;
         static::add($data);
     }
     foreach ($names2Update as $id => $data) {
         static::update($id, $data);
     }
 }
Example #8
0
 /**
  * 
  * $parameters is an ORM`s getList compatible array of parameters
  * 
  * 
  */
 public static function find($parameters, $behaviour = array('FALLBACK_TO_NOINDEX_ON_NOTFOUND' => true, 'USE_INDEX' => true, 'USE_ORM' => true))
 {
     /////////////////////////////////
     // parameter check and process
     Assert::expectArray($parameters, '$parameters');
     if (!is_array($behaviour)) {
         $behaviour = array();
     }
     if (!isset($behaviour['FALLBACK_TO_NOINDEX_ON_NOTFOUND'])) {
         $behaviour['FALLBACK_TO_NOINDEX_ON_NOTFOUND'] = true;
     }
     if (!isset($behaviour['USE_INDEX'])) {
         $behaviour['USE_INDEX'] = true;
     }
     if (!isset($behaviour['USE_ORM'])) {
         $behaviour['USE_ORM'] = true;
     }
     if (!isset($parameters['select'])) {
         $parameters['select'] = array('ID');
     }
     Assert::expectArray($parameters['select'], '$parameters[select]');
     if (isset($parameters['filter'])) {
         Assert::expectArray($parameters['filter'], '$parameters[filter]');
         // spikes, refactor later
         if (isset($parameters['filter']['PHRASE']) || isset($parameters['filter']['=PHRASE'])) {
             $key = isset($parameters['filter']['PHRASE']) ? 'PHRASE' : '=PHRASE';
             $parameters['filter'][$key] = Assert::expectStringNotNull($parameters['filter'][$key], '$parameters[filter][' . $key . ']');
             $parameters['filter'][$key] = str_replace('%', '', $parameters['filter'][$key]);
             // cannot pass '%' to like
         }
         if (isset($parameters['filter']['SITE_ID']) || isset($parameters['filter']['=SITE_ID'])) {
             $key = isset($parameters['filter']['SITE_ID']) ? 'SITE_ID' : '=SITE_ID';
             $parameters['filter'][$key] = Assert::expectStringNotNull($parameters['filter'][$key], '$parameters[filter][' . $key . ']');
             // stronger here
             if (!Location\SiteLocationTable::checkLinkUsageAny($parameters['filter'][$key])) {
                 unset($parameters['filter'][$key]);
             }
         }
     }
     if (isset($parameters['limit'])) {
         $parameters['limit'] = Assert::expectIntegerNonNegative($parameters['limit'], '$parameters[limit]');
     }
     if (isset($parameters['offset'])) {
         $parameters['offset'] = Assert::expectIntegerNonNegative($parameters['offset'], '$parameters[offset]');
     }
     /////////////////////////////////
     if (isset($parameters['filter']['PHRASE']) || isset($parameters['filter']['SITE_ID']) || isset($parameters['filter']['=PHRASE']) || isset($parameters['filter']['=SITE_ID']) || $behaviour['USE_ORM'] === false) {
         if (static::checkIndexValid() && $behaviour['USE_INDEX']) {
             $result = static::findUsingIndex($parameters);
             if (!$behaviour['FALLBACK_TO_NOINDEX_ON_NOTFOUND']) {
                 return $result;
             } else {
                 $temporalBuffer = array();
                 while ($item = $result->fetch()) {
                     $temporalBuffer[] = $item;
                 }
                 if (empty($temporalBuffer)) {
                     return static::findNoIndex($parameters);
                 } else {
                     return new DB\ArrayResult($temporalBuffer);
                 }
             }
         } else {
             return static::findNoIndex($parameters);
         }
     } else {
         return Location\LocationTable::getList($parameters);
     }
 }
Example #9
0
 private static function checkUpdateLinks($links)
 {
     $useCodes = static::getUseCodes();
     $useGroups = static::getUseGroups();
     $locationArgName = '$links[' . self::DB_LOCATION_FLAG . ']';
     $groupArgName = '$links[' . self::DB_GROUP_FLAG . ']';
     if (is_array($links[self::DB_LOCATION_FLAG])) {
         if ($useCodes) {
             $links[self::DB_LOCATION_FLAG] = Assert::expectArrayOfUniqueStringNotNull($links[self::DB_LOCATION_FLAG], $locationArgName);
         } else {
             $links[self::DB_LOCATION_FLAG] = Assert::expectArrayOfUniqueIntegerNotNull($links[self::DB_LOCATION_FLAG], $locationArgName);
         }
     }
     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], $groupArgName);
         } else {
             $links[self::DB_GROUP_FLAG] = Assert::expectArrayOfUniqueIntegerNotNull($links[self::DB_GROUP_FLAG], $groupArgName);
         }
     }
     return $links;
 }