LexikTranslationBundle icon indicating copy to clipboard operation
LexikTranslationBundle copied to clipboard

OVH Shared hosting

Open Donjohn opened this issue 8 years ago • 3 comments

Few issues with a OVH shared hosting

  1. you are not allowed to query "SHOW DATABASES". Therefore the bundle doesn't find tables and can't read translation from database ever. Or only after a dump...

I overwrote the DoctrineORMStorage translationsTablesExist function because $tmpConnection->getSchemaManager()->listDatabases() will never return the correct answer (line 39) short fix : deleted line 28 to 43 long fix : tbh dunno why you open a new connection and look yourself for the database... you already have the entity manager injected... If you want translation tables are on a different database, the em injected should be the one provided in config.yml (right ?)

  1. glob return nothing In the Translation/Translator class, function removeCacheFile($locale). $files = glob($localePattern); return an empty array. The pattern is ok, the function is either deactivated or can't find correctly files in a shared webhosting. Dunno the core reason but the Finder worked instead.
use Symfony\Component\Finder\Finder;

...

public function removeCacheFile($locale)
    {
        $localeExploded = explode('_', $locale);
        $finder = new Finder();
        $finder->files()->in($this->options['cache_dir'])->contains(sprintf('catalogue.*%s*.php', $localeExploded[0]));
        $deleted = true;
        foreach ($finder as $file) {

            $path = $file->getRealPath();
            $this->invalidateSystemCacheForFile($path);
            $deleted = unlink($path);

            $metadata = $path.'.meta';
            if (file_exists($metadata)) {
                $this->invalidateSystemCacheForFile($metadata);
                unlink($metadata);
            }
        }

        return $deleted;
    }
  1. opcache_invalidate is not available In the Translation/Translator class, function invalidateSystemCacheForFile($path) I had to test the function first
protected function invalidateSystemCacheForFile($path)
    {
        if (ini_get('apc.enabled')) {
            if (apc_exists($path) && !apc_delete_file($path)) {
                throw new \RuntimeException(sprintf('Failed to clear APC Cache for file %s', $path));
            }
        } elseif ('cli' === php_sapi_name() ? ini_get('opcache.enable_cli') : ini_get('opcache.enable')) {
            if (function_exists("opcache_invalidate") && !opcache_invalidate($path, true)) {
                throw new \RuntimeException(sprintf('Failed to clear OPCache for file %s', $path));
            }
        }
    }

Donjohn avatar Mar 06 '17 11:03 Donjohn

made a PR for glob and opcache, dunno what you wanna do for the SHOW DATABASES tho

https://github.com/lexik/LexikTranslationBundle/pull/245

Donjohn avatar Mar 08 '17 14:03 Donjohn

#210 was posted for the problem with SHOW DATABASES too. We should be able to close one or the other.

dinamic avatar Jan 05 '18 11:01 dinamic

I don't have an account with OVH, so I can't reproduce the problem. However, I think I have identified the part that causes the problem.

https://github.com/lexik/LexikTranslationBundle/blob/master/Storage/DoctrineORMStorage.php#L39

@cedric-g, could we do this any other way?

dinamic avatar Jan 05 '18 11:01 dinamic