Skip to content

Commit

Permalink
fix: eventable on joint statement
Browse files Browse the repository at this point in the history
  • Loading branch information
Suda Sankara Rao committed Oct 6, 2023
1 parent 58f2410 commit 0a88af8
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/Database/Concerns/Eventable.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ trait Eventable
/**
* Set event state.
*
* @param bool $event
* @param bool $event
*
* @return static
*/
public function eventState($event = false)
Expand All @@ -48,7 +49,8 @@ public function eventState($event = false)
/**
* Set event state.
*
* @param bool $event
* @param bool $event
*
* @return static
*/
public function es($event = false)
Expand All @@ -63,7 +65,8 @@ public function es($event = false)
*
* @deprecated 2.0
*
* @param bool|string $event
* @param bool|string $event
*
* @return static
*/
public function setEvent($event)
Expand All @@ -78,7 +81,8 @@ public function setEvent($event)
/**
* Set the event column.
*
* @param array|string $name
* @param array|string $name
*
* @return static
*/
public function eventColumn($name)
Expand All @@ -105,7 +109,8 @@ public function getLastId()
/**
* Run the query in async mode.
*
* @param array|string $events
* @param array|string $events
*
* @return static
*/
public function events($events = null)
Expand Down Expand Up @@ -143,7 +148,7 @@ public function updateEvent(array $values)

$bright = $this->getConfig();

if ($bright['timestamps'] !== false) {
if (false !== $bright['timestamps']) {
$values = $this->setTimeStamp($values);
}

Expand All @@ -157,7 +162,7 @@ protected function useEvent(): bool
{
$bright = $this->getConfig();

if (isset($bright['db_events']) && $bright['db_events'] == false) {
if (isset($bright['db_events']) && false == $bright['db_events']) {
return false;
}

Expand Down Expand Up @@ -187,7 +192,7 @@ protected function setUserId(array $values): array
/**
* Get the event tables.
*
* @param string $type
* @param string $type
*/
protected function getEventTables($type): array
{
Expand Down Expand Up @@ -243,7 +248,7 @@ protected function addInsertEvent(array $values): array

break;
default:
if (strpos($field, 'user.') !== false) {
if (false !== strpos($field, 'user.')) {
$value[$column] = user(ltrim($field, 'user.'));
} elseif (app()->has($field)) {
$value[$column] = app($field);
Expand All @@ -258,7 +263,7 @@ protected function addInsertEvent(array $values): array

$bright = $this->getConfig();

if ($bright['timestamps'] !== false) {
if (false !== $bright['timestamps']) {
foreach ($values as &$value) {
$value = $this->setTimeStamps($value);
}
Expand All @@ -270,7 +275,8 @@ protected function addInsertEvent(array $values): array
/**
* Event.
*
* @param string $type
* @param string $type
*
* @return static
*/
protected function atomicEvent($type = 'update')
Expand Down Expand Up @@ -299,10 +305,10 @@ protected function atomicEvent($type = 'update')

$alias = $mainAlias;
$column = \key($columns);
if (\strpos($column, '.') !== false) {
if (false !== \strpos($column, '.')) {
[$alias, $column] = \explode('.', $column);

$alias = $alias . '.';
$alias .= '.';
}

$field = isset($columns[$column]) ? $columns[$column] : null;
Expand Down Expand Up @@ -333,10 +339,10 @@ protected function atomicEvent($type = 'update')
*/
protected function getTableBaseName(): string
{
$table = $this->getExpressionValue($this->from);
$table = $this->getExpressionValue($this->from);

$from = \preg_split('/ as /i', $this->getExpressionValue($table));
$from = \preg_split('/ as /i', $table);

return $from[0];
return $from[0] ?? $table;
}
}

0 comments on commit 0a88af8

Please sign in to comment.