Skip to content
Closed
Changes from all 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
67 changes: 67 additions & 0 deletions administrator/components/com_admin/script.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function update($installer)
$this->clearRadCache();
$this->updateAssets();
$this->clearStatsCache();
$this->updateTemplateSourceFormats();
$this->convertTablesToUtf8mb4(true);
$this->cleanJoomlaCache();

Expand Down Expand Up @@ -1933,4 +1934,70 @@ private function cleanJoomlaCache()
$model->setState('client_id', 1);
$model->clean();
}

/**
* Method to update template source formats on Joomla Update
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
protected function updateTemplateSourceFormats()
{
$db = JFactory::getDbo();

try
{
// Get the params for the templates component
$params = $db->setQuery(
$db->getQuery(true)
->select($db->quoteName('params'))
->from($db->quoteName('#__extensions'))
->where($db->quoteName('name') . ' = ' . $db->quote('com_templates'))
->where($db->quoteName('type') . ' = ' . $db->quote('component'))
->where($db->quoteName('element') . ' = ' . $db->quote('com_templates'))
)->loadResult();
}
catch (JDatabaseExceptionExecuting $e)
{
echo JText::sprintf('JLIB_DATABASE_ERROR_FUNCTION_FAILED', $e->getCode(), $e->getMessage()) . '<br />';

return;
}

$params = json_decode($params, true);
$sourceformats = explode(',', $params['source_formats']);
Copy link
Contributor

@andrepereiradasilva andrepereiradasilva Nov 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you probably could replace all above code by just:

$sourceFormats = explode(',', JComponentHelper::getParams('com_templates')->get('source_formats', 'txt,less,ini,xml,js,php,css,scss,sass'));

not sure how explode will react if the is no , in source_formats param value tough


// Check if new source format are already there
if (!in_array('scss', $sourceformats))
{
$sourceformats[] = 'scss';
}

if (!in_array('sass', $sourceformats))
{
$sourceformats[] = 'sass';
}

$params['source_formats'] = implode(',', $sourceformats);
$params = json_encode($params);

$query = $db->getQuery(true)
->update($db->quoteName('#__extensions'))
->set($db->quoteName('params') . ' = ' . $db->quote($params))
->where($db->quoteName('name') . ' = ' . $db->quote('com_templates'))
->where($db->quoteName('type') . ' = ' . $db->quote('component'))
->where($db->quoteName('element') . ' = ' . $db->quote('com_templates'));

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

return;
}
}
}