/**
* @param $namespace
* @param $name
* @param $locale
* @return string
* @throws DriverException
*/
private function findContentAndFillCache($namespace, $name, $locale)
{
try {
/** @var array $result */
$result = $this->connection->select('*')->from(self::TABLE)->where(['namespace%s' => $namespace])->fetchAll();
} catch (DriverException $e) {
// check table not exist
if ($e->getCode() == 1146) {
$this->connection->query('
CREATE TABLE [' . self::TABLE . '] (
[id] int(11) NOT NULL AUTO_INCREMENT,
[namespace] varchar(255) NOT NULL,
[name] varchar(255) NOT NULL,
[locale] varchar(255) NOT NULL,
[content] text NOT NULL,
PRIMARY KEY ([id]),
UNIQUE KEY [uniq_record] ([namespace],[name],[locale])
);');
$result = [];
} else {
throw $e;
}
}
$tmp = [];
foreach ($result as $item) {
if (!isset($tmp[$item['name']])) {
$tmp[$item['name']] = [];
}
$tmp[$item['namespace']][$item['name']][$item['locale']] = $item['content'];
}
$this->saveCachedNamespace($namespace, $tmp);
return isset($tmp[$namespace][$name][$locale]) ? $tmp[$namespace][$name][$locale] : '';
}