fix #243 set proper cache according to php cache extensions available

This commit is contained in:
Nicolas Le Goff
2012-01-19 19:00:48 +01:00
parent 15375a4b41
commit d55516bb29
2 changed files with 78 additions and 16 deletions

View File

@@ -34,6 +34,7 @@ class appbox extends base
*
* constant defining the app type
*/
const BASE_TYPE = self::APPLICATION_BOX;
/**
@@ -44,6 +45,7 @@ class appbox extends base
protected $cache;
protected $connection;
protected $registry;
const CACHE_LIST_BASES = 'list_bases';
const CACHE_SBAS_IDS = 'sbas_ids';
@@ -67,7 +69,7 @@ class appbox extends base
*
* @return appbox
*/
protected function __construct(registryInterface $registry=null)
protected function __construct(registryInterface $registry = null)
{
$this->connection = connection::getPDOConnection();
if (!$registry)
@@ -101,7 +103,7 @@ class appbox extends base
* @param string $pic_type
* @return appbox
*/
public function write_collection_pic(collection $collection, system_file $pathfile=null, $pic_type)
public function write_collection_pic(collection $collection, system_file $pathfile = null, $pic_type)
{
if ($pathfile instanceof system_file)
{
@@ -159,7 +161,7 @@ class appbox extends base
* @param <type> $pic_type
* @return appbox
*/
public function write_databox_pic(databox $databox, system_file $pathfile=null, $pic_type)
public function write_databox_pic(databox $databox, system_file $pathfile = null, $pic_type)
{
if ($pathfile instanceof system_file)
@@ -220,7 +222,7 @@ class appbox extends base
$stmt = $this->get_connection()->prepare($sqlupd);
$stmt->execute(array(':ordre' => $ordre, ':base_id' => $collection->get_base_id()));
$stmt->closeCursor();
$collection->get_databox()->delete_data_from_cache(\databox::CACHE_COLLECTIONS);
return $this;
@@ -313,19 +315,19 @@ class appbox extends base
}
$upgrader->add_steps_complete(1);
$upgrader->set_current_message(_('Creating new tables'));
$core = bootstrap::getCore();
$em = $core->getEntityManager();
//create schema
if($em->getConnection()->getDatabasePlatform()->supportsAlterTable())
if ($em->getConnection()->getDatabasePlatform()->supportsAlterTable())
{
$tool = new \Doctrine\ORM\Tools\SchemaTool($em);
$metas = $em->getMetadataFactory()->getAllMetadata();
$tool->updateSchema($metas, true);
}
$upgrader->add_steps_complete(1);
/**
@@ -441,7 +443,7 @@ class appbox extends base
}
$connexionINI['driver'] = 'pdo_mysql';
$connexionINI['charset'] = 'UTF8';
$serverName = $registry->get('GV_ServerName');
$root = __DIR__ . '/../../';
@@ -490,6 +492,17 @@ class appbox extends base
'charset' => 'UTF8'
));
$cacheService = "array_cache";
if (extension_loaded('apc'))
{
$cacheService = "apc_cache";
}
elseif (extension_loaded('xcache'))
{
$cacheService = "xcache_cache";
}
$yaml = $configuration->getConfigurationHandler()->getParser()->dump($connexion, 2);
if (!file_put_contents($connexionFile->getPathname(), $yaml) !== false)
@@ -499,8 +512,22 @@ class appbox extends base
//rewrite service file
$serviceFile = $appConf->getServiceFile();
$service = $configuration->getConfigurationHandler()->getParser()->parse($serviceFile);
$yaml = $configuration->getConfigurationHandler()->getParser()->dump($service, 5);
$services = $configuration->getConfigurationHandler()->getParser()->parse($serviceFile);
foreach ($services as $serviceName => $service)
{
if ($serviceName === "doctrine_prod")
{
$services["doctrine_prod"]["options"]["orm"]["cache"] = array(
"query" => $cacheService,
"result" => $cacheService,
"metadata" => $cacheService
);
}
}
$yaml = $configuration->getConfigurationHandler()->getParser()->dump($services, 5);
if (!file_put_contents($serviceFile->getPathname(), $yaml) !== false)
{
@@ -516,6 +543,11 @@ class appbox extends base
{
$arrayConf[$key]["phraseanet"]["servername"] = $serverName;
}
if (is_array($value) && $key === 'prod')
{
$arrayConf[$key]["cache"] = $cacheService;
}
}
$configuration->write($arrayConf);