Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,16 @@ public function purge()
// Purge updates
/** @var \Joomla\Component\Joomlaupdate\Administrator\Model\UpdateModel $model */
$model = $this->getModel('Update');
$model->purge();
$result = $model->purge();

if ($result) {
$message = Text::_('COM_JOOMLAUPDATE_CHECKED_UPDATES');
} else {
$message = Text::_('COM_JOOMLAUPDATE_FAILED_TO_CHECK_UPDATES');
}

$url = 'index.php?option=com_joomlaupdate';
$this->setRedirect($url, $model->_message);
$this->setRedirect($url, $message);
}

/**
Expand Down
31 changes: 10 additions & 21 deletions administrator/components/com_joomlaupdate/src/Model/UpdateModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function applyUpdateSite(?string $updateSource = null, ?string $updateURL
$updateType = (pathinfo($updateURL, PATHINFO_EXTENSION) === 'xml') ? 'collection' : 'tuf';

$id = ExtensionHelper::getExtensionRecord('joomla', 'file')->extension_id;
$db = version_compare(JVERSION, '4.2.0', 'lt') ? $this->getDbo() : $this->getDatabase();
$db = $this->getDatabase();
$query = $db->createQuery()
->select($db->quoteName('us') . '.*')
->from($db->quoteName('#__update_sites_extensions', 'map'))
Expand Down Expand Up @@ -200,7 +200,7 @@ public function refreshUpdates($force = false)
*/
public function getCheckForSelfUpdate()
{
$db = version_compare(JVERSION, '4.2.0', 'lt') ? $this->getDbo() : $this->getDatabase();
$db = $this->getDatabase();

$query = $db->createQuery()
->select($db->quoteName('extension_id'))
Expand Down Expand Up @@ -271,7 +271,7 @@ public function getUpdateInformation()

// Fetch the update information from the database.
$id = ExtensionHelper::getExtensionRecord('joomla', 'file')->extension_id;
$db = version_compare(JVERSION, '4.2.0', 'lt') ? $this->getDbo() : $this->getDatabase();
$db = $this->getDatabase();
$query = $db->createQuery()
->select('*')
->from($db->quoteName('#__updates'))
Expand Down Expand Up @@ -343,7 +343,7 @@ public function getUpdateInformation()
*/
public function purge()
{
$db = version_compare(JVERSION, '4.2.0', 'lt') ? $this->getDbo() : $this->getDatabase();
$db = $this->getDatabase();

// Modify the database record
$update_site = new \stdClass();
Expand All @@ -357,15 +357,7 @@ public function purge()
->where($db->quoteName('update_site_id') . ' = 1');
$db->setQuery($query);

if ($db->execute()) {
$this->_message = Text::_('COM_JOOMLAUPDATE_CHECKED_UPDATES');

return true;
}

$this->_message = Text::_('COM_JOOMLAUPDATE_FAILED_TO_CHECK_UPDATES');

return false;
return $db->execute();
}

/**
Expand Down Expand Up @@ -944,7 +936,7 @@ public function finaliseUpgrade()
$installer->setUpgrade(true);
$installer->setOverwrite(true);

$db = version_compare(JVERSION, '4.2.0', 'lt') ? $this->getDbo() : $this->getDatabase();
$db = $this->getDatabase();
$installer->extension = new \Joomla\CMS\Table\Extension($db);
$installer->extension->load(ExtensionHelper::getExtensionRecord('joomla', 'file')->extension_id);

Expand Down Expand Up @@ -983,9 +975,6 @@ public function finaliseUpgrade()
return false;
}

// Get a database connector object.
$db = version_compare(JVERSION, '4.2.0', 'lt') ? $this->getDbo() : $this->getDatabase();

/*
* Check to see if a file extension by the same name is already installed.
* If it is, then update the table because if the files aren't there
Expand Down Expand Up @@ -1700,7 +1689,7 @@ private function getDatabaseSchemaCheck(): bool
*/
public function getNonCoreExtensions()
{
$db = version_compare(JVERSION, '4.2.0', 'lt') ? $this->getDbo() : $this->getDatabase();
$db = $this->getDatabase();
$query = $db->createQuery();

$query->select(
Expand Down Expand Up @@ -1748,7 +1737,7 @@ public function getNonCoreExtensions()
*/
public function getNonCorePlugins($folderFilter = ['system', 'user', 'authentication', 'actionlog', 'multifactorauth'])
{
$db = version_compare(JVERSION, '4.2.0', 'lt') ? $this->getDbo() : $this->getDatabase();
$db = $this->getDatabase();
$query = $db->createQuery();

$query->select(
Expand Down Expand Up @@ -1847,7 +1836,7 @@ public function fetchCompatibility($extensionID, $joomlaTargetVersion)
private function getUpdateSitesInfo($extensionID)
{
$id = (int) $extensionID;
$db = version_compare(JVERSION, '4.2.0', 'lt') ? $this->getDbo() : $this->getDatabase();
$db = $this->getDatabase();
$query = $db->createQuery();

$query->select(
Expand Down Expand Up @@ -2035,7 +2024,7 @@ protected function translateExtensionName(&$item)
*/
public function isTemplateActive($template)
{
$db = version_compare(JVERSION, '4.2.0', 'lt') ? $this->getDbo() : $this->getDatabase();
$db = $this->getDatabase();
$query = $db->createQuery();

$query->select(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace Joomla\Component\Workflow\Administrator\Controller;

use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\FormController;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
Expand Down Expand Up @@ -183,7 +184,7 @@ public function postSaveHook(BaseDatabaseModel $model, $validData = [])
$recordId = (int) $this->input->getInt($key);

// @todo Moves queries out of the controller.
$db = $model->getDbo();
$db = Factory::getDbo();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to move the whole logic with database access to the model.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but that is a bit outside of the scope of this PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then load it from the container at least.

$query = $db->createQuery();

$query->select('*')
Expand Down
53 changes: 1 addition & 52 deletions libraries/src/MVC/Model/BaseDatabaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ public function __construct($config = [], ?MVCFactoryInterface $factory = null)
if ($db) {
@trigger_error('Database is not available in constructor in 6.0.', E_USER_DEPRECATED);
$this->setDatabase($db);

// Is needed, when models use the deprecated MVC DatabaseAwareTrait, as the trait is overriding the local functions
$this->setDbo($db);
}

// Set the default view search path
Expand Down Expand Up @@ -394,7 +391,7 @@ protected function dispatchEvent(EventInterface $event)
* @since 4.2.0
* @throws \UnexpectedValueException
*
* @deprecated 4.3 will be removed in 7.0
* @deprecated 4.3 will be removed in 8.0
* Use getDatabase() instead
* Example: $model->getDatabase();
*/
Expand All @@ -406,52 +403,4 @@ public function getDbo()
throw new \UnexpectedValueException('Database driver not set in ' . __CLASS__);
}
}

/**
* Set the database driver.
*
* @param ?DatabaseInterface $db The database driver.
*
* @return void
*
* @since 4.2.0
*
* @deprecated 4.3 will be removed in 7.0
* Use setDatabase() instead
* Example: $model->setDatabase($db);
*/
public function setDbo(?DatabaseInterface $db = null)
{
if ($db === null) {
return;
}

$this->setDatabase($db);
}

/**
* Proxy for _db variable.
*
* @param string $name The name of the element
*
* @return mixed The value of the element if set, null otherwise
*
* @since 4.2.0
*
* @deprecated 4.3 will be removed in 7.0
* Use getDatabase() instead of directly accessing _db
*/
public function __get($name)
{
if ($name === '_db') {
return $this->getDatabase();
}

// Default the variable
if (!isset($this->$name)) {
$this->$name = null;
}

return $this->$name;
}
}
Loading