diff --git a/bin/doctrine b/bin/doctrine index 6d5b6ff1a1..6f3edd2aad 100755 --- a/bin/doctrine +++ b/bin/doctrine @@ -43,12 +43,13 @@ try 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 - , \Alchemy\Phrasea\Core\ServiceBuilder::ORM , $confService + , array('registry' => \registry::get_instance()) ); + $ormService = $ormServiceBuilder->buildService(); $em = $ormService->getService(); /* @var $em \Doctrine\ORM\EntityManager */ diff --git a/config/config.sample.yml b/config/config.sample.yml index 0172c7b3c8..7a0c5dff3a 100644 --- a/config/config.sample.yml +++ b/config/config.sample.yml @@ -2,7 +2,7 @@ #Declare which environment will be used by the application -environment : dev +environment : prod #Declare all your environment configurations @@ -25,6 +25,7 @@ dev: #Services are defined in service.yml configuration file template_engine: twig_debug orm: doctrine_dev + cache: array_cache ############## # PRODUCTION # @@ -39,6 +40,7 @@ prod: template_engine: twig orm: doctrine_prod + cache: apc_cache ############## # TEST # @@ -53,5 +55,6 @@ test: template_engine: twig_debug orm: doctrine_test + cache: array_cache \ No newline at end of file diff --git a/lib/Alchemy/Phrasea/Application/Setup.php b/lib/Alchemy/Phrasea/Application/Setup.php index c9d681a32e..9c8f9509e8 100644 --- a/lib/Alchemy/Phrasea/Application/Setup.php +++ b/lib/Alchemy/Phrasea/Application/Setup.php @@ -65,7 +65,7 @@ return call_user_func(function() { throw new \Exception(sprintf("Unable to copy %s", $serviceSampleFile)); } - + //copy connexion sample $connexionSampleFile = __DIR__ . "/../../../../config/connexions.sample.yml"; $connexionFile = __DIR__ . "/../../../../config/connexions.yml"; @@ -105,7 +105,7 @@ return call_user_func(function() 'main_connexion' => $connexionINI, 'test_connexion' => array( 'driver' => 'pdo_sqlite', - 'path' => $registry->get("GV_RootPath") . 'lib/unitTest/tests.sqlite', + 'path' => realpath($registry->get("GV_RootPath") . 'lib/unitTest/tests.sqlite'), 'charset' => 'UTF8' )); @@ -116,10 +116,34 @@ return call_user_func(function() 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 $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) { @@ -134,11 +158,17 @@ return call_user_func(function() { $arrayConf[$key]["phraseanet"]["servername"] = $serverName; } + + if (is_array($value) && $key === 'prod') + { + $arrayConf[$key]["cache"] = $cacheService; + } } $configuration->write($arrayConf); - - $app->redirect("/setup/installer/"); + + $app['install'] = true; +// $app->redirect("/setup/installer/"); } else { diff --git a/lib/Alchemy/Phrasea/Controller/Prod/UsrLists.php b/lib/Alchemy/Phrasea/Controller/Prod/UsrLists.php index 450174dfab..9bfa1f5d83 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/UsrLists.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/UsrLists.php @@ -344,14 +344,15 @@ class UsrLists implements ControllerProviderInterface $controllers->post('/list/{list_id}/add/{usr_id}/', function(Application $app, $list_id, $usr_id) { $em = $app['Core']->getEntityManager(); - + $user = $app['Core']->getAuthenticatedUser(); + try { $repository = $em->getRepository('\Entities\UsrList'); $list = $repository->findUserListByUserAndId($user, $list_id); /* @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->setUser($user_entry); @@ -399,12 +400,12 @@ class UsrLists implements ControllerProviderInterface $list = $repository->findUserListByUserAndId($user, $list_id); /* @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'); } - $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)) { @@ -436,7 +437,7 @@ class UsrLists implements ControllerProviderInterface } catch (\Exception $e) { - + $datas = array( 'success' => false , 'message' => _('Unable to share the list with the usr') diff --git a/lib/Alchemy/Phrasea/Controller/Setup/Installer.php b/lib/Alchemy/Phrasea/Controller/Setup/Installer.php index 5509e916fb..56aa8c41df 100644 --- a/lib/Alchemy/Phrasea/Controller/Setup/Installer.php +++ b/lib/Alchemy/Phrasea/Controller/Setup/Installer.php @@ -133,6 +133,8 @@ class Installer implements ControllerProviderInterface \phrasea::use_i18n(\Session_Handler::get_locale()); $request = $app['request']; + $servername = $request->getScheme() . '://' . $request->getHttpHost() . '/'; + $setupRegistry = new \Setup_Registry(); $setupRegistry->set('GV_ServerName', $servername); @@ -171,7 +173,8 @@ class Installer implements ControllerProviderInterface try { - $servername = $request->getScheme() . '://' . $request->getHttpHost() . '/'; + $setupRegistry = new \Setup_Registry(); + $setupRegistry->set('GV_ServerName', $servername); $appbox = \appbox::create($setupRegistry, $conn, $appbox_name, true); @@ -186,12 +189,14 @@ class Installer implements ControllerProviderInterface $serviceName = $configuration->getOrm(); $confService = $configuration->getService($serviceName); - $ormService = \Alchemy\Phrasea\Core\ServiceBuilder::build( + $ormServiceBuilder = new \Alchemy\Phrasea\Core\ServiceBuilder\Orm( $serviceName - , \Alchemy\Phrasea\Core\ServiceBuilder::ORM , $confService + , array('registry' => $setupRegistry) ); + $ormService = $ormServiceBuilder->buildService(); + if ($ormService->getType() === 'doctrine') { /* @var $em \Doctrine\ORM\EntityManager */ @@ -325,4 +330,4 @@ class Installer implements ControllerProviderInterface return $controllers; } -} \ No newline at end of file +} diff --git a/lib/Alchemy/Phrasea/Controller/Setup/Upgrader.php b/lib/Alchemy/Phrasea/Controller/Setup/Upgrader.php index cb799aff5c..cde1037be8 100644 --- a/lib/Alchemy/Phrasea/Controller/Setup/Upgrader.php +++ b/lib/Alchemy/Phrasea/Controller/Setup/Upgrader.php @@ -40,7 +40,6 @@ class Upgrader implements ControllerProviderInterface /* @var $twig \Twig_Environment */ $twig = $app['Core']->getTwig(); - ini_set('display_errors', 'on'); $html = $twig->render( '/setup/upgrader.html.twig' , array( @@ -60,7 +59,6 @@ class Upgrader implements ControllerProviderInterface $controllers->get('/status/', function() use ($app) { require_once __DIR__ . '/../../../../bootstrap.php'; - ini_set('display_errors', 'on'); $datas = \Setup_Upgrade::get_status(); @@ -70,7 +68,6 @@ class Upgrader implements ControllerProviderInterface $controllers->post('/execute/', function() use ($app) { require_once __DIR__ . '/../../../../bootstrap.php'; - ini_set('display_errors', 'on'); set_time_limit(0); session_write_close(); ignore_user_abort(true); diff --git a/lib/Alchemy/Phrasea/Core.php b/lib/Alchemy/Phrasea/Core.php index bc3de471a1..7ca125324d 100644 --- a/lib/Alchemy/Phrasea/Core.php +++ b/lib/Alchemy/Phrasea/Core.php @@ -56,6 +56,8 @@ class Core extends \Pimple ); $this->configuration = new Core\Configuration($handler, $environement); + $this->init(); + /** * Set version */ @@ -64,37 +66,6 @@ class Core extends \Pimple 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()) { $this['Registry'] = $this->share(function() @@ -102,8 +73,6 @@ class Core extends \Pimple return \registry::get_instance(); }); \phrasea::start(); - $appbox = \appbox::get_instance(); - $session = $appbox->get_session(); $this->enableEvents(); } 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() { $encoders = array( @@ -149,7 +166,7 @@ class Core extends \Pimple } return; } - + /** * Load Configuration * @@ -157,15 +174,18 @@ class Core extends \Pimple */ private function init() { - if ($this->getConfiguration()->isDisplayingErrors()) + if ($this->getConfiguration()->isInstalled()) { - ini_set('display_errors', 1); - error_reporting(E_ALL); + if ($this->getConfiguration()->isDisplayingErrors()) + { + ini_set('display_errors', 'on'); + error_reporting(E_ALL); // \Symfony\Component\HttpKernel\Debug\ErrorHandler::register(); - } - else - { - ini_set('display_errors', 0); + } + else + { + ini_set('display_errors', 'off'); + } } } @@ -179,6 +199,16 @@ class Core extends \Pimple return $this['Registry']; } + /** + * Getter + * + * @return \Registry + */ + public function getCache() + { + return $this['Cache']; + } + /** * Getter * @@ -294,17 +324,6 @@ class Core extends \Pimple 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')) { ini_set('log_errors', 'on'); @@ -441,15 +460,4 @@ class Core extends \Pimple return $this->conf->getEnvironnement(); } - public function getService($serviceName, $serviceScope) - { - $configuration = $this->configuration->getService($serviceName); - - return Core\ServiceBuilder::build( - $serviceName - , $serviceScope - , $configuration - ); - } - } diff --git a/lib/Alchemy/Phrasea/Core/Configuration.php b/lib/Alchemy/Phrasea/Core/Configuration.php index 0676dade14..1a7a0614a1 100644 --- a/lib/Alchemy/Phrasea/Core/Configuration.php +++ b/lib/Alchemy/Phrasea/Core/Configuration.php @@ -353,6 +353,15 @@ class Configuration { return $this->getConfiguration()->get('template_engine'); } + + /** + * Return cache service + * @return string + */ + public function getCache() + { + return $this->getConfiguration()->get('cache'); + } /** * Return configuration service for orm diff --git a/lib/Alchemy/Phrasea/Core/Service/Cache/Apc.php b/lib/Alchemy/Phrasea/Core/Service/Cache/ApcCache.php similarity index 59% rename from lib/Alchemy/Phrasea/Core/Service/Cache/Apc.php rename to lib/Alchemy/Phrasea/Core/Service/Cache/ApcCache.php index db6269cfc5..e023690cb7 100644 --- a/lib/Alchemy/Phrasea/Core/Service/Cache/Apc.php +++ b/lib/Alchemy/Phrasea/Core/Service/Cache/ApcCache.php @@ -15,8 +15,7 @@ use Alchemy\Phrasea\Core, Alchemy\Phrasea\Core\Service, Alchemy\Phrasea\Core\Service\ServiceAbstract, Alchemy\Phrasea\Core\Service\ServiceInterface; - -use Doctrine\Common\Cache\ApcCache; +use Doctrine\Common\Cache as CacheService; /** * @@ -24,7 +23,7 @@ use Doctrine\Common\Cache\ApcCache; * @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @link www.phraseanet.com */ -class Apc extends ServiceAbstract implements ServiceInterface +class ApcCache extends ServiceAbstract implements ServiceInterface { public function getScope() @@ -43,7 +42,12 @@ class Apc extends ServiceAbstract implements ServiceInterface 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() @@ -51,5 +55,17 @@ class Apc extends ServiceAbstract implements ServiceInterface 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; + } + } diff --git a/lib/Alchemy/Phrasea/Core/Service/Cache/Tab.php b/lib/Alchemy/Phrasea/Core/Service/Cache/ArrayCache.php similarity index 55% rename from lib/Alchemy/Phrasea/Core/Service/Cache/Tab.php rename to lib/Alchemy/Phrasea/Core/Service/Cache/ArrayCache.php index f0b3dd91dc..4387be15a3 100644 --- a/lib/Alchemy/Phrasea/Core/Service/Cache/Tab.php +++ b/lib/Alchemy/Phrasea/Core/Service/Cache/ArrayCache.php @@ -15,18 +15,18 @@ use Alchemy\Phrasea\Core, Alchemy\Phrasea\Core\Service, Alchemy\Phrasea\Core\Service\ServiceAbstract, Alchemy\Phrasea\Core\Service\ServiceInterface; - -use Doctrine\Common\Cache\ArrayCache; +use Doctrine\Common\Cache as CacheService; /** - * it's just like array cache + * Array cache + * * @package * @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @link www.phraseanet.com */ -class Tab extends ServiceAbstract implements ServiceInterface +class ArrayCache extends ServiceAbstract implements ServiceInterface { - + public function getScope() { return 'cache'; @@ -38,7 +38,12 @@ class Tab extends ServiceAbstract implements ServiceInterface */ public function getService() { - return new ArrayCache(); + $registry = $this->getRegistry(); + + $service = new CacheService\ArrayCache(); + $service->setNamespace($registry->get("GV_sit", "")); + + return $service; } public function getType() @@ -46,5 +51,17 @@ class Tab extends ServiceAbstract implements ServiceInterface 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; + } + } diff --git a/lib/Alchemy/Phrasea/Core/Service/Cache/Memcache.php b/lib/Alchemy/Phrasea/Core/Service/Cache/MemcacheCache.php similarity index 73% rename from lib/Alchemy/Phrasea/Core/Service/Cache/Memcache.php rename to lib/Alchemy/Phrasea/Core/Service/Cache/MemcacheCache.php index f906204bb6..9a6005c2d5 100644 --- a/lib/Alchemy/Phrasea/Core/Service/Cache/Memcache.php +++ b/lib/Alchemy/Phrasea/Core/Service/Cache/MemcacheCache.php @@ -15,7 +15,7 @@ use Alchemy\Phrasea\Core, Alchemy\Phrasea\Core\Service, Alchemy\Phrasea\Core\Service\ServiceAbstract, 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->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() @@ -72,5 +77,16 @@ class Memcache extends ServiceAbstract implements ServiceInterface 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; + } } diff --git a/lib/Alchemy/Phrasea/Core/Service/Cache/Xcache.php b/lib/Alchemy/Phrasea/Core/Service/Cache/XcacheCache.php similarity index 60% rename from lib/Alchemy/Phrasea/Core/Service/Cache/Xcache.php rename to lib/Alchemy/Phrasea/Core/Service/Cache/XcacheCache.php index 73770f8115..554156c564 100644 --- a/lib/Alchemy/Phrasea/Core/Service/Cache/Xcache.php +++ b/lib/Alchemy/Phrasea/Core/Service/Cache/XcacheCache.php @@ -15,7 +15,7 @@ use Alchemy\Phrasea\Core, Alchemy\Phrasea\Core\Service, Alchemy\Phrasea\Core\Service\ServiceAbstract, Alchemy\Phrasea\Core\Service\ServiceInterface; -use Doctrine\Common\Cache\XcacheCache; +use Doctrine\Common\Cache as CacheService; /** * it's just like array cache @@ -23,7 +23,7 @@ use Doctrine\Common\Cache\XcacheCache; * @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @link www.phraseanet.com */ -class Tab extends ServiceAbstract implements ServiceInterface +class XcacheCache extends ServiceAbstract implements ServiceInterface { public function getScope() @@ -41,7 +41,13 @@ class Tab extends ServiceAbstract implements ServiceInterface { 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() @@ -49,4 +55,16 @@ class Tab extends ServiceAbstract implements ServiceInterface 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; + } + } \ No newline at end of file diff --git a/lib/Alchemy/Phrasea/Core/Service/Log/Monolog.php b/lib/Alchemy/Phrasea/Core/Service/Log/Monolog.php index eb13117866..9d625d122a 100644 --- a/lib/Alchemy/Phrasea/Core/Service/Log/Monolog.php +++ b/lib/Alchemy/Phrasea/Core/Service/Log/Monolog.php @@ -37,9 +37,9 @@ class Monolog extends ServiceAbstract implements ServiceInterface */ 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)) { diff --git a/lib/Alchemy/Phrasea/Core/Service/Orm/Doctrine.php b/lib/Alchemy/Phrasea/Core/Service/Orm/Doctrine.php index df204c3fca..ae027a4d27 100644 --- a/lib/Alchemy/Phrasea/Core/Service/Orm/Doctrine.php +++ b/lib/Alchemy/Phrasea/Core/Service/Orm/Doctrine.php @@ -27,6 +27,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; */ class Doctrine extends ServiceAbstract implements ServiceInterface { + const ARRAYCACHE = 'array'; const MEMCACHED = 'memcached'; const XCACHE = 'xcache'; @@ -45,9 +46,9 @@ class Doctrine extends ServiceAbstract implements ServiceInterface protected $cacheServices = array(); 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(); @@ -373,12 +374,16 @@ class Doctrine extends ServiceAbstract implements ServiceInterface } } - $service = $this->findService( - $serviceName - , Core\ServiceBuilder::CACHE - , $configuration + $registry = $this->getDependency("registry"); + + $serviceBuilder = new Core\ServiceBuilder\Cache( + $serviceName, + $configuration, + array("registry" => $registry) ); + $service = $serviceBuilder->buildService(); + $this->cacheServices[$cacheDoctrine] = $service; return $service->getService(); @@ -416,14 +421,14 @@ class Doctrine extends ServiceAbstract implements ServiceInterface ); } - $service = $this->findService( - $serviceName - , Core\ServiceBuilder::LOG - , $configuration - , 'doctrine' //look for Log\Doctrine services + $serviceBuilder = new Core\ServiceBuilder\Log( + $serviceName, + $configuration, + array(), + "Doctrine" ); - return $service->getService(); + return $serviceBuilder->buildService()->getService(); } public function getService() diff --git a/lib/Alchemy/Phrasea/Core/Service/ServiceAbstract.php b/lib/Alchemy/Phrasea/Core/Service/ServiceAbstract.php index feb85a1e4d..5a3d97156b 100644 --- a/lib/Alchemy/Phrasea/Core/Service/ServiceAbstract.php +++ b/lib/Alchemy/Phrasea/Core/Service/ServiceAbstract.php @@ -20,18 +20,21 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; * @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @link www.phraseanet.com */ -class ServiceAbstract +abstract class ServiceAbstract { protected $name; protected $options; protected $configuration; + + private $dependencies; - public function __construct($name, Array $options) + public function __construct($name, Array $options, Array $dependencies) { $this->name = $name; $this->options = $options; - + $this->dependencies = $dependencies; + $spec = new Core\Configuration\Application(); $parser = new Core\Configuration\Parser\Yaml(); $handler = new Core\Configuration\Handler($spec, $parser); @@ -39,15 +42,36 @@ class ServiceAbstract $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() { return $this->configuration; } + + /** + * + * @return Array + */ + public function getDependencies() + { + return $this->dependencies; + } + /** * * @return string @@ -75,20 +99,4 @@ class ServiceAbstract 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 - ); - } } \ No newline at end of file diff --git a/lib/Alchemy/Phrasea/Core/Service/TemplateEngine/Twig.php b/lib/Alchemy/Phrasea/Core/Service/TemplateEngine/Twig.php index 23d2a88c25..e3039fe236 100644 --- a/lib/Alchemy/Phrasea/Core/Service/TemplateEngine/Twig.php +++ b/lib/Alchemy/Phrasea/Core/Service/TemplateEngine/Twig.php @@ -26,10 +26,9 @@ class Twig extends ServiceAbstract implements ServiceInterface protected $twig; protected $templatesPath = array(); - public function __construct($name, Array $options) + public function __construct($name, Array $options, Array $dependencies) { - - parent::__construct($name, $options); + parent::__construct($name, $options, $dependencies); $this->templatesPath = $this->resolvePaths(); diff --git a/lib/Alchemy/Phrasea/Core/ServiceBuilder.php b/lib/Alchemy/Phrasea/Core/ServiceBuilder.php deleted file mode 100644 index df4ce92687..0000000000 --- a/lib/Alchemy/Phrasea/Core/ServiceBuilder.php +++ /dev/null @@ -1,109 +0,0 @@ - '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) - ); - } - } - -} \ No newline at end of file diff --git a/lib/Alchemy/Phrasea/Core/ServiceBuilder/AbstractBuilder.php b/lib/Alchemy/Phrasea/Core/ServiceBuilder/AbstractBuilder.php new file mode 100644 index 0000000000..35eb9238d7 --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/ServiceBuilder/AbstractBuilder.php @@ -0,0 +1,73 @@ +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; + } + +} \ No newline at end of file diff --git a/lib/Alchemy/Phrasea/Core/ServiceBuilder/Cache.php b/lib/Alchemy/Phrasea/Core/ServiceBuilder/Cache.php new file mode 100644 index 0000000000..e1b6f51abf --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/ServiceBuilder/Cache.php @@ -0,0 +1,49 @@ +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) + ); + } + } + +} \ No newline at end of file diff --git a/lib/Alchemy/Phrasea/Core/ServiceBuilder/Log.php b/lib/Alchemy/Phrasea/Core/ServiceBuilder/Log.php new file mode 100644 index 0000000000..ce1f14baf4 --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/ServiceBuilder/Log.php @@ -0,0 +1,57 @@ +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) + ); + } + } + +} \ No newline at end of file diff --git a/lib/Alchemy/Phrasea/Core/ServiceBuilder/Orm.php b/lib/Alchemy/Phrasea/Core/ServiceBuilder/Orm.php new file mode 100644 index 0000000000..57f1a8c8b5 --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/ServiceBuilder/Orm.php @@ -0,0 +1,48 @@ +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) + ); + } + } + +} \ No newline at end of file diff --git a/lib/Alchemy/Phrasea/Core/ServiceBuilder/TemplateEngine.php b/lib/Alchemy/Phrasea/Core/ServiceBuilder/TemplateEngine.php new file mode 100644 index 0000000000..bbbb3b9380 --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/ServiceBuilder/TemplateEngine.php @@ -0,0 +1,48 @@ +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) + ); + } + } + +} \ No newline at end of file diff --git a/lib/Alchemy/Phrasea/Out/Module/PDF.php b/lib/Alchemy/Phrasea/Out/Module/PDF.php index d6c0067ea1..5194663d18 100644 --- a/lib/Alchemy/Phrasea/Out/Module/PDF.php +++ b/lib/Alchemy/Phrasea/Out/Module/PDF.php @@ -50,7 +50,6 @@ class PDF case self::LAYOUT_PREVIEWCAPTIONTDM: try { -// exit('prout'); $subdef = $record->get_subdef('preview'); if (!$subdef->is_physically_present()) { diff --git a/lib/classes/API/V1/adapter.class.php b/lib/classes/API/V1/adapter.class.php index 8c6b681e24..e5bda1403f 100644 --- a/lib/classes/API/V1/adapter.class.php +++ b/lib/classes/API/V1/adapter.class.php @@ -588,9 +588,9 @@ class API_V1_adapter extends API_V1_Abstract $em = $this->core->getEntityManager(); $repo = $em->getRepository('\Entities\Basket'); /* @var $repo \Repositories\BasketRepository */ - + $baskets = $repo->findActiveByUser($this->core->getAuthenticatedUser()); - + $ret = array(); foreach ($baskets as $basket) { @@ -737,8 +737,8 @@ class API_V1_adapter extends API_V1_Abstract 'updated_on' => $validation_datas->getUpdated()->format(DATE_ATOM), '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(); $note = $validation_datas->getNote(); @@ -1080,9 +1080,9 @@ class API_V1_adapter extends API_V1_Abstract $ret = array(); 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); } } diff --git a/lib/classes/appbox.class.php b/lib/classes/appbox.class.php index 8449425a4e..707023ddb0 100644 --- a/lib/classes/appbox.class.php +++ b/lib/classes/appbox.class.php @@ -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 $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__ . '/../../'; @@ -486,10 +488,21 @@ class appbox extends base 'main_connexion' => $connexionINI, 'test_connexion' => array( 'driver' => 'pdo_sqlite', - 'path' => $root . 'lib/unitTest/tests.sqlite', + 'path' => realpath($root . 'lib/unitTest/tests.sqlite'), '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); diff --git a/lib/classes/module/console/fileConfigCheck.class.php b/lib/classes/module/console/fileConfigCheck.class.php index 43ebd30aa1..9853ec3299 100644 --- a/lib/classes/module/console/fileConfigCheck.class.php +++ b/lib/classes/module/console/fileConfigCheck.class.php @@ -324,13 +324,13 @@ class module_console_fileConfigCheck extends Command } - $service = Core\ServiceBuilder::build( + $serviceBuilder = new Core\ServiceBuilder\TemplateEngine( $templateEngineName - , Core\ServiceBuilder::TEMPLATE_ENGINE , $configuration ); - + $service = $serviceBuilder->buildService(); + if ($service->getType() === 'twig') { $twig = $service->getService(); @@ -415,12 +415,16 @@ class module_console_fileConfigCheck extends Command throw $e; } - $service = Core\ServiceBuilder::build( + $registry = \registry::get_instance(); + + $serviceBuilder = new Core\ServiceBuilder\Orm( $ormName - , Core\ServiceBuilder::ORM , $configuration + , array('registry'=> $registry) ); + $service = $serviceBuilder->buildService(); + if ($service->getType() === 'doctrine') { $caches = $service->getCacheServices(); diff --git a/lib/classes/record/adapter.class.php b/lib/classes/record/adapter.class.php index 89ee92d828..b25ddc08d6 100644 --- a/lib/classes/record/adapter.class.php +++ b/lib/classes/record/adapter.class.php @@ -132,13 +132,13 @@ class record_adapter implements record_Interface, cache_cacheableInterface */ protected $modification_date; - const CACHE_ORIGINAL_NAME = 'originalname'; + const CACHE_ORIGINAL_NAME = 'originalname'; const CACHE_TECHNICAL_DATAS = 'technical_datas'; - const CACHE_MIME = 'mime'; - const CACHE_SHA256 = 'sha256'; - const CACHE_SUBDEFS = 'subdefs'; - const CACHE_GROUPING = 'grouping'; - const CACHE_STATUS = 'status'; + const CACHE_MIME = 'mime'; + const CACHE_SHA256 = 'sha256'; + const CACHE_SUBDEFS = 'subdefs'; + const CACHE_GROUPING = 'grouping'; + const CACHE_STATUS = 'status'; protected static $_regfields; @@ -186,12 +186,12 @@ class record_adapter implements record_Interface, cache_cacheableInterface } $connbas = $this->databox->get_connection(); - $sql = 'SELECT coll_id, record_id,credate , uuid, moddate, parent_record_id + $sql = 'SELECT coll_id, record_id,credate , uuid, moddate, parent_record_id , type, originalname, bitly, sha256, mime FROM record WHERE record_id = :record_id'; - $stmt = $connbas->prepare($sql); + $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->record_id)); - $row = $stmt->fetch(PDO::FETCH_ASSOC); + $row = $stmt->fetch(PDO::FETCH_ASSOC); $stmt->closeCursor(); if (!$row) @@ -210,16 +210,16 @@ class record_adapter implements record_Interface, cache_cacheableInterface $this->mime = $row['mime']; $datas = array( - 'mime' => $this->mime - , 'sha256' => $this->sha256 - , 'bitly_link' => $this->bitly_link - , 'original_name' => $this->original_name - , 'type' => $this->type - , 'grouping' => $this->grouping - , 'uuid' => $this->uuid - , 'modification_date' => $this->modification_date - , 'creation_date' => $this->creation_date - , 'base_id' => $this->base_id + 'mime' => $this->mime + , 'sha256' => $this->sha256 + , 'bitly_link' => $this->bitly_link + , 'original_name' => $this->original_name + , 'type' => $this->type + , 'grouping' => $this->grouping + , 'uuid' => $this->uuid + , 'modification_date' => $this->modification_date + , 'creation_date' => $this->creation_date + , 'base_id' => $this->base_id ); $this->set_data_to_cache($datas); @@ -292,9 +292,9 @@ class record_adapter implements record_Interface, cache_cacheableInterface $connbas = connection::getPDOConnection($this->get_sbas_id()); - $sql = 'UPDATE record SET type = :type WHERE record_id = :record_id'; + $sql = 'UPDATE record SET type = :type WHERE record_id = :record_id'; $stmt = $connbas->prepare($sql); - $stmt->execute(array(':type' => $type, ':record_id' => $this->get_record_id())); + $stmt->execute(array(':type' => $type, ':record_id' => $this->get_record_id())); $stmt->closeCursor(); if ($old_type !== $type) @@ -371,9 +371,9 @@ class record_adapter implements record_Interface, cache_cacheableInterface { $dstatus = databox_status::getDisplayStatus(); $sbas_id = $this->get_sbas_id(); - $appbox = appbox::get_instance(); + $appbox = appbox::get_instance(); $session = $appbox->get_session(); - $user = User_Adapter::getInstance($session->get_usr_id(), $appbox); + $user = User_Adapter::getInstance($session->get_usr_id(), $appbox); $status = ''; @@ -382,24 +382,24 @@ class record_adapter implements record_Interface, cache_cacheableInterface foreach ($dstatus[$sbas_id] as $n => $statbit) { if ($statbit['printable'] == '0' && - !$user->ACL()->has_right_on_base($this->base_id, 'chgstatus')) + !$user->ACL()->has_right_on_base($this->base_id, 'chgstatus')) continue; $x = (substr((strrev($this->get_status())), $n, 1)); $source0 = "/skins/icons/spacer.gif"; - $style0 = "visibility:hidden;display:none;"; + $style0 = "visibility:hidden;display:none;"; $source1 = "/skins/icons/spacer.gif"; - $style1 = "visibility:hidden;display:none;"; + $style1 = "visibility:hidden;display:none;"; if ($statbit["img_on"]) { $source1 = $statbit["img_on"]; - $style1 = "visibility:auto;display:none;"; + $style1 = "visibility:auto;display:none;"; } if ($statbit["img_off"]) { $source0 = $statbit["img_off"]; - $style0 = "visibility:auto;display:none;"; + $style0 = "visibility:auto;display:none;"; } if ($x == '1') { @@ -416,19 +416,19 @@ class record_adapter implements record_Interface, cache_cacheableInterface } } $status .= ''; + 'class="STAT_' . $this->base_id . '_' + . $this->record_id . '_' . $n . '_1" ' . + 'src="' . $source1 . '" title="' . + (isset($statbit["labelon"]) ? + $statbit["labelon"] : + $statbit["lib"]) . '"/>'; $status .= ''; + 'class="STAT_' . $this->base_id . '_' + . $this->record_id . '_' . $n . '_0" ' . + 'src="' . $source0 . '" title="' . + (isset($statbit["labeloff"]) ? + $statbit["labeloff"] : + ("non-" . $statbit["lib"])) . '"/>'; } } @@ -481,8 +481,8 @@ class record_adapter implements record_Interface, cache_cacheableInterface $sql = "UPDATE record SET coll_id = :coll_id WHERE record_id =:record_id"; $params = array( - ':coll_id' => $collection->get_coll_id(), - ':record_id' => $this->get_record_id() + ':coll_id' => $collection->get_coll_id(), + ':record_id' => $this->get_record_id() ); $stmt = $this->get_databox()->get_connection()->prepare($sql); @@ -492,7 +492,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface $this->base_id = $collection->get_base_id(); $appbox->get_session()->get_logger($this->get_databox()) - ->log($this, Session_Logger::EVENT_MOVE, $collection->get_coll_id(), ''); + ->log($this, Session_Logger::EVENT_MOVE, $collection->get_coll_id(), ''); $this->delete_data_from_cache(); @@ -509,6 +509,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface { return null; } + try { return $this->get_subdef('thumbnailGIF'); @@ -567,18 +568,18 @@ class record_adapter implements record_Interface, cache_cacheableInterface { } - $sql = 'SELECT BIN(status) as status FROM record + $sql = 'SELECT BIN(status) as status FROM record WHERE record_id = :record_id'; $stmt = $this->get_databox()->get_connection()->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); - $row = $stmt->fetch(PDO::FETCH_ASSOC); + $row = $stmt->fetch(PDO::FETCH_ASSOC); $stmt->closeCursor(); if (!$row) throw new Exception('status not found'); $status = $row['status']; - $n = strlen($status); + $n = strlen($status); while ($n < 64) { $status = '0' . $status; @@ -598,14 +599,21 @@ class record_adapter implements record_Interface, cache_cacheableInterface public function get_subdef($name) { $name = strtolower($name); + if (!in_array($name, $this->get_available_subdefs())) + { throw new Exception_Media_SubdefNotFound (); + } if (isset($this->subdefs[$name])) + { return $this->subdefs[$name]; + } if (!$this->subdefs) + { $this->subdefs = array(); + } $substitute = ($name !== 'document'); @@ -652,7 +660,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); + $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $stmt->closeCursor(); $subdefs = array('preview', 'thumbnail'); @@ -661,7 +669,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface { $subdefs[] = $row['name']; } - $subdefs = array_unique($subdefs); + $subdefs = array_unique($subdefs); $this->set_data_to_cache($subdefs, self::CACHE_SUBDEFS); return $subdefs; @@ -694,10 +702,10 @@ class record_adapter implements record_Interface, cache_cacheableInterface { $this->technical_datas = array(); $connbas = $this->get_databox()->get_connection(); - $sql = 'SELECT name, value FROM technical_datas WHERE record_id = :record_id'; - $stmt = $connbas->prepare($sql); + $sql = 'SELECT name, value FROM technical_datas WHERE record_id = :record_id'; + $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); + $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $stmt->closeCursor(); foreach ($rs as $row) @@ -773,7 +781,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface $dom_doc->formatOutput = true; $dom_doc->standalone = true; - $record = $dom_doc->createElement('record'); + $record = $dom_doc->createElement('record'); $record->setAttribute('record_id', $this->get_record_id()); $dom_doc->appendChild($record); $description = $dom_doc->createElement('description'); @@ -847,13 +855,13 @@ class record_adapter implements record_Interface, cache_cacheableInterface else { $value = array_pop($field->get_values()); - + $this->set_metadatas( - array( - 'meta_struct_id' => $field->get_meta_struct_id() - , 'meta_id' => $value->getId() - , 'value' => $original_name - ) + array( + 'meta_struct_id' => $field->get_meta_struct_id() + , 'meta_id' => $value->getId() + , 'value' => $original_name + ) ); } } @@ -862,8 +870,8 @@ class record_adapter implements record_Interface, cache_cacheableInterface SET originalname = :originalname WHERE record_id = :record_id'; $params = array( - ':originalname' => $original_name - , ':record_id' => $this->get_record_id() + ':originalname' => $original_name + , ':record_id' => $this->get_record_id() ); $stmt = $this->get_databox()->get_connection()->prepare($sql); @@ -881,7 +889,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface */ public function get_title($highlight = false, searchEngine_adapter $searchEngine = null) { - $sbas_id = $this->get_sbas_id(); + $sbas_id = $this->get_sbas_id(); $record_id = $this->get_record_id(); if ($this->is_grouping()) @@ -891,8 +899,8 @@ class record_adapter implements record_Interface, cache_cacheableInterface return $regfield['regname']; } - $title = ''; - $appbox = appbox::get_instance(); + $title = ''; + $appbox = appbox::get_instance(); $session = $appbox->get_session(); $fields = $this->get_databox()->get_meta_structure(); @@ -910,14 +918,14 @@ class record_adapter implements record_Interface, cache_cacheableInterface if (count($fields_to_retrieve) > 0) { $retrieved_fields = $this->get_caption()->get_highlight_fields($highlight, $fields_to_retrieve, $searchEngine); - $titles = array(); + $titles = array(); foreach ($retrieved_fields as $key => $value) { if (trim($value['value'] === '')) continue; $titles[] = $value['value']; } - $title = trim(implode(' - ', $titles)); + $title = trim(implode(' - ', $titles)); } if (trim($title) === '') @@ -1004,7 +1012,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface */ protected function searchRegFields(databox_descriptionStructure $meta_struct) { - $fields = null; + $fields = null; $fields["regname"] = ""; $fields["regdesc"] = ""; $fields["regdate"] = ""; @@ -1078,11 +1086,11 @@ class record_adapter implements record_Interface, cache_cacheableInterface public function substitute_subdef($name, system_file $pathfile) { $newfilename = $this->record_id . '_0_' . $name - . '.' . $pathfile->get_extension(); + . '.' . $pathfile->get_extension(); $base_url = ''; - $original_file = $subdef_def = false; + $original_file = $subdef_def = false; if ($name == 'document') { @@ -1132,7 +1140,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface } catch (Exception $e) { - $path = databox::dispatch($subdef_def->get_path()); + $path = databox::dispatch($subdef_def->get_path()); system_file::mkdir($path); $original_file = $path . $newfilename; } @@ -1142,9 +1150,9 @@ class record_adapter implements record_Interface, cache_cacheableInterface if (trim($subdef_def->get_baseurl()) !== '') { $base_url = str_replace( - array((string) $subdef_def->get_path(), $newfilename) - , array((string) $subdef_def->get_baseurl(), '') - , $path_file_dest + array((string) $subdef_def->get_path(), $newfilename) + , array((string) $subdef_def->get_baseurl(), '') + , $path_file_dest ); } @@ -1161,18 +1169,18 @@ class record_adapter implements record_Interface, cache_cacheableInterface try { - $appbox = \appbox::get_instance(); + $appbox = \appbox::get_instance(); $session = $appbox->get_session(); $connbas = connection::getPDOConnection($this->get_sbas_id()); - $sql = 'DELETE FROM subdef WHERE record_id= :record_id AND name=:name'; + $sql = 'DELETE FROM subdef WHERE record_id= :record_id AND name=:name'; $stmt = $connbas->prepare($sql); $stmt->execute( - array( - ':record_id' => $this->record_id - , ':name' => $name - ) + array( + ':record_id' => $this->record_id + , ':name' => $name + ) ); $image_size = $system_file->get_technical_datas(); @@ -1187,18 +1195,18 @@ class record_adapter implements record_Interface, cache_cacheableInterface $stmt = $connbas->prepare($sql); $stmt->execute(array( - ':record_id' => $this->record_id, - ':name' => $name, - ':baseurl' => $base_url, - ':filename' => $system_file->getFilename(), - ':width' => $image_size[system_file::TC_DATAS_WIDTH], - ':height' => $image_size[system_file::TC_DATAS_HEIGHT], - ':mime' => $system_file->get_mime(), - ':path' => $system_file->getPath(), - ':filesize' => $system_file->getSize() + ':record_id' => $this->record_id, + ':name' => $name, + ':baseurl' => $base_url, + ':filename' => $system_file->getFilename(), + ':width' => $image_size[system_file::TC_DATAS_WIDTH], + ':height' => $image_size[system_file::TC_DATAS_HEIGHT], + ':mime' => $system_file->get_mime(), + ':path' => $system_file->getPath(), + ':filesize' => $system_file->getSize() )); - $sql = 'UPDATE record SET moddate=NOW() WHERE record_id=:record_id'; + $sql = 'UPDATE record SET moddate=NOW() WHERE record_id=:record_id'; $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->closeCursor(); @@ -1217,7 +1225,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface $type = $name == 'document' ? 'HD' : $name; $session->get_logger($this->get_databox()) - ->log($this, Session_Logger::EVENT_SUBSTITUTE, $type, ''); + ->log($this, Session_Logger::EVENT_SUBSTITUTE, $type, ''); } catch (Exception $e) { @@ -1235,13 +1243,13 @@ class record_adapter implements record_Interface, cache_cacheableInterface protected function set_xml(DOMDocument $dom_doc) { $connbas = $this->get_databox()->get_connection(); - $sql = 'UPDATE record SET xml = :xml WHERE record_id= :record_id'; - $stmt = $connbas->prepare($sql); + $sql = 'UPDATE record SET xml = :xml WHERE record_id= :record_id'; + $stmt = $connbas->prepare($sql); $stmt->execute( - array( - ':xml' => $dom_doc->saveXML(), - ':record_id' => $this->record_id - ) + array( + ':xml' => $dom_doc->saveXML(), + ':record_id' => $this->record_id + ) ); $this->reindex(); @@ -1268,7 +1276,9 @@ class record_adapter implements record_Interface, cache_cacheableInterface } if (!is_scalar($params['value'])) + { throw new Exception('Metadata value should be scalar'); + } $databox_field = databox_field::get_instance($databox, $params['meta_struct_id']); @@ -1338,9 +1348,9 @@ class record_adapter implements record_Interface, cache_cacheableInterface public function reindex() { $connbas = connection::getPDOConnection($this->get_sbas_id()); - $sql = 'UPDATE record SET status=(status & ~7 | 4) + $sql = 'UPDATE record SET status=(status & ~7 | 4) WHERE record_id= :record_id'; - $stmt = $connbas->prepare($sql); + $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->record_id)); $this->delete_data_from_cache(self::CACHE_STATUS); @@ -1354,8 +1364,8 @@ class record_adapter implements record_Interface, cache_cacheableInterface public function rebuild_subdefs() { $connbas = connection::getPDOConnection($this->get_sbas_id()); - $sql = 'UPDATE record SET jeton=(jeton | ' . JETON_MAKE_SUBDEF . ') WHERE record_id = :record_id'; - $stmt = $connbas->prepare($sql); + $sql = 'UPDATE record SET jeton=(jeton | ' . JETON_MAKE_SUBDEF . ') WHERE record_id = :record_id'; + $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); return $this; @@ -1368,10 +1378,10 @@ class record_adapter implements record_Interface, cache_cacheableInterface public function write_metas() { $connbas = connection::getPDOConnection($this->get_sbas_id()); - $sql = 'UPDATE record + $sql = 'UPDATE record SET jeton = ' . (JETON_WRITE_META_DOC | JETON_WRITE_META_SUBDEF) . ' WHERE record_id= :record_id'; - $stmt = $connbas->prepare($sql); + $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->record_id)); return $this; @@ -1387,21 +1397,21 @@ class record_adapter implements record_Interface, cache_cacheableInterface $connbas = connection::getPDOConnection($this->get_sbas_id()); $registry = registry::get_instance(); - $sql = 'UPDATE record SET status = 0b' . $status . ' + $sql = 'UPDATE record SET status = 0b' . $status . ' WHERE record_id= :record_id'; - $stmt = $connbas->prepare($sql); + $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->record_id)); - $sql = 'REPLACE INTO status (id, record_id, name, value) VALUES (null, :record_id, :name, :value)'; + $sql = 'REPLACE INTO status (id, record_id, name, value) VALUES (null, :record_id, :name, :value)'; $stmt = $connbas->prepare($sql); $status = strrev($status); - for ($i = 4; $i < strlen($status); $i++) + for ($i = 4; $i < strlen($status); $i++) { $stmt->execute(array( - ':record_id' => $this->get_record_id(), - ':name' => $i, - ':value' => $status[$i] + ':record_id' => $this->get_record_id(), + ':name' => $i, + ':value' => $status[$i] )); } $stmt->closeCursor(); @@ -1411,10 +1421,10 @@ class record_adapter implements record_Interface, cache_cacheableInterface $sphinx = sphinxrt::get_instance($registry); $sbas_params = phrasea::sbas_params(); - $sbas_id = $this->get_sbas_id(); + $sbas_id = $this->get_sbas_id(); if (isset($sbas_params[$sbas_id])) { - $params = $sbas_params[$sbas_id]; + $params = $sbas_params[$sbas_id]; $sbas_crc = crc32(str_replace(array('.', '%'), '_', sprintf('%s_%s_%s_%s', $params['host'], $params['port'], $params['user'], $params['dbname']))); $sphinx->update_status(array("metadatas" . $sbas_crc, "metadatas" . $sbas_crc . "_stemmed_en", "metadatas" . $sbas_crc . "_stemmed_fr", "documents" . $sbas_crc), $this->get_sbas_id(), $this->get_record_id(), strrev($status)); } @@ -1457,9 +1467,9 @@ class record_adapter implements record_Interface, cache_cacheableInterface } } } - $regname = ''; - if ($sxe = simplexml_load_string($this->get_xml())) - $regname = (string) $sxe->description->$balisename; + $regname = ''; + if ($sxe = simplexml_load_string($this->get_xml())) + $regname = (string) $sxe->description->$balisename; return $regname; } @@ -1478,7 +1488,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface if ($is_grouping) { - $uuid = uuid::generate_v4(); + $uuid = uuid::generate_v4(); $sha256 = null; } else @@ -1486,7 +1496,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface $uuid = $system_file->read_uuid(); if (!uuid::is_valid($uuid)) { - $uuid = uuid::generate_v4(); + $uuid = uuid::generate_v4(); } $sha256 = $system_file->get_sha256(); } @@ -1510,32 +1520,32 @@ class record_adapter implements record_Interface, cache_cacheableInterface $stmt = $connbas->prepare($sql); $stmt->execute(array( - ':coll_id' => $coll_id - , ':parent_record_id' => ($is_grouping ? 1 : 0) - , ':type' => $type - , ':sha256' => $sha256 - , ':uuid' => $uuid - , ':originalname' => $original_name - , ':mime' => $system_file->get_mime() + ':coll_id' => $coll_id + , ':parent_record_id' => ($is_grouping ? 1 : 0) + , ':type' => $type + , ':sha256' => $sha256 + , ':uuid' => $uuid + , ':originalname' => $original_name + , ':mime' => $system_file->get_mime() )); $record_id = $connbas->lastInsertId(); - $record = new self($sbas_id, $record_id); + $record = new self($sbas_id, $record_id); try { - $appbox = appbox::get_instance(); + $appbox = appbox::get_instance(); $session = $appbox->get_session(); - $log_id = $session->get_logger($databox)->get_id(); + $log_id = $session->get_logger($databox)->get_id(); - $sql = 'INSERT INTO log_docs (id, log_id, date, record_id, action, final, comment) + $sql = 'INSERT INTO log_docs (id, log_id, date, record_id, action, final, comment) VALUES (null, :log_id, now(), :record_id, "add", :coll_id,"")'; $stmt = $connbas->prepare($sql); $stmt->execute(array( - ':log_id' => $log_id, - ':record_id' => $record_id, - ':coll_id' => $coll_id + ':log_id' => $log_id, + ':record_id' => $record_id, + ':coll_id' => $coll_id )); $stmt->closeCursor(); } @@ -1564,7 +1574,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface $tc_datas = $system_file->get_technical_datas(); - $sql = 'REPLACE INTO technical_datas (id, record_id, name, value) + $sql = 'REPLACE INTO technical_datas (id, record_id, name, value) VALUES (null, :record_id, :name, :value)'; $stmt = $connbas->prepare($sql); @@ -1574,9 +1584,9 @@ class record_adapter implements record_Interface, cache_cacheableInterface continue; $stmt->execute(array( - ':record_id' => $record_id - , ':name' => $name - , ':value' => $value + ':record_id' => $record_id + , ':name' => $name + , ':value' => $value )); } $stmt->closeCursor(); @@ -1610,14 +1620,14 @@ class record_adapter implements record_Interface, cache_cacheableInterface $stmt = $conn->prepare($sql); $stmt->execute($params); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); + $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $stmt->closeCursor(); $records = array(); foreach ($rs as $row) { - $k = count($records); + $k = count($records); $records[$k] = new record_adapter($sbas_id, $row['record_id']); } @@ -1642,11 +1652,11 @@ class record_adapter implements record_Interface, cache_cacheableInterface */ public function delete() { - $connbas = $this->get_databox()->get_connection(); - $sbas_id = $this->get_databox()->get_sbas_id(); - $appbox = appbox::get_instance(); + $connbas = $this->get_databox()->get_connection(); + $sbas_id = $this->get_databox()->get_sbas_id(); + $appbox = appbox::get_instance(); $registry = $appbox->get_registry(); - $conn = $appbox->get_connection(); + $conn = $appbox->get_connection(); $ftodel = array(); foreach ($this->get_subdefs() as $subdef) @@ -1654,30 +1664,30 @@ class record_adapter implements record_Interface, cache_cacheableInterface if (!$subdef->is_physically_present()) continue; - $ftodel[] = $subdef->get_pathfile(); + $ftodel[] = $subdef->get_pathfile(); $watermark = $subdef->get_path() . 'watermark_' . $subdef->get_file(); if (file_exists($watermark)) - $ftodel[] = $watermark; - $stamp = $subdef->get_path() . 'stamp_' . $subdef->get_file(); + $ftodel[] = $watermark; + $stamp = $subdef->get_path() . 'stamp_' . $subdef->get_file(); if (file_exists($stamp)) - $ftodel[] = $stamp; + $ftodel[] = $stamp; } $origcoll = phrasea::collFromBas($this->get_base_id()); $appbox->get_session()->get_logger($this->get_databox()) - ->log($this, Session_Logger::EVENT_DELETE, $origcoll, $this->get_xml()); + ->log($this, Session_Logger::EVENT_DELETE, $origcoll, $this->get_xml()); - $sql = "DELETE FROM record WHERE record_id = :record_id"; + $sql = "DELETE FROM record WHERE record_id = :record_id"; $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->closeCursor(); - $sql = 'SELECT id FROM metadatas WHERE record_id = :record_id'; + $sql = 'SELECT id FROM metadatas WHERE record_id = :record_id'; $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); - $rs = $stmt->fetchAll(); + $rs = $stmt->fetchAll(); $stmt->closeCursor(); try @@ -1688,7 +1698,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface if (isset($sbas_params[$sbas_id])) { - $params = $sbas_params[$sbas_id]; + $params = $sbas_params[$sbas_id]; $sbas_crc = crc32(str_replace(array('.', '%'), '_', sprintf('%s_%s_%s_%s', $params['host'], $params['port'], $params['user'], $params['dbname']))); foreach ($rs as $row) { @@ -1702,49 +1712,49 @@ class record_adapter implements record_Interface, cache_cacheableInterface unset($e); } - $sql = "DELETE FROM metadatas WHERE record_id = :record_id"; + $sql = "DELETE FROM metadatas WHERE record_id = :record_id"; $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->closeCursor(); - $sql = "DELETE FROM prop WHERE record_id = :record_id"; + $sql = "DELETE FROM prop WHERE record_id = :record_id"; $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->closeCursor(); - $sql = "DELETE FROM idx WHERE record_id = :record_id"; + $sql = "DELETE FROM idx WHERE record_id = :record_id"; $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->closeCursor(); - $sql = "DELETE FROM permalinks + $sql = "DELETE FROM permalinks WHERE subdef_id IN (SELECT subdef_id FROM subdef WHERE record_id=:record_id)"; $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->closeCursor(); - $sql = "DELETE FROM subdef WHERE record_id = :record_id"; + $sql = "DELETE FROM subdef WHERE record_id = :record_id"; $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->closeCursor(); - $sql = "DELETE FROM technical_datas WHERE record_id = :record_id"; + $sql = "DELETE FROM technical_datas WHERE record_id = :record_id"; $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->closeCursor(); - $sql = "DELETE FROM thit WHERE record_id = :record_id"; + $sql = "DELETE FROM thit WHERE record_id = :record_id"; $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->closeCursor(); - $sql = "DELETE FROM regroup WHERE rid_parent = :record_id"; + $sql = "DELETE FROM regroup WHERE rid_parent = :record_id"; $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->closeCursor(); - $sql = "DELETE FROM regroup WHERE rid_child = :record_id"; + $sql = "DELETE FROM regroup WHERE rid_child = :record_id"; $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->closeCursor(); @@ -1804,7 +1814,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface echo 'Aucune sous definition a faire pour ' . $this->get_type() . "\n"; } - $subdef_class = 'databox_subdef' . ucfirst($this->get_type()); + $subdef_class = 'databox_subdef' . ucfirst($this->get_type()); $record_subdefs = $this->get_subdefs(); foreach ($subdefs as $subdef) @@ -1866,7 +1876,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface */ protected function generate_subdef(databox_subdefInterface $subdef_class, $pathdest) { - $registry = registry::get_instance(); + $registry = registry::get_instance(); $generated = $subdef_class->generate($this, $pathdest, $registry); return $this; @@ -1918,12 +1928,12 @@ class record_adapter implements record_Interface, cache_cacheableInterface (null, :log_id, now(), :rec, :referrer, :site)'; $params = array( - ':log_id' => $log_id - , ':rec' => $this->get_record_id() - , ':referrer' => $referrer - , ':site' => $gv_sit + ':log_id' => $log_id + , ':rec' => $this->get_record_id() + , ':referrer' => $referrer + , ':site' => $gv_sit ); - $stmt = $connbas->prepare($sql); + $stmt = $connbas->prepare($sql); $stmt->execute($params); $stmt->closeCursor(); @@ -1964,7 +1974,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface public function get_container_baskets() { $Core = bootstrap::getCore(); - $em = $Core->getEntityManager(); + $em = $Core->getEntityManager(); $repo = $em->getRepository('\Entities\Basket'); @@ -1982,15 +1992,15 @@ class record_adapter implements record_Interface, cache_cacheableInterface public static function get_records_by_originalname(databox $databox, $original_name, $offset_start = 0, $how_many = 10) { $offset_start = (int) ($offset_start < 0 ? 0 : $offset_start); - $how_many = (int) (($how_many > 20 || $how_many < 1) ? 10 : $how_many); + $how_many = (int) (($how_many > 20 || $how_many < 1) ? 10 : $how_many); $sql = sprintf('SELECT record_id FROM record WHERE original_name = :original_name LIMIT %d, %d' - , $offset_start, $how_many); + , $offset_start, $how_many); $stmt = $databox->get_connection()->prepare($sql); $stmt->execute(array(':original_name' => $original_name)); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); + $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $stmt->closeCursor(); $records = array(); @@ -2027,18 +2037,18 @@ class record_adapter implements record_Interface, cache_cacheableInterface ORDER BY g.ord ASC, dateadd ASC, record_id ASC'; $params = array( - ':GV_site' => $appbox->get_registry()->get('GV_sit') - , ':usr_id' => $appbox->get_session()->get_usr_id() - , ':record_id' => $this->get_record_id() + ':GV_site' => $appbox->get_registry()->get('GV_sit') + , ':usr_id' => $appbox->get_session()->get_usr_id() + , ':record_id' => $this->get_record_id() ); $stmt = $this->get_databox()->get_connection()->prepare($sql); $stmt->execute($params); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); + $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $stmt->closeCursor(); $set = new set_selection(); - $i = 1; + $i = 1; foreach ($rs as $row) { $set->add_element(new record_adapter($this->get_sbas_id(), $row['record_id'], $i)); @@ -2071,14 +2081,14 @@ class record_adapter implements record_Interface, cache_cacheableInterface $params = array( - ':GV_site' => $appbox->get_registry()->get('GV_sit') - , ':usr_id' => $appbox->get_session()->get_usr_id() - , ':record_id' => $this->get_record_id() + ':GV_site' => $appbox->get_registry()->get('GV_sit') + , ':usr_id' => $appbox->get_session()->get_usr_id() + , ':record_id' => $this->get_record_id() ); $stmt = $this->get_databox()->get_connection()->prepare($sql); $stmt->execute($params); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); + $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $stmt->closeCursor(); $set = new set_selection(); @@ -2124,9 +2134,9 @@ class record_adapter implements record_Interface, cache_cacheableInterface VALUES (null, :parent_record_id, :record_id, NOW(), :ord)'; $params = array( - ':parent_record_id' => $this->get_record_id() - , ':record_id' => $record->get_record_id() - , ':ord' => $ord + ':parent_record_id' => $this->get_record_id() + , ':record_id' => $record->get_record_id() + , ':ord' => $ord ); $stmt = $connbas->prepare($sql); @@ -2134,7 +2144,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface $stmt->closeCursor(); - $sql = 'UPDATE record SET moddate = NOW() WHERE record_id = :record_id'; + $sql = 'UPDATE record SET moddate = NOW() WHERE record_id = :record_id'; $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->closeCursor(); @@ -2155,15 +2165,15 @@ class record_adapter implements record_Interface, cache_cacheableInterface AND rid_child = :record_id"; $params = array( - ':parent_record_id' => $this->get_record_id() - , ':record_id' => $record->get_record_id() + ':parent_record_id' => $this->get_record_id() + , ':record_id' => $record->get_record_id() ); $stmt = $connbas->prepare($sql); $stmt->execute($params); $stmt->closeCursor(); - $sql = 'UPDATE record SET moddate = NOW() WHERE record_id = :record_id'; + $sql = 'UPDATE record SET moddate = NOW() WHERE record_id = :record_id'; $stmt = $connbas->prepare($sql); $stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->closeCursor(); diff --git a/lib/classes/searchEngine/options.class.php b/lib/classes/searchEngine/options.class.php index 33fe812ea8..a684b86014 100644 --- a/lib/classes/searchEngine/options.class.php +++ b/lib/classes/searchEngine/options.class.php @@ -451,7 +451,17 @@ class searchEngine_options implements Serializable $value = new DateTime($value); } 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; } diff --git a/lib/unitTest/Alchemy/Phrasea/Controller/Prod/TooltipTest.php b/lib/unitTest/Alchemy/Phrasea/Controller/Prod/TooltipTest.php index 9fa4404dc3..265485231f 100644 --- a/lib/unitTest/Alchemy/Phrasea/Controller/Prod/TooltipTest.php +++ b/lib/unitTest/Alchemy/Phrasea/Controller/Prod/TooltipTest.php @@ -93,7 +93,7 @@ class ControllerTooltipTest extends \PhraseanetWebTestCaseAuthenticatedAbstract foreach ($routes as $route) { $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()); } diff --git a/lib/unitTest/Doctrine/Repositories/Basket.php b/lib/unitTest/Doctrine/Repositories/BasketTest.php similarity index 100% rename from lib/unitTest/Doctrine/Repositories/Basket.php rename to lib/unitTest/Doctrine/Repositories/BasketTest.php diff --git a/lib/unitTest/PhraseanetPHPUnitAbstract.class.inc b/lib/unitTest/PhraseanetPHPUnitAbstract.class.inc index a61533c63f..75aa77a467 100644 --- a/lib/unitTest/PhraseanetPHPUnitAbstract.class.inc +++ b/lib/unitTest/PhraseanetPHPUnitAbstract.class.inc @@ -818,12 +818,12 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase $serviceName = $configuration->getTemplating(); $confService = $configuration->getService($serviceName); - $templateService = \Alchemy\Phrasea\Core\ServiceBuilder::build( + $templateServiceBuilder = new \Alchemy\Phrasea\Core\ServiceBuilder\TemplateEngine( $serviceName - , \Alchemy\Phrasea\Core\ServiceBuilder::TEMPLATE_ENGINE , $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) { + echo "generate story 1\n"; self::$story_1 = \record_adapter::create( self::$collection , new system_file(__DIR__ . '/testfiles/test001.CR2') , false , true ); -// echo "generate story 1\n"; } return; @@ -1044,116 +1044,139 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase { 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::$generated_subdefs['a1'] = true; } 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::$generated_subdefs['a2'] = true; } 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::$generated_subdefs['a3'] = true; } 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::$generated_subdefs['a4'] = true; } 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::$generated_subdefs['a5'] = true; } 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::$generated_subdefs['a6'] = true; } 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::$generated_subdefs['a7'] = true; } 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::$generated_subdefs['a8'] = true; } 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::$generated_subdefs['a9'] = true; } 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::$generated_subdefs['a10'] = true; } 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::$generated_subdefs['a11'] = true; } 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::$generated_subdefs['a12'] = true; } 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::$generated_subdefs['a13'] = true; } 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::$generated_subdefs['a14'] = true; } 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::$generated_subdefs['a15'] = true; } 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::$generated_subdefs['a16'] = true; } 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::$generated_subdefs['a17'] = true; } 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::$generated_subdefs['a18'] = true; } 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::$generated_subdefs['a19'] = true; } 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::$generated_subdefs['a20'] = true; } 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::$generated_subdefs['a21'] = true; } 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::$generated_subdefs['a22'] = true; } 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::$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) { + echo "generate story 1\n"; self::$record_sf_1 = new system_file(__DIR__ . '/testfiles/test001.CR2'); 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) { + echo "generate story 1\n"; $file = new system_file(__DIR__ . '/testfiles/test001.CR2'); 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) { + echo "generate story 2\n"; self::$record_sf_2 = new system_file(__DIR__ . '/testfiles/test002.CR2'); 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) { + echo "generate story 3\n"; self::$record_sf_3 = new system_file(__DIR__ . '/testfiles/test003.CR2'); 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) { + echo "generate story 4\n"; self::$record_sf_4 = new system_file(__DIR__ . '/testfiles/test004.CR2'); 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) { + echo "generate story 5\n"; self::$record_sf_5 = new system_file(__DIR__ . '/testfiles/test005.CR2'); 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) { + echo "generate story 6\n"; self::$record_sf_6 = new system_file(__DIR__ . '/testfiles/test006.wav'); 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) { + echo "generate story 7\n"; self::$record_sf_7 = new system_file(__DIR__ . '/testfiles/test007.ppt'); 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) { + echo "generate story 8\n"; self::$record_sf_8 = new system_file(__DIR__ . '/testfiles/test008.ai'); 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) { + echo "generate story 9\n"; self::$record_sf_9 = new system_file(__DIR__ . '/testfiles/test009.TIFF'); 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) { + echo "generate story 10\n"; self::$record_sf_10 = new system_file(__DIR__ . '/testfiles/test010.fla'); 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) { + echo "generate story 11\n"; self::$record_sf_11 = new system_file(__DIR__ . '/testfiles/test011.swf'); 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) { + echo "generate story 12\n"; self::$record_sf_12 = new system_file(__DIR__ . '/testfiles/test012.wav'); 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) { + echo "generate story 13\n"; self::$record_sf_13 = new system_file(__DIR__ . '/testfiles/test013.ai'); 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) { + echo "generate story 14\n"; self::$record_sf_14 = new system_file(__DIR__ . '/testfiles/test014.swf'); 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) { + echo "generate story 15\n"; self::$record_sf_15 = new system_file(__DIR__ . '/testfiles/test015.eps'); 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) { + echo "generate story 16\n"; self::$record_sf_16 = new system_file(__DIR__ . '/testfiles/test016.ai'); 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) { + echo "generate story 17\n"; self::$record_sf_17 = new system_file(__DIR__ . '/testfiles/test017.wav'); 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) { + echo "generate story 18\n"; self::$record_sf_18 = new system_file(__DIR__ . '/testfiles/test018.TIFF'); 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) { + echo "generate story 19\n"; self::$record_sf_19 = new system_file(__DIR__ . '/testfiles/test019.mp3'); 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) { + echo "generate story 20\n"; self::$record_sf_20 = new system_file(__DIR__ . '/testfiles/test020.mp3'); 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) { + echo "generate story 21\n"; self::$record_sf_21 = new system_file(__DIR__ . '/testfiles/test021.fla'); 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) { + echo "generate story 22\n"; self::$record_sf_22 = new system_file(__DIR__ . '/testfiles/test022.swf'); 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) { + echo "generate story 23\n"; self::$record_sf_23 = new system_file(__DIR__ . '/testfiles/test023.mp4'); self::$record_23 = record_adapter::create(self::$collection, self::$record_sf_23); } diff --git a/lib/unitTest/api/v1/api_v1_adapterTest.php b/lib/unitTest/api/v1/api_v1_adapterTest.php index 8f4560ca88..77cba267a6 100644 --- a/lib/unitTest/api/v1/api_v1_adapterTest.php +++ b/lib/unitTest/api/v1/api_v1_adapterTest.php @@ -261,10 +261,13 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract } $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')); + $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); } diff --git a/lib/unitTest/system/system_fileTest.php b/lib/unitTest/system/system_fileTest.php index fd4b652c2c..4d7bc59964 100644 --- a/lib/unitTest/system/system_fileTest.php +++ b/lib/unitTest/system/system_fileTest.php @@ -257,7 +257,7 @@ class system_fileTest extends PhraseanetPHPUnitAbstract $this->assertArrayHasKey('meta_struct_id', $metadata); $this->assertArrayHasKey('meta_id', $metadata); $this->assertArrayHasKey('value', $metadata); - $this->assertTrue(is_array($metadata['value'])); + $this->assertTrue(is_scalar($metadata['value'])); $this->assertNull($metadata['meta_id']); $this->assertTrue(is_int($metadata['meta_struct_id'])); $this->assertTrue($metadata['meta_struct_id'] > 0); diff --git a/lib/unitTest/unitTestsTest.php b/lib/unitTest/unitTestsTest.php index d81dde1372..94a0500272 100644 --- a/lib/unitTest/unitTestsTest.php +++ b/lib/unitTest/unitTestsTest.php @@ -19,9 +19,10 @@ class unitTestsTest extends PhraseanetPHPUnitAbstract continue; if (substr($file->getFilename(), -4) !== '.php') continue; + if($file->getFilename() === "BoilerPlate.php") + continue; - - $this->assertRegExp('/[a-zA-Z0-9-_\.]+Test.php/', $file->getFilename(), 'Verify that all tests files names'); + $this->assertRegExp('/[a-zA-Z0-9-_\.]+Test.php/', $file->getPathname(), 'Verify that all tests files names'); } } diff --git a/lib/vendor/Silex b/lib/vendor/Silex index 90c2c4209a..95541210d0 160000 --- a/lib/vendor/Silex +++ b/lib/vendor/Silex @@ -1 +1 @@ -Subproject commit 90c2c4209a5cc3d8ceb147d8035876a321a3d541 +Subproject commit 95541210d0a47c3edc46dd67f201ab5286b0dd7b diff --git a/lib/vendor/Twig b/lib/vendor/Twig index 3fbe8d8c46..396435ecd0 160000 --- a/lib/vendor/Twig +++ b/lib/vendor/Twig @@ -1 +1 @@ -Subproject commit 3fbe8d8c469d8db70e6232f8c740130e5d07f4a1 +Subproject commit 396435ecd05556adb0a8bd05b14641cb4f8a8aa5 diff --git a/lib/vendor/Twig-extensions b/lib/vendor/Twig-extensions index a05ab5ed18..3076c97197 160000 --- a/lib/vendor/Twig-extensions +++ b/lib/vendor/Twig-extensions @@ -1 +1 @@ -Subproject commit a05ab5ed18a51ae45f3dcc2d0c4ec9b3a6386987 +Subproject commit 3076c971976e1baaf86e5820c7a1da3f5c1c14eb