Skip to content

Commit 46be0b6

Browse files
Hackwarlaoneosoftforge
authored
[6.0] Removing CMSObject from most of the codebase (#44655)
* Removing CMSObject from most of the codebase * Codestyle * Codestyle * Codestyle * Changing unit test * Codestyle - don't ask * More fixes to the tests * More fixes to the tests * Using a Registry object instead * Fixing comments * More fixes * Update InstallerHelper.php * Removing new usages of CMSObject * Update plugins/system/guidedtours/src/Extension/GuidedTours.php Co-authored-by: Allon Moritz <[email protected]> * Update administrator/components/com_media/helpers/media.php Co-authored-by: Allon Moritz <[email protected]> * Update administrator/components/com_media/helpers/media.php Co-authored-by: Allon Moritz <[email protected]> * Update InstallerHelper.php --------- Co-authored-by: Allon Moritz <[email protected]> Co-authored-by: Phil Walton <[email protected]>
1 parent decb2dd commit 46be0b6

File tree

36 files changed

+100
-160
lines changed

36 files changed

+100
-160
lines changed

administrator/components/com_actionlogs/src/Helper/ActionlogsHelper.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Joomla\CMS\Date\Date;
1414
use Joomla\CMS\Factory;
1515
use Joomla\CMS\Language\Text;
16-
use Joomla\CMS\Object\CMSObject;
1716
use Joomla\CMS\Router\Route;
1817
use Joomla\Filesystem\Path;
1918
use Joomla\String\StringHelper;
@@ -232,7 +231,7 @@ public static function getHumanReadableLogMessage($log, $generateLinks = true)
232231
* @param string $contentType
233232
* @param integer $id
234233
* @param string $urlVar
235-
* @param CMSObject $object
234+
* @param \stdClass $object
236235
*
237236
* @return string Link to the content item
238237
*

administrator/components/com_guidedtours/src/Model/TourModel.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Joomla\CMS\Language\Text;
1616
use Joomla\CMS\Log\Log;
1717
use Joomla\CMS\MVC\Model\AdminModel;
18-
use Joomla\CMS\Object\CMSObject;
1918
use Joomla\CMS\Plugin\PluginHelper;
2019
use Joomla\Component\Guidedtours\Administrator\Helper\GuidedtoursHelper;
2120
use Joomla\Database\ParameterType;
@@ -221,9 +220,9 @@ public function getItem($pk = null)
221220
return false;
222221
}
223222

224-
// Convert to the CMSObject before adding other data.
223+
// Convert to an object before adding other data.
225224
$properties = $table->getProperties(1);
226-
$item = ArrayHelper::toObject($properties, CMSObject::class);
225+
$item = ArrayHelper::toObject($properties);
227226

228227
if (property_exists($item, 'params')) {
229228
$registry = new Registry($item->params);

administrator/components/com_guidedtours/src/View/Step/HtmlView.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
1818
use Joomla\CMS\Toolbar\ToolbarHelper;
1919
use Joomla\Component\Guidedtours\Administrator\Model\StepModel;
20+
use Joomla\Registry\Registry;
2021

2122
// phpcs:disable PSR1.Files.SideEffects
2223
\defined('_JEXEC') or die;
@@ -53,7 +54,7 @@ class HtmlView extends BaseHtmlView
5354
/**
5455
* The actions the user is authorised to perform
5556
*
56-
* @var \Joomla\CMS\Object\CMSObject
57+
* @var Registry
5758
*/
5859
protected $canDo;
5960

administrator/components/com_installer/src/Helper/InstallerHelper.php

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Joomla\CMS\Factory;
1414
use Joomla\CMS\HTML\HTMLHelper;
1515
use Joomla\CMS\Language\Text;
16-
use Joomla\CMS\Object\CMSObject;
1716
use Joomla\Database\DatabaseInterface;
1817
use Joomla\Database\ParameterType;
1918

@@ -233,19 +232,19 @@ public static function getInstallationXML(
233232
/**
234233
* Get the download key of an extension going through their installation xml
235234
*
236-
* @param CMSObject $extension element of an extension
235+
* @param \stdClass $extension element of an extension
237236
*
238237
* @return array An array with the prefix, suffix and value of the download key
239238
*
240239
* @since 4.0.0
241240
*/
242-
public static function getDownloadKey(CMSObject $extension): array
241+
public static function getDownloadKey(\stdClass $extension): array
243242
{
244243
$installXmlFile = self::getInstallationXML(
245-
$extension->get('element'),
246-
$extension->get('type'),
247-
$extension->get('client_id'),
248-
$extension->get('folder')
244+
$extension->element,
245+
$extension->type,
246+
$extension->client_id,
247+
$extension->folder
249248
);
250249

251250
if (!$installXmlFile) {
@@ -264,7 +263,7 @@ public static function getDownloadKey(CMSObject $extension): array
264263

265264
$prefix = (string) $installXmlFile->dlid['prefix'];
266265
$suffix = (string) $installXmlFile->dlid['suffix'];
267-
$value = substr($extension->get('extra_query'), \strlen($prefix));
266+
$value = substr($extension->extra_query ?? '', \strlen($prefix));
268267

269268
if ($suffix) {
270269
$value = substr($value, 0, -\strlen($suffix));
@@ -309,7 +308,7 @@ public static function getExtensionDownloadKey(
309308
];
310309
}
311310

312-
// Try to retrieve the extension information as a CMSObject
311+
// Try to retrieve the extension information
313312
$query = $db->getQuery(true)
314313
->select($db->quoteName('extension_id'))
315314
->from($db->quoteName('#__extensions'))
@@ -323,7 +322,7 @@ public static function getExtensionDownloadKey(
323322
$query->bind(':folder', $folder, ParameterType::STRING);
324323

325324
try {
326-
$extension = new CMSObject($db->setQuery($query)->loadAssoc());
325+
$extension = $db->setQuery($query)->loadObject();
327326
} catch (\Exception $e) {
328327
return [
329328
'supported' => false,
@@ -355,15 +354,15 @@ public static function getDownloadKeySupportedSites($onlyEnabled = false): array
355354

356355
$extensions = self::getUpdateSitesInformation($onlyEnabled);
357356

358-
$filterClosure = function (CMSObject $extension) {
357+
$filterClosure = function ($extension) {
359358
$dlidInfo = self::getDownloadKey($extension);
360359

361360
return $dlidInfo['supported'];
362361
};
363362
$extensions = array_filter($extensions, $filterClosure);
364363

365-
$mapClosure = function (CMSObject $extension) {
366-
return $extension->get('update_site_id');
364+
$mapClosure = function ($extension) {
365+
return $extension->update_site_id ?? null;
367366
};
368367

369368
return array_map($mapClosure, $extensions);
@@ -391,7 +390,7 @@ public static function getDownloadKeyExistsSites(bool $exists = true, $onlyEnabl
391390
$extensions = self::getUpdateSitesInformation($onlyEnabled);
392391

393392
// Filter the extensions by what supports Download Keys
394-
$filterClosure = function (CMSObject $extension) use ($exists) {
393+
$filterClosure = function ($extension) use ($exists) {
395394
$dlidInfo = self::getDownloadKey($extension);
396395

397396
if (!$dlidInfo['supported']) {
@@ -403,8 +402,8 @@ public static function getDownloadKeyExistsSites(bool $exists = true, $onlyEnabl
403402
$extensions = array_filter($extensions, $filterClosure);
404403

405404
// Return only the update site IDs
406-
$mapClosure = function (CMSObject $extension) {
407-
return $extension->get('update_site_id');
405+
$mapClosure = function ($extension) {
406+
return $extension->update_site_id ?? null;
408407
};
409408

410409
return array_map($mapClosure, $extensions);
@@ -416,7 +415,7 @@ public static function getDownloadKeyExistsSites(bool $exists = true, $onlyEnabl
416415
*
417416
* @param bool $onlyEnabled Only return enabled update sites
418417
*
419-
* @return CMSObject[] List of update site and linked extension information
418+
* @return \stdClass[] List of update site and linked extension information
420419
* @since 4.0.0
421420
*/
422421
protected static function getUpdateSitesInformation(bool $onlyEnabled): array
@@ -473,14 +472,9 @@ protected static function getUpdateSitesInformation(bool $onlyEnabled): array
473472

474473
// Try to get all of the update sites, including related extension information
475474
try {
476-
$items = [];
477475
$db->setQuery($query);
478476

479-
foreach ($db->getIterator() as $item) {
480-
$items[] = new CMSObject($item);
481-
}
482-
483-
return $items;
477+
return $db->loadObjectList();
484478
} catch (\Exception $e) {
485479
return [];
486480
}

administrator/components/com_installer/src/Model/UpdatesiteModel.php

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

1313
use Joomla\CMS\Form\Form;
1414
use Joomla\CMS\MVC\Model\AdminModel;
15-
use Joomla\CMS\Object\CMSObject;
1615
use Joomla\Component\Installer\Administrator\Helper\InstallerHelper;
1716
use Joomla\Database\ParameterType;
1817

@@ -87,7 +86,7 @@ public function getItem($pk = null)
8786
$item = parent::getItem($pk);
8887

8988
$db = $this->getDatabase();
90-
$updateSiteId = (int) $item->get('update_site_id');
89+
$updateSiteId = (int) $item->update_site_id ?? 0;
9190
$query = $db->getQuery(true)
9291
->select(
9392
$db->quoteName(
@@ -116,13 +115,13 @@ public function getItem($pk = null)
116115
->bind(':updatesiteid', $updateSiteId, ParameterType::INTEGER);
117116

118117
$db->setQuery($query);
119-
$extension = new CMSObject($db->loadAssoc());
118+
$extension = $db->loadObject();
120119

121120
$downloadKey = InstallerHelper::getDownloadKey($extension);
122121

123-
$item->set('extra_query', $downloadKey['value'] ?? '');
124-
$item->set('downloadIdPrefix', $downloadKey['prefix'] ?? '');
125-
$item->set('downloadIdSuffix', $downloadKey['suffix'] ?? '');
122+
$item->extra_query = $downloadKey['value'] ?? '';
123+
$item->downloadIdPrefix = $downloadKey['prefix'] ?? '';
124+
$item->downloadIdSuffix = $downloadKey['suffix'] ?? '';
126125

127126
return $item;
128127
}

administrator/components/com_installer/src/Model/UpdatesitesModel.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Joomla\CMS\Installer\Installer;
1515
use Joomla\CMS\Language\Text;
1616
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
17-
use Joomla\CMS\Object\CMSObject;
1817
use Joomla\CMS\Plugin\PluginHelper;
1918
use Joomla\CMS\Router\Route;
2019
use Joomla\CMS\Table\UpdateSite as UpdateSiteTable;
@@ -444,8 +443,7 @@ public function getItems()
444443
array_walk(
445444
$items,
446445
static function ($item) {
447-
$data = new CMSObject($item);
448-
$item->downloadKey = InstallerHelper::getDownloadKey($data);
446+
$item->downloadKey = InstallerHelper::getDownloadKey($item);
449447
}
450448
);
451449

administrator/components/com_installer/src/View/Update/HtmlView.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Joomla\CMS\Application\CMSApplication;
1414
use Joomla\CMS\Factory;
1515
use Joomla\CMS\Language\Text;
16-
use Joomla\CMS\Object\CMSObject;
1716
use Joomla\Component\Installer\Administrator\Helper\InstallerHelper as CmsInstallerHelper;
1817
use Joomla\Component\Installer\Administrator\Model\UpdateModel;
1918
use Joomla\Component\Installer\Administrator\View\Installer\HtmlView as InstallerViewDefault;
@@ -32,7 +31,7 @@ class HtmlView extends InstallerViewDefault
3231
/**
3332
* List of update items.
3433
*
35-
* @var array
34+
* @var \stdClass[]
3635
*/
3736
protected $items;
3837

@@ -105,7 +104,7 @@ public function display($tpl = null)
105104
}
106105

107106
$mappingCallback = function ($item) {
108-
$dlkeyInfo = CmsInstallerHelper::getDownloadKey(new CMSObject($item));
107+
$dlkeyInfo = CmsInstallerHelper::getDownloadKey($item);
109108
$item->isMissingDownloadKey = $dlkeyInfo['supported'] && !$dlkeyInfo['valid'];
110109

111110
if ($item->isMissingDownloadKey) {

administrator/components/com_languages/src/Model/LanguageModel.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Joomla\CMS\Language\Text;
1717
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
1818
use Joomla\CMS\MVC\Model\AdminModel;
19-
use Joomla\CMS\Object\CMSObject;
2019
use Joomla\CMS\Plugin\PluginHelper;
2120
use Joomla\CMS\Table\Language;
2221
use Joomla\CMS\Table\Table;
@@ -128,7 +127,7 @@ public function getItem($langId = null)
128127
}
129128

130129
$properties = $table->getProperties(1);
131-
$value = ArrayHelper::toObject($properties, CMSObject::class);
130+
$value = ArrayHelper::toObject($properties);
132131

133132
return $value;
134133
}

administrator/components/com_mails/src/Model/TemplateModel.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Joomla\CMS\Language\LanguageHelper;
1717
use Joomla\CMS\Language\Text;
1818
use Joomla\CMS\MVC\Model\AdminModel;
19-
use Joomla\CMS\Object\CMSObject;
2019
use Joomla\CMS\Table\Table;
2120
use Joomla\Filesystem\Path;
2221
use Joomla\Registry\Registry;
@@ -176,9 +175,9 @@ public function getItem($pk = null)
176175
}
177176
}
178177

179-
// Convert to the CMSObject before adding other data.
178+
// Convert to an object before adding other data.
180179
$properties = $table->getProperties(1);
181-
$item = ArrayHelper::toObject($properties, CMSObject::class);
180+
$item = ArrayHelper::toObject($properties);
182181

183182
if (property_exists($item, 'params')) {
184183
$registry = new Registry($item->params);
@@ -222,9 +221,9 @@ public function getMaster($pk = null)
222221
}
223222
}
224223

225-
// Convert to the CMSObject before adding other data.
224+
// Convert to an object before adding other data.
226225
$properties = $table->getProperties(1);
227-
$item = ArrayHelper::toObject($properties, CMSObject::class);
226+
$item = ArrayHelper::toObject($properties);
228227

229228
if (property_exists($item, 'params')) {
230229
$registry = new Registry($item->params);

administrator/components/com_mails/src/View/Template/HtmlView.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
use Joomla\CMS\Language\Text;
1515
use Joomla\CMS\MVC\View\GenericDataException;
1616
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
17-
use Joomla\CMS\Object\CMSObject;
18-
use Joomla\CMS\Toolbar\Toolbar;
1917
use Joomla\CMS\Toolbar\ToolbarHelper;
2018
use Joomla\Component\Mails\Administrator\Helper\MailsHelper;
2119
use Joomla\Component\Mails\Administrator\Model\TemplateModel;
@@ -62,7 +60,7 @@ class HtmlView extends BaseHtmlView
6260
/**
6361
* Master data for the mail template
6462
*
65-
* @var CMSObject
63+
* @var \stdClass
6664
*/
6765
protected $master;
6866

0 commit comments

Comments
 (0)