简体   繁体   中英

SQLite error opening Symfony app on Heroku

Error itself:

2021-07-20T23:43:33.993462+00:00 app[web.1]: [20-Jul-2021 23:43:33 UTC] [critical] Uncaught PHP Exception Symfony\Component\ErrorHandler\Error\ClassNotFoundError: "Attempted to load class "SQLite3Cache" from namespace "Doctrine\Common\Cache".
2021-07-20T23:43:33.993688+00:00 app[web.1]: Did you forget a "use" statement for another namespace?" at /app/src/Utils/FilesCache.php line 23

The file contents of "FilesCache.php" are similar to what's provided in Symfony's documentation here with a few additions.

<?php
namespace App\Utils;

use App\Utils\Interfaces\CacheInterface;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
use Doctrine\Common\Cache\CacheProvider;
use Doctrine\Common\Cache\SQLite3Cache;
use Symfony\Component\Cache\Adapter\DoctrineAdapter;


class FilesCache implements CacheInterface
{
    public $cache;

    public function __construct()
    {
        //this is error line 23
        $provider = new SQLite3Cache(new \SQLite3(__DIR__ . '/cache/data.db'), 'TableName');

        $this->cache =  new TagAwareAdapter(
            new DoctrineAdapter(
                $provider,
                $namespace = '',
                $defaultLifetime = 0
            )
        );
    }
}

I've added both "pdo_sqlite" and "sqlite3" extensions to "composer.json". Composer update runs without issue.

I'm committing both the "composer.json" and "composer.lock" before pushing the local project repo to Heroku, which runs without issue as well and shows that both extensions are added.

remote: -----> Installing platform packages...
remote:        - php (8.0.8)
remote:        - ext-intl (bundled with php)
remote:        - ext-pdo_sqlite (bundled with php)
remote:        - ext-sqlite3 (bundled with php)
remote:        - composer (2.1.3)
remote:        - apache (2.4.48)
remote:        - nginx (1.20.1)

I know that SQLite isn't the proper choice for a production database, I'm following a course and I'd like to continue using what's provided from it.

Thank you in advance for any help!

As mentioned in the comments, the problem was the deprecation of doctrine/cache. I switched to a PDOAdapter and this fixed the issue.

 <?php
        namespace App\Utils;
        
        use App\Utils\Interfaces\CacheInterface;
        use Symfony\Component\Cache\Adapter\TagAwareAdapter;
        use Symfony\Component\Cache\Adapter\PdoAdapter;
        use Doctrine\DBAL\Driver\Connection;
        
        
        class FilesCache implements CacheInterface
        {
            public $cache;
    
            public function __construct()
            {
                $connection = \Doctrine\DBAL\DriverManager::getConnection([
                    'url' => 'sqlite:////%kernel.project_dir%/var/cache/data.db'
                ]);
        
                $this->cache =  new TagAwareAdapter(
                    new PdoAdapter(
                        $connection,
                        $namespace = '',
                        $defaultLifetime = 0
                    )
                );
            }
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM