Skip to content

Commit f19e3f3

Browse files
wilsongeMacJoomlaoneorichard67
authored
[5.0] Improve constructors of JTable objects (#40129)
* Improve constructors of JTable objects * Move static to self --------- Co-authored-by: Martin Carl Kopp <[email protected]> Co-authored-by: Allon Moritz <[email protected]> Co-authored-by: Richard Fath <[email protected]>
1 parent 087821f commit f19e3f3

File tree

45 files changed

+257
-174
lines changed

Some content is hidden

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

45 files changed

+257
-174
lines changed

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Joomla\CMS\Versioning\VersionableTableInterface;
1919
use Joomla\Database\DatabaseDriver;
2020
use Joomla\Database\ParameterType;
21+
use Joomla\Event\DispatcherInterface;
2122
use Joomla\Registry\Registry;
2223
use Joomla\Utilities\ArrayHelper;
2324

@@ -43,15 +44,16 @@ class BannerTable extends Table implements VersionableTableInterface
4344
/**
4445
* Constructor
4546
*
46-
* @param DatabaseDriver $db Database connector object
47+
* @param DatabaseDriver $db Database connector object
48+
* @param ?DispatcherInterface $dispatcher Event dispatcher for this table
4749
*
4850
* @since 1.5
4951
*/
50-
public function __construct(DatabaseDriver $db)
52+
public function __construct(DatabaseDriver $db, DispatcherInterface $dispatcher = null)
5153
{
5254
$this->typeAlias = 'com_banners.banner';
5355

54-
parent::__construct('#__banners', 'id', $db);
56+
parent::__construct('#__banners', 'id', $db, $dispatcher);
5557

5658
$this->created = Factory::getDate()->toSql();
5759
$this->setColumnAlias('published', 'state');
@@ -252,16 +254,14 @@ public function store($updateNulls = true)
252254
parent::store($updateNulls);
253255
} else {
254256
// Get the old row
255-
/** @var BannerTable $oldrow */
256-
$oldrow = Table::getInstance('BannerTable', __NAMESPACE__ . '\\', ['dbo' => $db]);
257+
$oldrow = new self($db, $this->getDispatcher());
257258

258259
if (!$oldrow->load($this->id) && $oldrow->getError()) {
259260
$this->setError($oldrow->getError());
260261
}
261262

262263
// Verify that the alias is unique
263-
/** @var BannerTable $table */
264-
$table = Table::getInstance('BannerTable', __NAMESPACE__ . '\\', ['dbo' => $db]);
264+
$table = new self($db, $this->getDispatcher());
265265

266266
if ($table->load(['alias' => $this->alias, 'catid' => $this->catid]) && ($table->id != $this->id || $this->id == 0)) {
267267
$this->setError(Text::_('COM_BANNERS_ERROR_UNIQUE_ALIAS'));
@@ -317,8 +317,7 @@ public function stick($pks = null, $state = 1, $userId = 0)
317317
}
318318

319319
// Get an instance of the table
320-
/** @var BannerTable $table */
321-
$table = Table::getInstance('BannerTable', __NAMESPACE__ . '\\', ['dbo' => $this->_db]);
320+
$table = new self($this->getDbo(), $this->getDispatcher());
322321

323322
// For all keys
324323
foreach ($pks as $pk) {

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Joomla\CMS\Table\Table;
1515
use Joomla\CMS\Versioning\VersionableTableInterface;
1616
use Joomla\Database\DatabaseDriver;
17+
use Joomla\Event\DispatcherInterface;
1718

1819
// phpcs:disable PSR1.Files.SideEffects
1920
\defined('_JEXEC') or die;
@@ -37,17 +38,18 @@ class ClientTable extends Table implements VersionableTableInterface
3738
/**
3839
* Constructor
3940
*
40-
* @param DatabaseDriver $db Database connector object
41+
* @param DatabaseDriver $db Database connector object
42+
* @param ?DispatcherInterface $dispatcher Event dispatcher for this table
4143
*
4244
* @since 1.5
4345
*/
44-
public function __construct(DatabaseDriver $db)
46+
public function __construct(DatabaseDriver $db, DispatcherInterface $dispatcher = null)
4547
{
4648
$this->typeAlias = 'com_banners.client';
4749

4850
$this->setColumnAlias('published', 'state');
4951

50-
parent::__construct('#__banner_clients', 'id', $db);
52+
parent::__construct('#__banner_clients', 'id', $db, $dispatcher);
5153
}
5254

5355
/**

administrator/components/com_contact/src/Table/ContactTable.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Joomla\CMS\User\CurrentUserTrait;
2323
use Joomla\CMS\Versioning\VersionableTableInterface;
2424
use Joomla\Database\DatabaseDriver;
25+
use Joomla\Event\DispatcherInterface;
2526
use Joomla\String\StringHelper;
2627

2728
// phpcs:disable PSR1.Files.SideEffects
@@ -57,15 +58,16 @@ class ContactTable extends Table implements VersionableTableInterface, TaggableT
5758
/**
5859
* Constructor
5960
*
60-
* @param DatabaseDriver $db Database connector object
61+
* @param DatabaseDriver $db Database connector object
62+
* @param ?DispatcherInterface $dispatcher Event dispatcher for this table
6163
*
6264
* @since 1.0
6365
*/
64-
public function __construct(DatabaseDriver $db)
66+
public function __construct(DatabaseDriver $db, DispatcherInterface $dispatcher = null)
6567
{
6668
$this->typeAlias = 'com_contact.contact';
6769

68-
parent::__construct('#__contact_details', 'id', $db);
70+
parent::__construct('#__contact_details', 'id', $db, $dispatcher);
6971

7072
$this->setColumnAlias('title', 'name');
7173
}
@@ -119,7 +121,7 @@ public function store($updateNulls = true)
119121
}
120122

121123
// Verify that the alias is unique
122-
$table = Table::getInstance('ContactTable', __NAMESPACE__ . '\\', ['dbo' => $this->getDbo()]);
124+
$table = new self($this->getDbo(), $this->getDispatcher());
123125

124126
if ($table->load(['alias' => $this->alias, 'catid' => $this->catid]) && ($table->id != $this->id || $this->id == 0)) {
125127
// Is the existing contact trashed?
@@ -255,7 +257,7 @@ public function generateAlias()
255257

256258

257259
/**
258-
* Get the type alias for the history table
260+
* Get the type alias for the history and tags mapping table
259261
*
260262
* @return string The alias as described above
261263
*

administrator/components/com_content/src/Table/FeaturedTable.php

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

1313
use Joomla\CMS\Table\Table;
1414
use Joomla\Database\DatabaseDriver;
15+
use Joomla\Event\DispatcherInterface;
1516

1617
// phpcs:disable PSR1.Files.SideEffects
1718
\defined('_JEXEC') or die;
@@ -27,12 +28,13 @@ class FeaturedTable extends Table
2728
/**
2829
* Constructor
2930
*
30-
* @param DatabaseDriver $db Database connector object
31+
* @param DatabaseDriver $db Database connector object
32+
* @param ?DispatcherInterface $dispatcher Event dispatcher for this table
3133
*
3234
* @since 1.6
3335
*/
34-
public function __construct(DatabaseDriver $db)
36+
public function __construct(DatabaseDriver $db, DispatcherInterface $dispatcher = null)
3537
{
36-
parent::__construct('#__content_frontpage', 'content_id', $db);
38+
parent::__construct('#__content_frontpage', 'content_id', $db, $dispatcher);
3739
}
3840
}

administrator/components/com_fields/src/Table/FieldTable.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Joomla\CMS\User\CurrentUserInterface;
1919
use Joomla\CMS\User\CurrentUserTrait;
2020
use Joomla\Database\DatabaseDriver;
21+
use Joomla\Event\DispatcherInterface;
2122
use Joomla\Registry\Registry;
2223
use Joomla\String\StringHelper;
2324

@@ -45,13 +46,14 @@ class FieldTable extends Table implements CurrentUserInterface
4546
/**
4647
* Class constructor.
4748
*
48-
* @param DatabaseDriver $db DatabaseDriver object.
49+
* @param DatabaseDriver $db Database connector object
50+
* @param ?DispatcherInterface $dispatcher Event dispatcher for this table
4951
*
5052
* @since 3.7.0
5153
*/
52-
public function __construct($db = null)
54+
public function __construct(DatabaseDriver $db, DispatcherInterface $dispatcher = null)
5355
{
54-
parent::__construct('#__fields', 'id', $db);
56+
parent::__construct('#__fields', 'id', $db, $dispatcher);
5557

5658
$this->setColumnAlias('published', 'state');
5759
}
@@ -150,7 +152,7 @@ public function check()
150152
$this->name = str_replace(',', '-', $this->name);
151153

152154
// Verify that the name is unique
153-
$table = new static($this->_db);
155+
$table = new self($this->_db, $this->getDispatcher());
154156

155157
if ($table->load(['name' => $this->name]) && ($table->id != $this->id || $this->id == 0)) {
156158
$this->setError(Text::_('COM_FIELDS_ERROR_UNIQUE_NAME'));

administrator/components/com_fields/src/Table/GroupTable.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Joomla\CMS\User\CurrentUserInterface;
1818
use Joomla\CMS\User\CurrentUserTrait;
1919
use Joomla\Database\DatabaseDriver;
20+
use Joomla\Event\DispatcherInterface;
2021
use Joomla\Registry\Registry;
2122

2223
// phpcs:disable PSR1.Files.SideEffects
@@ -43,13 +44,14 @@ class GroupTable extends Table implements CurrentUserInterface
4344
/**
4445
* Class constructor.
4546
*
46-
* @param DatabaseDriver $db DatabaseDriver object.
47+
* @param DatabaseDriver $db Database connector object
48+
* @param ?DispatcherInterface $dispatcher Event dispatcher for this table
4749
*
4850
* @since 3.7.0
4951
*/
50-
public function __construct($db = null)
52+
public function __construct(DatabaseDriver $db, DispatcherInterface $dispatcher = null)
5153
{
52-
parent::__construct('#__fields_groups', 'id', $db);
54+
parent::__construct('#__fields_groups', 'id', $db, $dispatcher);
5355

5456
$this->setColumnAlias('published', 'state');
5557
}

administrator/components/com_finder/src/Table/FilterTable.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Joomla\CMS\User\CurrentUserInterface;
1818
use Joomla\CMS\User\CurrentUserTrait;
1919
use Joomla\Database\DatabaseDriver;
20+
use Joomla\Event\DispatcherInterface;
2021
use Joomla\Registry\Registry;
2122

2223
// phpcs:disable PSR1.Files.SideEffects
@@ -51,13 +52,14 @@ class FilterTable extends Table implements CurrentUserInterface
5152
/**
5253
* Constructor
5354
*
54-
* @param DatabaseDriver $db Database Driver connector object.
55+
* @param DatabaseDriver $db Database connector object
56+
* @param ?DispatcherInterface $dispatcher Event dispatcher for this table
5557
*
5658
* @since 2.5
5759
*/
58-
public function __construct(DatabaseDriver $db)
60+
public function __construct(DatabaseDriver $db, DispatcherInterface $dispatcher = null)
5961
{
60-
parent::__construct('#__finder_filters', 'filter_id', $db);
62+
parent::__construct('#__finder_filters', 'filter_id', $db, $dispatcher);
6163

6264
$this->setColumnAlias('published', 'state');
6365
}
@@ -158,7 +160,7 @@ public function store($updateNulls = true)
158160
}
159161

160162
// Verify that the alias is unique
161-
$table = new static($this->getDbo());
163+
$table = new self($this->getDbo(), $this->getDispatcher());
162164

163165
if ($table->load(['alias' => $this->alias]) && ($table->filter_id != $this->filter_id || $this->filter_id == 0)) {
164166
$this->setError(Text::_('COM_FINDER_FILTER_ERROR_UNIQUE_ALIAS'));

administrator/components/com_finder/src/Table/LinkTable.php

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

1313
use Joomla\CMS\Table\Table;
1414
use Joomla\Database\DatabaseDriver;
15+
use Joomla\Event\DispatcherInterface;
1516

1617
// phpcs:disable PSR1.Files.SideEffects
1718
\defined('_JEXEC') or die;
@@ -35,13 +36,14 @@ class LinkTable extends Table
3536
/**
3637
* Constructor
3738
*
38-
* @param DatabaseDriver $db Database Driver connector object.
39+
* @param DatabaseDriver $db Database connector object
40+
* @param ?DispatcherInterface $dispatcher Event dispatcher for this table
3941
*
4042
* @since 2.5
4143
*/
42-
public function __construct(DatabaseDriver $db)
44+
public function __construct(DatabaseDriver $db, DispatcherInterface $dispatcher = null)
4345
{
44-
parent::__construct('#__finder_links', 'link_id', $db);
46+
parent::__construct('#__finder_links', 'link_id', $db, $dispatcher);
4547
}
4648

4749
/**

administrator/components/com_finder/src/Table/MapTable.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Joomla\CMS\Language\Text;
1616
use Joomla\CMS\Table\Nested;
1717
use Joomla\Database\DatabaseDriver;
18+
use Joomla\Event\DispatcherInterface;
1819

1920
// phpcs:disable PSR1.Files.SideEffects
2021
\defined('_JEXEC') or die;
@@ -30,13 +31,14 @@ class MapTable extends Nested
3031
/**
3132
* Constructor
3233
*
33-
* @param DatabaseDriver $db Database Driver connector object.
34+
* @param DatabaseDriver $db Database connector object
35+
* @param ?DispatcherInterface $dispatcher Event dispatcher for this table
3436
*
3537
* @since 2.5
3638
*/
37-
public function __construct(DatabaseDriver $db)
39+
public function __construct(DatabaseDriver $db, DispatcherInterface $dispatcher = null)
3840
{
39-
parent::__construct('#__finder_taxonomy', 'id', $db);
41+
parent::__construct('#__finder_taxonomy', 'id', $db, $dispatcher);
4042

4143
$this->setColumnAlias('published', 'state');
4244
$this->access = (int) Factory::getApplication()->get('access');

administrator/components/com_guidedtours/src/Table/StepTable.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Joomla\CMS\User\CurrentUserInterface;
1616
use Joomla\CMS\User\CurrentUserTrait;
1717
use Joomla\Database\DatabaseDriver;
18+
use Joomla\Event\DispatcherInterface;
1819

1920
// phpcs:disable PSR1.Files.SideEffects
2021
\defined('_JEXEC') or die;
@@ -40,13 +41,14 @@ class StepTable extends Table implements CurrentUserInterface
4041
/**
4142
* Constructor
4243
*
43-
* @param DatabaseDriver $db Database connector object
44+
* @param DatabaseDriver $db Database connector object
45+
* @param ?DispatcherInterface $dispatcher Event dispatcher for this table
4446
*
4547
* @since 4.3.0
4648
*/
47-
public function __construct(DatabaseDriver $db)
49+
public function __construct(DatabaseDriver $db, DispatcherInterface $dispatcher = null)
4850
{
49-
parent::__construct('#__guidedtour_steps', 'id', $db);
51+
parent::__construct('#__guidedtour_steps', 'id', $db, $dispatcher);
5052
}
5153

5254
/**

0 commit comments

Comments
 (0)