2024-03-06 15:01:57 +03:00
|
|
|
<?php
|
2024-03-09 18:57:05 +03:00
|
|
|
/**
|
|
|
|
* @package Joomla.Administrator
|
|
|
|
* @subpackage com_oauthserver
|
|
|
|
*
|
|
|
|
* @copyright (c) 2024. Webmasterskaya. <https://webmasterskaya.xyz>
|
|
|
|
* @license MIT; see LICENSE.txt
|
|
|
|
**/
|
2024-03-06 15:01:57 +03:00
|
|
|
|
|
|
|
namespace Webmasterskaya\Component\OauthServer\Administrator\Table;
|
|
|
|
|
|
|
|
use Joomla\CMS\Event\AbstractEvent;
|
|
|
|
use Joomla\CMS\Language\Text;
|
2024-03-09 18:57:05 +03:00
|
|
|
|
|
|
|
\defined('_JEXEC') or die;
|
2024-03-06 15:01:57 +03:00
|
|
|
|
|
|
|
trait RevokedTableTrait
|
|
|
|
{
|
2024-03-07 03:59:12 +03:00
|
|
|
public function revoke($pks = null): bool
|
2024-03-06 15:01:57 +03:00
|
|
|
{
|
|
|
|
// Pre-processing by observers
|
|
|
|
$event = AbstractEvent::create(
|
|
|
|
'onTableBeforeRevoke',
|
|
|
|
[
|
|
|
|
'subject' => $this,
|
2024-03-09 18:57:05 +03:00
|
|
|
'pks' => $pks,
|
2024-03-06 15:01:57 +03:00
|
|
|
]
|
|
|
|
);
|
|
|
|
$this->getDispatcher()->dispatch('onTableBeforeRevoke', $event);
|
|
|
|
|
2024-03-09 18:57:05 +03:00
|
|
|
if (!\is_null($pks))
|
|
|
|
{
|
|
|
|
if (!\is_array($pks))
|
|
|
|
{
|
2024-03-06 15:01:57 +03:00
|
|
|
$pks = [$pks];
|
|
|
|
}
|
|
|
|
|
2024-03-09 18:57:05 +03:00
|
|
|
foreach ($pks as $key => $pk)
|
|
|
|
{
|
|
|
|
if (!\is_array($pk))
|
|
|
|
{
|
2024-03-06 15:01:57 +03:00
|
|
|
$pks[$key] = [$this->_tbl_key => $pk];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there are no primary keys set check to see if the instance key is set.
|
2024-03-09 18:57:05 +03:00
|
|
|
if (empty($pks))
|
|
|
|
{
|
2024-03-06 15:01:57 +03:00
|
|
|
$pk = [];
|
|
|
|
|
2024-03-09 18:57:05 +03:00
|
|
|
foreach ($this->_tbl_keys as $key)
|
|
|
|
{
|
|
|
|
if ($this->$key)
|
|
|
|
{
|
2024-03-06 15:01:57 +03:00
|
|
|
$pk[$key] = $this->$key;
|
2024-03-09 18:57:05 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-03-06 15:01:57 +03:00
|
|
|
// We don't have a full primary key - return false
|
|
|
|
$this->setError(Text::_('JLIB_DATABASE_ERROR_NO_ROWS_SELECTED'));
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$pks = [$pk];
|
|
|
|
}
|
|
|
|
|
|
|
|
$revokedField = $this->getColumnAlias('revoked');
|
|
|
|
|
2024-03-09 18:57:05 +03:00
|
|
|
foreach ($pks as $pk)
|
|
|
|
{
|
2024-03-06 15:01:57 +03:00
|
|
|
$query = $this->_db->getQuery(true)
|
|
|
|
->update($this->_db->quoteName($this->_tbl))
|
|
|
|
->set($this->_db->quoteName($revokedField) . ' = 0');
|
|
|
|
|
|
|
|
// Build the WHERE clause for the primary keys.
|
|
|
|
$this->appendPrimaryKeys($query, $pk);
|
|
|
|
|
|
|
|
$this->_db->setQuery($query);
|
|
|
|
|
2024-03-09 18:57:05 +03:00
|
|
|
try
|
|
|
|
{
|
2024-03-06 15:01:57 +03:00
|
|
|
$this->_db->execute();
|
2024-03-09 18:57:05 +03:00
|
|
|
}
|
|
|
|
catch (\RuntimeException $e)
|
|
|
|
{
|
2024-03-06 15:01:57 +03:00
|
|
|
$this->setError($e->getMessage());
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the Table instance value is in the list of primary keys that were set, set the instance.
|
|
|
|
$ours = true;
|
|
|
|
|
2024-03-09 18:57:05 +03:00
|
|
|
foreach ($this->_tbl_keys as $key)
|
|
|
|
{
|
|
|
|
if ($this->$key != $pk[$key])
|
|
|
|
{
|
2024-03-06 15:01:57 +03:00
|
|
|
$ours = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-09 18:57:05 +03:00
|
|
|
if ($ours)
|
|
|
|
{
|
2024-03-06 15:01:57 +03:00
|
|
|
$this->$revokedField = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->setError('');
|
|
|
|
|
|
|
|
// Pre-processing by observers
|
|
|
|
$event = AbstractEvent::create(
|
|
|
|
'onTableAfterRevoke',
|
|
|
|
[
|
|
|
|
'subject' => $this,
|
2024-03-09 18:57:05 +03:00
|
|
|
'pks' => $pks
|
2024-03-06 15:01:57 +03:00
|
|
|
]
|
|
|
|
);
|
|
|
|
$this->getDispatcher()->dispatch('onTableAfterRevoke', $event);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2024-03-09 18:57:05 +03:00
|
|
|
|
2024-03-11 00:17:23 +03:00
|
|
|
abstract public function getDbo();
|
|
|
|
|
2024-03-09 18:57:05 +03:00
|
|
|
abstract public function getDispatcher();
|
|
|
|
|
|
|
|
abstract public function setError($error);
|
|
|
|
|
|
|
|
abstract public function getColumnAlias($column);
|
|
|
|
|
|
|
|
abstract public function appendPrimaryKeys($query, $pk = null);
|
|
|
|
}
|