Skip to content

Commit 2820bc1

Browse files
authored
[6.0] Updater: Remove Adapter classes from inheritance (joomla#43793)
* Updater: Remove Adapter classes from inheritance * Codestyle * Update Updater.php * Fixing database access * Fixing database access - part 2 * Removing LegacyErrorHandlingTrait again from Updater and UpdateAdapter * Removing unnecessary imports * Removing duplicate getAdapter() call
1 parent 2be8538 commit 2820bc1

File tree

3 files changed

+240
-22
lines changed

3 files changed

+240
-22
lines changed

libraries/src/Updater/Adapter/ExtensionAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ protected function _endElement($parser, $name)
134134

135135
// Check if DB & version is supported via <supported_databases> tag, assume supported if tag isn't present
136136
if (isset($this->currentUpdate->supported_databases)) {
137-
$db = Factory::getDbo();
137+
$db = $this->db;
138138
$dbType = strtolower($db->getServerType());
139139
$dbVersion = $db->getVersion();
140140
$supportedDbs = $this->currentUpdate->supported_databases;

libraries/src/Updater/UpdateAdapter.php

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99

1010
namespace Joomla\CMS\Updater;
1111

12-
use Joomla\CMS\Adapter\AdapterInstance;
1312
use Joomla\CMS\Event\Installer\BeforeUpdateSiteDownloadEvent;
1413
use Joomla\CMS\Factory;
1514
use Joomla\CMS\Http\HttpFactory;
1615
use Joomla\CMS\Language\Text;
1716
use Joomla\CMS\Log\Log;
17+
use Joomla\CMS\Object\LegacyPropertyManagementTrait;
1818
use Joomla\CMS\Plugin\PluginHelper;
1919
use Joomla\CMS\Version;
20+
use Joomla\Database\DatabaseDriver;
2021
use Joomla\Database\ParameterType;
2122
use Joomla\Registry\Registry;
2223

@@ -29,8 +30,18 @@
2930
*
3031
* @since 1.7.0
3132
*/
32-
abstract class UpdateAdapter extends AdapterInstance
33+
abstract class UpdateAdapter
3334
{
35+
use LegacyPropertyManagementTrait;
36+
37+
/**
38+
* Parent
39+
*
40+
* @var Updater
41+
* @since 1.6
42+
*/
43+
protected $parent = null;
44+
3445
/**
3546
* Resource handle for the XML Parser
3647
*
@@ -99,6 +110,37 @@ abstract class UpdateAdapter extends AdapterInstance
99110
*/
100111
protected $minimum_stability = Updater::STABILITY_STABLE;
101112

113+
/**
114+
* Database
115+
*
116+
* @var DatabaseDriver
117+
* @since 1.6
118+
*/
119+
protected $db = null;
120+
121+
/**
122+
* Constructor
123+
*
124+
* @param Updater $parent Parent object
125+
* @param DatabaseDriver $db Database object
126+
* @param array $options Configuration Options
127+
*
128+
* @since 1.6
129+
*/
130+
public function __construct(Updater $parent, DatabaseDriver $db, array $options = [])
131+
{
132+
$this->parent = $parent;
133+
134+
foreach ($options as $key => $value) {
135+
if (property_exists($this, $key)) {
136+
$this->$key = $value;
137+
}
138+
}
139+
140+
// Pull in the global dbo in case something happened to it.
141+
$this->db = $db ?: Factory::getDbo();
142+
}
143+
102144
/**
103145
* Gets the reference to the current direct parent
104146
*
@@ -153,7 +195,7 @@ protected function toggleUpdateSite($updateSiteId, $enabled = true)
153195
return;
154196
}
155197

156-
$db = $this->parent->getDbo();
198+
$db = $this->db;
157199
$query = $db->getQuery(true)
158200
->update($db->quoteName('#__update_sites'))
159201
->set($db->quoteName('enabled') . ' = :enabled')
@@ -184,7 +226,7 @@ protected function getUpdateSiteName($updateSiteId)
184226
return '';
185227
}
186228

187-
$db = $this->parent->getDbo();
229+
$db = $this->db;
188230
$query = $db->getQuery(true)
189231
->select($db->quoteName('name'))
190232
->from($db->quoteName('#__update_sites'))

0 commit comments

Comments
 (0)