Exemple #1
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;
 }
Exemple #2
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;
 }