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