Пример #1
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;
 }
Пример #2
0
 /**
  * Changes file storage id. Be careful! The method is too specific.
  * @param $primary
  * @param $newStorageId
  * @return UpdateResult
  * @throws \Bitrix\Main\ArgumentException
  * @internal
  */
 public static function changeStorageId($primary, $newStorageId)
 {
     $newStorageId = (int) $newStorageId;
     // check primary
     static::normalizePrimary($primary);
     static::validatePrimary($primary);
     // save data
     $connection = Application::getConnection();
     $helper = $connection->getSqlHelper();
     $tableName = static::getEntity()->getDBTableName();
     $update = $helper->prepareUpdate($tableName, array('STORAGE_ID' => $newStorageId));
     $id = array();
     foreach ($primary as $k => $v) {
         $id[] = $helper->prepareAssignment($tableName, $k, $v);
     }
     $where = implode(' AND ', $id);
     $sql = "UPDATE " . $tableName . " SET " . $update[0] . " WHERE " . $where;
     $connection->queryExecute($sql, $update[1]);
     $result = new UpdateResult();
     $result->setAffectedRowsCount($connection);
     $result->setData(array('PARENT_ID' => $newStorageId));
     return $result;
 }
Пример #3
0
 /**
  * Updates discount by primary key.
  *
  * @param mixed $primary		Discount primary key.
  * @param array $data			Discount data.
  * @return Main\Entity\UpdateResult
  */
 public static function update($primary, array $data)
 {
     $result = new Main\Entity\UpdateResult();
     $result->addError(new Main\Entity\EntityError(Loc::getMessage('CATALOG_DISCOUNT_ENTITY_MESS_UPDATE_BLOCKED')));
     return $result;
 }
Пример #4
0
 /**
  * @return Main\Entity\AddResult|Main\Entity\UpdateResult
  * @throws Main\ArgumentNullException
  * @throws Main\ArgumentOutOfRangeException
  * @throws \Exception
  */
 public function save()
 {
     global $USER;
     $result = new Result();
     $id = $this->getId();
     $fields = $this->fields->getValues();
     /** @var ShipmentItemStoreCollection $collection */
     $collection = $this->getCollection();
     /** @var Result $r */
     $r = $collection->checkAvailableQuantity($this);
     if (!$r->isSuccess()) {
         $result->addErrors($r->getErrors());
         return $result;
     }
     /** @var BasketItem $basketItem */
     $basketItem = $this->getBasketItem();
     if ($id > 0) {
         $fields = $this->fields->getChangedValues();
         if (!empty($fields) && is_array($fields)) {
             if (isset($fields["QUANTITY"]) && floatval($fields["QUANTITY"]) <= 0) {
                 throw new Main\ArgumentNullException('quantity');
             }
             $fields['DATE_MODIFY'] = new Main\Type\DateTime();
             $fields['MODIFIED_BY'] = $USER->GetID();
             $r = Internals\ShipmentItemStoreTable::update($id, $fields);
             if (!$r->isSuccess()) {
                 return $r;
             }
         }
         $result = new Main\Entity\UpdateResult();
     } else {
         if (!isset($fields["ORDER_DELIVERY_BASKET_ID"])) {
             $fields['ORDER_DELIVERY_BASKET_ID'] = $this->getParentShipmentItemId();
         }
         if (!isset($fields["BASKET_ID"])) {
             $fields['BASKET_ID'] = $basketItem->getId();
         }
         $fields['DATE_CREATE'] = new Main\Type\DateTime();
         if (!isset($fields["QUANTITY"]) || floatval($fields["QUANTITY"]) == 0) {
             return new Main\Entity\AddResult();
         }
         if ($basketItem->isBarcodeMulti() && isset($fields['BARCODE']) && strval(trim($fields['BARCODE'])) == "") {
             $result->addError(new ResultError(Loc::getMessage('SHIPMENT_ITEM_STORE_BARCODE_MULTI_EMPTY', array('#PRODUCT_NAME#' => $basketItem->getField('NAME'), '#STORE_ID#' => $fields['STORE_ID'])), 'SHIPMENT_ITEM_STORE_BARCODE_MULTI_EMPTY'));
             return $result;
         }
         $r = Internals\ShipmentItemStoreTable::add($fields);
         if (!$r->isSuccess()) {
             return $r;
         }
         $id = $r->getId();
         $this->setFieldNoDemand('ID', $id);
         $result = new Main\Entity\AddResult();
     }
     return $result;
 }
Пример #5
0
 /**
  * Move object from node to another node.
  * Use this method instead update.
  * @param $primary
  * @param $newParentId
  * @return \Bitrix\Main\Entity\UpdateResult
  */
 public static function move($primary, $newParentId)
 {
     $newParentId = (int) $newParentId;
     // check primary
     static::normalizePrimary($primary);
     static::validatePrimary($primary);
     $data = array('PARENT_ID' => $newParentId);
     $entity = static::getEntity();
     $result = new UpdateResult();
     $event = new Event($entity, self::EVENT_ON_BEFORE_MOVE, array("id" => $primary, "fields" => $data));
     $event->send();
     $event->getErrors($result);
     $data = $event->mergeFields($data);
     // check data
     //		static::checkFields($result, $primary, $data);
     if (!$result->isSuccess(true)) {
         return $result;
     }
     $event = new Event($entity, self::EVENT_ON_MOVE, array("id" => $primary, "fields" => $data));
     $event->send();
     ObjectPathTable::moveTo($primary['ID'], $newParentId);
     // save data
     $connection = Main\Application::getConnection();
     $helper = $connection->getSqlHelper();
     $tableName = static::getEntity()->getDBTableName();
     $update = $helper->prepareUpdate($tableName, array('PARENT_ID' => $newParentId));
     $id = array();
     foreach ($primary as $k => $v) {
         $id[] = $helper->prepareAssignment($tableName, $k, $v);
     }
     $where = implode(' AND ', $id);
     $sql = "UPDATE " . $tableName . " SET " . $update[0] . " WHERE " . $where;
     $connection->queryExecute($sql, $update[1]);
     $result = new UpdateResult();
     $result->setAffectedRowsCount($connection);
     $result->setData(array('PARENT_ID' => $newParentId));
     $event = new Event($entity, self::EVENT_ON_AFTER_MOVE, array("id" => $primary, "fields" => $data));
     $event->send();
     return $result;
 }