| @@ -26,15 +26,8 @@ | ||
| 26 | 26 | private Cache $cache |
| 27 | 27 | ) { |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - /** | |
| 31 | - * Resolves all tree map elements | |
| 32 | - * @param array $map | |
| 33 | - * @param array|null $subMap | |
| 34 | - * @param array $processed | |
| 35 | - * @return array | |
| 36 | - */ | |
| 37 | 30 | private function processTreeMapElements(array &$map, ?array $subMap = null, array &$processed = []): array |
| 38 | 31 | { |
| 39 | 32 | $processMap = ($subMap === null) ? $map : $subMap; |
| 40 | 33 | |
| @@ -68,11 +61,10 @@ | ||
| 68 | 61 | $treeMap[self::TREE_MAP_PARENTS][$generalType][$result->id][$result->parentId] = $result->type; |
| 69 | 62 | $treeMap[self::TREE_MAP_PARENTS][$result->type][$result->id][$result->parentId] = $result->type; |
| 70 | 63 | } |
| 71 | 64 | |
| 72 | - //Process elements | |
| 73 | - foreach ($treeMap as $mapType => $mayTypeMap) { | |
| 74 | - foreach ($mayTypeMap as $objectType => $map) { | |
| 65 | + foreach ($treeMap as $mapType => $mapsByObjectType) { | |
| 66 | + foreach ($mapsByObjectType as $objectType => $map) { | |
| 75 | 67 | $treeMap[$mapType][(string) $objectType] = $this->processTreeMapElements($map); |
| 76 | 68 | } |
| 77 | 69 | } |
| 78 | 70 | |
| @@ -87,18 +79,17 @@ | ||
| 87 | 79 | $map = $this->getTreeMap($query, $generalType); |
| 88 | 80 | $this->cache->add($cacheKey, $map); |
| 89 | 81 | } |
| 90 | 82 | |
| 91 | - | |
| 92 | 83 | return $map; |
| 93 | 84 | } |
| 94 | 85 | |
| 95 | - public function getPostTreeMap(): ?array | |
| 86 | + public function getPostTreeMap(): array | |
| 96 | 87 | { |
| 97 | 88 | if ($this->postTreeMap === null) { |
| 98 | - $query = "SELECT ID AS id, post_parent AS parentId, post_type AS type | |
| 99 | - FROM {$this->database->getPostsTable()} | |
| 100 | - WHERE post_parent != 0 AND post_type != 'revision'"; | |
| 89 | + $query = "SELECT `ID` AS `id`, `post_parent` AS `parentId`, `post_type` AS `type` | |
| 90 | + FROM `{$this->database->getPostsTable()}` | |
| 91 | + WHERE `post_parent` != 0 AND `post_type` != 'revision'"; | |
| 101 | 92 | |
| 102 | 93 | $this->postTreeMap = $this->getCachedTreeMap( |
| 103 | 94 | self::POST_TREE_MAP_CACHE_KEY, |
| 104 | 95 | ObjectHandler::GENERAL_POST_OBJECT_TYPE, |
| @@ -108,14 +99,14 @@ | ||
| 108 | 99 | |
| 109 | 100 | return $this->postTreeMap; |
| 110 | 101 | } |
| 111 | 102 | |
| 112 | - public function getTermTreeMap(): ?array | |
| 103 | + public function getTermTreeMap(): array | |
| 113 | 104 | { |
| 114 | 105 | if ($this->termTreeMap === null) { |
| 115 | - $query = "SELECT term_id AS id, parent AS parentId, taxonomy AS type | |
| 116 | - FROM {$this->database->getTermTaxonomyTable()} | |
| 117 | - WHERE parent != 0"; | |
| 106 | + $query = "SELECT `term_id` AS `id`, `parent` AS `parentId`, `taxonomy` AS `type` | |
| 107 | + FROM `{$this->database->getTermTaxonomyTable()}` | |
| 108 | + WHERE `parent` != 0"; | |
| 118 | 109 | |
| 119 | 110 | $this->termTreeMap = $this->getCachedTreeMap( |
| 120 | 111 | self::TERM_TREE_MAP_CACHE_KEY, |
| 121 | 112 | ObjectHandler::GENERAL_TERM_OBJECT_TYPE, |
| @@ -143,18 +134,18 @@ | ||
| 143 | 134 | |
| 144 | 135 | return $map; |
| 145 | 136 | } |
| 146 | 137 | |
| 147 | - public function getTermPostMap(): ?array | |
| 138 | + public function getTermPostMap(): array | |
| 148 | 139 | { |
| 149 | 140 | if ($this->termPostMap === null) { |
| 150 | 141 | $select = " |
| 151 | - SELECT tr.object_id AS objectId, tt.term_id AS parentId, p.post_type AS type | |
| 152 | - FROM {$this->database->getTermRelationshipsTable()} AS tr | |
| 153 | - LEFT JOIN {$this->database->getPostsTable()} AS p | |
| 154 | - ON (tr.object_id = p.ID) | |
| 155 | - LEFT JOIN {$this->database->getTermTaxonomyTable()} AS tt | |
| 156 | - ON (tr.term_taxonomy_id = tt.term_taxonomy_id)"; | |
| 142 | + SELECT `tr`.`object_id` AS `objectId`, `tt`.`term_id` AS `parentId`, `p`.`post_type` AS `type` | |
| 143 | + FROM `{$this->database->getTermRelationshipsTable()}` AS `tr` | |
| 144 | + LEFT JOIN `{$this->database->getPostsTable()}` AS `p` | |
| 145 | + ON (`tr`.`object_id` = `p`.`ID`) | |
| 146 | + LEFT JOIN `{$this->database->getTermTaxonomyTable()}` AS `tt` | |
| 147 | + ON (`tr`.`term_taxonomy_id` = `tt`.`term_taxonomy_id`)"; | |
| 157 | 148 | |
| 158 | 149 | $this->termPostMap = $this->getCachedMap(self::TERM_POST_MAP_CACHE_KEY, $select); |
| 159 | 150 | } |
| 160 | 151 | |
| @@ -160,16 +151,16 @@ | ||
| 160 | 151 | |
| 161 | 152 | return $this->termPostMap; |
| 162 | 153 | } |
| 163 | 154 | |
| 164 | - public function getPostTermMap(): ?array | |
| 155 | + public function getPostTermMap(): array | |
| 165 | 156 | { |
| 166 | 157 | if ($this->postTermMap === null) { |
| 167 | 158 | $select = " |
| 168 | - SELECT tr.object_id AS parentId, tt.term_id AS objectId, tt.taxonomy AS type | |
| 169 | - FROM {$this->database->getTermRelationshipsTable()} AS tr | |
| 170 | - LEFT JOIN {$this->database->getTermTaxonomyTable()} AS tt | |
| 171 | - ON (tr.term_taxonomy_id = tt.term_taxonomy_id)"; | |
| 159 | + SELECT `tr`.`object_id` AS `parentId`, `tt`.`term_id` AS `objectId`, `tt`.`taxonomy` AS `type` | |
| 160 | + FROM `{$this->database->getTermRelationshipsTable()}` AS `tr` | |
| 161 | + LEFT JOIN `{$this->database->getTermTaxonomyTable()}` AS `tt` | |
| 162 | + ON (`tr`.`term_taxonomy_id` = `tt`.`term_taxonomy_id`)"; | |
| 172 | 163 | |
| 173 | 164 | $this->postTermMap = $this->getCachedMap(self::POST_TERM_MAP_CACHE_KEY, $select); |
| 174 | 165 | } |
| 175 | 166 | |