|
14 | 14 | use Joomla\CMS\Table\CoreContent; |
15 | 15 | use Joomla\CMS\Table\Table; |
16 | 16 | use Joomla\CMS\Table\TableInterface; |
17 | | -use Joomla\CMS\UCM\UCMContent; |
18 | | -use Joomla\CMS\UCM\UCMType; |
19 | 17 | use Joomla\Database\DatabaseInterface; |
20 | 18 | use Joomla\Database\ParameterType; |
21 | 19 | use Joomla\Utilities\ArrayHelper; |
@@ -104,8 +102,14 @@ public function addTagMapping($ucmId, TableInterface $table, $tags = []) |
104 | 102 | $db = $table->getDbo(); |
105 | 103 | $key = $table->getKeyName(); |
106 | 104 | $item = $table->$key; |
107 | | - $ucm = new UCMType($this->typeAlias, $db); |
108 | | - $typeId = $ucm->getTypeId(); |
| 105 | + $query = $db->getQuery(true) |
| 106 | + ->select($db->quoteName('ct') . '.type_id') |
| 107 | + ->from($db->quoteName('#__content_types', 'ct')) |
| 108 | + ->where($db->quoteName('ct.type_alias') . ' = :alias') |
| 109 | + ->bind(':alias', $this->typeAlias); |
| 110 | + |
| 111 | + $db->setQuery($query); |
| 112 | + $typeId = $db->loadResult(); |
109 | 113 |
|
110 | 114 | // Insert the new tag maps |
111 | 115 | if (str_contains(implode(',', $tags), '#')) { |
@@ -325,10 +329,10 @@ public function deleteTagData(TableInterface $table, $contentItemId) |
325 | 329 |
|
326 | 330 | $result = $this->unTagItem($contentItemId[$key], $table); |
327 | 331 |
|
328 | | - /** @var CoreContent $ucmContentTable */ |
329 | | - $ucmContentTable = Table::getInstance('CoreContent'); |
| 332 | + /** @var CoreContent $coreContentTable */ |
| 333 | + $coreContentTable = Table::getInstance('CoreContent'); |
330 | 334 |
|
331 | | - return $result && $ucmContentTable->deleteByContentId($contentItemId[$key], $this->typeAlias); |
| 335 | + return $result && $coreContentTable->deleteByContentId($contentItemId[$key], $this->typeAlias); |
332 | 336 | } |
333 | 337 |
|
334 | 338 | /** |
@@ -845,18 +849,68 @@ public function postStoreProcess(TableInterface $table, $newTags = [], $replace |
845 | 849 | $result = $this->deleteTagData($table, $table->$key); |
846 | 850 | } else { |
847 | 851 | // Process the tags |
848 | | - $data = $this->getRowData($table); |
849 | | - $ucmContentTable = Table::getInstance('CoreContent'); |
850 | | - |
851 | | - $ucm = new UCMContent($table, $this->typeAlias); |
852 | | - $ucmData = $data ? $ucm->mapData($data) : $ucm->ucmData; |
853 | | - |
854 | | - $primaryId = $ucm->getPrimaryKey($ucmData['common']['core_type_id'], $ucmData['common']['core_content_item_id']); |
855 | | - $result = $ucmContentTable->load($primaryId); |
856 | | - $result = $result && $ucmContentTable->bind($ucmData['common']); |
857 | | - $result = $result && $ucmContentTable->check(); |
858 | | - $result = $result && $ucmContentTable->store(); |
859 | | - $ucmId = $ucmContentTable->core_content_id; |
| 852 | + $data = $this->getRowData($table); |
| 853 | + $coreContentTable = Table::getInstance('CoreContent'); |
| 854 | + $db = Factory::getDbo(); |
| 855 | + |
| 856 | + $query = $db->getQuery(true) |
| 857 | + ->select($db->quoteName('ct') . '.*') |
| 858 | + ->from($db->quoteName('#__content_types', 'ct')) |
| 859 | + ->where($db->quoteName('ct.type_alias') . ' = :alias') |
| 860 | + ->bind(':alias', $this->typeAlias); |
| 861 | + |
| 862 | + $db->setQuery($query); |
| 863 | + |
| 864 | + $contentType = $db->loadObject(); |
| 865 | + |
| 866 | + $fields = json_decode($contentType->field_mappings); |
| 867 | + |
| 868 | + $ucmData = []; |
| 869 | + |
| 870 | + $common = \is_object($fields->common) ? $fields->common : $fields->common[0]; |
| 871 | + |
| 872 | + foreach ($common as $i => $field) { |
| 873 | + if ($field && $field !== 'null' && \array_key_exists($field, $data)) { |
| 874 | + $ucmData['common'][$i] = $data[$field]; |
| 875 | + } |
| 876 | + } |
| 877 | + |
| 878 | + if (\array_key_exists('special', $ucmData)) { |
| 879 | + $special = \is_object($fields->special) ? $fields->special : $fields->special[0]; |
| 880 | + |
| 881 | + foreach ($special as $i => $field) { |
| 882 | + if ($field && $field !== 'null' && \array_key_exists($field, $data)) { |
| 883 | + $ucmData['special'][$i] = $data[$field]; |
| 884 | + } |
| 885 | + } |
| 886 | + } |
| 887 | + |
| 888 | + $ucmData['common']['core_type_alias'] = $contentType->type_alias; |
| 889 | + $ucmData['common']['core_type_id'] = $contentType->type_id; |
| 890 | + |
| 891 | + if (isset($ucmData['special'])) { |
| 892 | + $ucmData['special']['ucm_id'] = $ucmData['common']['ucm_id']; |
| 893 | + } |
| 894 | + |
| 895 | + $query = $db->getQuery(true) |
| 896 | + ->select($db->quoteName('ucm_id')) |
| 897 | + ->from($db->quoteName('#__ucm_base')) |
| 898 | + ->where( |
| 899 | + [ |
| 900 | + $db->quoteName('ucm_item_id') . ' = :itemId', |
| 901 | + $db->quoteName('ucm_type_id') . ' = :typeId', |
| 902 | + ] |
| 903 | + ) |
| 904 | + ->bind(':itemId', $ucmData['common']['core_content_item_id'], ParameterType::INTEGER) |
| 905 | + ->bind(':typeId', $ucmData['common']['core_type_id'], ParameterType::INTEGER); |
| 906 | + $db->setQuery($query); |
| 907 | + |
| 908 | + $primaryId = $db->loadResult(); |
| 909 | + $result = $coreContentTable->load($primaryId); |
| 910 | + $result = $result && $coreContentTable->bind($ucmData['common']); |
| 911 | + $result = $result && $coreContentTable->check(); |
| 912 | + $result = $result && $coreContentTable->store(); |
| 913 | + $ucmId = $coreContentTable->core_content_id; |
860 | 914 |
|
861 | 915 | // Store the tag data if the article data was saved and run related methods. |
862 | 916 | $result = $result && $this->tagItem($ucmId, $table, $newTags, $replace); |
|
0 commit comments