Skip to content

Conversation

@hissy
Copy link
Contributor

@hissy hissy commented Mar 29, 2024

Fixes #102, #57, #47

This PR converts values to integers when the table column type is an integer.

You can test this fix by adding an image slider block with entries with no images selected.

Cast int values before save
if ($b) {
$app = Application::getFacadeApplication();
/** @var Connection $connection */
$connection = $app->make(Connection::class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be a hard dependency of this class instead of relying on the service locator? IE:

protected $db;

public function __construct(Connection $db)
{
    $this->db = $db;
}

Comment on lines 54 to 62
if ($column->getName() === $key) {
if ($column->getType()->getName() === Type::INTEGER) {
if ($column->getNotnull()) {
$value = (int) $value;
} else {
$value = $value === null ? null : (int) $value;
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ($column->getName() === $key) {
if ($column->getType()->getName() === Type::INTEGER) {
if ($column->getNotnull()) {
$value = (int) $value;
} else {
$value = $value === null ? null : (int) $value;
}
}
}
if (
$column->getName() !== $key ||
$column->getType()->getName() === Type::INTEGER
) {
continue;
}
$value = ($column->getNotNull() || $column !== null) : (int) $value : null;
break;

Using an early return (early continue) is more readable to me here, also worth breaking when the proper column is matched

@hissy
Copy link
Contributor Author

hissy commented Mar 30, 2024

@KorvinSzanto

Done.

(BC note: If someone created a custom publisher that uses StandardPublisher as fallback, they must change their code)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty values in the xml

2 participants