Skip to content

Commit 811ab3f

Browse files
anuragteapotlaoneo
authored andcommitted
[4.0][GSoC 2018] Improve Override Management (#21851)
* Load correct core files of override files (#2) Start implements loadcorefile() in administrator/components/com_templates/Model/TemplateModel.php * CS (#3) Coding Standards * codingstandards * codingstandards (#4) * Test (#6) Phase 2 (2 part) Mechanism to find correct core file and implementation. * Remove Notice: Only available for html-folder * Remove Warning if core file not found (#11) Thanks. So one part of the issue joomla-projects/gsoc18_override_management#12 is done. * Implement the diff view in template manager Implement the diff view in template manager * coding standard (#17) * fix diff (#18) Fix bug in path in case of administrator template override. Fix bug in path in case of administrator template override. * Notification after update and TEST (#16) Find changed files of overridden files and show message. * coding standard (#21) * correction * correction (#26) * Correcthtmlpath (#27) * correction * change oldhtml to newhtml * List of updated override files. (#30) * addcss (#34) * Final Product (#39) Core and Diff view Updated override history list. Quick icon notification plugin. Override control plugin. * save 3 lines :) * New feature show status. (#47) show status in com_template view templates * link * corrected namespace * Button to Switch (#35) * wip add Switcher * wip style switcher * wip style switch make inline and change on off text * wip start with js * wip js * wip delete buttons and make js more robust * wip save to storage * wip delete old code * wip * wip lint * wip css * set default value for switcher * wip make switcher blue * wip * wip * build * correct names * create new functions * fist test code * use onchange * undo installer.min.js * add forgotten new line at the end of css file * correct align * correct compare.es6 - only deleted the toggle part * correct compare.js - only deleted the toggle part * wip * reduce timeout * wrap in funcitons * wip * add use strict to both js-files(compare and toggle) * add the timeout value of 500 again, because 200 are not enought in my case * use css class 'active' for toggle views * add strict * time out for editor * wip * improvments use newActive and switch * correction * width of switcher-spans * correct align * do not use global * wip * removed timeouts * JTEXT to TEXT * forgotton last line * deleted duplicated comments * css fix align * use unnamed functions in es6 * Sql files for fix database (#50) * sql files for database fix * delete space * Suggestion for displaying Dates in view updates files (#52) Correct Dates and do not use date of file any more * Store Date as UTC and show it in server time zone (#57) * modified and created date are created and stored in UTC * convert dates for displaying in model * spar a loop * normalize timezone in view * use language constants for dateformat * JToolbarHelper to ToolbarHelper * CS * namespace * plural * name * clean * text * fx * sin * files * s * Suggestion for language strings (#60) * language strings * correct typo * delete media folder plg_quickicon * add folder plg_quickicon to build/media_src * delete files in media folder * Move media folder - System (#66) * multi * cs * delete files in media folder for joomla toolbar (#67) * Fix button switchers style. (#70) * button * CS * changed uitab.addTab for updated files * Bring back core.js changes. (#69) * core.js * const * fix * form * core * hound * CS * scopr * grid * alpha * cs * lang * only override file * lang * override lang installer * Cs * sub * Update list of core extensions (#71) * Language changes (#76) * update * Update en-GB.com_templates.ini * override JLIB_HTML_PUBLISH_ITEM this is the hover text on the publish icon in the list of files * Change icon (#74) change the icon to use an outline for more consistency * lang * not core (#75) * not core * Update en-GB.plg_installer_override.ini * namespace * cs * Updated files (#82) * Update default_updated_files.php * Update en-GB.com_templates.ini * Update en-GB.com_templates.ini (#81) * Update en-GB.plg_quickicon_overridecheck.ini (#80) * Update en-GB.plg_quickicon_overridecheck.ini (#79) * remove space (#78) * Update en-GB.plg_quickicon_overridecheck.ini * Update en-GB.plg_quickicon_overridecheck.sys.ini * remove hardcoded id * null get function * state * clean * More changes "core" to "original" (#85) * cs * update * plural
1 parent 169a8e1 commit 811ab3f

File tree

37 files changed

+2004
-91
lines changed

37 files changed

+2004
-91
lines changed

administrator/components/com_admin/sql/others/mysql/utf8mb4-conversion-02.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ ALTER TABLE `#__users` MODIFY `name` varchar(400) NOT NULL DEFAULT '';
4848
--
4949
-- Step 2.2: Convert all tables to utf8mb4 chracter set with utf8mb4_unicode_ci collation
5050
-- except #__finder_xxx tables, those will have utf8mb4_general_ci collation.
51-
-- Note: The database driver for mysql will change utf8mb4 to utf8 if utf8mb4 is not supported
51+
-- Note: The database driver for mysql will change utf8mb4 to utf8 if utf8mb4 is not supported
5252
--
5353

5454
ALTER TABLE `#__assets` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
@@ -108,6 +108,7 @@ ALTER TABLE `#__redirect_links` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4
108108
ALTER TABLE `#__schemas` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
109109
ALTER TABLE `#__session` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
110110
ALTER TABLE `#__tags` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
111+
ALTER TABLE `#__template_overrides` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
111112
ALTER TABLE `#__template_styles` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
112113
ALTER TABLE `#__ucm_base` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
113114
ALTER TABLE `#__ucm_content` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
@@ -200,6 +201,7 @@ ALTER TABLE `#__redirect_links` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_un
200201
ALTER TABLE `#__schemas` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
201202
ALTER TABLE `#__session` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
202203
ALTER TABLE `#__tags` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
204+
ALTER TABLE `#__template_overrides` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
203205
ALTER TABLE `#__template_styles` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
204206
ALTER TABLE `#__ucm_base` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
205207
ALTER TABLE `#__ucm_content` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
CREATE TABLE IF NOT EXISTS `#__template_overrides` (
2+
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
3+
`template` varchar(50) NOT NULL DEFAULT '',
4+
`hash_id` varchar(255) NOT NULL DEFAULT '',
5+
`extension_id` int(11) DEFAULT 0,
6+
`state` tinyint(1) NOT NULL DEFAULT 0,
7+
`action` varchar(50) NOT NULL DEFAULT '',
8+
`client_id` tinyint(1) unsigned NOT NULL DEFAULT 0,
9+
`created_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
10+
`modified_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
11+
PRIMARY KEY (`id`),
12+
KEY `idx_template` (`template`),
13+
KEY `idx_extension_id` (`extension_id`)
14+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;
15+
16+
INSERT INTO `#__extensions` (`extension_id`, `package_id`, `name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `manifest_cache`, `params`, `checked_out`, `checked_out_time`, `ordering`, `state`, `namespace`) VALUES
17+
(491, 0, 'plg_installer_override', 'plugin', 'override', 'installer', 0, 1, 1, 1, '', '', 0, '0000-00-00 00:00:00', 4, 0, ''),
18+
(492, 0, 'plg_quickicon_overridecheck', 'plugin', 'overridecheck', 'quickicon', 0, 1, 1, 1, '', '', 0, '0000-00-00 00:00:00', 0, 0, ''),
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
CREATE TABLE IF NOT EXISTS "#__template_overrides" (
2+
"id" serial NOT NULL,
3+
"template" varchar(50) DEFAULT '' NOT NULL,
4+
"hash_id" varchar(255) DEFAULT '' NOT NULL,
5+
"extension_id" bigint DEFAULT 0,
6+
"state" smallint DEFAULT 0 NOT NULL,
7+
"action" varchar(50) DEFAULT '' NOT NULL,
8+
"client_id" smallint DEFAULT 0 NOT NULL,
9+
"created_date" timestamp without time zone DEFAULT '1970-01-01 00:00:00' NOT NULL,
10+
"modified_date" timestamp without time zone DEFAULT '1970-01-01 00:00:00' NOT NULL,
11+
PRIMARY KEY ("id")
12+
);
13+
CREATE INDEX "#__template_overrides_idx_template" ON "#__template_overrides" ("template");
14+
CREATE INDEX "#__template_overrides_idx_extension_id" ON "#__template_overrides" ("extension_id");
15+
16+
INSERT INTO "#__extensions" ("extension_id", "package_id", "name", "type", "element", "folder", "client_id", "enabled", "access", "protected", "manifest_cache", "params", "checked_out", "checked_out_time", "ordering", "state", "namespace") VALUES
17+
(491, 0, 'plg_installer_override', 'plugin', 'override', 'installer', 0, 1, 1, 1, '', '', 0, '1970-01-01 00:00:00', 4, 0, ''),
18+
(492, 0, 'plg_quickicon_overridecheck', 'plugin', 'overridecheck', 'quickicon', 0, 1, 1, 1, '', '', 0, '1970-01-01 00:00:00', 0, 0, '');

administrator/components/com_installer/Model/UpdateModel.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,9 @@ public function update($uids, $minimum_stability = Updater::STABILITY_STABLE)
404404
*/
405405
private function install($update)
406406
{
407+
// Load overrides plugin.
408+
PluginHelper::importPlugin('installer');
409+
407410
$app = Factory::getApplication();
408411

409412
if (!isset($update->get('downloadurl')->_data))

administrator/components/com_joomlaupdate/Model/UpdateModel.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Joomla\CMS\Log\Log;
2828
use Joomla\CMS\Http\HttpFactory;
2929
use Joomla\CMS\Installer\Installer;
30+
use Joomla\CMS\Plugin\PluginHelper;
3031

3132
/**
3233
* Joomla! update overview Model
@@ -389,7 +390,8 @@ protected function downloadPackage($url, $target)
389390
}
390391

391392
/**
392-
* Create restoration file.
393+
* Create restoration file and trigger onJoomlaBeforeUpdate event, which find the updated core files
394+
* which have changed during the update, where there are override for.
393395
*
394396
* @param string $basename Optional base path to the file.
395397
*
@@ -399,11 +401,17 @@ protected function downloadPackage($url, $target)
399401
*/
400402
public function createRestorationFile($basename = null)
401403
{
404+
// Load overrides plugin.
405+
PluginHelper::importPlugin('installer');
406+
402407
// Get a password
403408
$password = UserHelper::genRandomPassword(32);
404409
$app = Factory::getApplication();
405410
$app->setUserState('com_joomlaupdate.password', $password);
406411

412+
// Trigger event before joomla update.
413+
$app->triggerEvent('onJoomlaBeforeUpdate');
414+
407415
// Do we have to use FTP?
408416
$method = Factory::getApplication()->getUserStateFromRequest('com_joomlaupdate.method', 'method', 'direct', 'cmd');
409417

@@ -826,19 +834,28 @@ public function finaliseUpgrade()
826834
}
827835

828836
/**
829-
* Removes the extracted package file.
837+
* Removes the extracted package file and trigger onJoomlaAfterUpdate event, which find the updated core files
838+
* which have changed during the update, where there are override for.
830839
*
831840
* @return void
832841
*
833842
* @since 2.5.4
834843
*/
835844
public function cleanUp()
836845
{
846+
// Load overrides plugin.
847+
PluginHelper::importPlugin('installer');
848+
849+
$app = Factory::getApplication();
850+
851+
// Trigger event after joomla update.
852+
$app->triggerEvent('onJoomlaAfterUpdate');
853+
837854
// Remove the update package.
838855
$config = Factory::getConfig();
839856
$tempdir = $config->get('tmp_path');
840857

841-
$file = Factory::getApplication()->getUserState('com_joomlaupdate.file', null);
858+
$file = $app->getUserState('com_joomlaupdate.file', null);
842859
$target = $tempdir . '/' . $file;
843860

844861
if (!@unlink($target))

administrator/components/com_templates/Controller/TemplateController.php

Lines changed: 106 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@
1111

1212
defined('_JEXEC') or die;
1313

14+
use Joomla\CMS\Client\ClientHelper;
15+
use Joomla\CMS\Factory;
16+
use Joomla\CMS\Language\Text;
1417
use Joomla\CMS\MVC\Controller\BaseController;
1518
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
16-
use Joomla\Component\Installer\Administrator\Model\InstallModel;
17-
use Joomla\CMS\Language\Text;
19+
use Joomla\CMS\Plugin\PluginHelper;
1820
use Joomla\CMS\Router\Route;
1921
use Joomla\CMS\Session\Session;
20-
use Joomla\CMS\Client\ClientHelper;
21-
use Joomla\CMS\Factory;
22+
use Joomla\Component\Installer\Administrator\Model\InstallModel;
23+
use Joomla\Utilities\ArrayHelper;
2224

2325
/**
2426
* Template style controller class.
@@ -44,6 +46,9 @@ public function __construct($config = array(), MVCFactoryInterface $factory = nu
4446

4547
// Apply, Save & New, and Save As copy should be standard on forms.
4648
$this->registerTask('apply', 'save');
49+
$this->registerTask('unpublish', 'publish');
50+
$this->registerTask('publish', 'publish');
51+
$this->registerTask('deleteOverrideHistory', 'publish');
4752
}
4853

4954
/**
@@ -74,6 +79,64 @@ public function close()
7479
$this->setRedirect(Route::_($url, false));
7580
}
7681

82+
/**
83+
* Marked as Checked/Unchecked of override history.
84+
*
85+
* @return void
86+
*
87+
* @since __DEPLOY_VERSION__
88+
*/
89+
public function publish()
90+
{
91+
// Check for request forgeries.
92+
Session::checkToken() or jexit(Text::_('JINVALID_TOKEN'));
93+
94+
$app = Factory::getApplication();
95+
$file = $this->input->get('file');
96+
$id = $this->input->get('id');
97+
98+
$ids = $this->input->get('cid', array(), 'array');
99+
$values = array('publish' => 1, 'unpublish' => 0, 'deleteOverrideHistory' => -3);
100+
$task = $this->getTask();
101+
$value = ArrayHelper::getValue($values, $task, 0, 'int');
102+
103+
if (empty($ids))
104+
{
105+
$this->setMessage(Text::_('COM_TEMPLATES_ERROR_NO_FILE_SELECTED'), 'warning');
106+
}
107+
else
108+
{
109+
/* @var \Joomla\Component\Templates\Administrator\Model\TemplateModel $model */
110+
$model = $this->getModel();
111+
112+
// Change the state of the records.
113+
if (!$model->publish($ids, $value, $id))
114+
{
115+
$this->setMessage(implode('<br>', $model->getErrors()), 'warning');
116+
}
117+
else
118+
{
119+
if ($value === 1)
120+
{
121+
$ntext = 'COM_TEMPLATES_N_OVERRIDE_CHECKED';
122+
}
123+
elseif ($value === 0)
124+
{
125+
$ntext = 'COM_TEMPLATES_N_OVERRIDE_UNCHECKED';
126+
}
127+
elseif ($value === -3)
128+
{
129+
$ntext = 'COM_TEMPLATES_N_OVERRIDE_DELETED';
130+
}
131+
132+
$this->setMessage(Text::plural($ntext, count($ids)));
133+
}
134+
}
135+
136+
$url = 'index.php?option=com_templates&view=template&id=' . $id . '&file=' . $file;
137+
$this->setRedirect(Route::_($url, false));
138+
}
139+
77140
/**
78141
* Method for copying the template.
79142
*
@@ -738,4 +801,43 @@ public function extractArchive()
738801
$this->setRedirect(Route::_($url, false));
739802
}
740803
}
804+
805+
/**
806+
* Fetch and report updates in \JSON format, for AJAX requests
807+
*
808+
* @return void
809+
*
810+
* @since __DEPLOY_VERSION__
811+
*/
812+
public function ajax()
813+
{
814+
$app = $this->app;
815+
816+
if (!Session::checkToken('get'))
817+
{
818+
$app->setHeader('status', 403, true);
819+
$app->sendHeaders();
820+
echo Text::_('JINVALID_TOKEN');
821+
$app->close();
822+
}
823+
824+
// Checks status of installer override plugin.
825+
if (!PluginHelper::isEnabled('installer', 'override'))
826+
{
827+
$error = array('installerOverride' => 'disabled');
828+
829+
echo json_encode($error);
830+
831+
$app->close();
832+
}
833+
834+
/* @var \Joomla\Component\Templates\Administrator\Model\TemplateModel $model */
835+
$model = $this->getModel();
836+
837+
$result = $model->getUpdatedList(true, true);
838+
839+
echo json_encode($result);
840+
841+
$app->close();
842+
}
741843
}

0 commit comments

Comments
 (0)