예제 #1
0
 public static function update($primary, array $data)
 {
     $result = parent::update($primary, $data);
     if (CACHED_b_lang !== false && $result->isSuccess()) {
         $cache = \Bitrix\Main\Application::getInstance()->getManagedCache();
         $cache->cleanDir("b_lang");
     }
     return $result;
 }
예제 #2
0
 public static function update($primary, array $data)
 {
     if (empty($data)) {
         return new Entity\UpdateResult();
     }
     $serviceForUpdate = static::getByPrimary($primary)->fetch();
     if (!$serviceForUpdate) {
         $updateResult = new Entity\UpdateResult();
         $updateResult->addError(new Entity\EntityError(Localization\Loc::getMessage('mail_mailservice_not_found')));
         return $updateResult;
     }
     if (isset($data['ICON']) && is_array($data['ICON'])) {
         $iconError = $data['ICON']['name'] ? \CFile::checkImageFile($data['ICON']) : null;
         if (is_null($iconError)) {
             $data['ICON']['MODULE_ID'] = 'mail';
             \CFile::saveForDB($data, 'ICON', 'mail/mailservices/icon');
         }
     }
     $updateResult = parent::update($primary, $data);
     if ($updateResult->isSuccess()) {
         $serviceId = is_array($primary) ? $primary['ID'] : $primary;
         $isSiteChanged = isset($data['SITE_ID']) && $data['SITE_ID'] != $serviceForUpdate['SITE_ID'];
         $isDeactivated = isset($data['ACTIVE']) && $data['ACTIVE'] == 'N' && $serviceForUpdate['ACTIVE'] == 'Y';
         if (($isSiteChanged || $isDeactivated) && $serviceForUpdate['SERVICE_TYPE'] == 'imap') {
             $emptyService = static::getList(array('filter' => array('=SITE_ID' => $serviceForUpdate['SITE_ID'], 'ACTIVE' => 'Y', '=SERVER' => '', '=PORT' => '', '=ENCRYPTION' => '', '=LINK' => ''), 'limit' => 1))->fetch();
         }
         if ($isSiteChanged || $isDeactivated && $emptyService) {
             $mbData = $emptyService ? array('SERVICE_ID' => $emptyService['ID'], 'NAME' => $emptyService['NAME']) : array('ACTIVE' => 'N', 'SERVICE_ID' => 0);
         } else {
             $mbData = array();
             foreach ($data as $key => $value) {
                 if (empty($value)) {
                     continue;
                 }
                 switch ($key) {
                     case 'ACTIVE':
                     case 'NAME':
                     case 'SERVER':
                     case 'PORT':
                     case 'LINK':
                         $mbData[$key] = $value;
                         break;
                     case 'ENCRYPTION':
                         $mbData['USE_TLS'] = $value;
                         break;
                 }
             }
         }
         $selectResult = \CMailbox::getList(array(), array('SERVICE_ID' => $serviceId));
         while ($mailbox = $selectResult->fetch()) {
             \CMailbox::update($mailbox['ID'], $mbData);
         }
     }
     return $updateResult;
 }
예제 #3
0
 public static function update($primary, array $data)
 {
     $primary = Assert::expectIntegerPositive($primary, '$primary');
     // first update parent, and if it succeed, do updates of the connected data
     if (isset($data['NAME'])) {
         $name = $data['NAME'];
         unset($data['NAME']);
     }
     $updResult = parent::update($primary, $data);
     // update connected data
     if ($updResult->isSuccess()) {
         // names
         if (isset($name)) {
             Name\GroupTable::updateMultipleForOwner($primary, $name);
         }
     }
     return $updResult;
 }
예제 #4
0
 public static function update($primary, $data = array())
 {
     $primary = Assert::expectIntegerPositive($primary, Loc::getMessage('SALE_LOCATION_GROUP_ENTITY_PRIMARY_FIELD'));
     // first update parent, and if it succeed, do updates of the connected data
     if (isset($data['NAME'])) {
         $name = $data['NAME'];
         unset($data['NAME']);
     }
     $updResult = parent::update($primary, $data);
     // update connected data
     if ($updResult->isSuccess()) {
         // names
         if (isset($name)) {
             Name\GroupTable::updateMultipleForOwner($primary, $name);
         }
     }
     return $updResult;
 }
예제 #5
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;
 }
예제 #6
0
 /**
  * Updates a connection between location and entity
  * 
  * @param mixed $primary relation primary key value
  * @param mixed[] $data data to update with (See getMap() of a certain implementation for $data key details)
  * 
  * @return Bitrix\Main\Entity\UpdateResult
  */
 public static function update($primary, $data = array())
 {
     $linkFld = static::getLinkField();
     if ($primary && isset($data[$linkFld])) {
         // it will break below, at parent::delete()
         $link = static::getByPrimary($primary)->fetch();
     }
     $res = parent::update($primary, $data);
     if ($res->isSuccess() && isset($data[$linkFld]) && $data[$linkFld] != $link[$linkFld]) {
         static::resetLinkUsage($link[static::getLinkField()]);
         // for donor entity we need to recalc link existence
         static::setLinkUsage($data[$linkFld], $data[static::getTypeField()], true);
         // we know there ARE links for retsepient entity
     }
     $GLOBALS['CACHE_MANAGER']->ClearByTag('sale-location-data');
     return $res;
 }
예제 #7
0
 /**
  * {@inheritdoc}
  */
 public static function update($primary, array $data)
 {
     $data['MODIFIED_BY'] = static::getUserId();
     return parent::update($primary, $data);
 }
예제 #8
0
 public static function update($primary, array $data)
 {
     $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 ($data as $k => $v) {
         $arUserField = $fields[$k];
         if (is_callable(array($arUserField["USER_TYPE"]["CLASS_NAME"], "onbeforesave"))) {
             if ($arUserField["USER_TYPE"]['BASE_TYPE'] == 'file' && !empty($v['old_id']) && $v['error'] === 4) {
                 // no files changed. dear uf manager, please keep current file
                 $arUserField['VALUE'] = $v;
             }
             $data[$k] = call_user_func_array(array($arUserField["USER_TYPE"]["CLASS_NAME"], "onbeforesave"), array($arUserField, $data[$k]));
         }
         if (strlen($data[$k]) <= 0) {
             $data[$k] = false;
         } else {
             // convert string datetime to DateTime object
             if ($arUserField['USER_TYPE_ID'] == 'datetime') {
                 try {
                     $data[$k] = Type\DateTime::createFromUserTime($v);
                 } catch (Main\ObjectException $e) {
                     $data[$k] = '';
                 }
             }
         }
     }
     return parent::update($primary, $data);
 }
예제 #9
0
파일: mailing.php 프로젝트: Hawkart/megatv
 /**
  * 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();
     }
 }
예제 #10
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);
 }
예제 #11
0
 /**
  * @param mixed $primary
  * @param array $data
  *
  * @return Entity\UpdateResult
  */
 public static function update($primary, $data)
 {
     global $USER_FIELD_MANAGER;
     // get old data
     $oldData = static::getByPrimary($primary)->fetch();
     // update row
     $result = parent::update($primary, $data);
     if (!$result->isSuccess(true)) {
         return $result;
     }
     // rename table in db
     if ($data['TABLE_NAME'] !== $oldData['TABLE_NAME']) {
         $connection = Application::getConnection();
         $sqlHelper = $connection->getSqlHelper();
         $connection->renameTable($oldData['TABLE_NAME'], $data['TABLE_NAME']);
         if ($connection instanceof MssqlConnection) {
             // rename constraint
             $connection->query(sprintf("EXEC sp_rename %s, %s, 'OBJECT'", $sqlHelper->quote($oldData['TABLE_NAME'] . '_ibpk_1'), $sqlHelper->quote($data['TABLE_NAME'] . '_ibpk_1')));
         }
         // rename also uf multiple tables and its constraints, sequences, and triggers
         foreach ($USER_FIELD_MANAGER->getUserFields('HLBLOCK_' . $oldData['ID']) as $field) {
             if ($field['MULTIPLE'] == 'Y') {
                 $oldUtmTableName = static::getMultipleValueTableName($oldData, $field);
                 $newUtmTableName = static::getMultipleValueTableName($data, $field);
                 $connection->renameTable($oldUtmTableName, $newUtmTableName);
             }
         }
     }
     return $result;
 }