Skip to content

Commit f5366e5

Browse files
committed
Select a proper expression when performing exists queries
ipl\Orm translates this, due to a quirk in PHP where numerical strings are interpreted as integer keys in arrays, to the second column of the given base model. This is undocumented behavior and must be avoided.
1 parent 33c8e8e commit f5366e5

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

application/controllers/ContactGroupsController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use ipl\Html\Form;
1919
use ipl\Html\HtmlString;
2020
use ipl\Html\TemplateString;
21+
use ipl\Sql\Expression;
2122
use ipl\Stdlib\Filter;
2223
use ipl\Web\Compat\CompatController;
2324
use ipl\Web\Compat\SearchControls;
@@ -91,8 +92,8 @@ public function indexAction(): void
9192
);
9293

9394
$emptyStateMessage = null;
94-
if (Contact::on(Database::get())->columns('1')->limit(1)->first() === null) {
95-
if (Channel::on(Database::get())->columns('1')->limit(1)->first() === null) {
95+
if (Contact::on(Database::get())->columns([new Expression('1')])->limit(1)->first() === null) {
96+
if (Channel::on(Database::get())->columns([new Expression('1')])->limit(1)->first() === null) {
9697
$addButton->disable($this->translate('A channel is required to add a contact group'));
9798

9899
$emptyStateMessage = TemplateString::create(

application/forms/ChannelForm.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use ipl\I18n\GettextTranslator;
2121
use ipl\I18n\StaticTranslator;
2222
use ipl\Sql\Connection;
23+
use ipl\Sql\Expression;
2324
use ipl\Stdlib\Filter;
2425
use ipl\Validator\EmailAddressValidator;
2526
use ipl\Web\Common\CsrfCounterMeasure;
@@ -128,13 +129,13 @@ protected function assemble(): void
128129

129130
if ($this->channelId !== null) {
130131
$isInUse = Contact::on($this->db)
131-
->columns('1')
132+
->columns([new Expression('1')])
132133
->filter(Filter::equal('default_channel_id', $this->channelId))
133134
->first();
134135

135136
if ($isInUse === null) {
136137
$isInUse = RuleEscalationRecipient::on($this->db)
137-
->columns('1')
138+
->columns([new Expression('1')])
138139
->filter(Filter::equal('channel_id', $this->channelId))
139140
->first();
140141
}

library/Notifications/Model/Rotation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public function delete(): void
145145
$requirePriorityUpdate = true;
146146
if (RotationConfigForm::EXPERIMENTAL_OVERRIDES) {
147147
$rotations = self::on($db)
148-
->columns('1')
148+
->columns([new Expression('1')])
149149
->filter(Filter::equal('schedule_id', $this->schedule_id))
150150
->filter(Filter::equal('priority', $this->priority))
151151
->first();

0 commit comments

Comments
 (0)