Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cast database ID to integer #250

Closed
wants to merge 1 commit into from
Closed

Conversation

fritzmg
Copy link
Sponsor Contributor

@fritzmg fritzmg commented May 23, 2024

Fixes #249

@CMSworker
Copy link
Contributor

Thank you. I tested your changes, unfortunatelly still getting an error in some cases when trying to add a new article. Now the error states line 281.

Duplicating your code inside the if-statement at the beginning of the function seem to resolve it:

private function getChildTranslation(int $id, string $table, string $ptable, string $parentField): ?int
    {
        if (isset($this->translationCache[$table])) {
            
            // Cast ID to integer due to return type (#249)
            if (null !== ($this->translationCache[$table][$id] ?? null)) {
                $this->translationCache[$table][$id] = (int) $this->translationCache[$table][$id];
            }

            return $this->translationCache[$table][$id] ?? null;
        }

        $this->translationCache[$table] = $this->connection->fetchAllKeyValue(
            <<<SQL
                    SELECT
                        c.id,
                        IFNULL(ct.id, 0)
                    FROM $table c
                        JOIN $ptable p ON c.pid=p.id
                        LEFT JOIN $table ct ON c.languageMain=ct.id
                        LEFT JOIN $ptable pt ON p.$parentField=pt.id
                    WHERE pt.id > 0
                SQL,
        );

        // Cast ID to integer due to return type (#249)
        if (null !== ($this->translationCache[$table][$id] ?? null)) {
            $this->translationCache[$table][$id] = (int) $this->translationCache[$table][$id];
        }

        return $this->translationCache[$table][$id] ?? null;
    }

@fritzmg
Copy link
Sponsor Contributor Author

fritzmg commented May 27, 2024

Hm that should not be necessary.

@aschempp
Copy link
Member

I have fixed this differently in c7624ff. Your case would not apply to the early-return statement in the function.

@aschempp aschempp closed this May 27, 2024
@fritzmg fritzmg deleted the patch-5 branch May 27, 2024 09:18
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.

Kindelemente in Fremdsprachen-Archiv werden nicht angezeigt
3 participants