5 use Doctrine\DBAL\ArrayParameterType;
6 use Doctrine\DBAL\Connection;
7 use Doctrine\DBAL\ParameterType;
8 use Doctrine\DBAL\Query\Expression\CompositeExpression;
9 use Doctrine\DBAL\Query\QueryBuilder as DbalQueryBuilder;
45 public function __construct(
protected readonly Connection $backup_connection) {
46 parent::__construct($backup_connection);
57 return $this->backup_connection;
85 $alias = $this->getTableAlias();
88 $expr = $clause->prepare($this, $alias);
89 if ($clause instanceof
WhereClause && ($expr instanceof CompositeExpression || is_string($expr))) {
90 $this->andWhere($expr);
105 if ($prefix ===
'') {
109 if (!str_starts_with(
$table, $prefix)) {
110 return "{$prefix}{$table}";
122 return (string) $this->table_name;
131 return $this->table_alias;
146 $parameters = $this->getParameters();
147 $key =
':qb' . (count($parameters) + 1);
153 $type = ParameterType::INTEGER;
158 $type = ParameterType::INTEGER;
162 $type = ParameterType::INTEGER;
166 $type = ParameterType::INTEGER;
171 $type = ParameterType::STRING;
176 $type = ParameterType::INTEGER;
183 if (count(
$value) === 1) {
186 if (
$type === ParameterType::INTEGER) {
187 $type = ArrayParameterType::INTEGER;
189 $type = ArrayParameterType::STRING;
202 public function execute(
bool $track_query =
true) {
204 if ($this instanceof
Select) {
205 return parent::executeQuery();
207 return parent::executeStatement();
212 if ($this instanceof
Select) {
213 return parent::executeQuery();
215 return parent::executeStatement();
225 public function from(
string $table, ?
string $alias =
null): self {
226 $this->table_name =
$table;
227 $this->table_alias = $alias;
229 return parent::from($this->prefix(
$table), $alias);
238 $this->table_name =
$table;
240 return parent::insert($this->prefix(
$table));
249 $this->table_name =
$table;
251 return parent::update($this->prefix(
$table));
259 public function delete(
string $table):
self {
260 $this->table_name =
$table;
262 return parent::delete($this->prefix(
$table));
268 public function join(
string $fromAlias,
string $join,
string $alias, ?
string $condition =
null): self {
269 return parent::join($fromAlias, $this->prefix($join), $alias, $condition);
275 public function innerJoin(
string $fromAlias,
string $join,
string $alias, ?
string $condition =
null): self {
276 return parent::innerJoin($fromAlias, $this->prefix($join), $alias, $condition);
282 public function leftJoin(
string $fromAlias,
string $join,
string $alias, ?
string $condition =
null): self {
283 return parent::leftJoin($fromAlias, $this->prefix($join), $alias, $condition);
289 public function rightJoin(
string $fromAlias,
string $join,
string $alias, ?
string $condition =
null): self {
290 return parent::rightJoin($fromAlias, $this->prefix($join), $alias, $condition);
296 public function orderBy(
string $sort, ?
string $order =
null): self {
297 if (isset($order) && !in_array(strtoupper($order), [
'ASC',
'DESC'])) {
298 throw new DomainException(
"'{$order}' is not a valid order by direction");
301 return parent::orderBy($sort, $order);
307 public function addOrderBy(
string $sort, ?
string $order =
null): self {
308 if (isset($order) && !in_array(strtoupper($order), [
'ASC',
'DESC'])) {
309 throw new DomainException(
"'{$order}' is not a valid order by direction");
312 return parent::addOrderBy($sort, $order);
323 public function merge($parts =
null, $boolean =
'AND') {
328 $parts = (array) $parts;
330 $parts = array_filter($parts,
function ($e) {
335 if (!$e instanceof CompositeExpression && !is_string($e)) {
345 if (count($parts) === 1) {
346 return array_shift($parts);
351 $parts = array_values($parts);
352 if (strtoupper($boolean) ===
'OR') {
353 return call_user_func_array([$this->expr(),
'or'], $parts);
356 return call_user_func_array([$this->expr(),
'and'], $parts);
375 public function compare(
string $x,
string $comparison, $y =
null, ?
string $type =
null, ?
bool $case_sensitive =
null) {
389 public function between(
string $x, $lower =
null, $upper =
null, ?
string $type =
null) {
392 $wheres[] = $this->compare($x,
'>=', $lower,
$type);
396 $wheres[] = $this->compare($x,
'<=', $upper,
$type);
399 return $this->merge($wheres);
410 return "qbt{$this->join_index}";
423 public function joinEntitiesTable(
string $from_alias =
'',
string $from_column =
'guid', ?
string $join_type =
'inner', ?
string $joined_alias =
null): string {
424 if (in_array($joined_alias, $this->joins)) {
425 return $joined_alias;
429 $from_column =
"{$from_alias}.{$from_column}";
432 $hash = sha1(serialize([
434 EntityTable::TABLE_NAME,
438 if (!isset($joined_alias) && !empty($this->joins[$hash])) {
439 return $this->joins[$hash];
442 $condition =
function (QueryBuilder
$qb, $joined_alias) use ($from_column) {
443 return $qb->compare(
"{$joined_alias}.guid",
'=', $from_column);
446 $clause =
new JoinClause(EntityTable::TABLE_NAME, $joined_alias, $condition, $join_type);
447 $joined_alias = $clause->prepare($this, $from_alias);
449 $this->joins[$hash] = $joined_alias;
451 return $joined_alias;
465 public function joinMetadataTable(
string $from_alias =
'',
string $from_column =
'guid',
$name =
null, ?
string $join_type =
'inner', ?
string $joined_alias =
null): string {
466 if (in_array($joined_alias, $this->joins)) {
467 return $joined_alias;
471 $from_column =
"{$from_alias}.{$from_column}";
474 $hash = sha1(serialize([
476 MetadataTable::TABLE_NAME,
481 if (!isset($joined_alias) && !empty($this->joins[$hash])) {
482 return $this->joins[$hash];
485 $condition =
function (QueryBuilder
$qb, $joined_alias) use ($from_column,
$name) {
487 $qb->compare(
"{$joined_alias}.entity_guid",
'=', $from_column),
492 $clause =
new JoinClause(MetadataTable::TABLE_NAME, $joined_alias, $condition, $join_type);
494 $joined_alias = $clause->prepare($this, $from_alias);
496 $this->joins[$hash] = $joined_alias;
498 return $joined_alias;
512 public function joinAnnotationTable(
string $from_alias =
'',
string $from_column =
'guid',
$name =
null, ?
string $join_type =
'inner', ?
string $joined_alias =
null): string {
513 if (in_array($joined_alias, $this->joins)) {
514 return $joined_alias;
518 $from_column =
"{$from_alias}.{$from_column}";
521 $hash = sha1(serialize([
523 AnnotationsTable::TABLE_NAME,
528 if (!isset($joined_alias) && !empty($this->joins[$hash])) {
529 return $this->joins[$hash];
532 $condition =
function (QueryBuilder
$qb, $joined_alias) use ($from_column,
$name) {
534 $qb->compare(
"{$joined_alias}.entity_guid",
'=', $from_column),
539 $clause =
new JoinClause(AnnotationsTable::TABLE_NAME, $joined_alias, $condition, $join_type);
541 $joined_alias = $clause->prepare($this, $from_alias);
543 $this->joins[$hash] = $joined_alias;
545 return $joined_alias;
560 public function joinRelationshipTable(
string $from_alias =
'',
string $from_column =
'guid',
$name =
null,
bool $inverse =
false, ?
string $join_type =
'inner', ?
string $joined_alias =
null): string {
561 if (in_array($joined_alias, $this->joins)) {
562 return $joined_alias;
566 $from_column =
"{$from_alias}.{$from_column}";
569 $hash = sha1(serialize([
571 RelationshipsTable::TABLE_NAME,
577 if (!isset($joined_alias) && !empty($this->joins[$hash])) {
578 return $this->joins[$hash];
581 $condition =
function (QueryBuilder
$qb, $joined_alias) use ($from_column,
$name, $inverse) {
584 $parts[] =
$qb->compare(
"{$joined_alias}.guid_one",
'=', $from_column);
586 $parts[] =
$qb->compare(
"{$joined_alias}.guid_two",
'=', $from_column);
590 return $qb->merge($parts);
593 $clause =
new JoinClause(RelationshipsTable::TABLE_NAME, $joined_alias, $condition, $join_type);
595 $joined_alias = $clause->prepare($this, $from_alias);
597 $this->joins[$hash] = $joined_alias;
599 return $joined_alias;
if(! $user||! $user->canDelete()) $name
return[ 'admin/delete_admin_notices'=>['access'=> 'admin'], 'admin/menu/save'=>['access'=> 'admin'], 'admin/plugins/activate'=>['access'=> 'admin'], 'admin/plugins/activate_all'=>['access'=> 'admin'], 'admin/plugins/deactivate'=>['access'=> 'admin'], 'admin/plugins/deactivate_all'=>['access'=> 'admin'], 'admin/plugins/set_priority'=>['access'=> 'admin'], 'admin/security/security_txt'=>['access'=> 'admin'], 'admin/security/settings'=>['access'=> 'admin'], 'admin/security/regenerate_site_secret'=>['access'=> 'admin'], 'admin/site/cache/invalidate'=>['access'=> 'admin'], 'admin/site/flush_cache'=>['access'=> 'admin'], 'admin/site/icons'=>['access'=> 'admin'], 'admin/site/set_maintenance_mode'=>['access'=> 'admin'], 'admin/site/set_robots'=>['access'=> 'admin'], 'admin/site/theme'=>['access'=> 'admin'], 'admin/site/unlock_upgrade'=>['access'=> 'admin'], 'admin/site/settings'=>['access'=> 'admin'], 'admin/upgrade'=>['access'=> 'admin'], 'admin/upgrade/reset'=>['access'=> 'admin'], 'admin/user/ban'=>['access'=> 'admin'], 'admin/user/bulk/ban'=>['access'=> 'admin'], 'admin/user/bulk/delete'=>['access'=> 'admin'], 'admin/user/bulk/unban'=>['access'=> 'admin'], 'admin/user/bulk/validate'=>['access'=> 'admin'], 'admin/user/change_email'=>['access'=> 'admin'], 'admin/user/delete'=>['access'=> 'admin'], 'admin/user/login_as'=>['access'=> 'admin'], 'admin/user/logout_as'=>[], 'admin/user/makeadmin'=>['access'=> 'admin'], 'admin/user/resetpassword'=>['access'=> 'admin'], 'admin/user/removeadmin'=>['access'=> 'admin'], 'admin/user/unban'=>['access'=> 'admin'], 'admin/user/validate'=>['access'=> 'admin'], 'annotation/delete'=>[], 'avatar/upload'=>[], 'comment/save'=>[], 'diagnostics/download'=>['access'=> 'admin'], 'entity/chooserestoredestination'=>[], 'entity/delete'=>[], 'entity/mute'=>[], 'entity/restore'=>[], 'entity/subscribe'=>[], 'entity/trash'=>[], 'entity/unmute'=>[], 'entity/unsubscribe'=>[], 'login'=>['access'=> 'logged_out'], 'logout'=>[], 'notifications/mute'=>['access'=> 'public'], 'plugins/settings/remove'=>['access'=> 'admin'], 'plugins/settings/save'=>['access'=> 'admin'], 'plugins/usersettings/save'=>[], 'register'=>['access'=> 'logged_out', 'middleware'=>[\Elgg\Router\Middleware\RegistrationAllowedGatekeeper::class,],], 'river/delete'=>[], 'settings/notifications'=>[], 'settings/notifications/subscriptions'=>[], 'user/changepassword'=>['access'=> 'public'], 'user/requestnewpassword'=>['access'=> 'public'], 'useradd'=>['access'=> 'admin'], 'usersettings/save'=>[], 'widgets/add'=>[], 'widgets/delete'=>[], 'widgets/move'=>[], 'widgets/save'=>[],]
Interface that allows resolving statements and/or extending query builder.
Utility class for building composite comparison expression.
Extends QueryBuilder with JOIN clauses.
Builds a clause from closure or composite expression.
Database abstraction query builder.
join(string $fromAlias, string $join, string $alias, ?string $condition=null)
{}
merge($parts=null, $boolean='AND')
Merges multiple composite expressions with a boolean.
joinMetadataTable(string $from_alias='', string $from_column='guid', $name=null, ?string $join_type='inner', ?string $joined_alias=null)
Join metadata table from alias and return joined table alias.
between(string $x, $lower=null, $upper=null, ?string $type=null)
Build a between clause.
getNextJoinAlias()
Get an index of the next available join alias.
joinAnnotationTable(string $from_alias='', string $from_column='guid', $name=null, ?string $join_type='inner', ?string $joined_alias=null)
Join annotations table from alias and return joined table alias.
rightJoin(string $fromAlias, string $join, string $alias, ?string $condition=null)
{}
compare(string $x, string $comparison, $y=null, ?string $type=null, ?bool $case_sensitive=null)
Build value comparison clause.
prefix(string $table)
Prefixes the table name with installation DB prefix.
leftJoin(string $fromAlias, string $join, string $alias, ?string $condition=null)
{}
subquery(string $table, ?string $alias=null)
Creates a new SelectQueryBuilder for join/where sub queries using the DB connection of the primary Qu...
joinEntitiesTable(string $from_alias='', string $from_column='guid', ?string $join_type='inner', ?string $joined_alias=null)
Join entity table from alias and return joined table alias.
param($value, string $type=ELGG_VALUE_STRING, ?string $key=null)
Sets a new parameter assigning it a unique parameter key/name if none provided Returns the name of th...
addOrderBy(string $sort, ?string $order=null)
{}
getConnection()
Returns the connection.
getTableAlias()
Returns the alias of the primary table.
from(string $table, ?string $alias=null)
{}
orderBy(string $sort, ?string $order=null)
{}
innerJoin(string $fromAlias, string $join, string $alias, ?string $condition=null)
{}
execute(bool $track_query=true)
addClause(Clause $clause, ?string $alias=null)
Apply clause to this instance.
getTableName()
Returns the name of the primary table.
__construct(protected readonly Connection $backup_connection)
Initializes a new QueryBuilder.
joinRelationshipTable(string $from_alias='', string $from_column='guid', $name=null, bool $inverse=false, ?string $join_type='inner', ?string $joined_alias=null)
Join relationship table from alias and return joined table alias.
Query builder for fetching data from the database.
getConnection(string $type)
Gets (if required, also creates) a DB connection.
Exception thrown if a value does not adhere to a defined valid data domain.
Functions for use as event handlers or other situations where you need a globally accessible callable...
const ELGG_VALUE_TIMESTAMP
const ELGG_VALUE_INTEGER
Value types.
if($item instanceof \ElggEntity) elseif($item instanceof \ElggRiverItem) elseif($item instanceof \ElggRelationship) elseif(is_callable([ $item, 'getType']))
_elgg_services()
Get the global service provider.
if($container instanceof ElggGroup && $container->guid !=elgg_get_page_owner_guid()) $key
if(parse_url(elgg_get_site_url(), PHP_URL_PATH) !=='/') if(file_exists(elgg_get_root_path() . 'robots.txt'))
Set robots.txt.