| Conditions | 5 |
| Paths | 4 |
| Total Lines | 27 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 29 | public function isSlugUnique() |
||
| 30 | { |
||
| 31 | $this->onlyAdmin(); |
||
| 32 | $this->onlyPost(); |
||
| 33 | |||
| 34 | $postSlug = $this->request->getData("postSlug"); |
||
| 35 | $postId = $this->request->getData("postId"); |
||
| 36 | |||
| 37 | $data = false; |
||
| 38 | if (!$this->slug->isSlugValid($postSlug) || !$this->isInt($postId)) { |
||
| 39 | echo json_encode($data); |
||
| 40 | die(); |
||
|
1 ignored issue
–
show
|
|||
| 41 | } |
||
| 42 | |||
| 43 | $postModel = new PostModel($this->container); |
||
| 44 | |||
| 45 | $data = $postModel->isPostSlugUnique($postSlug); |
||
| 46 | |||
| 47 | if ($data === false) //slug is not unique, but could be from the same post |
||
| 48 | { |
||
| 49 | $slugOfId = $postModel->getPostSlugFromId($postId); |
||
| 50 | if ($slugOfId === $postSlug) { |
||
| 51 | //it's the same post, return true |
||
| 52 | $data = true; |
||
| 53 | } |
||
| 54 | } |
||
| 55 | echo json_encode($data); |
||
| 56 | } |
||
| 58 | } |