Skip to content

Commit

Permalink
Database: Update phpDoc and code style
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhwinder33445 committed Jul 12, 2024
1 parent b0c890b commit cce7f68
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions library/Notifications/Common/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class Database
/**
* @var string[] Tables with a deleted flag
*
* The filter `deleted=n` is automatically added to these tables.
* The filter `deleted=n` is automatically added to these tables, when select statement is executed
*/
private const TABLES_WITH_DELETED_FLAG = [
'channel',
Expand Down Expand Up @@ -135,29 +135,28 @@ private static function getConnection(): Connection
});
}

$db->getQueryBuilder()
->on(QueryBuilder::ON_ASSEMBLE_SELECT, function (Select $select) {
$from = $select->getFrom();
$baseTableName = reset($from);
$db->getQueryBuilder()->on(QueryBuilder::ON_ASSEMBLE_SELECT, function (Select $select) {
$from = $select->getFrom();
$baseTableName = reset($from);

if (! in_array($baseTableName, self::TABLES_WITH_DELETED_FLAG, true)) {
return;
}
if (! in_array($baseTableName, self::TABLES_WITH_DELETED_FLAG, true)) {
return;
}

$baseTableAlias = key($from);
if (! is_string($baseTableAlias)) {
$baseTableAlias = $baseTableName;
}
$baseTableAlias = key($from);
if (! is_string($baseTableAlias)) {
$baseTableAlias = $baseTableName;
}

$condition = 'deleted = ?';
$where = $select->getWhere();
$condition = 'deleted = ?';
$where = $select->getWhere();

if ($where && self::hasCondition($baseTableAlias, $condition, $where)) {
return;
}
if ($where && self::hasCondition($baseTableAlias, $condition, $where)) {
return;
}

$select->where([$baseTableAlias . '.' . $condition => 'n']);
});
$select->where([$baseTableAlias . '.' . $condition => 'n']);
});

$db->getQueryBuilder()->on(QueryBuilder::ON_ASSEMBLE_INSERT, function (Insert $insert) use ($adapter) {
$tableName = $insert->getInto();
Expand Down

0 comments on commit cce7f68

Please sign in to comment.