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

[bug] don't work xPDOManager->createObjectContainer() in MySQL > 8 #207

Open
catsmeatman opened this issue Jul 21, 2021 · 1 comment
Open

Comments

@catsmeatman
Copy link

catsmeatman commented Jul 21, 2021

In src/xPDO/Om/mysql/xPDOManager.php:117 must check is exist table, but this is not working in MySQL8.

When try $manger->createObjectContainer() result is

Error Code: 1146. Table 'eparket.modx_epshop_payment' doesn't exist because table not created yet.`

Fix

$existsStmt = $this->xpdo->query("SELECT table_name FROM information_schema.tables where table_name = $tableName");

if (count($existsStmt->fetchAll()) > 0) {
    return true;
}
@wshawn
Copy link

wshawn commented Sep 24, 2021

That is not a fix. You are actually accessing the Database Management system's internal database - not your table.

I use the following function to create the tables:

  /**
     * Creates the database tables associated with the package.
     *
     * @return bool
     */
    public function createSchemaTables(): bool
    {
        $out = false;
        $schemaObjects = $this->getSchemaObjectNames();
        if (count($schemaObjects) > 0) {
            $manager = $this->modx->getManager();
            if ($manager instanceof xPDOManager) {
                $i = 0;
                foreach ($schemaObjects as $className) {
                    $i += ($manager->createObjectContainer($this->packageNamespace . $className) ? 1 : 0);
                }
                $out = (count($schemaObjects) == $i) ?: false;
            }
        }
        return $out;
    }

This might be a bit dated. There were issues with the namespace being correctly translated to table names. See #161

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

No branches or pull requests

2 participants