Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions administrator/components/com_admin/script.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Joomla\CMS\Language\Text;
use Joomla\CMS\Log\Log;
use Joomla\CMS\Table\Table;
use Joomla\Database\ParameterType;
use Joomla\Database\UTF8MB4SupportInterface;

/**
Expand Down Expand Up @@ -6202,6 +6203,9 @@ public function postflight($action, $installer)
}
}

// Update UCM content types.
$this->updateContentTypes();

return true;
}

Expand Down Expand Up @@ -6474,4 +6478,69 @@ private function finderItems(Table $tableItem): array

return $menuItems;
}

/**
* Updates content type table classes.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
private function updateContentTypes(): void
{
// Content types to update.
$contentTypes = [
'com_contact.contact',
'com_newsfeeds.newsfeed',
'com_tags.tag',
'com_banners.banner',
'com_banners.client',
'com_users.note',
];

// Get table definitions.
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select(
[
$db->quoteName('type_alias'),
$db->quoteName('table'),
]
)
->from($db->quoteName('#__content_types'))
->whereIn($db->quoteName('type_alias'), $contentTypes, ParameterType::STRING);

$db->setQuery($query);
$contentTypes = $db->loadObjectList();

// Prepare the update query.
$query = $db->getQuery(true)
->update($db->quoteName('#__content_types'))
->set($db->quoteName('table') . ' = :table')
->where($db->quoteName('type_alias') . ' = :typeAlias')
->bind(':table', $table)
->bind(':typeAlias', $typeAlias);

$db->setQuery($query);

foreach ($contentTypes as $contentType)
{
list($component, $tableType) = explode('.', $contentType->type_alias);

$tablePrefix = 'Joomla\\Component\\' . ucfirst(substr($component, 4)) . '\\Administrator\\Table\\';
$tableType = ucfirst($tableType) . 'Table';

// Bind type alias.
$typeAlias = $contentType->type_alias;

// Update table definition.
$table = json_decode($contentType->table);
$table->special->type = $tableType;
$table->special->prefix = $tablePrefix;
$table = json_encode($table);

// Execute the query.
$db->execute();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `#__content_types` MODIFY `table` varchar(2048) NOT NULL DEFAULT '';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "#__content_types" ALTER COLUMN "table" TYPE character varying(2048);
Loading