Merge branch '3.6' of github.com:alchemy-fr/Phraseanet into 3.6

This commit is contained in:
Romain Neutron
2012-01-20 13:00:17 +01:00
37 changed files with 871 additions and 466 deletions

View File

@@ -43,12 +43,13 @@ try
exit(sprintf("Doctrine is not declared as your ORM but %s is", $confService->get("type"))); exit(sprintf("Doctrine is not declared as your ORM but %s is", $confService->get("type")));
} }
$ormService = \Alchemy\Phrasea\Core\ServiceBuilder::build( $ormServiceBuilder = new \Alchemy\Phrasea\Core\ServiceBuilder\Orm(
$serviceName $serviceName
, \Alchemy\Phrasea\Core\ServiceBuilder::ORM
, $confService , $confService
, array('registry' => \registry::get_instance())
); );
$ormService = $ormServiceBuilder->buildService();
$em = $ormService->getService(); $em = $ormService->getService();
/* @var $em \Doctrine\ORM\EntityManager */ /* @var $em \Doctrine\ORM\EntityManager */

View File

@@ -2,7 +2,7 @@
#Declare which environment will be used by the application #Declare which environment will be used by the application
environment : dev environment : prod
#Declare all your environment configurations #Declare all your environment configurations
@@ -25,6 +25,7 @@ dev:
#Services are defined in service.yml configuration file #Services are defined in service.yml configuration file
template_engine: twig_debug template_engine: twig_debug
orm: doctrine_dev orm: doctrine_dev
cache: array_cache
############## ##############
# PRODUCTION # # PRODUCTION #
@@ -39,6 +40,7 @@ prod:
template_engine: twig template_engine: twig
orm: doctrine_prod orm: doctrine_prod
cache: apc_cache
############## ##############
# TEST # # TEST #
@@ -53,5 +55,6 @@ test:
template_engine: twig_debug template_engine: twig_debug
orm: doctrine_test orm: doctrine_test
cache: array_cache

View File

@@ -105,7 +105,7 @@ return call_user_func(function()
'main_connexion' => $connexionINI, 'main_connexion' => $connexionINI,
'test_connexion' => array( 'test_connexion' => array(
'driver' => 'pdo_sqlite', 'driver' => 'pdo_sqlite',
'path' => $registry->get("GV_RootPath") . 'lib/unitTest/tests.sqlite', 'path' => realpath($registry->get("GV_RootPath") . 'lib/unitTest/tests.sqlite'),
'charset' => 'UTF8' 'charset' => 'UTF8'
)); ));
@@ -116,10 +116,34 @@ return call_user_func(function()
throw new \Exception(sprintf(_('Impossible d\'ecrire dans le fichier %s'), $connexionFile->getPathname())); throw new \Exception(sprintf(_('Impossible d\'ecrire dans le fichier %s'), $connexionFile->getPathname()));
} }
$cacheService = "array_cache";
if (extension_loaded('apc'))
{
$cacheService = "apc_cache";
}
elseif (extension_loaded('xcache'))
{
$cacheService = "xcache_cache";
}
//rewrite service file //rewrite service file
$serviceFile = $appConf->getServiceFile(); $serviceFile = $appConf->getServiceFile();
$service = $configuration->getConfigurationHandler()->getParser()->parse($serviceFile); $services = $configuration->getConfigurationHandler()->getParser()->parse($serviceFile);
$yaml = $configuration->getConfigurationHandler()->getParser()->dump($service, 5);
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) if (!file_put_contents($serviceFile->getPathname(), $yaml) !== false)
{ {
@@ -134,11 +158,17 @@ return call_user_func(function()
{ {
$arrayConf[$key]["phraseanet"]["servername"] = $serverName; $arrayConf[$key]["phraseanet"]["servername"] = $serverName;
} }
if (is_array($value) && $key === 'prod')
{
$arrayConf[$key]["cache"] = $cacheService;
}
} }
$configuration->write($arrayConf); $configuration->write($arrayConf);
$app->redirect("/setup/installer/"); $app['install'] = true;
// $app->redirect("/setup/installer/");
} }
else else
{ {

View File

@@ -344,6 +344,7 @@ class UsrLists implements ControllerProviderInterface
$controllers->post('/list/{list_id}/add/{usr_id}/', function(Application $app, $list_id, $usr_id) $controllers->post('/list/{list_id}/add/{usr_id}/', function(Application $app, $list_id, $usr_id)
{ {
$em = $app['Core']->getEntityManager(); $em = $app['Core']->getEntityManager();
$user = $app['Core']->getAuthenticatedUser();
try try
{ {
@@ -351,7 +352,7 @@ class UsrLists implements ControllerProviderInterface
$list = $repository->findUserListByUserAndId($user, $list_id); $list = $repository->findUserListByUserAndId($user, $list_id);
/* @var $list \Entities\UsrList */ /* @var $list \Entities\UsrList */
$user_entry = \User_Adapter::getInstance($usr_id, appbox::get_instance()); $user_entry = \User_Adapter::getInstance($usr_id, \appbox::get_instance());
$entry = new \Entities\UsrListEntry(); $entry = new \Entities\UsrListEntry();
$entry->setUser($user_entry); $entry->setUser($user_entry);
@@ -399,12 +400,12 @@ class UsrLists implements ControllerProviderInterface
$list = $repository->findUserListByUserAndId($user, $list_id); $list = $repository->findUserListByUserAndId($user, $list_id);
/* @var $list \Entities\UsrList */ /* @var $list \Entities\UsrList */
if($list->getOwner($user)->getList() < \Entities\UsrListOwner::ROLE_EDITOR) if($list->getOwner($user)->getRole() < \Entities\UsrListOwner::ROLE_EDITOR)
{ {
throw new \Exception('You are not authorized to do this'); throw new \Exception('You are not authorized to do this');
} }
$new_owner = \User_Adapter::getInstance($usr_id, appbox::get_instance()); $new_owner = \User_Adapter::getInstance($usr_id, \appbox::get_instance());
if($list->hasAccess($new_owner)) if($list->hasAccess($new_owner))
{ {

View File

@@ -133,6 +133,8 @@ class Installer implements ControllerProviderInterface
\phrasea::use_i18n(\Session_Handler::get_locale()); \phrasea::use_i18n(\Session_Handler::get_locale());
$request = $app['request']; $request = $app['request'];
$servername = $request->getScheme() . '://' . $request->getHttpHost() . '/';
$setupRegistry = new \Setup_Registry(); $setupRegistry = new \Setup_Registry();
$setupRegistry->set('GV_ServerName', $servername); $setupRegistry->set('GV_ServerName', $servername);
@@ -171,7 +173,8 @@ class Installer implements ControllerProviderInterface
try try
{ {
$servername = $request->getScheme() . '://' . $request->getHttpHost() . '/'; $setupRegistry = new \Setup_Registry();
$setupRegistry->set('GV_ServerName', $servername);
$appbox = \appbox::create($setupRegistry, $conn, $appbox_name, true); $appbox = \appbox::create($setupRegistry, $conn, $appbox_name, true);
@@ -186,12 +189,14 @@ class Installer implements ControllerProviderInterface
$serviceName = $configuration->getOrm(); $serviceName = $configuration->getOrm();
$confService = $configuration->getService($serviceName); $confService = $configuration->getService($serviceName);
$ormService = \Alchemy\Phrasea\Core\ServiceBuilder::build( $ormServiceBuilder = new \Alchemy\Phrasea\Core\ServiceBuilder\Orm(
$serviceName $serviceName
, \Alchemy\Phrasea\Core\ServiceBuilder::ORM
, $confService , $confService
, array('registry' => $setupRegistry)
); );
$ormService = $ormServiceBuilder->buildService();
if ($ormService->getType() === 'doctrine') if ($ormService->getType() === 'doctrine')
{ {
/* @var $em \Doctrine\ORM\EntityManager */ /* @var $em \Doctrine\ORM\EntityManager */

View File

@@ -40,7 +40,6 @@ class Upgrader implements ControllerProviderInterface
/* @var $twig \Twig_Environment */ /* @var $twig \Twig_Environment */
$twig = $app['Core']->getTwig(); $twig = $app['Core']->getTwig();
ini_set('display_errors', 'on');
$html = $twig->render( $html = $twig->render(
'/setup/upgrader.html.twig' '/setup/upgrader.html.twig'
, array( , array(
@@ -60,7 +59,6 @@ class Upgrader implements ControllerProviderInterface
$controllers->get('/status/', function() use ($app) $controllers->get('/status/', function() use ($app)
{ {
require_once __DIR__ . '/../../../../bootstrap.php'; require_once __DIR__ . '/../../../../bootstrap.php';
ini_set('display_errors', 'on');
$datas = \Setup_Upgrade::get_status(); $datas = \Setup_Upgrade::get_status();
@@ -70,7 +68,6 @@ class Upgrader implements ControllerProviderInterface
$controllers->post('/execute/', function() use ($app) $controllers->post('/execute/', function() use ($app)
{ {
require_once __DIR__ . '/../../../../bootstrap.php'; require_once __DIR__ . '/../../../../bootstrap.php';
ini_set('display_errors', 'on');
set_time_limit(0); set_time_limit(0);
session_write_close(); session_write_close();
ignore_user_abort(true); ignore_user_abort(true);

View File

@@ -56,6 +56,8 @@ class Core extends \Pimple
); );
$this->configuration = new Core\Configuration($handler, $environement); $this->configuration = new Core\Configuration($handler, $environement);
$this->init();
/** /**
* Set version * Set version
*/ */
@@ -64,37 +66,6 @@ class Core extends \Pimple
return new Core\Version(); return new Core\Version();
}); });
$core = $this;
/**
* Set Entity Manager using configuration
*/
$this['EM'] = $this->share(function() use ($core)
{
$serviceName = $core->getConfiguration()->getOrm();
$service = $core->getService(
$serviceName
, Core\ServiceBuilder::ORM
);
return $service->getService();
});
$this["Twig"] = $this->share(function() use ($core)
{
$serviceName = $core->getConfiguration()->getTemplating();
$service = $core->getService(
$serviceName
, Core\ServiceBuilder::TEMPLATE_ENGINE
);
return $service->getService();
});
if (\setup::is_installed()) if (\setup::is_installed())
{ {
$this['Registry'] = $this->share(function() $this['Registry'] = $this->share(function()
@@ -102,8 +73,6 @@ class Core extends \Pimple
return \registry::get_instance(); return \registry::get_instance();
}); });
\phrasea::start(); \phrasea::start();
$appbox = \appbox::get_instance();
$session = $appbox->get_session();
$this->enableEvents(); $this->enableEvents();
} }
else else
@@ -115,6 +84,54 @@ class Core extends \Pimple
}); });
} }
$core = $this;
/**
* Set Entity Manager using configuration
*/
$this['EM'] = $this->share(function() use ($core)
{
$serviceName = $core->getConfiguration()->getOrm();
$configuration = $core->getConfiguration()->getService($serviceName);
$serviceBuilder = new Core\ServiceBuilder\Orm(
$serviceName
, $configuration
, array("registry" => $core["Registry"])
);
return $serviceBuilder->buildService()->getService();
});
$this["Twig"] = $this->share(function() use ($core)
{
$serviceName = $core->getConfiguration()->getTemplating();
$configuration = $core->getConfiguration()->getService($serviceName);
$serviceBuilder = new Core\ServiceBuilder\TemplateEngine(
$serviceName, $configuration
);
return $serviceBuilder->buildService()->getService();
});
$this["Cache"] = $this->share(function() use ($core)
{
$serviceName = $core->getConfiguration()->getCache();
$configuration = $core->getConfiguration()->getService($serviceName);
$serviceBuilder = new Core\ServiceBuilder\Cache(
$serviceName
, $configuration
, array("registry" => $core["Registry"])
);
return $serviceBuilder->buildService()->getService();
});
$this['Serializer'] = $this->share(function() $this['Serializer'] = $this->share(function()
{ {
$encoders = array( $encoders = array(
@@ -156,16 +173,19 @@ class Core extends \Pimple
* @param type $environnement * @param type $environnement
*/ */
private function init() private function init()
{
if ($this->getConfiguration()->isInstalled())
{ {
if ($this->getConfiguration()->isDisplayingErrors()) if ($this->getConfiguration()->isDisplayingErrors())
{ {
ini_set('display_errors', 1); ini_set('display_errors', 'on');
error_reporting(E_ALL); error_reporting(E_ALL);
// \Symfony\Component\HttpKernel\Debug\ErrorHandler::register(); // \Symfony\Component\HttpKernel\Debug\ErrorHandler::register();
} }
else else
{ {
ini_set('display_errors', 0); ini_set('display_errors', 'off');
}
} }
} }
@@ -179,6 +199,16 @@ class Core extends \Pimple
return $this['Registry']; return $this['Registry'];
} }
/**
* Getter
*
* @return \Registry
*/
public function getCache()
{
return $this['Cache'];
}
/** /**
* Getter * Getter
* *
@@ -294,17 +324,6 @@ class Core extends \Pimple
ini_set('error_log', $php_log); ini_set('error_log', $php_log);
if ($this->getRegistry()->get('GV_debug'))
{
ini_set('display_errors', 'on');
ini_set('display_startup_errors', 'on');
}
else
{
ini_set('display_errors', 'off');
ini_set('display_startup_errors', 'off');
}
if ($this->getRegistry()->get('GV_log_errors')) if ($this->getRegistry()->get('GV_log_errors'))
{ {
ini_set('log_errors', 'on'); ini_set('log_errors', 'on');
@@ -441,15 +460,4 @@ class Core extends \Pimple
return $this->conf->getEnvironnement(); return $this->conf->getEnvironnement();
} }
public function getService($serviceName, $serviceScope)
{
$configuration = $this->configuration->getService($serviceName);
return Core\ServiceBuilder::build(
$serviceName
, $serviceScope
, $configuration
);
}
} }

View File

@@ -354,6 +354,15 @@ class Configuration
return $this->getConfiguration()->get('template_engine'); return $this->getConfiguration()->get('template_engine');
} }
/**
* Return cache service
* @return string
*/
public function getCache()
{
return $this->getConfiguration()->get('cache');
}
/** /**
* Return configuration service for orm * Return configuration service for orm
* @return string * @return string

View File

@@ -15,8 +15,7 @@ use Alchemy\Phrasea\Core,
Alchemy\Phrasea\Core\Service, Alchemy\Phrasea\Core\Service,
Alchemy\Phrasea\Core\Service\ServiceAbstract, Alchemy\Phrasea\Core\Service\ServiceAbstract,
Alchemy\Phrasea\Core\Service\ServiceInterface; Alchemy\Phrasea\Core\Service\ServiceInterface;
use Doctrine\Common\Cache as CacheService;
use Doctrine\Common\Cache\ApcCache;
/** /**
* *
@@ -24,7 +23,7 @@ use Doctrine\Common\Cache\ApcCache;
* @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com * @link www.phraseanet.com
*/ */
class Apc extends ServiceAbstract implements ServiceInterface class ApcCache extends ServiceAbstract implements ServiceInterface
{ {
public function getScope() public function getScope()
@@ -43,7 +42,12 @@ class Apc extends ServiceAbstract implements ServiceInterface
throw new \Exception('The APC cache requires the APC extension.'); throw new \Exception('The APC cache requires the APC extension.');
} }
return new ApcCache(); $registry = $this->getRegistry();
$service = new CacheService\ApcCache();
$service->setNamespace($registry->get("GV_sit", ""));
return $service;
} }
public function getType() public function getType()
@@ -51,5 +55,17 @@ class Apc extends ServiceAbstract implements ServiceInterface
return 'apc'; return 'apc';
} }
private function getRegistry()
{
$registry = $this->getDependency("registry");
if (!$registry instanceof \registryInterface)
{
throw new \Exception(sprintf('Registry dependency does not implement registryInterface for %s service', $this->name));
}
return $registry;
}
} }

View File

@@ -15,16 +15,16 @@ use Alchemy\Phrasea\Core,
Alchemy\Phrasea\Core\Service, Alchemy\Phrasea\Core\Service,
Alchemy\Phrasea\Core\Service\ServiceAbstract, Alchemy\Phrasea\Core\Service\ServiceAbstract,
Alchemy\Phrasea\Core\Service\ServiceInterface; Alchemy\Phrasea\Core\Service\ServiceInterface;
use Doctrine\Common\Cache as CacheService;
use Doctrine\Common\Cache\ArrayCache;
/** /**
* it's just like array cache * Array cache
*
* @package * @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com * @link www.phraseanet.com
*/ */
class Tab extends ServiceAbstract implements ServiceInterface class ArrayCache extends ServiceAbstract implements ServiceInterface
{ {
public function getScope() public function getScope()
@@ -38,7 +38,12 @@ class Tab extends ServiceAbstract implements ServiceInterface
*/ */
public function getService() public function getService()
{ {
return new ArrayCache(); $registry = $this->getRegistry();
$service = new CacheService\ArrayCache();
$service->setNamespace($registry->get("GV_sit", ""));
return $service;
} }
public function getType() public function getType()
@@ -46,5 +51,17 @@ class Tab extends ServiceAbstract implements ServiceInterface
return 'array'; return 'array';
} }
private function getRegistry()
{
$registry = $this->getDependency("registry");
if (!$registry instanceof \registryInterface)
{
throw new \Exception(sprintf('Registry dependency does not implement registryInterface for %s service', $this->name));
}
return $registry;
}
} }

View File

@@ -15,7 +15,7 @@ use Alchemy\Phrasea\Core,
Alchemy\Phrasea\Core\Service, Alchemy\Phrasea\Core\Service,
Alchemy\Phrasea\Core\Service\ServiceAbstract, Alchemy\Phrasea\Core\Service\ServiceAbstract,
Alchemy\Phrasea\Core\Service\ServiceInterface; Alchemy\Phrasea\Core\Service\ServiceInterface;
use Doctrine\Common\Cache\MemcacheCache; use Doctrine\Common\Cache as CacheService;
/** /**
* *
@@ -54,7 +54,12 @@ class Memcache extends ServiceAbstract implements ServiceInterface
$memchache = new \Memcache(); $memchache = new \Memcache();
$memchache->connect($this->host, $this->port); $memchache->connect($this->host, $this->port);
return new MemcacheCache($memchache); $registry = $this->getRegistry();
$service = new CacheService\MemcacheCache($memchache);
$service->setNamespace($registry->get("GV_sit", ""));
return $service;
} }
public function getType() public function getType()
@@ -72,5 +77,16 @@ class Memcache extends ServiceAbstract implements ServiceInterface
return $this->port; return $this->port;
} }
private function getRegistry()
{
$registry = $this->getDependency("registry");
if (!$registry instanceof \registryInterface)
{
throw new \Exception(sprintf('Registry dependency does not implement registryInterface for %s service', $this->name));
}
return $registry;
}
} }

View File

@@ -15,7 +15,7 @@ use Alchemy\Phrasea\Core,
Alchemy\Phrasea\Core\Service, Alchemy\Phrasea\Core\Service,
Alchemy\Phrasea\Core\Service\ServiceAbstract, Alchemy\Phrasea\Core\Service\ServiceAbstract,
Alchemy\Phrasea\Core\Service\ServiceInterface; Alchemy\Phrasea\Core\Service\ServiceInterface;
use Doctrine\Common\Cache\XcacheCache; use Doctrine\Common\Cache as CacheService;
/** /**
* it's just like array cache * it's just like array cache
@@ -23,7 +23,7 @@ use Doctrine\Common\Cache\XcacheCache;
* @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com * @link www.phraseanet.com
*/ */
class Tab extends ServiceAbstract implements ServiceInterface class XcacheCache extends ServiceAbstract implements ServiceInterface
{ {
public function getScope() public function getScope()
@@ -41,7 +41,13 @@ class Tab extends ServiceAbstract implements ServiceInterface
{ {
throw new \Exception('The XCache cache requires the XCache extension.'); throw new \Exception('The XCache cache requires the XCache extension.');
} }
return new XcacheCache();
$registry = $this->getRegistry();
$service = new CacheService\XcacheCache();
$service->setNamespace($registry->get("GV_sit", ""));
return $service;
} }
public function getType() public function getType()
@@ -49,4 +55,16 @@ class Tab extends ServiceAbstract implements ServiceInterface
return 'xcache'; return 'xcache';
} }
private function getRegistry()
{
$registry = $this->getDependency("registry");
if (!$registry instanceof \registryInterface)
{
throw new \Exception(sprintf('Registry dependency does not implement registryInterface for %s service', $this->name));
}
return $registry;
}
} }

View File

@@ -37,9 +37,9 @@ class Monolog extends ServiceAbstract implements ServiceInterface
*/ */
protected $monolog; protected $monolog;
public function __construct($name, Array $options) public function __construct($name, Array $options,Array $dependencies)
{ {
parent::__construct($name, $options); parent::__construct($name, $options, $dependencies);
if (empty($options)) if (empty($options))
{ {

View File

@@ -27,6 +27,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
*/ */
class Doctrine extends ServiceAbstract implements ServiceInterface class Doctrine extends ServiceAbstract implements ServiceInterface
{ {
const ARRAYCACHE = 'array'; const ARRAYCACHE = 'array';
const MEMCACHED = 'memcached'; const MEMCACHED = 'memcached';
const XCACHE = 'xcache'; const XCACHE = 'xcache';
@@ -45,9 +46,9 @@ class Doctrine extends ServiceAbstract implements ServiceInterface
protected $cacheServices = array(); protected $cacheServices = array();
protected $debug; protected $debug;
public function __construct($name, Array $options = array()) public function __construct($name, Array $options, Array $dependencies)
{ {
parent::__construct($name, $options); parent::__construct($name, $options, $dependencies);
static::loadClasses(); static::loadClasses();
@@ -373,12 +374,16 @@ class Doctrine extends ServiceAbstract implements ServiceInterface
} }
} }
$service = $this->findService( $registry = $this->getDependency("registry");
$serviceName
, Core\ServiceBuilder::CACHE $serviceBuilder = new Core\ServiceBuilder\Cache(
, $configuration $serviceName,
$configuration,
array("registry" => $registry)
); );
$service = $serviceBuilder->buildService();
$this->cacheServices[$cacheDoctrine] = $service; $this->cacheServices[$cacheDoctrine] = $service;
return $service->getService(); return $service->getService();
@@ -416,14 +421,14 @@ class Doctrine extends ServiceAbstract implements ServiceInterface
); );
} }
$service = $this->findService( $serviceBuilder = new Core\ServiceBuilder\Log(
$serviceName $serviceName,
, Core\ServiceBuilder::LOG $configuration,
, $configuration array(),
, 'doctrine' //look for Log\Doctrine services "Doctrine"
); );
return $service->getService(); return $serviceBuilder->buildService()->getService();
} }
public function getService() public function getService()

View File

@@ -20,17 +20,20 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
* @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com * @link www.phraseanet.com
*/ */
class ServiceAbstract abstract class ServiceAbstract
{ {
protected $name; protected $name;
protected $options; protected $options;
protected $configuration; protected $configuration;
public function __construct($name, Array $options) private $dependencies;
public function __construct($name, Array $options, Array $dependencies)
{ {
$this->name = $name; $this->name = $name;
$this->options = $options; $this->options = $options;
$this->dependencies = $dependencies;
$spec = new Core\Configuration\Application(); $spec = new Core\Configuration\Application();
$parser = new Core\Configuration\Parser\Yaml(); $parser = new Core\Configuration\Parser\Yaml();
@@ -39,15 +42,36 @@ class ServiceAbstract
$this->configuration = new Core\Configuration($handler); $this->configuration = new Core\Configuration($handler);
} }
protected function getDependency($name)
{
if(!array_key_exists($name, $this->dependencies))
{
throw new \Exception(sprintf("Unknow dependency %s for %s service ", $name, $this->name));
}
return $this->dependencies[$name];
}
/** /**
* *
* @return Core\Configuration * @return Array
*/ */
protected function getConfiguration() protected function getConfiguration()
{ {
return $this->configuration; return $this->configuration;
} }
/**
*
* @return Array
*/
public function getDependencies()
{
return $this->dependencies;
}
/** /**
* *
* @return string * @return string
@@ -75,20 +99,4 @@ class ServiceAbstract
return ''; return '';
} }
/**
*
* @param type $serviceName
* @param type $serviceScope
* @return ServiceInterface
*/
protected function findService($serviceName, $serviceScope, ParameterBag $configuration, $namespace = null)
{
return Core\ServiceBuilder::build(
$serviceName
, $serviceScope
, $configuration
, $namespace
);
}
} }

View File

@@ -26,10 +26,9 @@ class Twig extends ServiceAbstract implements ServiceInterface
protected $twig; protected $twig;
protected $templatesPath = array(); protected $templatesPath = array();
public function __construct($name, Array $options) public function __construct($name, Array $options, Array $dependencies)
{ {
parent::__construct($name, $options, $dependencies);
parent::__construct($name, $options);
$this->templatesPath = $this->resolvePaths(); $this->templatesPath = $this->resolvePaths();

View File

@@ -1,109 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class ServiceBuilder
{
const LOG = 'log';
const TEMPLATE_ENGINE = 'template_engine';
const ORM = 'orm';
const CACHE = 'cache';
protected static $scopes = array(
self::ORM, self::TEMPLATE_ENGINE, self::LOG, self::CACHE
);
protected static $typeToService = array(
'echo' => 'normal', 'array' => 'tab'
);
protected static $optionsNotMandatory = array(
'twig', 'apc', 'xcache', 'memcache', 'array', 'echo'
);
public static function build($serviceName, $serviceScope, ParameterBag $configuration, $namespace = null)
{
$serviceType = $configuration->get("type");
if(!in_array($serviceType, self::$optionsNotMandatory))
{
$options = $configuration->get("options");
}
else
{
try
{
$options = $configuration->get("options");
}
catch(\Exception $e)
{
$options = array();
}
}
if (!in_array($serviceScope, self::$scopes))
{
throw new \Exception(sprintf("Unknow service scope of type %s", $serviceScope));
}
$composedScope = explode("_", $serviceScope);
if (count($composedScope) > 1)
{
$scope = "";
foreach ($composedScope as $word)
{
$scope .= ucfirst($word);
}
$serviceScope = $scope;
}
if (is_string($namespace))
{
$serviceScope = sprintf("%s\%s", ucfirst($serviceScope), ucfirst($namespace));
}
if(array_key_exists($serviceType, self::$typeToService))
{
$serviceType = self::$typeToService[$serviceType];
}
$className = sprintf(
"\Alchemy\Phrasea\Core\Service\%s\%s"
, ucfirst($serviceScope)
, ucfirst($serviceType)
);
if (class_exists($className))
{
return new $className($serviceName, $options);
}
else
{
throw new \Exception(sprintf(
'Unknow service %s for %s scopes looked for classname %s'
, str_replace('/', '_', $serviceType)
, $serviceScope
, $className)
);
}
}
}

View File

@@ -0,0 +1,73 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\ServiceBuilder;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
abstract class AbstractBuilder
{
protected static $optionsNotMandatory = array();
private $service;
public function __construct($name, ParameterBag $configuration, Array $dependencies = array(), $namespace = null)
{
if (!is_string($name) && empty($name))
{
throw new \Exception(sprintf("Service name must be a string %s given", var_export($name, true)));
}
$this->service = static::create($name, $configuration, $dependencies, $namespace);
}
/**
*
* @return ServiceAbstract
*/
public function buildService()
{
return $this->service;
}
public static function create($name, ParameterBag $configuration, Array $dependencies = array(), $namespace = null)
{
throw new \Exception("Abstract factory does not create any concrete Service");
}
protected static function getServiceOptions($type, ParameterBag $configuration)
{
if(!in_array($type, static::$optionsNotMandatory))
{
$options = $configuration->get("options");
}
else
{
try
{
$options = $configuration->get("options");
}
catch(\Exception $e)
{
$options = array();
}
}
return $options;
}
}

View File

@@ -0,0 +1,49 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\ServiceBuilder;
use Alchemy\Phrasea\Core\Service;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Cache extends AbstractBuilder
{
protected static $optionsNotMandatory = array('apc', 'xcache', 'memcache', 'array');
public static function create($name, ParameterBag $configuration, Array $dependencies = array(), $namespace = null)
{
$type = $configuration->get("type");
$options = parent::getServiceOptions($type, $configuration);
$className = sprintf("\Alchemy\Phrasea\Core\Service\Cache\%sCache", ucfirst($type));
if (class_exists($className))
{
return new $className($name, $options, $dependencies);
}
else
{
throw new \Exception(sprintf(
'Unknow service %s for cache scopes looked for classname %s'
, str_replace('/', '_', $type)
, $className)
);
}
}
}

View File

@@ -0,0 +1,57 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\ServiceBuilder;
use Alchemy\Phrasea\Core\Service;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Log extends AbstractBuilder
{
protected static $optionsNotMandatory = array('echo');
public static function create($name, ParameterBag $configuration, Array $dependencies = array(), $namespace = null)
{
$type = $configuration->get("type");
$options = parent::getServiceOptions($type, $configuration);
if (is_string($namespace))
{
$className = sprintf("\Alchemy\Phrasea\Core\Service\Log\%s\%s", $namespace, ucfirst($type));
}
else
{
$className = sprintf("\Alchemy\Phrasea\Core\Service\Log\%s", ucfirst($type));
}
if (class_exists($className))
{
return new $className($name, $options, $dependencies);
}
else
{
throw new \Exception(sprintf(
'Unknow service %s for log looked for classname %s'
, str_replace('/', '_', $type)
, $className)
);
}
}
}

View File

@@ -0,0 +1,48 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\ServiceBuilder;
use Alchemy\Phrasea\Core\Service;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Orm extends AbstractBuilder
{
public static function create($name, ParameterBag $configuration, Array $dependencies = array(), $namespace = null)
{
$type = $configuration->get("type");
$options = parent::getServiceOptions($type, $configuration);
$className = sprintf("\Alchemy\Phrasea\Core\Service\Orm\%s", ucfirst($type));
if (class_exists($className))
{
return new $className($name, $options, $dependencies);
}
else
{
throw new \Exception(sprintf(
'Unknow service %s for orm looked for classname %s'
, str_replace('/', '_', $type)
, $className)
);
}
}
}

View File

@@ -0,0 +1,48 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\ServiceBuilder;
use Alchemy\Phrasea\Core\Service;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class TemplateEngine extends AbstractBuilder
{
public static function create($name, ParameterBag $configuration, Array $dependencies = array(), $namespace = null)
{
$type = $configuration->get("type");
$options = parent::getServiceOptions($type, $configuration);
$className = sprintf("\Alchemy\Phrasea\Core\Service\TemplateEngine\%s", ucfirst($type));
if (class_exists($className))
{
return new $className($name, $options, $dependencies);
}
else
{
throw new \Exception(sprintf(
'Unknow service %s for template engine looked for classname %s'
, str_replace('/', '_', ucfirst($type))
, $className)
);
}
}
}

View File

@@ -50,7 +50,6 @@ class PDF
case self::LAYOUT_PREVIEWCAPTIONTDM: case self::LAYOUT_PREVIEWCAPTIONTDM:
try try
{ {
// exit('prout');
$subdef = $record->get_subdef('preview'); $subdef = $record->get_subdef('preview');
if (!$subdef->is_physically_present()) if (!$subdef->is_physically_present())
{ {

View File

@@ -738,7 +738,7 @@ class API_V1_adapter extends API_V1_Abstract
'note' => $validation_datas->getNote() 'note' => $validation_datas->getNote()
); );
if($user->get_id() == $this->core->getAuthenticatedUser()->get_id()) if ($user->get_id() == $this->core->getAuthenticatedUser()->get_id())
{ {
$agreement = $validation_datas->getAgreement(); $agreement = $validation_datas->getAgreement();
$note = $validation_datas->getNote(); $note = $validation_datas->getNote();
@@ -1080,9 +1080,9 @@ class API_V1_adapter extends API_V1_Abstract
$ret = array(); $ret = array();
foreach ($caption->get_fields() as $field) foreach ($caption->get_fields() as $field)
{ {
foreach($field->get_values as $value) foreach ($field->get_values() as $value)
{ {
$ret[$value->getId()] = $this->list_record_caption_field($value); $ret[$value->getId()] = $this->list_record_caption_field($value, $field);
} }
} }

View File

@@ -34,6 +34,7 @@ class appbox extends base
* *
* constant defining the app type * constant defining the app type
*/ */
const BASE_TYPE = self::APPLICATION_BOX; const BASE_TYPE = self::APPLICATION_BOX;
/** /**
@@ -44,6 +45,7 @@ class appbox extends base
protected $cache; protected $cache;
protected $connection; protected $connection;
protected $registry; protected $registry;
const CACHE_LIST_BASES = 'list_bases'; const CACHE_LIST_BASES = 'list_bases';
const CACHE_SBAS_IDS = 'sbas_ids'; const CACHE_SBAS_IDS = 'sbas_ids';
@@ -67,7 +69,7 @@ class appbox extends base
* *
* @return appbox * @return appbox
*/ */
protected function __construct(registryInterface $registry=null) protected function __construct(registryInterface $registry = null)
{ {
$this->connection = connection::getPDOConnection(); $this->connection = connection::getPDOConnection();
if (!$registry) if (!$registry)
@@ -101,7 +103,7 @@ class appbox extends base
* @param string $pic_type * @param string $pic_type
* @return appbox * @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) if ($pathfile instanceof system_file)
{ {
@@ -159,7 +161,7 @@ class appbox extends base
* @param <type> $pic_type * @param <type> $pic_type
* @return appbox * @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) if ($pathfile instanceof system_file)
@@ -319,7 +321,7 @@ class appbox extends base
$em = $core->getEntityManager(); $em = $core->getEntityManager();
//create schema //create schema
if($em->getConnection()->getDatabasePlatform()->supportsAlterTable()) if ($em->getConnection()->getDatabasePlatform()->supportsAlterTable())
{ {
$tool = new \Doctrine\ORM\Tools\SchemaTool($em); $tool = new \Doctrine\ORM\Tools\SchemaTool($em);
$metas = $em->getMetadataFactory()->getAllMetadata(); $metas = $em->getMetadataFactory()->getAllMetadata();
@@ -486,10 +488,21 @@ class appbox extends base
'main_connexion' => $connexionINI, 'main_connexion' => $connexionINI,
'test_connexion' => array( 'test_connexion' => array(
'driver' => 'pdo_sqlite', 'driver' => 'pdo_sqlite',
'path' => $root . 'lib/unitTest/tests.sqlite', 'path' => realpath($root . 'lib/unitTest/tests.sqlite'),
'charset' => 'UTF8' '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); $yaml = $configuration->getConfigurationHandler()->getParser()->dump($connexion, 2);
if (!file_put_contents($connexionFile->getPathname(), $yaml) !== false) if (!file_put_contents($connexionFile->getPathname(), $yaml) !== false)
@@ -499,8 +512,22 @@ class appbox extends base
//rewrite service file //rewrite service file
$serviceFile = $appConf->getServiceFile(); $serviceFile = $appConf->getServiceFile();
$service = $configuration->getConfigurationHandler()->getParser()->parse($serviceFile); $services = $configuration->getConfigurationHandler()->getParser()->parse($serviceFile);
$yaml = $configuration->getConfigurationHandler()->getParser()->dump($service, 5);
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) if (!file_put_contents($serviceFile->getPathname(), $yaml) !== false)
{ {
@@ -516,6 +543,11 @@ class appbox extends base
{ {
$arrayConf[$key]["phraseanet"]["servername"] = $serverName; $arrayConf[$key]["phraseanet"]["servername"] = $serverName;
} }
if (is_array($value) && $key === 'prod')
{
$arrayConf[$key]["cache"] = $cacheService;
}
} }
$configuration->write($arrayConf); $configuration->write($arrayConf);

View File

@@ -324,12 +324,12 @@ class module_console_fileConfigCheck extends Command
} }
$service = Core\ServiceBuilder::build( $serviceBuilder = new Core\ServiceBuilder\TemplateEngine(
$templateEngineName $templateEngineName
, Core\ServiceBuilder::TEMPLATE_ENGINE
, $configuration , $configuration
); );
$service = $serviceBuilder->buildService();
if ($service->getType() === 'twig') if ($service->getType() === 'twig')
{ {
@@ -415,12 +415,16 @@ class module_console_fileConfigCheck extends Command
throw $e; throw $e;
} }
$service = Core\ServiceBuilder::build( $registry = \registry::get_instance();
$serviceBuilder = new Core\ServiceBuilder\Orm(
$ormName $ormName
, Core\ServiceBuilder::ORM
, $configuration , $configuration
, array('registry'=> $registry)
); );
$service = $serviceBuilder->buildService();
if ($service->getType() === 'doctrine') if ($service->getType() === 'doctrine')
{ {
$caches = $service->getCacheServices(); $caches = $service->getCacheServices();

View File

@@ -509,6 +509,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface
{ {
return null; return null;
} }
try try
{ {
return $this->get_subdef('thumbnailGIF'); return $this->get_subdef('thumbnailGIF');
@@ -598,14 +599,21 @@ class record_adapter implements record_Interface, cache_cacheableInterface
public function get_subdef($name) public function get_subdef($name)
{ {
$name = strtolower($name); $name = strtolower($name);
if (!in_array($name, $this->get_available_subdefs())) if (!in_array($name, $this->get_available_subdefs()))
{
throw new Exception_Media_SubdefNotFound (); throw new Exception_Media_SubdefNotFound ();
}
if (isset($this->subdefs[$name])) if (isset($this->subdefs[$name]))
{
return $this->subdefs[$name]; return $this->subdefs[$name];
}
if (!$this->subdefs) if (!$this->subdefs)
{
$this->subdefs = array(); $this->subdefs = array();
}
$substitute = ($name !== 'document'); $substitute = ($name !== 'document');
@@ -1268,7 +1276,9 @@ class record_adapter implements record_Interface, cache_cacheableInterface
} }
if (!is_scalar($params['value'])) if (!is_scalar($params['value']))
{
throw new Exception('Metadata value should be scalar'); throw new Exception('Metadata value should be scalar');
}
$databox_field = databox_field::get_instance($databox, $params['meta_struct_id']); $databox_field = databox_field::get_instance($databox, $params['meta_struct_id']);

View File

@@ -451,7 +451,17 @@ class searchEngine_options implements Serializable
$value = new DateTime($value); $value = new DateTime($value);
} }
elseif ($value instanceof stdClass) elseif ($value instanceof stdClass)
$value = (array) $value; {
$tmpvalue = (array) $value;
$value = array();
foreach($tmpvalue as $k=>$data)
{
$k = ctype_digit($k) ? (int) $k : $k;
$value[$k] = $data;
}
}
$this->$key = $value; $this->$key = $value;
} }

View File

@@ -93,7 +93,7 @@ class ControllerTooltipTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
foreach ($routes as $route) foreach ($routes as $route)
{ {
$option = new \searchEngine_options(); $option = new \searchEngine_options();
$crawler = $this->client->request('POST', $route, array('options_serial' => $option->serialize())); $crawler = $this->client->request('POST', $route, array('options_serial' => serialize($option)));
$this->assertTrue($this->client->getResponse()->isOk()); $this->assertTrue($this->client->getResponse()->isOk());
} }

View File

@@ -818,12 +818,12 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
$serviceName = $configuration->getTemplating(); $serviceName = $configuration->getTemplating();
$confService = $configuration->getService($serviceName); $confService = $configuration->getService($serviceName);
$templateService = \Alchemy\Phrasea\Core\ServiceBuilder::build( $templateServiceBuilder = new \Alchemy\Phrasea\Core\ServiceBuilder\TemplateEngine(
$serviceName $serviceName
, \Alchemy\Phrasea\Core\ServiceBuilder::TEMPLATE_ENGINE
, $confService , $confService
); );
$this->app['Core']["Twig"] = $templateService->getService();
$this->app['Core']["Twig"] = $templateServiceBuilder->buildService()->getService();
} }
/** /**
@@ -1021,13 +1021,13 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
{ {
if (static::$need_story && !self::$story_1 instanceof record_adapter) if (static::$need_story && !self::$story_1 instanceof record_adapter)
{ {
echo "generate story 1\n";
self::$story_1 = \record_adapter::create( self::$story_1 = \record_adapter::create(
self::$collection self::$collection
, new system_file(__DIR__ . '/testfiles/test001.CR2') , new system_file(__DIR__ . '/testfiles/test001.CR2')
, false , false
, true , true
); );
// echo "generate story 1\n";
} }
return; return;
@@ -1044,116 +1044,139 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
{ {
if (self::$record_1 instanceof record_adapter && !isset(self::$generated_subdefs['a1'])) if (self::$record_1 instanceof record_adapter && !isset(self::$generated_subdefs['a1']))
{ {
echo "Generate subdefs 1 \n";
self::$record_1->generate_subdefs(self::$collection->get_databox()); self::$record_1->generate_subdefs(self::$collection->get_databox());
self::$generated_subdefs['a1'] = true; self::$generated_subdefs['a1'] = true;
} }
if (self::$record_2 instanceof record_adapter && !isset(self::$generated_subdefs['a2'])) if (self::$record_2 instanceof record_adapter && !isset(self::$generated_subdefs['a2']))
{ {
echo "Generate subdefs 2 \n";
self::$record_2->generate_subdefs(self::$collection->get_databox()); self::$record_2->generate_subdefs(self::$collection->get_databox());
self::$generated_subdefs['a2'] = true; self::$generated_subdefs['a2'] = true;
} }
if (self::$record_3 instanceof record_adapter && !isset(self::$generated_subdefs['a3'])) if (self::$record_3 instanceof record_adapter && !isset(self::$generated_subdefs['a3']))
{ {
echo "Generate subdefs 3 \n";
self::$record_3->generate_subdefs(self::$collection->get_databox()); self::$record_3->generate_subdefs(self::$collection->get_databox());
self::$generated_subdefs['a3'] = true; self::$generated_subdefs['a3'] = true;
} }
if (self::$record_4 instanceof record_adapter && !isset(self::$generated_subdefs['a4'])) if (self::$record_4 instanceof record_adapter && !isset(self::$generated_subdefs['a4']))
{ {
echo "Generate subdefs 4 \n";
self::$record_4->generate_subdefs(self::$collection->get_databox()); self::$record_4->generate_subdefs(self::$collection->get_databox());
self::$generated_subdefs['a4'] = true; self::$generated_subdefs['a4'] = true;
} }
if (self::$record_5 instanceof record_adapter && !isset(self::$generated_subdefs['a5'])) if (self::$record_5 instanceof record_adapter && !isset(self::$generated_subdefs['a5']))
{ {
echo "Generate subdefs 5 \n";
self::$record_5->generate_subdefs(self::$collection->get_databox()); self::$record_5->generate_subdefs(self::$collection->get_databox());
self::$generated_subdefs['a5'] = true; self::$generated_subdefs['a5'] = true;
} }
if (self::$record_6 instanceof record_adapter && !isset(self::$generated_subdefs['a6'])) if (self::$record_6 instanceof record_adapter && !isset(self::$generated_subdefs['a6']))
{ {
echo "Generate subdefs 6 \n";
self::$record_6->generate_subdefs(self::$collection->get_databox()); self::$record_6->generate_subdefs(self::$collection->get_databox());
self::$generated_subdefs['a6'] = true; self::$generated_subdefs['a6'] = true;
} }
if (self::$record_7 instanceof record_adapter && !isset(self::$generated_subdefs['a7'])) if (self::$record_7 instanceof record_adapter && !isset(self::$generated_subdefs['a7']))
{ {
echo "Generate subdefs 7 \n";
self::$record_7->generate_subdefs(self::$collection->get_databox()); self::$record_7->generate_subdefs(self::$collection->get_databox());
self::$generated_subdefs['a7'] = true; self::$generated_subdefs['a7'] = true;
} }
if (self::$record_8 instanceof record_adapter && !isset(self::$generated_subdefs['a8'])) if (self::$record_8 instanceof record_adapter && !isset(self::$generated_subdefs['a8']))
{ {
echo "Generate subdefs 8 \n";
self::$record_8->generate_subdefs(self::$collection->get_databox()); self::$record_8->generate_subdefs(self::$collection->get_databox());
self::$generated_subdefs['a8'] = true; self::$generated_subdefs['a8'] = true;
} }
if (self::$record_9 instanceof record_adapter && !isset(self::$generated_subdefs['a9'])) if (self::$record_9 instanceof record_adapter && !isset(self::$generated_subdefs['a9']))
{ {
echo "Generate subdefs 9 \n";
self::$record_9->generate_subdefs(self::$collection->get_databox()); self::$record_9->generate_subdefs(self::$collection->get_databox());
self::$generated_subdefs['a9'] = true; self::$generated_subdefs['a9'] = true;
} }
if (self::$record_10 instanceof record_adapter && !isset(self::$generated_subdefs['a10'])) if (self::$record_10 instanceof record_adapter && !isset(self::$generated_subdefs['a10']))
{ {
echo "Generate subdefs 10 \n";
self::$record_10->generate_subdefs(self::$collection->get_databox()); self::$record_10->generate_subdefs(self::$collection->get_databox());
self::$generated_subdefs['a10'] = true; self::$generated_subdefs['a10'] = true;
} }
if (self::$record_11 instanceof record_adapter && !isset(self::$generated_subdefs['a11'])) if (self::$record_11 instanceof record_adapter && !isset(self::$generated_subdefs['a11']))
{ {
echo "Generate subdefs 11 \n";
self::$record_11->generate_subdefs(self::$collection->get_databox()); self::$record_11->generate_subdefs(self::$collection->get_databox());
self::$generated_subdefs['a11'] = true; self::$generated_subdefs['a11'] = true;
} }
if (self::$record_12 instanceof record_adapter && !isset(self::$generated_subdefs['a12'])) if (self::$record_12 instanceof record_adapter && !isset(self::$generated_subdefs['a12']))
{ {
echo "Generate subdefs 12 \n";
self::$record_12->generate_subdefs(self::$collection->get_databox()); self::$record_12->generate_subdefs(self::$collection->get_databox());
self::$generated_subdefs['a12'] = true; self::$generated_subdefs['a12'] = true;
} }
if (self::$record_13 instanceof record_adapter && !isset(self::$generated_subdefs['a13'])) if (self::$record_13 instanceof record_adapter && !isset(self::$generated_subdefs['a13']))
{ {
echo "Generate subdefs 13 \n";
self::$record_13->generate_subdefs(self::$collection->get_databox()); self::$record_13->generate_subdefs(self::$collection->get_databox());
self::$generated_subdefs['a13'] = true; self::$generated_subdefs['a13'] = true;
} }
if (self::$record_14 instanceof record_adapter && !isset(self::$generated_subdefs['a14'])) if (self::$record_14 instanceof record_adapter && !isset(self::$generated_subdefs['a14']))
{ {
echo "Generate subdefs 14 \n";
self::$record_14->generate_subdefs(self::$collection->get_databox()); self::$record_14->generate_subdefs(self::$collection->get_databox());
self::$generated_subdefs['a14'] = true; self::$generated_subdefs['a14'] = true;
} }
if (self::$record_15 instanceof record_adapter && !isset(self::$generated_subdefs['a15'])) if (self::$record_15 instanceof record_adapter && !isset(self::$generated_subdefs['a15']))
{ {
echo "Generate subdefs 15 \n";
self::$record_15->generate_subdefs(self::$collection->get_databox()); self::$record_15->generate_subdefs(self::$collection->get_databox());
self::$generated_subdefs['a15'] = true; self::$generated_subdefs['a15'] = true;
} }
if (self::$record_16 instanceof record_adapter && !isset(self::$generated_subdefs['a16'])) if (self::$record_16 instanceof record_adapter && !isset(self::$generated_subdefs['a16']))
{ {
echo "Generate subdefs 16 \n";
self::$record_16->generate_subdefs(self::$collection->get_databox()); self::$record_16->generate_subdefs(self::$collection->get_databox());
self::$generated_subdefs['a16'] = true; self::$generated_subdefs['a16'] = true;
} }
if (self::$record_17 instanceof record_adapter && !isset(self::$generated_subdefs['a17'])) if (self::$record_17 instanceof record_adapter && !isset(self::$generated_subdefs['a17']))
{ {
echo "Generate subdefs 17 \n";
self::$record_17->generate_subdefs(self::$collection->get_databox()); self::$record_17->generate_subdefs(self::$collection->get_databox());
self::$generated_subdefs['a17'] = true; self::$generated_subdefs['a17'] = true;
} }
if (self::$record_18 instanceof record_adapter && !isset(self::$generated_subdefs['a18'])) if (self::$record_18 instanceof record_adapter && !isset(self::$generated_subdefs['a18']))
{ {
echo "Generate subdefs 18 \n";
self::$record_18->generate_subdefs(self::$collection->get_databox()); self::$record_18->generate_subdefs(self::$collection->get_databox());
self::$generated_subdefs['a18'] = true; self::$generated_subdefs['a18'] = true;
} }
if (self::$record_19 instanceof record_adapter && !isset(self::$generated_subdefs['a19'])) if (self::$record_19 instanceof record_adapter && !isset(self::$generated_subdefs['a19']))
{ {
echo "Generate subdefs 19 \n";
self::$record_19->generate_subdefs(self::$collection->get_databox()); self::$record_19->generate_subdefs(self::$collection->get_databox());
self::$generated_subdefs['a19'] = true; self::$generated_subdefs['a19'] = true;
} }
if (self::$record_20 instanceof record_adapter && !isset(self::$generated_subdefs['a20'])) if (self::$record_20 instanceof record_adapter && !isset(self::$generated_subdefs['a20']))
{ {
echo "Generate subdefs 20 \n";
self::$record_20->generate_subdefs(self::$collection->get_databox()); self::$record_20->generate_subdefs(self::$collection->get_databox());
self::$generated_subdefs['a20'] = true; self::$generated_subdefs['a20'] = true;
} }
if (self::$record_21 instanceof record_adapter && !isset(self::$generated_subdefs['a21'])) if (self::$record_21 instanceof record_adapter && !isset(self::$generated_subdefs['a21']))
{ {
echo "Generate subdefs 21 \n";
self::$record_21->generate_subdefs(self::$collection->get_databox()); self::$record_21->generate_subdefs(self::$collection->get_databox());
self::$generated_subdefs['a21'] = true; self::$generated_subdefs['a21'] = true;
} }
if (self::$record_22 instanceof record_adapter && !isset(self::$generated_subdefs['a22'])) if (self::$record_22 instanceof record_adapter && !isset(self::$generated_subdefs['a22']))
{ {
echo "Generate subdefs 22 \n";
self::$record_22->generate_subdefs(self::$collection->get_databox()); self::$record_22->generate_subdefs(self::$collection->get_databox());
self::$generated_subdefs['a22'] = true; self::$generated_subdefs['a22'] = true;
} }
if (self::$record_23 instanceof record_adapter && !isset(self::$generated_subdefs['a23'])) if (self::$record_23 instanceof record_adapter && !isset(self::$generated_subdefs['a23']))
{ {
echo "Generate subdefs 23 \n";
self::$record_23->generate_subdefs(self::$collection->get_databox()); self::$record_23->generate_subdefs(self::$collection->get_databox());
self::$generated_subdefs['a23'] = true; self::$generated_subdefs['a23'] = true;
} }
@@ -1171,121 +1194,145 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
{ {
if ((static::$need_records === true || static::$need_records >= 1) && !self::$record_1 instanceof record_adapter) if ((static::$need_records === true || static::$need_records >= 1) && !self::$record_1 instanceof record_adapter)
{ {
echo "generate story 1\n";
self::$record_sf_1 = new system_file(__DIR__ . '/testfiles/test001.CR2'); self::$record_sf_1 = new system_file(__DIR__ . '/testfiles/test001.CR2');
self::$record_1 = record_adapter::create(self::$collection, self::$record_sf_1); self::$record_1 = record_adapter::create(self::$collection, self::$record_sf_1);
} }
if ((static::$need_records === true || static::$need_records >= 1) && !self::$record_no_access instanceof record_adapter) if ((static::$need_records === true || static::$need_records >= 1) && !self::$record_no_access instanceof record_adapter)
{ {
echo "generate story 1\n";
$file = new system_file(__DIR__ . '/testfiles/test001.CR2'); $file = new system_file(__DIR__ . '/testfiles/test001.CR2');
self::$record_no_access = record_adapter::create(self::$collection_no_access, $file); self::$record_no_access = record_adapter::create(self::$collection_no_access, $file);
} }
if ((static::$need_records === true || static::$need_records >= 2) && !self::$record_2 instanceof record_adapter) if ((static::$need_records === true || static::$need_records >= 2) && !self::$record_2 instanceof record_adapter)
{ {
echo "generate story 2\n";
self::$record_sf_2 = new system_file(__DIR__ . '/testfiles/test002.CR2'); self::$record_sf_2 = new system_file(__DIR__ . '/testfiles/test002.CR2');
self::$record_2 = record_adapter::create(self::$collection, self::$record_sf_2); self::$record_2 = record_adapter::create(self::$collection, self::$record_sf_2);
} }
if ((static::$need_records === true || static::$need_records >= 3) && !self::$record_3 instanceof record_adapter) if ((static::$need_records === true || static::$need_records >= 3) && !self::$record_3 instanceof record_adapter)
{ {
echo "generate story 3\n";
self::$record_sf_3 = new system_file(__DIR__ . '/testfiles/test003.CR2'); self::$record_sf_3 = new system_file(__DIR__ . '/testfiles/test003.CR2');
self::$record_3 = record_adapter::create(self::$collection, self::$record_sf_3); self::$record_3 = record_adapter::create(self::$collection, self::$record_sf_3);
} }
if ((static::$need_records === true || static::$need_records >= 4) && !self::$record_4 instanceof record_adapter) if ((static::$need_records === true || static::$need_records >= 4) && !self::$record_4 instanceof record_adapter)
{ {
echo "generate story 4\n";
self::$record_sf_4 = new system_file(__DIR__ . '/testfiles/test004.CR2'); self::$record_sf_4 = new system_file(__DIR__ . '/testfiles/test004.CR2');
self::$record_4 = record_adapter::create(self::$collection, self::$record_sf_4); self::$record_4 = record_adapter::create(self::$collection, self::$record_sf_4);
} }
if ((static::$need_records === true || static::$need_records >= 5) && !self::$record_5 instanceof record_adapter) if ((static::$need_records === true || static::$need_records >= 5) && !self::$record_5 instanceof record_adapter)
{ {
echo "generate story 5\n";
self::$record_sf_5 = new system_file(__DIR__ . '/testfiles/test005.CR2'); self::$record_sf_5 = new system_file(__DIR__ . '/testfiles/test005.CR2');
self::$record_5 = record_adapter::create(self::$collection, self::$record_sf_5); self::$record_5 = record_adapter::create(self::$collection, self::$record_sf_5);
} }
if ((static::$need_records === true || static::$need_records >= 6) && !self::$record_6 instanceof record_adapter) if ((static::$need_records === true || static::$need_records >= 6) && !self::$record_6 instanceof record_adapter)
{ {
echo "generate story 6\n";
self::$record_sf_6 = new system_file(__DIR__ . '/testfiles/test006.wav'); self::$record_sf_6 = new system_file(__DIR__ . '/testfiles/test006.wav');
self::$record_6 = record_adapter::create(self::$collection, self::$record_sf_6); self::$record_6 = record_adapter::create(self::$collection, self::$record_sf_6);
} }
if ((static::$need_records === true || static::$need_records >= 7) && !self::$record_7 instanceof record_adapter) if ((static::$need_records === true || static::$need_records >= 7) && !self::$record_7 instanceof record_adapter)
{ {
echo "generate story 7\n";
self::$record_sf_7 = new system_file(__DIR__ . '/testfiles/test007.ppt'); self::$record_sf_7 = new system_file(__DIR__ . '/testfiles/test007.ppt');
self::$record_7 = record_adapter::create(self::$collection, self::$record_sf_7); self::$record_7 = record_adapter::create(self::$collection, self::$record_sf_7);
} }
if ((static::$need_records === true || static::$need_records >= 8) && !self::$record_8 instanceof record_adapter) if ((static::$need_records === true || static::$need_records >= 8) && !self::$record_8 instanceof record_adapter)
{ {
echo "generate story 8\n";
self::$record_sf_8 = new system_file(__DIR__ . '/testfiles/test008.ai'); self::$record_sf_8 = new system_file(__DIR__ . '/testfiles/test008.ai');
self::$record_8 = record_adapter::create(self::$collection, self::$record_sf_8); self::$record_8 = record_adapter::create(self::$collection, self::$record_sf_8);
} }
if ((static::$need_records === true || static::$need_records >= 9) && !self::$record_9 instanceof record_adapter) if ((static::$need_records === true || static::$need_records >= 9) && !self::$record_9 instanceof record_adapter)
{ {
echo "generate story 9\n";
self::$record_sf_9 = new system_file(__DIR__ . '/testfiles/test009.TIFF'); self::$record_sf_9 = new system_file(__DIR__ . '/testfiles/test009.TIFF');
self::$record_9 = record_adapter::create(self::$collection, self::$record_sf_9); self::$record_9 = record_adapter::create(self::$collection, self::$record_sf_9);
} }
if ((static::$need_records === true || static::$need_records >= 10) && !self::$record_10 instanceof record_adapter) if ((static::$need_records === true || static::$need_records >= 10) && !self::$record_10 instanceof record_adapter)
{ {
echo "generate story 10\n";
self::$record_sf_10 = new system_file(__DIR__ . '/testfiles/test010.fla'); self::$record_sf_10 = new system_file(__DIR__ . '/testfiles/test010.fla');
self::$record_10 = record_adapter::create(self::$collection, self::$record_sf_10); self::$record_10 = record_adapter::create(self::$collection, self::$record_sf_10);
} }
if ((static::$need_records === true || static::$need_records >= 11) && !self::$record_11 instanceof record_adapter) if ((static::$need_records === true || static::$need_records >= 11) && !self::$record_11 instanceof record_adapter)
{ {
echo "generate story 11\n";
self::$record_sf_11 = new system_file(__DIR__ . '/testfiles/test011.swf'); self::$record_sf_11 = new system_file(__DIR__ . '/testfiles/test011.swf');
self::$record_11 = record_adapter::create(self::$collection, self::$record_sf_11); self::$record_11 = record_adapter::create(self::$collection, self::$record_sf_11);
} }
if ((static::$need_records === true || static::$need_records >= 12) && !self::$record_12 instanceof record_adapter) if ((static::$need_records === true || static::$need_records >= 12) && !self::$record_12 instanceof record_adapter)
{ {
echo "generate story 12\n";
self::$record_sf_12 = new system_file(__DIR__ . '/testfiles/test012.wav'); self::$record_sf_12 = new system_file(__DIR__ . '/testfiles/test012.wav');
self::$record_12 = record_adapter::create(self::$collection, self::$record_sf_12); self::$record_12 = record_adapter::create(self::$collection, self::$record_sf_12);
} }
if ((static::$need_records === true || static::$need_records >= 13) && !self::$record_13 instanceof record_adapter) if ((static::$need_records === true || static::$need_records >= 13) && !self::$record_13 instanceof record_adapter)
{ {
echo "generate story 13\n";
self::$record_sf_13 = new system_file(__DIR__ . '/testfiles/test013.ai'); self::$record_sf_13 = new system_file(__DIR__ . '/testfiles/test013.ai');
self::$record_13 = record_adapter::create(self::$collection, self::$record_sf_13); self::$record_13 = record_adapter::create(self::$collection, self::$record_sf_13);
} }
if ((static::$need_records === true || static::$need_records >= 14) && !self::$record_14 instanceof record_adapter) if ((static::$need_records === true || static::$need_records >= 14) && !self::$record_14 instanceof record_adapter)
{ {
echo "generate story 14\n";
self::$record_sf_14 = new system_file(__DIR__ . '/testfiles/test014.swf'); self::$record_sf_14 = new system_file(__DIR__ . '/testfiles/test014.swf');
self::$record_14 = record_adapter::create(self::$collection, self::$record_sf_14); self::$record_14 = record_adapter::create(self::$collection, self::$record_sf_14);
} }
if ((static::$need_records === true || static::$need_records >= 15) && !self::$record_15 instanceof record_adapter) if ((static::$need_records === true || static::$need_records >= 15) && !self::$record_15 instanceof record_adapter)
{ {
echo "generate story 15\n";
self::$record_sf_15 = new system_file(__DIR__ . '/testfiles/test015.eps'); self::$record_sf_15 = new system_file(__DIR__ . '/testfiles/test015.eps');
self::$record_15 = record_adapter::create(self::$collection, self::$record_sf_15); self::$record_15 = record_adapter::create(self::$collection, self::$record_sf_15);
} }
if ((static::$need_records === true || static::$need_records >= 16) && !self::$record_16 instanceof record_adapter) if ((static::$need_records === true || static::$need_records >= 16) && !self::$record_16 instanceof record_adapter)
{ {
echo "generate story 16\n";
self::$record_sf_16 = new system_file(__DIR__ . '/testfiles/test016.ai'); self::$record_sf_16 = new system_file(__DIR__ . '/testfiles/test016.ai');
self::$record_16 = record_adapter::create(self::$collection, self::$record_sf_16); self::$record_16 = record_adapter::create(self::$collection, self::$record_sf_16);
} }
if ((static::$need_records === true || static::$need_records >= 17) && !self::$record_17 instanceof record_adapter) if ((static::$need_records === true || static::$need_records >= 17) && !self::$record_17 instanceof record_adapter)
{ {
echo "generate story 17\n";
self::$record_sf_17 = new system_file(__DIR__ . '/testfiles/test017.wav'); self::$record_sf_17 = new system_file(__DIR__ . '/testfiles/test017.wav');
self::$record_17 = record_adapter::create(self::$collection, self::$record_sf_17); self::$record_17 = record_adapter::create(self::$collection, self::$record_sf_17);
} }
if ((static::$need_records === true || static::$need_records >= 18) && !self::$record_18 instanceof record_adapter) if ((static::$need_records === true || static::$need_records >= 18) && !self::$record_18 instanceof record_adapter)
{ {
echo "generate story 18\n";
self::$record_sf_18 = new system_file(__DIR__ . '/testfiles/test018.TIFF'); self::$record_sf_18 = new system_file(__DIR__ . '/testfiles/test018.TIFF');
self::$record_18 = record_adapter::create(self::$collection, self::$record_sf_18); self::$record_18 = record_adapter::create(self::$collection, self::$record_sf_18);
} }
if ((static::$need_records === true || static::$need_records >= 19) && !self::$record_19 instanceof record_adapter) if ((static::$need_records === true || static::$need_records >= 19) && !self::$record_19 instanceof record_adapter)
{ {
echo "generate story 19\n";
self::$record_sf_19 = new system_file(__DIR__ . '/testfiles/test019.mp3'); self::$record_sf_19 = new system_file(__DIR__ . '/testfiles/test019.mp3');
self::$record_19 = record_adapter::create(self::$collection, self::$record_sf_19); self::$record_19 = record_adapter::create(self::$collection, self::$record_sf_19);
} }
if ((static::$need_records === true || static::$need_records >= 20) && !self::$record_20 instanceof record_adapter) if ((static::$need_records === true || static::$need_records >= 20) && !self::$record_20 instanceof record_adapter)
{ {
echo "generate story 20\n";
self::$record_sf_20 = new system_file(__DIR__ . '/testfiles/test020.mp3'); self::$record_sf_20 = new system_file(__DIR__ . '/testfiles/test020.mp3');
self::$record_20 = record_adapter::create(self::$collection, self::$record_sf_20); self::$record_20 = record_adapter::create(self::$collection, self::$record_sf_20);
} }
if ((static::$need_records === true || static::$need_records >= 21) && !self::$record_21 instanceof record_adapter) if ((static::$need_records === true || static::$need_records >= 21) && !self::$record_21 instanceof record_adapter)
{ {
echo "generate story 21\n";
self::$record_sf_21 = new system_file(__DIR__ . '/testfiles/test021.fla'); self::$record_sf_21 = new system_file(__DIR__ . '/testfiles/test021.fla');
self::$record_21 = record_adapter::create(self::$collection, self::$record_sf_21); self::$record_21 = record_adapter::create(self::$collection, self::$record_sf_21);
} }
if ((static::$need_records === true || static::$need_records >= 22) && !self::$record_22 instanceof record_adapter) if ((static::$need_records === true || static::$need_records >= 22) && !self::$record_22 instanceof record_adapter)
{ {
echo "generate story 22\n";
self::$record_sf_22 = new system_file(__DIR__ . '/testfiles/test022.swf'); self::$record_sf_22 = new system_file(__DIR__ . '/testfiles/test022.swf');
self::$record_22 = record_adapter::create(self::$collection, self::$record_sf_22); self::$record_22 = record_adapter::create(self::$collection, self::$record_sf_22);
} }
if ((static::$need_records === true || static::$need_records >= 23) && !self::$record_23 instanceof record_adapter) if ((static::$need_records === true || static::$need_records >= 23) && !self::$record_23 instanceof record_adapter)
{ {
echo "generate story 23\n";
self::$record_sf_23 = new system_file(__DIR__ . '/testfiles/test023.mp4'); self::$record_sf_23 = new system_file(__DIR__ . '/testfiles/test023.mp4');
self::$record_23 = record_adapter::create(self::$collection, self::$record_sf_23); self::$record_23 = record_adapter::create(self::$collection, self::$record_sf_23);
} }

View File

@@ -261,10 +261,13 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
} }
$metadatas = array_shift($metadatas); $metadatas = array_shift($metadatas);
$metadatas["value"] = array("new_value"); $metadatas["value"] = "new_value";
$request = new Request(array("metadatas" => array($metadatas)), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json')); $request = new Request(array("metadatas" => array($metadatas)), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
$result = $this->object->set_record_metadatas($request, self::$record_1->get_sbas_id(), self::$record_1->get_record_id()); $result = $this->object->set_record_metadatas($request, self::$record_1->get_sbas_id(), self::$record_1->get_record_id());
$this->checkResponseField($result, "metadatas", PHPUnit_Framework_Constraint_IsType::TYPE_OBJECT); $this->checkResponseField($result, "metadatas", PHPUnit_Framework_Constraint_IsType::TYPE_OBJECT);
} }

View File

@@ -257,7 +257,7 @@ class system_fileTest extends PhraseanetPHPUnitAbstract
$this->assertArrayHasKey('meta_struct_id', $metadata); $this->assertArrayHasKey('meta_struct_id', $metadata);
$this->assertArrayHasKey('meta_id', $metadata); $this->assertArrayHasKey('meta_id', $metadata);
$this->assertArrayHasKey('value', $metadata); $this->assertArrayHasKey('value', $metadata);
$this->assertTrue(is_array($metadata['value'])); $this->assertTrue(is_scalar($metadata['value']));
$this->assertNull($metadata['meta_id']); $this->assertNull($metadata['meta_id']);
$this->assertTrue(is_int($metadata['meta_struct_id'])); $this->assertTrue(is_int($metadata['meta_struct_id']));
$this->assertTrue($metadata['meta_struct_id'] > 0); $this->assertTrue($metadata['meta_struct_id'] > 0);

View File

@@ -19,9 +19,10 @@ class unitTestsTest extends PhraseanetPHPUnitAbstract
continue; continue;
if (substr($file->getFilename(), -4) !== '.php') if (substr($file->getFilename(), -4) !== '.php')
continue; continue;
if($file->getFilename() === "BoilerPlate.php")
continue;
$this->assertRegExp('/[a-zA-Z0-9-_\.]+Test.php/', $file->getPathname(), 'Verify that all tests files names');
$this->assertRegExp('/[a-zA-Z0-9-_\.]+Test.php/', $file->getFilename(), 'Verify that all tests files names');
} }
} }