Revert "Revert "Define BlockPostQuery for nicer args processing for quering""

This reverts commit 62e393a76d.
This commit is contained in:
Sam
2022-04-12 18:22:50 +02:00
committed by Veljko V
parent 319017f09d
commit c32dc0a372
8 changed files with 205 additions and 98 deletions

View File

@ -5,6 +5,7 @@ namespace MailPoet\API\JSON\v1;
use MailPoet\API\JSON\Endpoint as APIEndpoint;
use MailPoet\Config\AccessControl;
use MailPoet\Newsletter\AutomatedLatestContent as ALC;
use MailPoet\Newsletter\BlockPostQuery;
use MailPoet\Util\APIPermissionHelper;
use MailPoet\WP\Functions as WPFunctions;
use MailPoet\WP\Posts as WPPosts;
@ -87,12 +88,12 @@ class AutomatedLatestContent extends APIEndpoint {
public function getPosts($data = []) {
return $this->successResponse(
$this->getPermittedPosts($this->ALC->getPosts($data))
$this->getPermittedPosts($this->ALC->getPosts(new BlockPostQuery(['args' => $data])))
);
}
public function getTransformedPosts($data = []) {
$posts = $this->getPermittedPosts($this->ALC->getPosts($data));
$posts = $this->getPermittedPosts($this->ALC->getPosts(new BlockPostQuery(['args' => $data])));
return $this->successResponse(
$this->ALC->transformPosts($data, $posts)
);
@ -103,7 +104,8 @@ class AutomatedLatestContent extends APIEndpoint {
$renderedPosts = [];
foreach ($data['blocks'] as $block) {
$posts = $this->getPermittedPosts($this->ALC->getPosts($block, $usedPosts));
$query = new BlockPostQuery(['args' => $block, 'postsToExclude' => $usedPosts]);
$posts = $this->getPermittedPosts($this->ALC->getPosts($query));
$renderedPosts[] = $this->ALC->transformPosts($block, $posts);
foreach ($posts as $post) {