From 561ebd55085b80c761a2c6c1f460b86484e4fe05 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Tue, 13 May 2014 14:06:09 +0200 Subject: [PATCH] Made ARG_QUERY optional --- src/Api/Jobs/LogJobs/GetLogJob.php | 6 ++++-- src/Api/Jobs/PostJobs/ListPostsJob.php | 6 ++++-- src/Api/Jobs/TagJobs/ListTagsJob.php | 6 ++++-- src/Api/Jobs/UserJobs/ListUsersJob.php | 6 ++++-- tests/Api/ApiArgumentTest.php | 8 ++++---- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/Api/Jobs/LogJobs/GetLogJob.php b/src/Api/Jobs/LogJobs/GetLogJob.php index 04e26cf8..29ecf36d 100644 --- a/src/Api/Jobs/LogJobs/GetLogJob.php +++ b/src/Api/Jobs/LogJobs/GetLogJob.php @@ -19,7 +19,9 @@ class GetLogJob extends AbstractJob implements IPagedJob $pageSize = $this->pager->getPageSize(); $page = $this->pager->getPageNumber(); $name = $this->getArgument(JobArgs::ARG_LOG_ID); - $query = $this->getArgument(JobArgs::ARG_QUERY); + $query = $this->hasArgument(JobArgs::ARG_QUERY) + ? $this->getArgument(JobArgs::ARG_QUERY) + : ''; //parse input $page = max(1, intval($page)); @@ -53,7 +55,7 @@ class GetLogJob extends AbstractJob implements IPagedJob return JobArgs::Conjunction( $this->pager->getRequiredArguments(), JobArgs::ARG_LOG_ID, - JobArgs::ARG_QUERY); + JobArgs::Optional(JobArgs::ARG_QUERY)); } public function getRequiredPrivileges() diff --git a/src/Api/Jobs/PostJobs/ListPostsJob.php b/src/Api/Jobs/PostJobs/ListPostsJob.php index 42f308f7..dea4dd27 100644 --- a/src/Api/Jobs/PostJobs/ListPostsJob.php +++ b/src/Api/Jobs/PostJobs/ListPostsJob.php @@ -18,7 +18,9 @@ class ListPostsJob extends AbstractJob implements IPagedJob { $pageSize = $this->pager->getPageSize(); $page = $this->pager->getPageNumber(); - $query = $this->getArgument(JobArgs::ARG_QUERY); + $query = $this->hasArgument(JobArgs::ARG_QUERY) + ? $this->getArgument(JobArgs::ARG_QUERY) + : ''; $posts = PostSearchService::getEntities($query, $pageSize, $page); $postCount = PostSearchService::getEntityCount($query); @@ -32,7 +34,7 @@ class ListPostsJob extends AbstractJob implements IPagedJob { return JobArgs::Conjunction( $this->pager->getRequiredArguments(), - JobArgs::ARG_QUERY); + JobArgs::Optional(JobArgs::ARG_QUERY)); } public function getRequiredPrivileges() diff --git a/src/Api/Jobs/TagJobs/ListTagsJob.php b/src/Api/Jobs/TagJobs/ListTagsJob.php index a33d009d..fa9bcc57 100644 --- a/src/Api/Jobs/TagJobs/ListTagsJob.php +++ b/src/Api/Jobs/TagJobs/ListTagsJob.php @@ -18,7 +18,9 @@ class ListTagsJob extends AbstractJob implements IPagedJob { $pageSize = $this->pager->getPageSize(); $page = $this->pager->getPageNumber(); - $query = $this->getArgument(JobArgs::ARG_QUERY); + $query = $this->hasArgument(JobArgs::ARG_QUERY) + ? $this->getArgument(JobArgs::ARG_QUERY) + : ''; $tags = TagSearchService::getEntities($query, $pageSize, $page); $tagCount = TagSearchService::getEntityCount($query); @@ -30,7 +32,7 @@ class ListTagsJob extends AbstractJob implements IPagedJob { return JobArgs::Conjunction( $this->pager->getRequiredArguments(), - JobArgs::ARG_QUERY); + JobArgs::Optional(JobArgs::ARG_QUERY)); } public function getRequiredPrivileges() diff --git a/src/Api/Jobs/UserJobs/ListUsersJob.php b/src/Api/Jobs/UserJobs/ListUsersJob.php index cc700558..8e5bb2f3 100644 --- a/src/Api/Jobs/UserJobs/ListUsersJob.php +++ b/src/Api/Jobs/UserJobs/ListUsersJob.php @@ -18,7 +18,9 @@ class ListUsersJob extends AbstractJob implements IPagedJob { $pageSize = $this->pager->getPageSize(); $page = $this->pager->getPageNumber(); - $filter = $this->getArgument(JobArgs::ARG_QUERY); + $filter = $this->hasArgument(JobArgs::ARG_QUERY) + ? $this->getArgument(JobArgs::ARG_QUERY) + : ''; $users = UserSearchService::getEntities($filter, $pageSize, $page); $userCount = UserSearchService::getEntityCount($filter); @@ -30,7 +32,7 @@ class ListUsersJob extends AbstractJob implements IPagedJob { return JobArgs::Conjunction( $this->pager->getRequiredArguments(), - JobArgs::ARG_QUERY); + JobArgs::Optional(JobArgs::ARG_QUERY)); } public function getRequiredPrivileges() diff --git a/tests/Api/ApiArgumentTest.php b/tests/Api/ApiArgumentTest.php index 6c6616b6..b4fb8ed0 100644 --- a/tests/Api/ApiArgumentTest.php +++ b/tests/Api/ApiArgumentTest.php @@ -179,7 +179,7 @@ class ApiArgumentTest extends AbstractFullApiTest { $this->testArguments(new GetLogJob(), JobArgs::Conjunction( - JobArgs::ARG_QUERY, + JobArgs::Optional(JobArgs::ARG_QUERY), JobArgs::ARG_LOG_ID, JobArgs::Optional(JobArgs::ARG_PAGE_NUMBER))); } @@ -227,7 +227,7 @@ class ApiArgumentTest extends AbstractFullApiTest { $this->testArguments(new ListPostsJob(), JobArgs::Conjunction( - JobArgs::ARG_QUERY, + JobArgs::Optional(JobArgs::ARG_QUERY), JobArgs::Optional(JobArgs::ARG_PAGE_NUMBER))); } @@ -244,7 +244,7 @@ class ApiArgumentTest extends AbstractFullApiTest { $this->testArguments(new ListTagsJob(), JobArgs::Conjunction( - JobArgs::ARG_QUERY, + JobArgs::Optional(JobArgs::ARG_QUERY), JobArgs::Optional(JobArgs::ARG_PAGE_NUMBER))); } @@ -252,7 +252,7 @@ class ApiArgumentTest extends AbstractFullApiTest { $this->testArguments(new ListUsersJob(), JobArgs::Conjunction( - JobArgs::ARG_QUERY, + JobArgs::Optional(JobArgs::ARG_QUERY), JobArgs::Optional(JobArgs::ARG_PAGE_NUMBER))); }