| Conditions | 4 |
| Paths | 4 |
| Total Lines | 25 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 32 | public function isSlugUnique() |
||
| 33 | { |
||
| 34 | $this->onlyAdmin(); |
||
| 35 | $this->onlyPost(); |
||
| 36 | |||
| 37 | $postSlug = $this->request->getData("postSlug"); |
||
| 38 | $postId = (int)$this->request->getData("postId"); |
||
| 39 | |||
| 40 | $data = false; |
||
| 41 | if (!$this->slug->isSlugValid($postSlug)) { |
||
| 42 | echo json_encode($data); |
||
| 43 | die(); |
||
| 44 | } |
||
| 45 | |||
| 46 | $data = $this->postModel->isPostSlugUnique(/** @scrutinizer ignore-type */$postSlug); //we have checked that slug is valid so no type error |
||
| 47 | |||
| 48 | if ($data === false) //slug is not unique, but could be from the same post |
||
| 49 | { |
||
| 50 | $slugOfId = $this->postModel->getPostSlugFromId($postId); |
||
| 51 | if ($slugOfId === $postSlug) { |
||
| 52 | //it's the same post, return true |
||
| 53 | $data = true; |
||
| 54 | } |
||
| 55 | } |
||
| 56 | echo json_encode($data); |
||
| 57 | } |
||
| 59 | } |