Skip to content

Commit 9c38f84

Browse files
authored
Improve component installer script (#570)
* Improve component installer script * Remove un-used import * Toolbar is not available in document in Joomla 4.
1 parent e9f577e commit 9c38f84

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

src/administrator/components/com_weblinks/script.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
use Joomla\CMS\Installer\InstallerAdapter;
1717
use Joomla\CMS\Language\Text;
1818
use Joomla\CMS\Table\Category;
19-
use Joomla\Database\DatabaseInterface;
19+
use Joomla\Database\DatabaseAwareInterface;
20+
use Joomla\Database\DatabaseAwareTrait;
2021
use Joomla\Filesystem\File;
2122
use Joomla\Filesystem\Folder;
2223

@@ -25,8 +26,10 @@
2526
*
2627
* @since 3.4
2728
*/
28-
class Com_WeblinksInstallerScript
29+
class Com_WeblinksInstallerScript implements DatabaseAwareInterface
2930
{
31+
use DatabaseAwareTrait;
32+
3033
/**
3134
* Function called before extension installation/update/removal procedure commences
3235
*
@@ -87,7 +90,7 @@ public function preflight($type, $parent)
8790
public function install($parent)
8891
{
8992
// Initialize a new category
90-
$category = new Category(Factory::getContainer()->get(DatabaseInterface::class));
93+
$category = new Category($this->getDatabase());
9194

9295
// Check if the Uncategorised category exists before adding it
9396
if (!$category->load(['extension' => 'com_weblinks', 'title' => 'Uncategorised'])) {
@@ -142,7 +145,7 @@ public function install($parent)
142145
public function postflight($type, $parent)
143146
{
144147
// Only execute database changes on MySQL databases
145-
$dbName = Factory::getContainer()->get(DatabaseInterface::class)->name;
148+
$dbName = $this->getDatabase()->name;
146149

147150
if (strpos($dbName, 'mysql') !== false) {
148151
// Add Missing Table Columns if needed
@@ -166,7 +169,7 @@ public function postflight($type, $parent)
166169
private function insertMissingUcmRecords()
167170
{
168171
// Insert the rows in the #__content_types table if they don't exist already
169-
$db = Factory::getContainer()->get(DatabaseInterface::class);
172+
$db = $this->getDatabase();
170173

171174
// Get the type ID for a Weblink
172175
$query = $db->getQuery(true);
@@ -288,7 +291,7 @@ private function dropColumnsIfNeeded()
288291
'approved',
289292
];
290293

291-
$db = Factory::getContainer()->get(DatabaseInterface::class);
294+
$db = $this->getDatabase();
292295
$table = $db->getTableColumns('#__weblinks');
293296

294297
$columns = array_intersect($oldColumns, array_keys($table));
@@ -309,7 +312,7 @@ private function dropColumnsIfNeeded()
309312
*/
310313
private function addColumnsIfNeeded()
311314
{
312-
$db = Factory::getContainer()->get(DatabaseInterface::class);
315+
$db = $this->getDatabase();
313316
$table = $db->getTableColumns('#__weblinks');
314317

315318
if (!\array_key_exists('version', $table)) {

src/administrator/components/com_weblinks/src/View/Weblinks/HtmlView.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Joomla\CMS\Language\Text;
2121
use Joomla\CMS\MVC\View\GenericDataException;
2222
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
23+
use Joomla\CMS\Toolbar\Toolbar;
2324
use Joomla\CMS\Toolbar\ToolbarHelper;
2425
use Joomla\Component\Weblinks\Administrator\Model\WeblinksModel;
2526

@@ -135,7 +136,7 @@ protected function addToolbar()
135136
$user = $this->getCurrentUser();
136137

137138
// Get the toolbar object instance
138-
$toolbar = $this->getDocument()->getToolbar();
139+
$toolbar = Toolbar::getInstance('toolbar');
139140

140141
ToolbarHelper::title(Text::_('COM_WEBLINKS_MANAGER_WEBLINKS'), 'link weblinks');
141142

src/administrator/manifests/packages/weblinks/script.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Pkg_WeblinksInstallerScript extends InstallerScript
2828
*/
2929
public function __construct()
3030
{
31-
$this->minimumJoomla = '4.3.0';
31+
$this->minimumJoomla = '4.4.0';
3232
$this->minimumPhp = JOOMLA_MINIMUM_PHP;
3333
}
3434
}

0 commit comments

Comments
 (0)