refactor: replace Joomla-7-deprecated APIs (forward compatibility)
Removes accessors deprecated in Joomla 5 and slated for removal in 7
(extension already runs on 6; this future-proofs for 7):
- Factory::getDbo() -> Factory::getContainer()->get(DatabaseInterface::class)
across plugins, controllers, static helpers, and the install script
- Factory::getUser() -> Factory::getApplication()->getIdentity()
- Factory::getSession() -> Factory::getApplication()->getSession()
- jexit(Text::_('JINVALID_TOKEN')) -> throw new \RuntimeException(..., 403),
consistent with the access-denied checks already in those controllers
Note: SQL update-version concern is already resolved — the release bumped
to 01.05.00, which matches the 01.05.00.sql update slot.
This commit is contained in:
@@ -47,7 +47,7 @@ class TagsController extends ApiController
|
||||
throw new \RuntimeException('content_type and content_id are required', 400);
|
||||
}
|
||||
|
||||
$db = Factory::getDbo();
|
||||
$db = Factory::getContainer()->get(\Joomla\Database\DatabaseInterface::class);
|
||||
$query = $db->getQuery(true)
|
||||
->select($db->quoteName('id'))
|
||||
->from($db->quoteName('#__mokoog_tags'))
|
||||
|
||||
@@ -27,13 +27,13 @@ class BatchController extends BaseController
|
||||
*/
|
||||
public function count(): void
|
||||
{
|
||||
Session::checkToken('get') || jexit(Text::_('JINVALID_TOKEN'));
|
||||
Session::checkToken('get') || throw new \RuntimeException(Text::_('JINVALID_TOKEN'), 403);
|
||||
|
||||
if (!Factory::getApplication()->getIdentity()->authorise('core.create', 'com_mokoog')) {
|
||||
throw new \RuntimeException(Text::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403);
|
||||
}
|
||||
|
||||
$db = Factory::getDbo();
|
||||
$db = Factory::getContainer()->get(\Joomla\Database\DatabaseInterface::class);
|
||||
$query = $db->getQuery(true)
|
||||
->select('COUNT(*)')
|
||||
->from($db->quoteName('#__content', 'c'))
|
||||
@@ -60,7 +60,7 @@ class BatchController extends BaseController
|
||||
*/
|
||||
public function process(): void
|
||||
{
|
||||
Session::checkToken('get') || jexit(Text::_('JINVALID_TOKEN'));
|
||||
Session::checkToken('get') || throw new \RuntimeException(Text::_('JINVALID_TOKEN'), 403);
|
||||
|
||||
if (!Factory::getApplication()->getIdentity()->authorise('core.create', 'com_mokoog')) {
|
||||
throw new \RuntimeException(Text::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403);
|
||||
@@ -69,7 +69,7 @@ class BatchController extends BaseController
|
||||
$app = Factory::getApplication();
|
||||
$limit = min($app->getInput()->getInt('limit', 50), 200);
|
||||
|
||||
$db = Factory::getDbo();
|
||||
$db = Factory::getContainer()->get(\Joomla\Database\DatabaseInterface::class);
|
||||
$query = $db->getQuery(true)
|
||||
->select($db->quoteName([
|
||||
'c.id', 'c.title', 'c.metadesc', 'c.introtext', 'c.fulltext', 'c.images',
|
||||
|
||||
@@ -36,14 +36,14 @@ class ImportExportController extends BaseController
|
||||
*/
|
||||
public function export(): void
|
||||
{
|
||||
Session::checkToken('get') || jexit(Text::_('JINVALID_TOKEN'));
|
||||
Session::checkToken('get') || throw new \RuntimeException(Text::_('JINVALID_TOKEN'), 403);
|
||||
|
||||
if (!Factory::getApplication()->getIdentity()->authorise('core.manage', 'com_mokoog')) {
|
||||
throw new \RuntimeException(Text::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403);
|
||||
}
|
||||
|
||||
$app = Factory::getApplication();
|
||||
$db = Factory::getDbo();
|
||||
$db = Factory::getContainer()->get(\Joomla\Database\DatabaseInterface::class);
|
||||
|
||||
// Join with #__content to get article titles for reference
|
||||
$query = $db->getQuery(true)
|
||||
@@ -102,7 +102,7 @@ class ImportExportController extends BaseController
|
||||
*/
|
||||
public function import(): void
|
||||
{
|
||||
Session::checkToken() || jexit(Text::_('JINVALID_TOKEN'));
|
||||
Session::checkToken() || throw new \RuntimeException(Text::_('JINVALID_TOKEN'), 403);
|
||||
|
||||
$identity = Factory::getApplication()->getIdentity();
|
||||
|
||||
@@ -161,7 +161,7 @@ class ImportExportController extends BaseController
|
||||
return;
|
||||
}
|
||||
|
||||
$db = Factory::getDbo();
|
||||
$db = Factory::getContainer()->get(\Joomla\Database\DatabaseInterface::class);
|
||||
$header = fgetcsv($handle);
|
||||
$created = 0;
|
||||
$updated = 0;
|
||||
|
||||
@@ -13,7 +13,7 @@ defined('_JEXEC') or die;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Text;
|
||||
|
||||
$db = Factory::getDbo();
|
||||
$db = Factory::getContainer()->get(\Joomla\Database\DatabaseInterface::class);
|
||||
|
||||
// Total published articles
|
||||
$db->setQuery($db->getQuery(true)->select('COUNT(*)')->from('#__content')->where('state = 1'));
|
||||
|
||||
@@ -187,7 +187,7 @@ final class MokoOGContent extends CMSPlugin implements SubscriberInterface
|
||||
$contentType = $supportedContexts[$context];
|
||||
$contentId = (int) $article->id;
|
||||
|
||||
$db = Factory::getDbo();
|
||||
$db = Factory::getContainer()->get(\Joomla\Database\DatabaseInterface::class);
|
||||
$query = $db->getQuery(true)
|
||||
->delete($db->quoteName('#__mokoog_tags'))
|
||||
->where($db->quoteName('content_type') . ' = ' . $db->quote($contentType))
|
||||
@@ -208,7 +208,7 @@ final class MokoOGContent extends CMSPlugin implements SubscriberInterface
|
||||
*/
|
||||
private function loadOgData(string $contentType, int $contentId, string $language = '*'): ?object
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
$db = Factory::getContainer()->get(\Joomla\Database\DatabaseInterface::class);
|
||||
$query = $db->getQuery(true)
|
||||
->select($db->quoteName([
|
||||
'og_title', 'og_description', 'og_image', 'og_type', 'og_video',
|
||||
@@ -239,7 +239,7 @@ final class MokoOGContent extends CMSPlugin implements SubscriberInterface
|
||||
*/
|
||||
private function saveOgData(string $contentType, int $contentId, array $ogData, string $language = '*'): void
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
$db = Factory::getContainer()->get(\Joomla\Database\DatabaseInterface::class);
|
||||
|
||||
// Check if record exists for this content + language
|
||||
$query = $db->getQuery(true)
|
||||
|
||||
@@ -241,7 +241,7 @@ final class MokoOG extends CMSPlugin implements SubscriberInterface
|
||||
|
||||
// Pinterest article:tag rich pins (from Joomla content tags)
|
||||
if ($option === 'com_content' && $view === 'article' && $id > 0) {
|
||||
$db = Factory::getDbo();
|
||||
$db = Factory::getContainer()->get(\Joomla\Database\DatabaseInterface::class);
|
||||
$tagQuery = $db->getQuery(true)
|
||||
->select($db->quoteName('t.title'))
|
||||
->from($db->quoteName('#__tags', 't'))
|
||||
@@ -467,7 +467,7 @@ final class MokoOG extends CMSPlugin implements SubscriberInterface
|
||||
return $this->loadOgDataByMenu((int) $menuItem->id) ?: $empty;
|
||||
}
|
||||
|
||||
$db = Factory::getDbo();
|
||||
$db = Factory::getContainer()->get(\Joomla\Database\DatabaseInterface::class);
|
||||
$query = $db->getQuery(true)
|
||||
->select('*')
|
||||
->from($db->quoteName('#__mokoog_tags'))
|
||||
@@ -493,7 +493,7 @@ final class MokoOG extends CMSPlugin implements SubscriberInterface
|
||||
*/
|
||||
private function loadOgDataByType(string $contentType, int $contentId): ?object
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
$db = Factory::getContainer()->get(\Joomla\Database\DatabaseInterface::class);
|
||||
$lang = Factory::getLanguage()->getTag();
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
@@ -520,7 +520,7 @@ final class MokoOG extends CMSPlugin implements SubscriberInterface
|
||||
*/
|
||||
private function loadOgDataByMenu(int $menuId): ?object
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
$db = Factory::getContainer()->get(\Joomla\Database\DatabaseInterface::class);
|
||||
$lang = Factory::getLanguage()->getTag();
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
@@ -615,7 +615,7 @@ final class MokoOG extends CMSPlugin implements SubscriberInterface
|
||||
|
||||
// Fallback: check the article's category for an image
|
||||
if ($view === 'article') {
|
||||
$db = Factory::getDbo();
|
||||
$db = Factory::getContainer()->get(\Joomla\Database\DatabaseInterface::class);
|
||||
$catQuery = $db->getQuery(true)
|
||||
->select($db->quoteName('cat.params'))
|
||||
->from($db->quoteName('#__categories', 'cat'))
|
||||
@@ -674,7 +674,7 @@ final class MokoOG extends CMSPlugin implements SubscriberInterface
|
||||
return $cache[$id];
|
||||
}
|
||||
|
||||
$db = Factory::getDbo();
|
||||
$db = Factory::getContainer()->get(\Joomla\Database\DatabaseInterface::class);
|
||||
$query = $db->getQuery(true)
|
||||
->select($db->quoteName([
|
||||
'a.title', 'a.introtext', 'a.fulltext', 'a.images',
|
||||
@@ -947,20 +947,20 @@ final class MokoOG extends CMSPlugin implements SubscriberInterface
|
||||
*/
|
||||
private function warnMissingLicenseKey(): void
|
||||
{
|
||||
$session = Factory::getSession();
|
||||
$session = Factory::getApplication()->getSession();
|
||||
|
||||
if ($session->get('mokoog.license_warned', false)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$user = Factory::getUser();
|
||||
$user = Factory::getApplication()->getIdentity();
|
||||
|
||||
if ($user->guest || !$user->authorise('core.manage')) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$db = Factory::getDbo();
|
||||
$db = Factory::getContainer()->get(\Joomla\Database\DatabaseInterface::class);
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
->select($db->quoteName('extra_query'))
|
||||
@@ -1011,7 +1011,7 @@ final class MokoOG extends CMSPlugin implements SubscriberInterface
|
||||
}
|
||||
|
||||
try {
|
||||
$db = Factory::getDbo();
|
||||
$db = Factory::getContainer()->get(\Joomla\Database\DatabaseInterface::class);
|
||||
$query = $db->getQuery(true)
|
||||
->select('p.id, p.sku, p.price, p.currency, p.stock_qty')
|
||||
->select('c.title AS name, c.introtext AS description, c.images')
|
||||
|
||||
@@ -37,7 +37,7 @@ class JsonLdBuilder
|
||||
$article = $cachedArticle;
|
||||
|
||||
if (!$article) {
|
||||
$db = Factory::getDbo();
|
||||
$db = Factory::getContainer()->get(\Joomla\Database\DatabaseInterface::class);
|
||||
$query = $db->getQuery(true)
|
||||
->select($db->quoteName([
|
||||
'a.created', 'a.modified', 'a.publish_up',
|
||||
@@ -179,7 +179,7 @@ class JsonLdBuilder
|
||||
$product = $cachedProduct;
|
||||
|
||||
if (!$product) {
|
||||
$db = Factory::getDbo();
|
||||
$db = Factory::getContainer()->get(\Joomla\Database\DatabaseInterface::class);
|
||||
$query = $db->getQuery(true)
|
||||
->select('p.sku, p.price, p.currency, p.stock_qty')
|
||||
->from($db->quoteName('#__mokosuite_crm_products', 'p'))
|
||||
|
||||
@@ -35,7 +35,7 @@ class SitemapBuilder
|
||||
$allowed = ['always', 'hourly', 'daily', 'weekly', 'monthly', 'yearly', 'never'];
|
||||
$changefreq = \in_array($changefreq, $allowed, true) ? $changefreq : 'weekly';
|
||||
|
||||
$db = Factory::getDbo();
|
||||
$db = Factory::getContainer()->get(\Joomla\Database\DatabaseInterface::class);
|
||||
|
||||
// Get all published articles
|
||||
$query = $db->getQuery(true)
|
||||
|
||||
+4
-4
@@ -55,7 +55,7 @@ class Pkg_MokoOGInstallerScript
|
||||
|
||||
if ($type === 'install')
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
$db = Factory::getContainer()->get(\Joomla\Database\DatabaseInterface::class);
|
||||
|
||||
foreach (['system', 'content', 'webservices'] as $folder)
|
||||
{
|
||||
@@ -79,7 +79,7 @@ class Pkg_MokoOGInstallerScript
|
||||
{
|
||||
try
|
||||
{
|
||||
$db = \Joomla\CMS\Factory::getDbo();
|
||||
$db = \Joomla\CMS\Factory::getContainer()->get(\Joomla\Database\DatabaseInterface::class);
|
||||
$db->setQuery(
|
||||
$db->getQuery(true)
|
||||
->select($db->quoteName('us.extra_query'))
|
||||
@@ -103,7 +103,7 @@ class Pkg_MokoOGInstallerScript
|
||||
|
||||
try
|
||||
{
|
||||
$db = \Joomla\CMS\Factory::getDbo();
|
||||
$db = \Joomla\CMS\Factory::getContainer()->get(\Joomla\Database\DatabaseInterface::class);
|
||||
$db->setQuery(
|
||||
$db->getQuery(true)
|
||||
->select($db->quoteName('us.update_site_id'))
|
||||
@@ -133,7 +133,7 @@ class Pkg_MokoOGInstallerScript
|
||||
{
|
||||
try
|
||||
{
|
||||
$db = \Joomla\CMS\Factory::getDbo();
|
||||
$db = \Joomla\CMS\Factory::getContainer()->get(\Joomla\Database\DatabaseInterface::class);
|
||||
$db->setQuery(
|
||||
$db->getQuery(true)
|
||||
->select([$db->quoteName('update_site_id'), $db->quoteName('extra_query')])
|
||||
|
||||
Reference in New Issue
Block a user