EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
fix kb article move
Yuri Kuznetsov0f2689deeeaa
diff --git a/application/Espo/Modules/Crm/Controllers/KnowledgeBaseArticle.php b/application/Espo/Modules/Crm/Controllers/KnowledgeBaseArticle.phpindex 7c4a9c4f25..943be8d5c6 100644--- a/application/Espo/Modules/Crm/Controllers/KnowledgeBaseArticle.php+++ b/application/Espo/Modules/Crm/Controllers/KnowledgeBaseArticle.php@@ -35,6 +35,7 @@ use Espo\Core\Api\Request;use Espo\Core\Exceptions\Error;use Espo\Core\Exceptions\Forbidden;use Espo\Core\Exceptions\NotFound;+use Espo\Core\Select\SearchParams;use Espo\Core\Select\Where\Item as WhereItem;use Espo\Core\Utils\Json;use Espo\Modules\Crm\Tools\KnowledgeBase\Service as KBService;@@ -105,15 +106,9 @@ class KnowledgeBaseArticle extends Recordthrow new BadRequest();}- $where = null;+ $searchParams = $this->fetchSearchParams($request);- if (!empty($data->where)) {- $where = WhereItem::fromRawAndGroup(- Json::decode(Json::encode($data->where), true)- );- }-- $this->getArticleService()->moveToTop($data->id, $where);+ $this->getArticleService()->moveToTop($data->id, $searchParams);return true;}@@ -132,15 +127,9 @@ class KnowledgeBaseArticle extends Recordthrow new BadRequest();}- $where = null;-- if (!empty($data->where)) {- $where = WhereItem::fromRawAndGroup(- Json::decode(Json::encode($data->where), true)- );- }+ $searchParams = $this->fetchSearchParams($request);- $this->getArticleService()->moveUp($data->id, $where);+ $this->getArticleService()->moveUp($data->id, $searchParams);return true;}@@ -159,15 +148,9 @@ class KnowledgeBaseArticle extends Recordthrow new BadRequest();}- $where = null;+ $searchParams = $this->fetchSearchParams($request);- if (!empty($data->where)) {- $where = WhereItem::fromRawAndGroup(- Json::decode(Json::encode($data->where), true)- );- }-- $this->getArticleService()->moveDown($data->id, $where);+ $this->getArticleService()->moveDown($data->id, $searchParams);return true;}@@ -186,15 +169,9 @@ class KnowledgeBaseArticle extends Recordthrow new BadRequest();}- $where = null;-- if (!empty($data->where)) {- $where = WhereItem::fromRawAndGroup(- Json::decode(Json::encode($data->where), true)- );- }+ $searchParams = $this->fetchSearchParams($request);- $this->getArticleService()->moveToBottom($data->id, $where);+ $this->getArticleService()->moveToBottom($data->id, $searchParams);return true;}@@ -203,4 +180,19 @@ class KnowledgeBaseArticle extends Record{return $this->injectableFactory->create(KBService::class);}++ private function fetchSearchParams(Request $request): SearchParams+ {+ $body = $request->getParsedBody();++ $searchParams = SearchParams::create();++ if ($body->whereGroup ?? null) {+ $rawWhere = Json::decode(Json::encode($body->whereGroup), true);++ $searchParams = SearchParams::fromRaw(['where' => $rawWhere]);+ }++ return $searchParams;+ }}diff --git a/application/Espo/Modules/Crm/Tools/KnowledgeBase/Service.php b/application/Espo/Modules/Crm/Tools/KnowledgeBase/Service.phpindex 28b62c5f53..fc9eab5c9a 100644--- a/application/Espo/Modules/Crm/Tools/KnowledgeBase/Service.php+++ b/application/Espo/Modules/Crm/Tools/KnowledgeBase/Service.php@@ -30,6 +30,7 @@namespace Espo\Modules\Crm\Tools\KnowledgeBase;use Espo\Core\Acl;+use Espo\Core\Exceptions\BadRequest;use Espo\Core\Exceptions\Error;use Espo\Core\Exceptions\Forbidden;use Espo\Core\Exceptions\NotFound;@@ -46,25 +47,13 @@ use Espo\Tools\Attachment\FieldData;class Service{- private EntityManager $entityManager;- private AttachmentAccessChecker $attachmentAccessChecker;- private ServiceContainer $serviceContainer;- private SelectBuilderFactory $selectBuilderFactory;- private Acl $acl;-public function __construct(- EntityManager $entityManager,- AttachmentAccessChecker $attachmentAccessChecker,- ServiceContainer $serviceContainer,- SelectBuilderFactory $selectBuilderFactory,- Acl $acl- ) {- $this->entityManager = $entityManager;- $this->attachmentAccessChecker = $attachmentAccessChecker;- $this->serviceContainer = $serviceContainer;- $this->selectBuilderFactory = $selectBuilderFactory;- $this->acl = $acl;- }+ private EntityManager $entityManager,+ private AttachmentAccessChecker $attachmentAccessChecker,+ private ServiceContainer $serviceContainer,+ private SelectBuilderFactory $selectBuilderFactory,+ private Acl $acl,+ ) {}/*** Copy article attachments for re-using (e.g. in an email).@@ -132,8 +121,9 @@ class Service* @throws NotFound* @throws Forbidden* @throws Error+ * @throws BadRequest*/- public function moveUp(string $id, ?WhereItem $where = null): void+ public function moveUp(string $id, SearchParams $params): void{/** @var ?KnowledgeBaseArticle $entity */$entity = $this->entityManager->getEntityById(KnowledgeBaseArticle::ENTITY_TYPE, $id);@@ -152,12 +142,6 @@ class Servicethrow new Error();}- $params = SearchParams::create();-- if ($where) {- $params = $params->withWhere($where);- }-$query = $this->selectBuilderFactory->create()->from(KnowledgeBaseArticle::ENTITY_TYPE)@@ -194,8 +178,9 @@ class Service* @throws NotFound* @throws Forbidden* @throws Error+ * @throws BadRequest*/- public function moveDown(string $id, ?WhereItem $where = null): void+ public function moveDown(string $id, SearchParams $params): void{/** @var ?KnowledgeBaseArticle $entity */$entity = $this->entityManager->getEntityById(KnowledgeBaseArticle::ENTITY_TYPE, $id);@@ -214,12 +199,6 @@ class Servicethrow new Error();}- $params = SearchParams::create();-- if ($where) {- $params = $params->withWhere($where);- }-$query = $this->selectBuilderFactory->create()->from(KnowledgeBaseArticle::ENTITY_TYPE)@@ -256,8 +235,9 @@ class Service* @throws NotFound* @throws Forbidden* @throws Error+ * @throws BadRequest*/- public function moveToTop(string $id, ?WhereItem $where = null): void+ public function moveToTop(string $id, SearchParams $params): void{/** @var ?KnowledgeBaseArticle $entity */$entity = $this->entityManager->getEntityById(KnowledgeBaseArticle::ENTITY_TYPE, $id);@@ -276,12 +256,6 @@ class Servicethrow new Error();}- $params = SearchParams::create();-- if ($where) {- $params = $params->withWhere($where);- }-$query = $this->selectBuilderFactory->create()->from(KnowledgeBaseArticle::ENTITY_TYPE)@@ -315,8 +289,9 @@ class Service* @throws NotFound* @throws Forbidden* @throws Error+ * @throws BadRequest*/- public function moveToBottom(string $id, ?WhereItem $where = null): void+ public function moveToBottom(string $id, SearchParams $params): void{/** @var ?KnowledgeBaseArticle $entity */$entity = $this->entityManager->getEntityById(KnowledgeBaseArticle::ENTITY_TYPE, $id);@@ -335,12 +310,6 @@ class Servicethrow new Error();}- $params = SearchParams::create();-- if ($where) {- $params = $params->withWhere($where);- }-$query = $this->selectBuilderFactory->create()->from(KnowledgeBaseArticle::ENTITY_TYPE)diff --git a/client/modules/crm/src/handlers/knowledge-base-article/move.js b/client/modules/crm/src/handlers/knowledge-base-article/move.jsindex 38beabfa57..1d001379c6 100644--- a/client/modules/crm/src/handlers/knowledge-base-article/move.js+++ b/client/modules/crm/src/handlers/knowledge-base-article/move.js@@ -71,7 +71,7 @@ class MoveActionHandler extends RowActionHandler {Espo.Ajax.postRequest('KnowledgeBaseArticle/action/moveToTop', {id: model.id,- where: this.collection.getWhere(),+ whereGroup: this.collection.getWhere(),}).then(() => {this.collection.fetch().then(() => Espo.Ui.notify(false));@@ -89,7 +89,7 @@ class MoveActionHandler extends RowActionHandler {Espo.Ajax.postRequest('KnowledgeBaseArticle/action/moveUp', {id: model.id,- where: this.collection.getWhere(),+ whereGroup: this.collection.getWhere(),}).then(() => {this.collection.fetch().then(() => Espo.Ui.notify(false));@@ -107,7 +107,7 @@ class MoveActionHandler extends RowActionHandler {Espo.Ajax.postRequest('KnowledgeBaseArticle/action/moveDown', {id: model.id,- where: this.collection.getWhere(),+ whereGroup: this.collection.getWhere(),}).then(() => {this.collection.fetch().then(() => Espo.Ui.notify(false));@@ -125,7 +125,7 @@ class MoveActionHandler extends RowActionHandler {Espo.Ajax.postRequest('KnowledgeBaseArticle/action/moveToBottom', {id: model.id,- where: this.collection.getWhere(),+ whereGroup: this.collection.getWhere(),}).then(() => {this.collection.fetch().then(() => Espo.Ui.notify(false));