Exemplo n.º 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);
 }
Exemplo n.º 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;
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
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;
 }
Exemplo n.º 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;
 }
Exemplo n.º 6
0
 /**
  * Available keys in $behaviour
  * REBALANCE - if set to true, method will rebalance tree after insertion
  * DELETE_SUBTREE - if set to true, only node will be deleted, and it`s subtree left unattached
  */
 public static function delete($primary, $behaviour = array('REBALANCE' => true, 'DELETE_SUBTREE' => true))
 {
     if (!is_array($behaviour)) {
         $behaviour = array();
     }
     if (!isset($behaviour['REBALANCE'])) {
         $behaviour['REBALANCE'] = true;
     }
     if (!isset($behaviour['DELETE_SUBTREE'])) {
         $behaviour['DELETE_SUBTREE'] = true;
     }
     if ($behaviour['DELETE_SUBTREE']) {
         // it means we want to delete not only the following node, but the whole subtree that belongs to it
         // note that with this option set to Y tree structure integrity will be compromised
         $node = self::getNodeInfo($primary);
         if (intval($node['ID'])) {
             $node['LEFT_MARGIN'] = intval($node['LEFT_MARGIN']);
             $node['RIGHT_MARGIN'] = intval($node['RIGHT_MARGIN']);
             // low-level
             Main\HttpApplication::getConnection()->query('delete from ' . static::getTableName() . ' where LEFT_MARGIN > ' . $node['LEFT_MARGIN'] . ' and RIGHT_MARGIN < ' . $node['RIGHT_MARGIN']);
             /*
             // high-level, but extremely slow
             
             // select whole subtree
             $res = self::getList(array(
             	'filter' =>  array(
             		'>LEFT_MARGIN' => $node['LEFT_MARGIN'],
             		'<RIGHT_MARGIN' => $node['RIGHT_MARGIN']
             	),
             	'order' => array(
             		'LEFT_MARGIN' => 'asc'
             	)
             ));
             
             // delete it
             while($item = $res->fetch())
             	static::delete($item['ID'], array('REBALANCE' => false, 'DELETE_SUBTREE' => false));
             */
             // and also remove free spece, if needed
             if ($behaviour['REBALANCE']) {
                 self::manageFreeSpace($node['RIGHT_MARGIN'], $node['RIGHT_MARGIN'] - $node['LEFT_MARGIN'] + 1, self::SPACE_REMOVE);
             }
         } else {
             throw new Main\SystemException('Node not found');
         }
     }
     return parent::delete($primary);
 }
Exemplo n.º 7
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;
 }
Exemplo n.º 8
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;
 }
Exemplo n.º 9
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;
 }
Exemplo n.º 10
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;
 }
Exemplo n.º 11
0
 /**
  * Available keys in $additional
  * REBALANCE - if set to true, method will rebalance tree after insertion
  * DELETE_SUBTREE - if set to true, only node will be deleted, and it`s subtree left unattached
  * @param $primary
  * @param array $additional
  * @return Entity\DeleteResult
  * @throws Main\SystemException
  * @throws Tree\NodeIncorrectException
  * @throws Tree\NodeNotFoundException
  * @throws \Exception
  */
 public static function deleteExtended($primary, array $additional = array())
 {
     $rebalance = isset($additional['REBALANCE']) && $additional['REBALANCE'] == false;
     $deleteSubtree = isset($additional['DELETE_SUBTREE']) && $additional['DELETE_SUBTREE'] == false;
     if ($deleteSubtree) {
         // it means we want to delete not only the following node, but the whole subtree that belongs to it
         // note that with this option set to Y tree structure integrity will be compromised
         $node = self::getNodeInfo($primary);
         if (intval($node['ID'])) {
             static::checkNodeThrowException($node);
             // low-level
             Main\HttpApplication::getConnection()->query('delete from ' . static::getTableName() . ' where LEFT_MARGIN > ' . $node['LEFT_MARGIN'] . ' and RIGHT_MARGIN < ' . $node['RIGHT_MARGIN']);
             // and also remove free spece, if needed
             if ($rebalance) {
                 self::manageFreeSpace($node['RIGHT_MARGIN'], $node['RIGHT_MARGIN'] - $node['LEFT_MARGIN'] + 1, self::SPACE_REMOVE);
             }
         } else {
             throw new Tree\NodeNotFoundException(false, array('INFO' => array('ID' => $primary)));
         }
     }
     return parent::delete($primary);
 }
Exemplo n.º 12
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;
 }