-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswitcheditor.install.php
119 lines (116 loc) · 3.91 KB
/
switcheditor.install.php
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
<?php
/**
* @package Switch Editor
* @copyright Copyright (C) 2023 ConseilGouz. All rights reserved.
* From anything-digital.com Switch Editor
* @license GNU/GPLv2
*/
// no direct access
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\Filesystem\File;
use Joomla\Filesystem\Folder;
use Joomla\CMS\Version;
class pkg_SwitchEditorInstallerScript
{
protected $db;
public function __construct()
{
$this->db = Factory::getDbo();
}
public function postflight($type, $parent)
{
if ('uninstall' == $type)
{
return;
}
$j = new Version();
$version=substr($j->getShortVersion(), 0,1);
// remove obsolete files
if ($version >= "4") { // Joomla 4.X
$obsloteFiles = ["helper.php"];
foreach ($obsloteFiles as $file) {
$f = JPATH_ADMINISTRATOR . '/modules/mod_switcheditor/' . $file;
if (@is_file($f)) {
File::delete($f);
}
$f = JPATH_ROOT . '/modules/mod_switcheditor/' . $file;
if (@is_file($f)) {
File::delete($f);
}
}
}
// plugin not used anymore
$query = $this->db->getQuery(true)
->delete('#__extensions')
->where($this->db->quoteName('element') . ' like "switcheditor" AND '
.$this->db->quoteName('type'). 'like "plugin"');
$this->db->setQuery($query);
$this->db->execute();
$f = JPATH_ROOT . '/plugins/system/switcheditor';
if (@is_dir($f)) {
Folder::delete($f);
}
// update admin module if not enabled : access = registered, position = status, enable it
$query = $this->db->getQuery(true)
->select($this->db->quoteName('id'))
->from('#__modules')
->where($this->db->quoteName('module') . '="mod_switcheditor"')
->where($this->db->quoteName('client_id') . '=1')
->where($this->db->quoteName('published') . '=0'); // not yet published
$this->db->setQuery($query);
$id = $this->db->loadResult();
if ($id) {
$id = (int) $id;
// update the module position & publication
$query = $this->db->getQuery(true)
->update('#__modules')
->set($this->db->quoteName('published') . '=1')
->set($this->db->quoteName('position') . '= "status"')
->set($this->db->quoteName('access') . '=2') // registred mini
->where($this->db->quoteName('id') . '=' . $id);
$this->db->setQuery($query);
$this->db->execute();
// remove any previous module menu entries
$query = $this->db->getQuery(true)->delete('#__modules_menu')->where($this->db->quoteName('moduleid') . '=' . $id);
$this->db->setQuery($query);
$this->db->execute();
// insert a new module menu entry
$query = $this->db->getQuery(true)->insert('#__modules_menu')->values($id . ', 0');
$this->db->setQuery($query);
$this->db->execute();
}
// update site module if not enabled : access = registered, enable it
$query = $this->db->getQuery(true)
->select($this->db->quoteName('id'))
->from('#__modules')
->where($this->db->quoteName('module') . '="mod_switcheditor"')
->where($this->db->quoteName('client_id') . '=0')
->where($this->db->quoteName('published') . '=0'); // not yet published
$this->db->setQuery($query);
$id = $this->db->loadResult();
if ($id) {
$id = (int) $id;
// update the module position & publication
$query = $this->db->getQuery(true)
->update('#__modules')
->set($this->db->quoteName('published') . '=1')
->set($this->db->quoteName('access') . '=2') // registred mini
->where($this->db->quoteName('id') . '=' . $id);
$this->db->setQuery($query);
$this->db->execute();
// enable module on all menus
$menu = new stdClass();
$menu->menuid = 0;
$menu->moduleid=$id;
// Insert the object into the modules_menu table.
$result = $this->db->insertObject('#__modules_menu', $menu);
}
// SwitchEditor is now on Github
$query = $this->db->getQuery(true)
->delete('#__update_sites')
->where($this->db->quoteName('location') . ' like "%conseilgouz.com/updates/pkg_switcheditor%"');
$this->db->setQuery($query);
$this->db->execute();
}
}