Skip to content

Commit f9360e5

Browse files
authored
[6.0] Remove instances of Table::getInstance() from core code (#44090)
1 parent b78fbba commit f9360e5

File tree

100 files changed

+342
-329
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+342
-329
lines changed

administrator/components/com_admin/script.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Joomla\CMS\Installer\Installer;
1616
use Joomla\CMS\Language\Text;
1717
use Joomla\CMS\Log\Log;
18-
use Joomla\CMS\Table\Table;
18+
use Joomla\CMS\Table\Asset;
1919
use Joomla\Database\ParameterType;
2020
use Joomla\Filesystem\File;
2121
use Joomla\Filesystem\Folder;
@@ -564,8 +564,7 @@ public function updateAssets($installer)
564564
];
565565

566566
foreach ($newComponents as $component) {
567-
/** @var \Joomla\CMS\Table\Asset $asset */
568-
$asset = Table::getInstance('Asset');
567+
$asset = new Asset(Factory::getDbo());
569568

570569
if ($asset->loadByName($component)) {
571570
continue;

administrator/components/com_associations/src/Model/AssociationsModel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Joomla\CMS\Language\Text;
1515
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
1616
use Joomla\CMS\MVC\Model\ListModel;
17-
use Joomla\CMS\Table\Table;
17+
use Joomla\CMS\Table\Category;
1818
use Joomla\Component\Associations\Administrator\Helper\AssociationsHelper;
1919
use Joomla\Database\Exception\ExecutionFailureException;
2020
use Joomla\Database\ParameterType;
@@ -389,7 +389,7 @@ protected function getListQuery()
389389
$baselevel = 1;
390390

391391
if ($categoryId = $this->getState('filter.category_id')) {
392-
$categoryTable = Table::getInstance('Category', '\\Joomla\\CMS\\Table\\');
392+
$categoryTable = new Category($db);
393393
$categoryTable->load($categoryId);
394394
$baselevel = (int) $categoryTable->level;
395395

administrator/components/com_banners/src/Helper/BannersHelper.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Joomla\CMS\Helper\ContentHelper;
1616
use Joomla\CMS\HTML\HTMLHelper;
1717
use Joomla\CMS\Language\Text;
18-
use Joomla\CMS\Table\Table;
1918
use Joomla\Database\ParameterType;
2019

2120
// phpcs:disable PSR1.Files.SideEffects
@@ -78,7 +77,7 @@ public static function updateReset()
7877

7978
if ($purchaseType < 0 && $row->cid) {
8079
/** @var \Joomla\Component\Banners\Administrator\Table\ClientTable $client */
81-
$client = Table::getInstance('ClientTable', '\\Joomla\\Component\\Banners\\Administrator\\Table\\');
80+
$client = $app->bootComponent('com_banners')->getMVCFactory()->createTable('Client', 'Administrator');
8281
$client->load($row->cid);
8382
$purchaseType = $client->purchase_type;
8483
}

administrator/components/com_banners/src/Table/BannerTable.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Joomla\CMS\Language\Text;
1717
use Joomla\CMS\Table\Table;
1818
use Joomla\CMS\Versioning\VersionableTableInterface;
19-
use Joomla\Database\DatabaseDriver;
19+
use Joomla\Database\DatabaseInterface;
2020
use Joomla\Database\ParameterType;
2121
use Joomla\Event\DispatcherInterface;
2222
use Joomla\Registry\Registry;
@@ -44,12 +44,12 @@ class BannerTable extends Table implements VersionableTableInterface
4444
/**
4545
* Constructor
4646
*
47-
* @param DatabaseDriver $db Database connector object
47+
* @param DatabaseInterface $db Database connector object
4848
* @param ?DispatcherInterface $dispatcher Event dispatcher for this table
4949
*
5050
* @since 1.5
5151
*/
52-
public function __construct(DatabaseDriver $db, ?DispatcherInterface $dispatcher = null)
52+
public function __construct(DatabaseInterface $db, ?DispatcherInterface $dispatcher = null)
5353
{
5454
$this->typeAlias = 'com_banners.banner';
5555

administrator/components/com_banners/src/Table/ClientTable.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Joomla\CMS\Language\Text;
1414
use Joomla\CMS\Table\Table;
1515
use Joomla\CMS\Versioning\VersionableTableInterface;
16-
use Joomla\Database\DatabaseDriver;
16+
use Joomla\Database\DatabaseInterface;
1717
use Joomla\Event\DispatcherInterface;
1818

1919
// phpcs:disable PSR1.Files.SideEffects
@@ -38,12 +38,12 @@ class ClientTable extends Table implements VersionableTableInterface
3838
/**
3939
* Constructor
4040
*
41-
* @param DatabaseDriver $db Database connector object
41+
* @param DatabaseInterface $db Database connector object
4242
* @param ?DispatcherInterface $dispatcher Event dispatcher for this table
4343
*
4444
* @since 1.5
4545
*/
46-
public function __construct(DatabaseDriver $db, ?DispatcherInterface $dispatcher = null)
46+
public function __construct(DatabaseInterface $db, ?DispatcherInterface $dispatcher = null)
4747
{
4848
$this->typeAlias = 'com_banners.client';
4949

administrator/components/com_categories/src/Controller/AjaxController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010

1111
namespace Joomla\Component\Categories\Administrator\Controller;
1212

13+
use Joomla\CMS\Factory;
1314
use Joomla\CMS\Language\Associations;
1415
use Joomla\CMS\Language\LanguageHelper;
1516
use Joomla\CMS\Language\Text;
1617
use Joomla\CMS\MVC\Controller\BaseController;
1718
use Joomla\CMS\Response\JsonResponse;
1819
use Joomla\CMS\Session\Session;
19-
use Joomla\CMS\Table\Table;
20+
use Joomla\CMS\Table\Category;
2021

2122
// phpcs:disable PSR1.Files.SideEffects
2223
\defined('_JEXEC') or die;
@@ -63,8 +64,7 @@ public function fetchAssociations()
6364
unset($associations[$excludeLang]);
6465

6566
// Add the title to each of the associated records
66-
Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_categories/tables');
67-
$categoryTable = Table::getInstance('Category', '\\Joomla\\CMS\\Table\\');
67+
$categoryTable = new Category(Factory::getDbo());
6868

6969
foreach ($associations as $association) {
7070
$categoryTable->load($association->id);

administrator/components/com_categories/src/Helper/CategoriesHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
use Joomla\CMS\Factory;
1414
use Joomla\CMS\Language\Associations;
15-
use Joomla\CMS\Table\Table;
15+
use Joomla\Component\Categories\Administrator\Table\CategoryTable;
1616
use Joomla\Database\ParameterType;
1717

1818
// phpcs:disable PSR1.Files.SideEffects
@@ -74,7 +74,7 @@ public static function getAssociations($pk, $extension = 'com_content')
7474
*/
7575
public static function validateCategoryId($catid, $extension)
7676
{
77-
$categoryTable = Table::getInstance('CategoryTable', '\\Joomla\\Component\\Categories\\Administrator\\Table\\');
77+
$categoryTable = new CategoryTable(Factory::getDbo());
7878

7979
$data = [];
8080
$data['id'] = $catid;

administrator/components/com_categories/src/Model/CategoriesModel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Joomla\CMS\Language\Associations;
1717
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
1818
use Joomla\CMS\MVC\Model\ListModel;
19-
use Joomla\CMS\Table\Table;
19+
use Joomla\CMS\Table\Category;
2020
use Joomla\Database\ParameterType;
2121
use Joomla\Database\QueryInterface;
2222
use Joomla\Utilities\ArrayHelper;
@@ -251,7 +251,7 @@ protected function getListQuery()
251251

252252
if (\count($categoryId)) {
253253
// Case: Using both categories filter and by level filter
254-
$categoryTable = Table::getInstance('Category', 'JTable');
254+
$categoryTable = new Category($db);
255255
$subCatItemsWhere = [];
256256

257257
foreach ($categoryId as $filterCatId) {

administrator/components/com_config/src/Model/ApplicationModel.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
use Joomla\CMS\Mail\MailTemplate;
2828
use Joomla\CMS\MVC\Model\FormModel;
2929
use Joomla\CMS\Table\Asset;
30-
use Joomla\CMS\Table\Table;
30+
use Joomla\CMS\Table\Extension;
3131
use Joomla\CMS\Uri\Uri;
3232
use Joomla\CMS\User\UserHelper;
3333
use Joomla\Database\DatabaseDriver;
@@ -397,7 +397,7 @@ public function save($data)
397397
return false;
398398
}
399399

400-
$asset = Table::getInstance('asset');
400+
$asset = new Asset($this->getDatabase());
401401

402402
if ($asset->loadByName('root.1')) {
403403
$asset->rules = (string) $rules;
@@ -420,7 +420,7 @@ public function save($data)
420420
if (isset($data['filters'])) {
421421
$registry = new Registry(['filters' => $data['filters']]);
422422

423-
$extension = Table::getInstance('extension');
423+
$extension = new Extension($this->getDatabase());
424424

425425
// Get extension_id
426426
$extensionId = $extension->find(['name' => 'com_config']);
@@ -943,8 +943,7 @@ public function storePermissions($permission = null)
943943
}
944944

945945
try {
946-
/** @var Asset $asset */
947-
$asset = Table::getInstance('asset');
946+
$asset = new Asset($this->getDatabase());
948947
$result = $asset->loadByName($permission['component']);
949948

950949
if ($result === false) {
@@ -956,8 +955,7 @@ public function storePermissions($permission = null)
956955
$asset->title = (string) $permission['title'];
957956

958957
// Get the parent asset id so we have a correct tree.
959-
/** @var Asset $parentAsset */
960-
$parentAsset = Table::getInstance('Asset');
958+
$parentAsset = new Asset($this->getDatabase());
961959

962960
if (strpos($asset->name, '.') !== false) {
963961
$assetParts = explode('.', $asset->name);

administrator/components/com_config/src/Model/ComponentModel.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
use Joomla\CMS\Language\Text;
1919
use Joomla\CMS\MVC\Model\FormModel;
2020
use Joomla\CMS\Plugin\PluginHelper;
21-
use Joomla\CMS\Table\Table;
21+
use Joomla\CMS\Table\Asset;
22+
use Joomla\CMS\Table\Extension;
2223
use Joomla\Filesystem\Path;
2324

2425
// phpcs:disable PSR1.Files.SideEffects
@@ -156,7 +157,7 @@ public function getComponent()
156157
*/
157158
public function save($data)
158159
{
159-
$table = Table::getInstance('extension');
160+
$table = new Extension($this->getDatabase());
160161
$context = $this->option . '.' . $this->name;
161162
PluginHelper::importPlugin('extension');
162163

@@ -184,10 +185,10 @@ public function save($data)
184185
}
185186

186187
$rules = new Rules($data['params']['rules']);
187-
$asset = Table::getInstance('asset');
188+
$asset = new Asset($this->getDatabase());
188189

189190
if (!$asset->loadByName($data['option'])) {
190-
$root = Table::getInstance('asset');
191+
$root = new Asset($this->getDatabase());
191192
$root->loadByName('root.1');
192193
$asset->name = $data['option'];
193194
$asset->title = $data['option'];

0 commit comments

Comments
 (0)