Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.0] Removing CMSObject from most of the codebase #44655

Open
wants to merge 13 commits into
base: 6.0-dev
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@
use Joomla\CMS\Date\Date;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Object\CMSObject;
use Joomla\CMS\Router\Route;
use Joomla\Filesystem\Path;
use Joomla\String\StringHelper;
@@ -232,7 +231,7 @@ public static function getHumanReadableLogMessage($log, $generateLinks = true)
* @param string $contentType
* @param integer $id
* @param string $urlVar
* @param CMSObject $object
* @param \stdClass $object
*
* @return string Link to the content item
*
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@
use Joomla\CMS\Language\Text;
use Joomla\CMS\Log\Log;
use Joomla\CMS\MVC\Model\AdminModel;
use Joomla\CMS\Object\CMSObject;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Component\Guidedtours\Administrator\Helper\GuidedtoursHelper;
use Joomla\Database\ParameterType;
@@ -221,9 +220,9 @@ public function getItem($pk = null)
return false;
}

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

if (property_exists($item, 'params')) {
$registry = new Registry($item->params);
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@
use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Object\CMSObject;
use Joomla\Database\DatabaseInterface;
use Joomla\Database\ParameterType;

@@ -233,19 +232,19 @@ public static function getInstallationXML(
/**
* Get the download key of an extension going through their installation xml
*
* @param CMSObject $extension element of an extension
* @param \stdClass $extension element of an extension
*
* @return array An array with the prefix, suffix and value of the download key
*
* @since 4.0.0
*/
public static function getDownloadKey(CMSObject $extension): array
public static function getDownloadKey(\stdClass $extension): array
{
$installXmlFile = self::getInstallationXML(
$extension->get('element'),
$extension->get('type'),
$extension->get('client_id'),
$extension->get('folder')
$extension->element,
$extension->type,
$extension->client_id,
$extension->folder
);

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

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

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

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

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

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

$filterClosure = function (CMSObject $extension) {
$filterClosure = function ($extension) {
$dlidInfo = self::getDownloadKey($extension);

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

$mapClosure = function (CMSObject $extension) {
return $extension->get('update_site_id');
$mapClosure = function ($extension) {
return $extension->update_site_id ?? null;
};

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

// Filter the extensions by what supports Download Keys
$filterClosure = function (CMSObject $extension) use ($exists) {
$filterClosure = function ($extension) use ($exists) {
$dlidInfo = self::getDownloadKey($extension);

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

// Return only the update site IDs
$mapClosure = function (CMSObject $extension) {
return $extension->get('update_site_id');
$mapClosure = function ($extension) {
return $extension->update_site_id ?? null;
};

return array_map($mapClosure, $extensions);
@@ -416,7 +415,7 @@ public static function getDownloadKeyExistsSites(bool $exists = true, $onlyEnabl
*
* @param bool $onlyEnabled Only return enabled update sites
*
* @return CMSObject[] List of update site and linked extension information
* @return \stdClass[] List of update site and linked extension information
* @since 4.0.0
*/
protected static function getUpdateSitesInformation(bool $onlyEnabled): array
@@ -473,12 +472,8 @@ protected static function getUpdateSitesInformation(bool $onlyEnabled): array

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

foreach ($db->getIterator() as $item) {
$items[] = new CMSObject($item);
}
$items = $db->loadObjectList();

return $items;
} catch (\Exception $e) {
Original file line number Diff line number Diff line change
@@ -12,7 +12,6 @@

use Joomla\CMS\Form\Form;
use Joomla\CMS\MVC\Model\AdminModel;
use Joomla\CMS\Object\CMSObject;
use Joomla\Component\Installer\Administrator\Helper\InstallerHelper;
use Joomla\Database\ParameterType;

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

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

$db->setQuery($query);
$extension = new CMSObject($db->loadAssoc());
$extension = $db->loadObject();

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

$item->set('extra_query', $downloadKey['value'] ?? '');
$item->set('downloadIdPrefix', $downloadKey['prefix'] ?? '');
$item->set('downloadIdSuffix', $downloadKey['suffix'] ?? '');
$item->extra_query = $downloadKey['value'] ?? '';
$item->downloadIdPrefix = $downloadKey['prefix'] ?? '';
$item->downloadIdSuffix = $downloadKey['suffix'] ?? '';

return $item;
}
Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@
use Joomla\CMS\Installer\Installer;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\CMS\Object\CMSObject;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Table\UpdateSite as UpdateSiteTable;
@@ -444,8 +443,7 @@ public function getItems()
array_walk(
$items,
static function ($item) {
$data = new CMSObject($item);
$item->downloadKey = InstallerHelper::getDownloadKey($data);
$item->downloadKey = InstallerHelper::getDownloadKey($item);
}
);

Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Object\CMSObject;
use Joomla\Component\Installer\Administrator\Helper\InstallerHelper as CmsInstallerHelper;
use Joomla\Component\Installer\Administrator\Model\UpdateModel;
use Joomla\Component\Installer\Administrator\View\Installer\HtmlView as InstallerViewDefault;
@@ -32,7 +31,7 @@ class HtmlView extends InstallerViewDefault
/**
* List of update items.
*
* @var array
* @var \stdClass[]
*/
protected $items;

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

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

if ($item->isMissingDownloadKey) {
Original file line number Diff line number Diff line change
@@ -16,7 +16,6 @@
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\CMS\MVC\Model\AdminModel;
use Joomla\CMS\Object\CMSObject;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Table\Table;
use Joomla\Utilities\ArrayHelper;
@@ -127,7 +126,7 @@ public function getItem($langId = null)
}

$properties = $table->getProperties(1);
$value = ArrayHelper::toObject($properties, CMSObject::class);
$value = ArrayHelper::toObject($properties);

return $value;
}
Original file line number Diff line number Diff line change
@@ -16,7 +16,6 @@
use Joomla\CMS\Language\LanguageHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Model\AdminModel;
use Joomla\CMS\Object\CMSObject;
use Joomla\CMS\Table\Table;
use Joomla\Filesystem\Path;
use Joomla\Registry\Registry;
@@ -176,9 +175,9 @@ public function getItem($pk = null)
}
}

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

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

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

if (property_exists($item, 'params')) {
$registry = new Registry($item->params);
Original file line number Diff line number Diff line change
@@ -14,8 +14,6 @@
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Object\CMSObject;
use Joomla\CMS\Toolbar\Toolbar;
use Joomla\CMS\Toolbar\ToolbarHelper;
use Joomla\Component\Mails\Administrator\Helper\MailsHelper;
use Joomla\Component\Mails\Administrator\Model\TemplateModel;
@@ -62,7 +60,7 @@ class HtmlView extends BaseHtmlView
/**
* Master data for the mail template
*
* @var CMSObject
* @var \stdClass
*/
protected $master;

18 changes: 7 additions & 11 deletions administrator/components/com_media/helpers/media.php
Original file line number Diff line number Diff line change
@@ -10,8 +10,6 @@
* @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
*/

use Joomla\CMS\Object\CMSObject;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
@@ -26,26 +24,24 @@ abstract class MediaHelper
/**
* Generates the URL to the object in the action logs component
*
* @param string $contentType The content type
* @param integer $id The integer id
* @param CMSObject $mediaObject The media object being uploaded
* @param string $contentType The content type
* @param integer $id The integer id
* @param stdClass $mediaObject The media object being uploaded
*
* @return string The link for the action log
*
* @since 3.9.27
*/
public static function getContentTypeLink($contentType, $id, CMSObject $mediaObject)
public static function getContentTypeLink($contentType, $id, $mediaObject)
{
if ($contentType === 'com_media.file') {
return '';
}

$link = 'index.php?option=com_media';
$adapter = $mediaObject->get('adapter');
$uploadedPath = $mediaObject->get('path');
$link = 'index.php?option=com_media';

if (!empty($adapter) && !empty($uploadedPath)) {
$link .= '&path=' . $adapter . ':' . $uploadedPath;
if (!empty($mediaObject->adapter) && !empty($mediaObject->path)) {
$link .= '&path=' . $mediaObject->adapter . ':' . $mediaObject->path;
}

return $link;
5 changes: 2 additions & 3 deletions administrator/components/com_menus/src/Model/MenuModel.php
Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
use Joomla\CMS\MVC\Model\AdminModel;
use Joomla\CMS\Object\CMSObject;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Table\Table;
use Joomla\Registry\Registry;
@@ -121,7 +120,7 @@ protected function populateState()
*
* @param integer $itemId The id of the menu item to get.
*
* @return mixed Menu item data object on success, false on failure.
* @return \stdClass|false Menu item data object on success, false on failure.
*
* @since 1.6
*/
@@ -143,7 +142,7 @@ public function getItem($itemId = null)
}

$properties = $table->getProperties(1);
$value = ArrayHelper::toObject($properties, CMSObject::class);
$value = ArrayHelper::toObject($properties);

return $value;
}
Loading