Beispiel #1
1
 public static function delete($id)
 {
     //We know for sure that languages and sites can refer to the culture.
     //Other entities should place CultureOnBeforeDelete event handler.
     $result = new Entity\DeleteResult();
     $res = LanguageTable::getList(array('filter' => array('=CULTURE_ID' => $id)));
     while ($language = $res->fetch()) {
         $result->addError(new Entity\EntityError(Loc::getMessage("culture_err_del_lang", array("#LID#" => $language["LID"]))));
     }
     $res = \Bitrix\Main\SiteTable::getList(array('filter' => array('=CULTURE_ID' => $id)));
     while ($site = $res->fetch()) {
         $result->addError(new Entity\EntityError(Loc::getMessage("culture_err_del_site", array("#LID#" => $site["LID"]))));
     }
     if (!$result->isSuccess()) {
         return $result;
     }
     return parent::delete($id);
 }
Beispiel #2
0
 public static function getListWithInner(array $parameters = array())
 {
     if (isset($parameters['filter'])) {
         $parameters['filter'] = array('LOGIC' => 'OR', $parameters['filter'], array('ID' => PaySystemInner::getId()));
     }
     return parent::getList($parameters);
 }
Beispiel #3
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;
 }
Beispiel #4
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;
 }
Beispiel #5
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;
 }
Beispiel #6
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;
 }
Beispiel #7
0
 public static function checkFields(Result $result, $primary, array $data)
 {
     parent::checkFields($result, $primary, $data);
     if ($result instanceof Entity\AddResult) {
         $entity = self::getEntity();
         if (!$data["CODE"]) {
             $result->addError(new Entity\FieldError($entity->getField("CODE"), "Can not be empty!", FieldError::EMPTY_REQUIRED));
         } elseif (!$data["FOLDER"]) {
             $result->addError(new Entity\FieldError($entity->getField("FOLDER"), "Can not be empty!", FieldError::EMPTY_REQUIRED));
         } elseif (!$data["NAME"]) {
             $result->addError(new Entity\FieldError($entity->getField("NAME"), "Can not be empty!", FieldError::EMPTY_REQUIRED));
         }
     }
 }
Beispiel #8
0
 public static function add($data)
 {
     if (!isset($data['SORT'])) {
         $data['TEMPLATE_ID'] = intval($data['TEMPLATE_ID']);
         if ($data['TEMPLATE_ID']) {
             $item = static::getList(array('runtime' => array('MAX_SORT' => array('dat_type' => 'integer', 'expression' => array('MAX(SORT)'))), 'filter' => array('=TEMPLATE_ID' => $data['TEMPLATE_ID']), 'select' => array('MAX_SORT')))->fetch();
             if (intval($item['MAX_SORT'])) {
                 $data['SORT'] = intval($item['MAX_SORT']) + 1;
             } else {
                 $data['SORT'] = 1;
             }
         }
     }
     return parent::add($data);
 }
Beispiel #9
0
 public static function checkFields(Result $result, $primary, array $data)
 {
     parent::checkFields($result, $primary, $data);
     $availablePlatforms = self::getSupportedPlatforms();
     if ($result instanceof Entity\AddResult) {
         $entity = self::getEntity();
         if (!$data["APP_CODE"]) {
             $result->addError(new Entity\FieldError($entity->getField("APP_CODE"), "Can not be empty!", 1));
         } else {
             if (!$data["PLATFORM"]) {
                 $result->addError(new Entity\FieldError($entity->getField("PLATFORM"), "Can not be empty!", 1));
             } elseif (!in_array($data["PLATFORM"], $availablePlatforms)) {
                 $result->addError(new Entity\FieldError($entity->getField("PLATFORM"), "The passed value in not available!", 1));
             }
         }
         $selectResult = self::getList(array("filter" => array("APP_CODE" => $data["APP_CODE"], "PLATFORM" => $data["PLATFORM"])));
         if ($selectResult->getSelectedRowsCount() > 0) {
             $result->addError(new Entity\EntityError("Such configuration is already exists!", 1000));
         }
     }
 }
Beispiel #10
0
 public static function checkFields($data, $action = 'update', $throwException = false)
 {
     // 1. Способ накопления ошибок (массив?)
     // 2. во внешней авторизации пропускаются проверки, которые должны быть стандартными
     //    может передавать в checkFields параметр excludes? а может просто сделать копию data без этих полей
     if (is_set($data, "PERSONAL_PHOTO")) {
         if (strlen($data["PERSONAL_PHOTO"]["name"]) <= 0 && strlen($data["PERSONAL_PHOTO"]["del"]) <= 0) {
             unset($data["PERSONAL_PHOTO"]);
         } else {
             $result = CFile::CheckImageFile($data["PERSONAL_PHOTO"]);
             if (strlen($result) > 0) {
                 static::$errors[] = $result;
             }
         }
     }
     //		if(is_set($data, "PERSONAL_BIRTHDAY") && strlen($data["PERSONAL_BIRTHDAY"])>0 && !CheckDateTime($data["PERSONAL_BIRTHDAY"]))
     //		{
     //			static::$errors[] = GetMessage("WRONG_PERSONAL_BIRTHDAY");
     //		}
     if (is_set($data, "WORK_LOGO")) {
         if (strlen($data["WORK_LOGO"]["name"]) <= 0 && strlen($data["WORK_LOGO"]["del"]) <= 0) {
             unset($data["WORK_LOGO"]);
         } else {
             $result = CFile::CheckImageFile($data["WORK_LOGO"]);
             if (strlen($result) > 0) {
                 static::$errors[] = $result;
             }
         }
     }
     parent::checkFields($data, $action, $throwException);
 }
Beispiel #11
0
 protected static final function makeSortSpace($primary, $direction = self::SORT_FREE_AFTER, $primaryParent, $knownSort = false)
 {
     $primary = Assert::expectIntegerPositive($primary, '$primary');
     $primaryParent = Assert::expectIntegerPositive($primary, '$primaryParent');
     $nodeFound = false;
     $sorts = array();
     $nextNodeId = false;
     $prevNodeId = false;
     $prev = false;
     $res = self::getChildren($primaryParent, array('select' => array('ID', 'SORT', 'CODE'), 'order' => array('SORT' => 'asc')));
     while ($item = $res->Fetch()) {
         if ($nodeFound && !$nextNodeId) {
             $nextNodeId = $item['ID'];
         }
         if ($item['ID'] == $primary) {
             $nodeFound = true;
             $prevNodeId = $prev;
         }
         $sorts[$item['ID']] = $item['SORT'];
         $prev = $item['ID'];
     }
     // no node exists or they are not neighbours
     if (!$nodeFound) {
         return false;
     }
     // add extra items
     if (!$prevNodeId) {
         $sorts = array('FH' => 0) + $sorts;
         $prevNodeId = 'FH';
     }
     if (!$nextNodeId) {
         $sorts['FT'] = PHP_INT_MAX;
         $nextNodeId = 'FT';
     }
     // handle some obvious situations
     if ($direction == self::SORT_FREE_BEFORE) {
         if ($knownSort && $knownSort < $sorts[$prevNodeId] && $knownSort < $sorts[$primary]) {
             return $knownSort;
         }
         // its okay, current sort fits
         // inequation above is not true, but there is free space between nodes
         if ($sorts[$primary] - $sorts[$prevNodeId] > 1) {
             return $sorts[$prevNodeId] + 1;
         }
         $startShift = $primary;
         $return = $sorts[$prevNodeId] + self::SORT_HOLE_SIZE_HALF;
     } else {
         if ($knownSort && $knownSort < $sorts[$primary] && $knownSort < $sorts[$nextNodeId]) {
             return $knownSort;
         }
         // its okay, current sort fits
         // inequation above is not true, but there is free space between nodes
         if ($sorts[$nextNodeId] - $sorts[$primary] > 1) {
             return $sorts[$primary] + 1;
         }
         $startShift = $nextNodeId;
         $return = $sorts[$primary] + self::SORT_HOLE_SIZE_HALF;
     }
     // .. or else we forced to make a hole
     $begin = false;
     $shift = $sorts[$startShift] + self::SORT_HOLE_SIZE;
     foreach ($sorts as $id => $sVal) {
         if ($id == $startShift) {
             $begin = true;
         }
         if ($begin && $sVal <= $shift) {
             $shift = $sVal + self::SORT_HOLE_SIZE;
             parent::update($id, array('SORT' => $shift));
         }
     }
     return $return;
 }
Beispiel #12
0
 /**
  * @param Base|string $entity
  *
  * @return bool
  */
 public static function destroy($entity)
 {
     if ($entity instanceof Base) {
         $entityName = $entity->getDataClass();
     } else {
         $entityName = static::normalizeEntityClass($entity);
     }
     if (isset(self::$instances[$entityName])) {
         unset(self::$instances[$entityName]);
         DataManager::unsetEntity($entityName);
         return true;
     }
     return false;
 }
Beispiel #13
0
 /**
  * Overrides parent update  to sate update date to current.
  * @param mixed $primary Primary key.
  * @param array $data Data fields.
  * @return Entity\UpdateResult
  */
 public static function update($primary, array $data)
 {
     $data["LAST_UPDATE"] = DateTime::createFromTimestamp(time());
     return parent::update($primary, $data);
 }
Beispiel #14
0
 public static function add($sitemapId, $entityId)
 {
     parent::add(array('ENTITY_TYPE' => static::ENTITY_TYPE, 'ENTITY_ID' => $entityId, 'SITEMAP_ID' => $sitemapId));
 }
Beispiel #15
0
 /**
  * Removes a task from favorites for a particular (or current) user. This function DOES NOT check permissions.
  * 
  * @param mixed[] Primary key for \Bitrix\Tasks\Task\FavoriteTable entity
  * @param mixed[] Behaviour flags
  * 
  *  <li> AFFECT_CHILDREN boolean if true, all child tasks also will be added to favorite. (default false)
  * 
  * @return \Bitrix\Main\Entity\DeleteResult
  */
 public static function delete($primary, $behaviour = array('AFFECT_CHILDREN' => false))
 {
     if (!is_array($behaviour)) {
         $behaviour = array();
     }
     if (!isset($behaviour['AFFECT_CHILDREN'])) {
         $behaviour['AFFECT_CHILDREN'] = false;
     }
     $primary = static::processPrimary($primary);
     $result = parent::delete($primary);
     if ($result->isSuccess() && $behaviour['AFFECT_CHILDREN']) {
         // add also all children...
         $res = TaskTable::getChildrenTasksData($primary['TASK_ID'], array('runtime' => TaskTable::getRuntimeFieldMixins(array('IN_FAVORITE'), array('USER_ID' => $primary['USER_ID'])), 'select' => array('IN_FAVORITE')));
         while ($item = $res->fetch()) {
             if ($item['IN_FAVORITE']) {
                 // our client
                 static::delete(array('TASK_ID' => $item['ID']), array('AFFECT_CHILDREN' => false));
             }
         }
     }
     return $result;
 }
Beispiel #16
0
 /**
  * Removes a connection between location and entity
  * 
  * @param mixed $primary relation primary key value
  * 
  * @return Bitrix\Main\Entity\DeleteResult
  */
 public static function delete($primary)
 {
     if ($primary) {
         // it will break below, at parent::delete()
         $link = static::getByPrimary($primary)->fetch();
     }
     $res = parent::delete($primary);
     if ($res->isSuccess()) {
         static::resetLinkUsage($link[static::getLinkField()]);
     }
     $GLOBALS['CACHE_MANAGER']->ClearByTag('sale-location-data');
     return $res;
 }
Beispiel #17
0
 /**
  * @param mixed $primary
  *
  * @return Main\DB\Result|Entity\DeleteResult
  */
 public static function delete($primary)
 {
     global $USER_FIELD_MANAGER;
     // get old data
     $hlblock = static::getByPrimary($primary)->fetch();
     // get file fields
     $file_fields = array();
     $fields = $USER_FIELD_MANAGER->getUserFields('HLBLOCK_' . $hlblock['ID']);
     foreach ($fields as $name => $field) {
         if ($field['USER_TYPE']['BASE_TYPE'] === 'file') {
             $file_fields[] = $name;
         }
     }
     // delete files
     if (!empty($file_fields)) {
         $oldEntity = static::compileEntity($hlblock);
         $query = new Entity\Query($oldEntity);
         // select file ids
         $query->setSelect($file_fields);
         // if they are not empty
         $filter = array('LOGIC' => 'OR');
         foreach ($file_fields as $file_field) {
             $filter['!' . $file_field] = false;
         }
         $query->setFilter($filter);
         // go
         $result = $query->exec();
         while ($row = $result->fetch()) {
             foreach ($file_fields as $file_field) {
                 if (!empty($row[$file_field])) {
                     if (is_array($row[$file_field])) {
                         foreach ($row[$file_field] as $value) {
                             \CFile::delete($value);
                         }
                     } else {
                         \CFile::delete($row[$file_field]);
                     }
                 }
             }
         }
     }
     $connection = Application::getConnection();
     foreach ($fields as $field) {
         // delete from uf registry
         if ($field['USER_TYPE']['BASE_TYPE'] === 'enum') {
             $enumField = new \CUserFieldEnum();
             $enumField->DeleteFieldEnum($field['ID']);
         }
         $connection->query("DELETE FROM b_user_field_lang WHERE USER_FIELD_ID = " . $field['ID']);
         $connection->query("DELETE FROM b_user_field WHERE ID = " . $field['ID']);
         // if multiple - drop utm table
         if ($field['MULTIPLE'] == 'Y') {
             $utmTableName = static::getMultipleValueTableName($hlblock, $field);
             $connection->dropTable($utmTableName);
         }
     }
     // clear uf cache
     global $CACHE_MANAGER;
     if (CACHED_b_user_field !== false) {
         $CACHE_MANAGER->cleanDir("b_user_field");
     }
     // remove row
     $result = parent::delete($primary);
     // drop hl table
     $connection->dropTable($hlblock['TABLE_NAME']);
     return $result;
 }
Beispiel #18
0
 /**
  * Links one item with another. Low-level method.
  */
 public static function createLink($id, $parentId, $behaviour = array('LINK_DATA' => array()))
 {
     static::applyCreateRestrictions($id, $parentId);
     if (!is_array($behaviour)) {
         $behaviour = array();
     }
     // check here if there is a link already
     //_dump_r('Create: '.$parentId.' => '.$id.' ('.$behaviour['LINK_DATA']['TYPE'].')');
     $parentColName = static::getPARENTIDColumnName();
     $idColName = static::getIDColumnName();
     // delete broken previous links, if any (but not the link to itself)
     $dbConnection = Main\HttpApplication::getConnection();
     $dbConnection->query("delete from " . static::getTableName() . " where " . $idColName . " = '" . intval($id) . "' and " . $parentColName . " != '" . intval($id) . "'");
     $success = true;
     $lastAddResult = null;
     if ($parentId) {
         // check if parent exists. if not - add it
         $item = static::getList(array('filter' => array('=' . $parentColName => $parentId, '=' . $idColName => $parentId), 'select' => array($idColName)))->fetch();
         if (!is_array($item)) {
             //_dump_r('link: '.$parentId.' => '.$parentId);
             $lastAddResult = parent::add(array($parentColName => $parentId, $idColName => $parentId));
             if (!$lastAddResult->isSuccess()) {
                 $success = false;
             }
         }
     }
     // check if link to itself exists. if not - add it
     $item = static::getList(array('filter' => array('=' . $parentColName => $id, '=' . $idColName => $id), 'select' => array($idColName)))->fetch();
     if (!is_array($item)) {
         //_dump_r('link: '.$id.' => '.$id);
         $lastAddResult = parent::add(array($parentColName => $id, $idColName => $id));
         if (!$lastAddResult->isSuccess()) {
             $success = false;
         }
     }
     $linkedWithParent = false;
     // TODO: the following part could be rewritten using just db-side insert-select
     if ($success && $parentId) {
         $subtree = array();
         $res = static::getSubTree($id);
         while ($item = $res->fetch()) {
             $subtree[] = $item[$idColName];
         }
         // link each child (including self) to each parent in the path(es)
         $res = static::getPathToNode($parentId, array('select' => array($parentColName)));
         while ($item = $res->fetch()) {
             foreach ($subtree as $itemId) {
                 if ($item[$parentColName] == $parentId && $itemId == $id) {
                     if (!is_array($behaviour['LINK_DATA'])) {
                         $behaviour['LINK_DATA'] = array();
                     }
                     $lastAddResult = parent::add(array_merge(array($idColName => $id, $parentColName => $parentId, static::getDIRECTColumnName() => true), $behaviour['LINK_DATA']));
                     if (!$lastAddResult->isSuccess()) {
                         $success = false;
                         break;
                     }
                 } else {
                     $lastAddResult = parent::add(array($idColName => $itemId, $parentColName => $item[$parentColName]));
                     if (!$lastAddResult->isSuccess()) {
                         $success = false;
                         break;
                     }
                 }
             }
         }
     }
     return array('RESULT' => $success, 'LAST_DB_RESULT' => $lastAddResult);
 }
Beispiel #19
0
 public static function delete($primary)
 {
     // get old data
     $oldData = static::getByPrimary($primary)->fetch();
     // remove row
     $result = parent::delete($primary);
     // remove files
     $entityName = static::getEntity()->getName();
     $hlblock = HighloadBlockTable::getList(array('select' => array('ID'), 'filter' => array('=NAME' => $entityName)))->fetch();
     // add other fields
     $fields = $GLOBALS['USER_FIELD_MANAGER']->getUserFields('HLBLOCK_' . $hlblock['ID']);
     foreach ($oldData as $k => $v) {
         $arUserField = $fields[$k];
         if ($arUserField["USER_TYPE"]["BASE_TYPE"] == "file") {
             if (is_array($oldData[$k])) {
                 foreach ($oldData[$k] as $value) {
                     \CFile::delete($value);
                 }
             } else {
                 \CFile::delete($oldData[$k]);
             }
         }
     }
     return $result;
 }
Beispiel #20
0
 /**
  * Ad subscription row
  *
  * @param array $parameters
  * @return \Bitrix\Main\DB\Result
  */
 public static function addUnSubscription(array $parameters = array())
 {
     $primary = array('MAILING_ID' => $parameters['MAILING_ID'], 'CONTACT_ID' => $parameters['CONTACT_ID']);
     $fields = array('IS_UNSUB' => 'Y');
     $row = static::getRowById($primary);
     if ($row) {
         $result = parent::update($primary, $fields);
         return $result->isSuccess();
     } else {
         $result = parent::add($fields + $parameters);
         return $result->isSuccess();
     }
 }
Beispiel #21
0
 public static function delete($primary)
 {
     $serviceForDelete = static::getByPrimary($primary)->fetch();
     if (!$serviceForDelete) {
         $deleteResult = new Entity\DeleteResult();
         $deleteResult->addError(new Entity\EntityError(Localization\Loc::getMessage('mail_mailservice_not_found')));
         return $deleteResult;
     }
     $deleteResult = parent::delete($primary);
     if ($deleteResult->isSuccess()) {
         $serviceId = is_array($primary) ? $primary['ID'] : $primary;
         if (in_array($serviceForDelete['SERVICE_TYPE'], array('controller', 'domain'))) {
             $mbData = array('ACTIVE' => 'N', 'SERVICE_ID' => 0);
         } else {
             $emptyService = static::getList(array('filter' => array('=SITE_ID' => $serviceForDelete['SITE_ID'], 'ACTIVE' => 'Y', '=SERVER' => '', '=PORT' => '', '=ENCRYPTION' => '', '=LINK' => ''), 'limit' => 1))->fetch();
             $mbData = $emptyService ? array('SERVICE_ID' => $emptyService['ID'], 'NAME' => $emptyService['NAME']) : array('ACTIVE' => 'N', 'SERVICE_ID' => 0);
         }
         $selectResult = \CMailbox::getList(array(), array('SERVICE_ID' => $serviceId));
         while ($mailbox = $selectResult->fetch()) {
             \CMailbox::update($mailbox['ID'], $mbData);
         }
     }
     return $deleteResult;
 }
Beispiel #22
0
 /**
  * {@inheritdoc}
  */
 public static function update($primary, array $data)
 {
     $data['MODIFIED_BY'] = static::getUserId();
     return parent::update($primary, $data);
 }
Beispiel #23
0
 /**
  * Links one item with another. Low-level method.
  */
 public static function createLink($id, $parentId, $behaviour = array())
 {
     $id = Assert::expectIntegerPositive($id, '$id');
     $parentId = Assert::expectIntegerNonNegative($parentId, '$parentId');
     // parent id might be equal to 0
     if (!is_array($behaviour)) {
         $behaviour = array();
     }
     $parentColName = static::getPARENTIDColumnName();
     $idColName = static::getIDColumnName();
     // delete broken previous links, if any
     $dbConnection = Main\HttpApplication::getConnection();
     $dbConnection->query("delete from " . static::getTableName() . " where " . $idColName . " = '" . intval($id) . "'");
     $success = true;
     $lastAddResult = null;
     // check if parent exists. if not - add it
     $item = static::getList(array('filter' => array('=' . $parentColName => $parentId, '=' . $idColName => $parentId), 'select' => array($idColName)))->fetch();
     if (!is_array($item)) {
         $lastAddResult = parent::add(array($parentColName => $parentId, $idColName => $parentId));
         if (!$lastAddResult->isSuccess()) {
             $success = false;
         }
     }
     $linkedWithParent = false;
     // the following part could be rewritten using just db-side insert-select
     if ($success) {
         if ($parentId > 0) {
             // link to all parents in the path
             $res = static::getPathToNode($parentId, array('select' => array($parentColName), 'filter' => array('!=' . $parentColName => $parentId)));
             while ($item = $res->fetch()) {
                 if ($item[$parentColName] == $parentId) {
                     $linkedWithParent = true;
                 }
                 $lastAddResult = parent::add(array($idColName => $id, $parentColName => $item[$parentColName]));
                 if (!$lastAddResult->isSuccess()) {
                     $success = false;
                     break;
                 }
             }
         }
     }
     if ($success) {
         // link to itself
         $lastAddResult = parent::add(array($idColName => $id, $parentColName => $id));
         if (!$lastAddResult->isSuccess()) {
             $success = false;
         }
     }
     if ($success && !$linkedWithParent) {
         // link to parent
         $lastAddResult = parent::add(array($idColName => $id, $parentColName => $parentId, 'DIRECT' => true));
         if (!$lastAddResult->isSuccess()) {
             $success = false;
         }
     }
     return array('RESULT' => $success, 'LAST_DB_RESULT' => $lastAddResult);
 }