script.install.php
3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
/**
* @package Better Preview
* @version 6.1.0
*
* @author Peter van Westen <info@regularlabs.com>
* @link http://www.regularlabs.com
* @copyright Copyright © 2018 Regular Labs All Rights Reserved
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
*/
defined('_JEXEC') or die;
require_once __DIR__ . '/script.install.helper.php';
class PlgSystemBetterPreviewInstallerScript extends PlgSystemBetterPreviewInstallerScriptHelper
{
public $name = 'BETTER_PREVIEW';
public $alias = 'betterpreview';
public $extension_type = 'plugin';
public function uninstall($adapter)
{
$this->uninstallPlugin($this->extname, 'editors-xtd');
}
public function onAfterInstall($route)
{
$this->createTable();
$this->convertOldSettings();
$this->fixSystemPluginOrdering();
JFactory::getCache()->clean('_system');
$this->deleteOldModule();
}
public function createTable()
{
$query = "CREATE TABLE IF NOT EXISTS `#__betterpreview_sefs` (
`url` char(255) NOT NULL,
`sef` char(255) NOT NULL,
`created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
KEY (`url`(50))
) DEFAULT CHARSET=utf8;";
$this->db->setQuery($query);
$this->db->execute();
$query = 'SHOW INDEX FROM ' . $this->db->quoteName('#__betterpreview_sefs');
$this->db->setQuery($query);
$index = $this->db->loadObject();
if ( ! empty($index->Key_name) && $index->Key_name == 'PRIMARY')
{
$query = 'ALTER TABLE ' . $this->db->quoteName('#__betterpreview_sefs')
. ' DROP INDEX ' . $this->db->quoteName($index->Key_name) . ','
. ' ADD INDEX ' . $this->db->quoteName('url') . ' (' . $this->db->quoteName('url') . '(50));';
$this->db->setQuery($query);
$this->db->execute();
}
// delete all cached sef urls
$this->db->truncateTable('#__betterpreview_sefs');
}
public function fixSystemPluginOrdering()
{
// force system plugin ordering
$query = $this->db->getQuery(true)
->update('#__extensions')
->set($this->db->quoteName('ordering') . ' = -1')
->where($this->db->quoteName('element') . ' = ' . $this->db->quote('betterpreview'))
->where($this->db->quoteName('folder') . ' = ' . $this->db->quote('system'));
$this->db->setQuery($query);
$this->db->execute();
}
public function convertOldSettings()
{
$query = $this->db->getQuery(true)
->select('params')
->from('#__extensions')
->where($this->db->quoteName('element') . ' = ' . $this->db->quote('betterpreview'))
->where($this->db->quoteName('folder') . ' = ' . $this->db->quote('system'));
$this->db->setQuery($query);
$params = $this->db->loadResult();
if (strpos($params, 'default_menu_id') !== false)
{
return;
}
$params = str_replace('"use_home_menu_id":"0"', '"default_menu_id":"-1"', $params);
$query = $this->db->getQuery(true)
->update('#__extensions')
->set($this->db->quoteName('params') . ' = ' . $this->db->quote($params))
->where($this->db->quoteName('element') . ' = ' . $this->db->quote('betterpreview'))
->where($this->db->quoteName('folder') . ' = ' . $this->db->quote('system'));
$this->db->setQuery($query);
$this->db->execute();
}
public function deleteOldModule()
{
// delete old module
$query = $this->db->getQuery(true)
->delete('#__extensions')
->where($this->db->quoteName('element') . ' = ' . $this->db->quote('mod_betterpreview'));
$this->db->setQuery($query);
$this->db->execute();
$query->clear()
->delete('#__modules')
->where($this->db->quoteName('module') . ' = ' . $this->db->quote('mod_betterpreview'));
$this->db->setQuery($query);
$this->db->execute();
$folder = JPATH_ADMINISTRATOR . '/modules/mod_betterpreview';
if (JFolder::exists($folder))
{
JFolder::delete($folder);
}
JFactory::getCache()->clean('_system');
}
}