Skip to content

Commit

Permalink
[5.0] tinyMCE b/c fixes (#40626)
Browse files Browse the repository at this point in the history
Co-authored-by: Richard Fath <richard67@users.noreply.github.com>
Co-authored-by: Brian Teeman <brian@teeman.net>
  • Loading branch information
3 people committed May 29, 2023
1 parent cf6c2ce commit 25ef885
Show file tree
Hide file tree
Showing 13 changed files with 738 additions and 82 deletions.
97 changes: 97 additions & 0 deletions administrator/components/com_admin/script.php
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,103 @@ public function postflight($action, $installer)
}

// Add here code which shall be executed only when updating from an older version than 5.0.0
if (!$this->migrateTinymceConfiguration()) {
return false;
}

return true;
}

/**
* Migrate TinyMCE editor plugin configuration
*
* @return boolean True on success
*
* @since __DEPLOY_VERSION__
*/
private function migrateTinymceConfiguration(): bool
{
$db = Factory::getDbo();

try {
// Get the TinyMCE editor plugin's parameters
$params = $db->setQuery(
$db->getQuery(true)
->select($db->quoteName('params'))
->from($db->quoteName('#__extensions'))
->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
->where($db->quoteName('folder') . ' = ' . $db->quote('editors'))
->where($db->quoteName('element') . ' = ' . $db->quote('tinymce'))
)->loadResult();
} catch (Exception $e) {
echo Text::sprintf('JLIB_DATABASE_ERROR_FUNCTION_FAILED', $e->getCode(), $e->getMessage()) . '<br>';

return false;
}

$params = json_decode($params, true);

// If there are no toolbars there is nothing to migrate
if (!isset($params['configuration']['toolbars'])) {
return true;
}

// Each set has its own toolbar configuration
foreach ($params['configuration']['toolbars'] as $setIdx => $toolbarConfig) {
// Migrate menu items if there is a menu
if (isset($toolbarConfig['menu'])) {
/**
* Replace array values with menu item names ("old name" -> "new name"):
* "blockformats" -> "blocks"
* "fontformats" -> "fontfamily"
* "fontsizes" -> "fontsize"
* "formats" -> "styles"
* "template" -> "jtemplate"
*/
$params['configuration']['toolbars'][$setIdx]['menu'] = str_replace(
['blockformats', 'fontformats', 'fontsizes', 'formats', 'template'],
['blocks', 'fontfamily', 'fontsize', 'styles', 'jtemplate'],
$toolbarConfig['menu']
);
}

// There could be no toolbar at all, or only toolbar1, or both toolbar1 and toolbar2
foreach (['toolbar1', 'toolbar2'] as $toolbarIdx) {
// Migrate toolbar buttons if that toolbar exists
if (isset($toolbarConfig[$toolbarIdx])) {
/**
* Replace array values with button names ("old name" -> "new name"):
* "fontselect" -> "fontfamily"
* "fontsizeselect" -> "fontsize"
* "formatselect" -> "blocks"
* "styleselect" -> "styles"
* "template" -> "jtemplate"
*/
$params['configuration']['toolbars'][$setIdx][$toolbarIdx] = str_replace(
['fontselect', 'fontsizeselect', 'formatselect', 'styleselect', 'template'],
['fontfamily', 'fontsize', 'blocks', 'styles', 'jtemplate'],
$toolbarConfig[$toolbarIdx]
);
}
}
}

$params = json_encode($params);

$query = $db->getQuery(true)
->update($db->quoteName('#__extensions'))
->set($db->quoteName('params') . ' = ' . $db->quote($params))
->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
->where($db->quoteName('folder') . ' = ' . $db->quote('editors'))
->where($db->quoteName('element') . ' = ' . $db->quote('tinymce'));

try {
$db->setQuery($query)->execute();
} catch (Exception $e) {
echo Text::sprintf('JLIB_DATABASE_ERROR_FUNCTION_FAILED', $e->getCode(), $e->getMessage()) . '<br>';

return false;
}

return true;
}
Expand Down
6 changes: 5 additions & 1 deletion build/build-modules-js/init/exemptions/tinymce.es6.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const {
existsSync, copy, readFile, writeFile, mkdir,
existsSync, copy, readFile, writeFile, mkdir, removeSync,
} = require('fs-extra');
const CssNano = require('cssnano');
const Postcss = require('postcss');
Expand Down Expand Up @@ -94,4 +94,8 @@ module.exports.tinyMCE = async (packageName, version) => {

// Restore our code on the vendor folders
await copy(join(RootPath, 'build/media_source/vendor/tinymce/templates'), join(RootPath, 'media/vendor/tinymce/templates'), { preserveTimestamps: true });
// Drop the template plugin
if (existsSync(join(RootPath, 'media/vendor/tinymce/plugins/template'))) {
removeSync(join(RootPath, 'media/vendor/tinymce/plugins/template'));
}
};
Loading

0 comments on commit 25ef885

Please sign in to comment.