-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_component_builder.php
142 lines (129 loc) · 3.87 KB
/
install_component_builder.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
/**
* @package Joomla.Component.Builder
*
* @created 30th April, 2015
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
use Joomla\CMS\Factory;
/**
* Script File of Componentbuilder Package
*/
class pkg_component_builderInstallerScript
{
/**
* Called after any type of action
*
* @return boolean True on success
*/
public function postflight($type, $parent)
{
// enable the JCB plugins
$this->enableJCBPlugins();
// only run these if we have an update
if ('update' == $type)
{
// update the update server location
$this->updateServerLocation();
}
}
/**
* Update server location
*
* @return void
*/
protected function updateServerLocation()
{
$location = "https://git.vdm.dev/joomla/Component-Builder/raw/branch/5.x/componentbuilder_update_server.xml";
$elements = ['pkg_component_builder', 'com_componentbuilder'];
// Get the Package Update Site Details
foreach ($elements as $element)
{
if (($sites = $this->getUpdateSites($element)) !== null)
{
foreach ($sites as $site)
{
if ($site->location !== $location)
{
// Update the update site location
$site->location = $location;
Factory::getDbo()->updateObject('#__update_sites', $site, 'update_site_id');
}
}
}
}
}
/**
* Get Update Sites
*
* @return array|null
*/
protected function getUpdateSites(string $element): ?array
{
// Get The Database object
$db = Factory::getDbo();
// Get the Package Update Site Details
$query = $db->getQuery(true);
$query->select($db->quoteName(array('s.location', 's.update_site_id')));
$query->from($db->quoteName('#__update_sites', 's'));
$query->join('LEFT', $db->quoteName('#__update_sites_extensions', 'u') . ' ON ' . $db->quoteName('s.update_site_id') . ' = ' . $db->quoteName('u.update_site_id'));
$query->join('LEFT', $db->quoteName('#__extensions', 'e') . ' ON ' . $db->quoteName('u.extension_id') . ' = ' . $db->quoteName('e.extension_id'));
$query->where($db->quoteName('e.element') . ' = ' . $db->quote($element));
$db->setQuery($query);
$db->execute();
if ($db->getNumRows())
{
return $db->loadObjectList();
}
return null;
}
/**
* Enable all JCB Plugins
*
* @return void
*/
protected function enableJCBPlugins()
{
// Get The Database object
$db = Factory::getDbo();
// enable all JCB plugins Always!
$plugins = [
'componentbuilderadminheaderstabs',
'componentbuildercomponentdashboardheaderstabs',
'componentbuildercomponentheaderstabs',
'componentbuildercustomadminheaderstabs',
'componentbuilderlanguagetabs',
'componentbuildersiteheaderstabs',
'componentbuilderdynamicgetheaderstabs',
'componentbuilderprivacytabs',
'componentbuilderfieldorderingtabs',
'componentbuilderactionlogcompiler',
'componentbuilderexportcompiler',
'componentbuilderfieldorderingcompiler',
'componentbuilderheaderscompiler',
'componentbuilderlanguagepackaging',
'componentbuilderpowersautoloadercompiler',
'componentbuilderprivacycompiler'
];
// Create a new query object.
$query = $db->getQuery(true);
// we must update the enabled field
$fields = [
$db->quoteName('enabled') . ' = 1'
];
// Conditions for which records should be updated.
$conditions = [
$db->quoteName('element') . ' IN (' . implode(',', array_map([$db, 'quote'], $plugins)) . ')'
];
// load the update query
$query->update($db->quoteName('#__extensions'))->set($fields)->where($conditions);
// Reset the query using our newly populated query object.
$db->setQuery($query);
$db->execute();
}
}