Skip to content

Commit ba91f96

Browse files
authored
[5.4] Deprecating UCM code (#44910)
The UCM system was added in Joomla 3.2.0 and already at that time had major flaws. In 12 years of development, it hasn't been extended in any way and instead we've rather reduced it instead. (The content versioning was a part of it and has been made standalone in 4.0.) I think it can be said that the concept (which barely exists to start with) has failed and we should remove the remnants of it. This PR deprecates all UCM classes that I could find. It also removes the code where we are using the UCM classes in a functional way. For the moment it keeps it, where it might be used by third party code to keep it backwards compatible. This means that we keep this code in the batch methods, where $this->contentType and $this->type is set with this code, even though neither of the two attributes are used anywhere. We could remove this in 6.0 and drop everything in 7.0 finally.
1 parent 35bf0b4 commit ba91f96

File tree

9 files changed

+126
-49
lines changed

9 files changed

+126
-49
lines changed

libraries/src/Form/Field/OrderingField.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
use Joomla\CMS\Form\FormField;
1313
use Joomla\CMS\HTML\HTMLHelper;
14-
use Joomla\CMS\UCM\UCMType;
1514
use Joomla\Database\ParameterType;
1615
use Joomla\Database\QueryInterface;
1716

@@ -152,9 +151,16 @@ protected function getInput()
152151
*/
153152
protected function getQuery()
154153
{
155-
$categoryId = (int) $this->form->getValue('catid');
156-
$ucmType = new UCMType();
157-
$ucmRow = $ucmType->getType($ucmType->getTypeId($this->contentType));
154+
$categoryId = (int) $this->form->getValue('catid');
155+
$db = $this->getDatabase();
156+
$query = $db->getQuery(true)
157+
->select($db->quoteName('ct') . '.*')
158+
->from($db->quoteName('#__content_types', 'ct'))
159+
->where($db->quoteName('ct.type_alias') . ' = :alias')
160+
->bind(':alias', $this->contentType);
161+
162+
$db->setQuery($query);
163+
$ucmRow = $db->loadObject();
158164
$ucmMapCommon = json_decode($ucmRow->field_mappings)->common;
159165

160166
if (\is_object($ucmMapCommon)) {
@@ -165,7 +171,6 @@ protected function getQuery()
165171
$title = $ucmMapCommon[0]->core_title;
166172
}
167173

168-
$db = $this->getDatabase();
169174
$query = $db->getQuery(true);
170175
$query->select([$db->quoteName($ordering, 'value'), $db->quoteName($title, 'text')])
171176
->from($db->quoteName(json_decode($ucmRow->table)->special->dbtable))

libraries/src/Helper/TagsHelper.php

Lines changed: 73 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
use Joomla\CMS\Table\CoreContent;
1515
use Joomla\CMS\Table\Table;
1616
use Joomla\CMS\Table\TableInterface;
17-
use Joomla\CMS\UCM\UCMContent;
18-
use Joomla\CMS\UCM\UCMType;
1917
use Joomla\Database\DatabaseInterface;
2018
use Joomla\Database\ParameterType;
2119
use Joomla\Utilities\ArrayHelper;
@@ -104,8 +102,14 @@ public function addTagMapping($ucmId, TableInterface $table, $tags = [])
104102
$db = $table->getDbo();
105103
$key = $table->getKeyName();
106104
$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();
109113

110114
// Insert the new tag maps
111115
if (str_contains(implode(',', $tags), '#')) {
@@ -325,10 +329,10 @@ public function deleteTagData(TableInterface $table, $contentItemId)
325329

326330
$result = $this->unTagItem($contentItemId[$key], $table);
327331

328-
/** @var CoreContent $ucmContentTable */
329-
$ucmContentTable = Table::getInstance('CoreContent');
332+
/** @var CoreContent $coreContentTable */
333+
$coreContentTable = Table::getInstance('CoreContent');
330334

331-
return $result && $ucmContentTable->deleteByContentId($contentItemId[$key], $this->typeAlias);
335+
return $result && $coreContentTable->deleteByContentId($contentItemId[$key], $this->typeAlias);
332336
}
333337

334338
/**
@@ -845,18 +849,68 @@ public function postStoreProcess(TableInterface $table, $newTags = [], $replace
845849
$result = $this->deleteTagData($table, $table->$key);
846850
} else {
847851
// 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;
860914

861915
// Store the tag data if the article data was saved and run related methods.
862916
$result = $result && $this->tagItem($ucmId, $table, $newTags, $replace);

libraries/src/MVC/View/CategoryFeedView.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Joomla\CMS\Helper\RouteHelper;
1515
use Joomla\CMS\Language\Text;
1616
use Joomla\CMS\Router\Route;
17-
use Joomla\CMS\UCM\UCMType;
1817

1918
// phpcs:disable PSR1.Files.SideEffects
2019
\defined('_JEXEC') or die;
@@ -45,8 +44,15 @@ public function display($tpl = null)
4544
$extension = $app->getInput()->getString('option');
4645
$contentType = $extension . '.' . $this->viewName;
4746

48-
$ucmType = new UCMType();
49-
$ucmRow = $ucmType->getTypeByAlias($contentType);
47+
$db = Factory::getDbo();
48+
$query = $db->getQuery(true)
49+
->select($db->quoteName('ct') . '.*')
50+
->from($db->quoteName('#__content_types', 'ct'))
51+
->where($db->quoteName('ct.type_alias') . ' = :alias')
52+
->bind(':alias', $contentType);
53+
54+
$db->setQuery($query);
55+
$ucmRow = $db->loadObject();
5056
$ucmMapCommon = json_decode($ucmRow->field_mappings)->common;
5157
$createdField = null;
5258
$titleField = null;

libraries/src/Table/CoreContent.php

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -154,23 +154,6 @@ public function check()
154154
return true;
155155
}
156156

157-
/**
158-
* Override \Joomla\CMS\Table\Table delete method to include deleting corresponding row from #__ucm_base.
159-
*
160-
* @param integer $pk primary key value to delete. Must be set or throws an exception.
161-
*
162-
* @return boolean True on success.
163-
*
164-
* @since 3.1
165-
* @throws \UnexpectedValueException
166-
*/
167-
public function delete($pk = null)
168-
{
169-
$baseTable = new Ucm($this->getDatabase(), $this->getDispatcher());
170-
171-
return parent::delete($pk) && $baseTable->delete($pk);
172-
}
173-
174157
/**
175158
* Method to delete a row from the #__ucm_content table by content_item_id.
176159
*
@@ -179,8 +162,8 @@ public function delete($pk = null)
179162
*
180163
* @return boolean True on success.
181164
*
182-
* @since 3.1
183165
* @throws \UnexpectedValueException
166+
* @since 3.1
184167
*/
185168
public function deleteByContentId($contentItemId = null, $typeAlias = null)
186169
{
@@ -263,9 +246,7 @@ public function store($updateNulls = true)
263246
$this->setRules('{}');
264247
}
265248

266-
$result = parent::store($updateNulls);
267-
268-
return $result && $this->storeUcmBase($updateNulls, $isNew);
249+
return parent::store($updateNulls);
269250
}
270251

271252
/**
@@ -277,6 +258,7 @@ public function store($updateNulls = true)
277258
* @return boolean True on success.
278259
*
279260
* @since 3.1
261+
* @deprecated __DEPLOY_VERSION__ will be removed in 7.0 without replacement
280262
*/
281263
protected function storeUcmBase($updateNulls = true, $isNew = false)
282264
{

libraries/src/Table/Ucm.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* UCM map table
2121
*
2222
* @since 3.1
23+
* @deprecated __DEPLOY_VERSION__ will be removed in 7.0 without replacement
2324
*/
2425
class Ucm extends Table
2526
{
@@ -30,6 +31,7 @@ class Ucm extends Table
3031
* @param ?DispatcherInterface $dispatcher Event dispatcher for this table
3132
*
3233
* @since 3.1
34+
* @deprecated __DEPLOY_VERSION__ will be removed in 7.0 without replacement
3335
*/
3436
public function __construct(DatabaseInterface $db, ?DispatcherInterface $dispatcher = null)
3537
{

libraries/src/UCM/UCM.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* Interface to handle UCM
1818
*
1919
* @since 3.1
20+
* @deprecated __DEPLOY_VERSION__ will be removed in 7.0 without replacement
2021
*/
2122
interface UCM
2223
{

libraries/src/UCM/UCMBase.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* Base class for implementing UCM
2323
*
2424
* @since 3.1
25+
* @deprecated __DEPLOY_VERSION__ will be removed in 7.0 without replacement
2526
*/
2627
class UCMBase implements UCM
2728
{
@@ -30,6 +31,7 @@ class UCMBase implements UCM
3031
*
3132
* @var UCMType
3233
* @since 3.1
34+
* @deprecated __DEPLOY_VERSION__ will be removed in 7.0 without replacement
3335
*/
3436
protected $type;
3537

@@ -38,6 +40,7 @@ class UCMBase implements UCM
3840
*
3941
* @var string
4042
* @since 3.1
43+
* @deprecated __DEPLOY_VERSION__ will be removed in 7.0 without replacement
4144
*/
4245
protected $alias;
4346

@@ -48,6 +51,7 @@ class UCMBase implements UCM
4851
* @param ?UCMType $type The type object
4952
*
5053
* @since 3.1
54+
* @deprecated __DEPLOY_VERSION__ will be removed in 7.0 without replacement
5155
*/
5256
public function __construct($alias = null, ?UCMType $type = null)
5357
{
@@ -67,8 +71,9 @@ public function __construct($alias = null, ?UCMType $type = null)
6771
*
6872
* @return boolean True on success
6973
*
70-
* @since 3.1
7174
* @throws \Exception
75+
* @since 3.1
76+
* @deprecated __DEPLOY_VERSION__ will be removed in 7.0 without replacement
7277
*/
7378
protected function store($data, ?TableInterface $table = null, $primaryKey = null)
7479
{
@@ -104,6 +109,7 @@ protected function store($data, ?TableInterface $table = null, $primaryKey = nul
104109
* @return UCMType The UCM content type
105110
*
106111
* @since 3.1
112+
* @deprecated __DEPLOY_VERSION__ will be removed in 7.0 without replacement
107113
*/
108114
public function getType()
109115
{
@@ -123,6 +129,7 @@ public function getType()
123129
* @return array Data array of UCM mappings
124130
*
125131
* @since 3.1
132+
* @deprecated __DEPLOY_VERSION__ will be removed in 7.0 without replacement
126133
*/
127134
public function mapBase($original, ?UCMType $type = null)
128135
{

libraries/src/UCM/UCMContent.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* Base class for implementing UCM
2424
*
2525
* @since 3.1
26+
* @deprecated __DEPLOY_VERSION__ will be removed in 7.0 without replacement
2627
*/
2728
class UCMContent extends UCMBase
2829
{
@@ -31,6 +32,7 @@ class UCMContent extends UCMBase
3132
*
3233
* @var Table
3334
* @since 3.1
35+
* @deprecated __DEPLOY_VERSION__ will be removed in 7.0 without replacement
3436
*/
3537
protected $table;
3638

@@ -39,6 +41,7 @@ class UCMContent extends UCMBase
3941
*
4042
* @var array[]
4143
* @since 3.1
44+
* @deprecated __DEPLOY_VERSION__ will be removed in 7.0 without replacement
4245
*/
4346
public $ucmData;
4447

@@ -50,6 +53,7 @@ class UCMContent extends UCMBase
5053
* @param ?UCMType $type The type object
5154
*
5255
* @since 3.1
56+
* @deprecated __DEPLOY_VERSION__ will be removed in 7.0 without replacement
5357
*/
5458
public function __construct(?TableInterface $table = null, $alias = null, ?UCMType $type = null)
5559
{
@@ -72,6 +76,7 @@ public function __construct(?TableInterface $table = null, $alias = null, ?UCMTy
7276
* @return boolean true
7377
*
7478
* @since 3.1
79+
* @deprecated __DEPLOY_VERSION__ will be removed in 7.0 without replacement
7580
*/
7681
public function save($original = null, ?UCMType $type = null)
7782
{
@@ -99,6 +104,7 @@ public function save($original = null, ?UCMType $type = null)
99104
* @return boolean True if success
100105
*
101106
* @since 3.1
107+
* @deprecated __DEPLOY_VERSION__ will be removed in 7.0 without replacement
102108
*/
103109
public function delete($pk, ?UCMType $type = null)
104110
{
@@ -130,6 +136,7 @@ public function delete($pk, ?UCMType $type = null)
130136
* @return array[] $ucmData The mapped UCM data
131137
*
132138
* @since 3.1
139+
* @deprecated __DEPLOY_VERSION__ will be removed in 7.0 without replacement
133140
*/
134141
public function mapData($original, ?UCMType $type = null)
135142
{
@@ -179,6 +186,7 @@ public function mapData($original, ?UCMType $type = null)
179186
* @return boolean true on success
180187
*
181188
* @since 3.1
189+
* @deprecated __DEPLOY_VERSION__ will be removed in 7.0 without replacement
182190
*/
183191
protected function store($data, ?TableInterface $table = null, $primaryKey = null)
184192
{
@@ -211,6 +219,7 @@ protected function store($data, ?TableInterface $table = null, $primaryKey = nul
211219
* @return integer The integer of the primary key
212220
*
213221
* @since 3.1
222+
* @deprecated __DEPLOY_VERSION__ will be removed in 7.0 without replacement
214223
*/
215224
public function getPrimaryKey($typeId, $contentItemId)
216225
{

0 commit comments

Comments
 (0)