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(
@@ -157,15 +174,18 @@ class Core extends \Pimple
*/ */
private function init() private function init()
{ {
if ($this->getConfiguration()->isDisplayingErrors()) if ($this->getConfiguration()->isInstalled())
{ {
ini_set('display_errors', 1); if ($this->getConfiguration()->isDisplayingErrors())
error_reporting(E_ALL); {
ini_set('display_errors', 'on');
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

@@ -132,13 +132,13 @@ class record_adapter implements record_Interface, cache_cacheableInterface
*/ */
protected $modification_date; protected $modification_date;
const CACHE_ORIGINAL_NAME = 'originalname'; const CACHE_ORIGINAL_NAME = 'originalname';
const CACHE_TECHNICAL_DATAS = 'technical_datas'; const CACHE_TECHNICAL_DATAS = 'technical_datas';
const CACHE_MIME = 'mime'; const CACHE_MIME = 'mime';
const CACHE_SHA256 = 'sha256'; const CACHE_SHA256 = 'sha256';
const CACHE_SUBDEFS = 'subdefs'; const CACHE_SUBDEFS = 'subdefs';
const CACHE_GROUPING = 'grouping'; const CACHE_GROUPING = 'grouping';
const CACHE_STATUS = 'status'; const CACHE_STATUS = 'status';
protected static $_regfields; protected static $_regfields;
@@ -186,12 +186,12 @@ class record_adapter implements record_Interface, cache_cacheableInterface
} }
$connbas = $this->databox->get_connection(); $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 , type, originalname, bitly, sha256, mime
FROM record WHERE record_id = :record_id'; FROM record WHERE record_id = :record_id';
$stmt = $connbas->prepare($sql); $stmt = $connbas->prepare($sql);
$stmt->execute(array(':record_id' => $this->record_id)); $stmt->execute(array(':record_id' => $this->record_id));
$row = $stmt->fetch(PDO::FETCH_ASSOC); $row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
if (!$row) if (!$row)
@@ -210,16 +210,16 @@ class record_adapter implements record_Interface, cache_cacheableInterface
$this->mime = $row['mime']; $this->mime = $row['mime'];
$datas = array( $datas = array(
'mime' => $this->mime 'mime' => $this->mime
, 'sha256' => $this->sha256 , 'sha256' => $this->sha256
, 'bitly_link' => $this->bitly_link , 'bitly_link' => $this->bitly_link
, 'original_name' => $this->original_name , 'original_name' => $this->original_name
, 'type' => $this->type , 'type' => $this->type
, 'grouping' => $this->grouping , 'grouping' => $this->grouping
, 'uuid' => $this->uuid , 'uuid' => $this->uuid
, 'modification_date' => $this->modification_date , 'modification_date' => $this->modification_date
, 'creation_date' => $this->creation_date , 'creation_date' => $this->creation_date
, 'base_id' => $this->base_id , 'base_id' => $this->base_id
); );
$this->set_data_to_cache($datas); $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()); $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 = $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(); $stmt->closeCursor();
if ($old_type !== $type) if ($old_type !== $type)
@@ -371,9 +371,9 @@ class record_adapter implements record_Interface, cache_cacheableInterface
{ {
$dstatus = databox_status::getDisplayStatus(); $dstatus = databox_status::getDisplayStatus();
$sbas_id = $this->get_sbas_id(); $sbas_id = $this->get_sbas_id();
$appbox = appbox::get_instance(); $appbox = appbox::get_instance();
$session = $appbox->get_session(); $session = $appbox->get_session();
$user = User_Adapter::getInstance($session->get_usr_id(), $appbox); $user = User_Adapter::getInstance($session->get_usr_id(), $appbox);
$status = ''; $status = '';
@@ -382,24 +382,24 @@ class record_adapter implements record_Interface, cache_cacheableInterface
foreach ($dstatus[$sbas_id] as $n => $statbit) foreach ($dstatus[$sbas_id] as $n => $statbit)
{ {
if ($statbit['printable'] == '0' && 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; continue;
$x = (substr((strrev($this->get_status())), $n, 1)); $x = (substr((strrev($this->get_status())), $n, 1));
$source0 = "/skins/icons/spacer.gif"; $source0 = "/skins/icons/spacer.gif";
$style0 = "visibility:hidden;display:none;"; $style0 = "visibility:hidden;display:none;";
$source1 = "/skins/icons/spacer.gif"; $source1 = "/skins/icons/spacer.gif";
$style1 = "visibility:hidden;display:none;"; $style1 = "visibility:hidden;display:none;";
if ($statbit["img_on"]) if ($statbit["img_on"])
{ {
$source1 = $statbit["img_on"]; $source1 = $statbit["img_on"];
$style1 = "visibility:auto;display:none;"; $style1 = "visibility:auto;display:none;";
} }
if ($statbit["img_off"]) if ($statbit["img_off"])
{ {
$source0 = $statbit["img_off"]; $source0 = $statbit["img_off"];
$style0 = "visibility:auto;display:none;"; $style0 = "visibility:auto;display:none;";
} }
if ($x == '1') if ($x == '1')
{ {
@@ -416,19 +416,19 @@ class record_adapter implements record_Interface, cache_cacheableInterface
} }
} }
$status .= '<img style="margin:1px;' . $style1 . '" ' . $status .= '<img style="margin:1px;' . $style1 . '" ' .
'class="STAT_' . $this->base_id . '_' 'class="STAT_' . $this->base_id . '_'
. $this->record_id . '_' . $n . '_1" ' . . $this->record_id . '_' . $n . '_1" ' .
'src="' . $source1 . '" title="' . 'src="' . $source1 . '" title="' .
(isset($statbit["labelon"]) ? (isset($statbit["labelon"]) ?
$statbit["labelon"] : $statbit["labelon"] :
$statbit["lib"]) . '"/>'; $statbit["lib"]) . '"/>';
$status .= '<img style="margin:1px;' . $style0 . '" ' . $status .= '<img style="margin:1px;' . $style0 . '" ' .
'class="STAT_' . $this->base_id . '_' 'class="STAT_' . $this->base_id . '_'
. $this->record_id . '_' . $n . '_0" ' . . $this->record_id . '_' . $n . '_0" ' .
'src="' . $source0 . '" title="' . 'src="' . $source0 . '" title="' .
(isset($statbit["labeloff"]) ? (isset($statbit["labeloff"]) ?
$statbit["labeloff"] : $statbit["labeloff"] :
("non-" . $statbit["lib"])) . '"/>'; ("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"; $sql = "UPDATE record SET coll_id = :coll_id WHERE record_id =:record_id";
$params = array( $params = array(
':coll_id' => $collection->get_coll_id(), ':coll_id' => $collection->get_coll_id(),
':record_id' => $this->get_record_id() ':record_id' => $this->get_record_id()
); );
$stmt = $this->get_databox()->get_connection()->prepare($sql); $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(); $this->base_id = $collection->get_base_id();
$appbox->get_session()->get_logger($this->get_databox()) $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(); $this->delete_data_from_cache();
@@ -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');
@@ -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'; WHERE record_id = :record_id';
$stmt = $this->get_databox()->get_connection()->prepare($sql); $stmt = $this->get_databox()->get_connection()->prepare($sql);
$stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->execute(array(':record_id' => $this->get_record_id()));
$row = $stmt->fetch(PDO::FETCH_ASSOC); $row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
if (!$row) if (!$row)
throw new Exception('status not found'); throw new Exception('status not found');
$status = $row['status']; $status = $row['status'];
$n = strlen($status); $n = strlen($status);
while ($n < 64) while ($n < 64)
{ {
$status = '0' . $status; $status = '0' . $status;
@@ -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');
@@ -652,7 +660,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface
$stmt = $connbas->prepare($sql); $stmt = $connbas->prepare($sql);
$stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->execute(array(':record_id' => $this->get_record_id()));
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
$subdefs = array('preview', 'thumbnail'); $subdefs = array('preview', 'thumbnail');
@@ -661,7 +669,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface
{ {
$subdefs[] = $row['name']; $subdefs[] = $row['name'];
} }
$subdefs = array_unique($subdefs); $subdefs = array_unique($subdefs);
$this->set_data_to_cache($subdefs, self::CACHE_SUBDEFS); $this->set_data_to_cache($subdefs, self::CACHE_SUBDEFS);
return $subdefs; return $subdefs;
@@ -694,10 +702,10 @@ class record_adapter implements record_Interface, cache_cacheableInterface
{ {
$this->technical_datas = array(); $this->technical_datas = array();
$connbas = $this->get_databox()->get_connection(); $connbas = $this->get_databox()->get_connection();
$sql = 'SELECT name, value FROM technical_datas WHERE record_id = :record_id'; $sql = 'SELECT name, value FROM technical_datas WHERE record_id = :record_id';
$stmt = $connbas->prepare($sql); $stmt = $connbas->prepare($sql);
$stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->execute(array(':record_id' => $this->get_record_id()));
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
foreach ($rs as $row) foreach ($rs as $row)
@@ -773,7 +781,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface
$dom_doc->formatOutput = true; $dom_doc->formatOutput = true;
$dom_doc->standalone = true; $dom_doc->standalone = true;
$record = $dom_doc->createElement('record'); $record = $dom_doc->createElement('record');
$record->setAttribute('record_id', $this->get_record_id()); $record->setAttribute('record_id', $this->get_record_id());
$dom_doc->appendChild($record); $dom_doc->appendChild($record);
$description = $dom_doc->createElement('description'); $description = $dom_doc->createElement('description');
@@ -849,11 +857,11 @@ class record_adapter implements record_Interface, cache_cacheableInterface
$value = array_pop($field->get_values()); $value = array_pop($field->get_values());
$this->set_metadatas( $this->set_metadatas(
array( array(
'meta_struct_id' => $field->get_meta_struct_id() 'meta_struct_id' => $field->get_meta_struct_id()
, 'meta_id' => $value->getId() , 'meta_id' => $value->getId()
, 'value' => $original_name , 'value' => $original_name
) )
); );
} }
} }
@@ -862,8 +870,8 @@ class record_adapter implements record_Interface, cache_cacheableInterface
SET originalname = :originalname WHERE record_id = :record_id'; SET originalname = :originalname WHERE record_id = :record_id';
$params = array( $params = array(
':originalname' => $original_name ':originalname' => $original_name
, ':record_id' => $this->get_record_id() , ':record_id' => $this->get_record_id()
); );
$stmt = $this->get_databox()->get_connection()->prepare($sql); $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) 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(); $record_id = $this->get_record_id();
if ($this->is_grouping()) if ($this->is_grouping())
@@ -891,8 +899,8 @@ class record_adapter implements record_Interface, cache_cacheableInterface
return $regfield['regname']; return $regfield['regname'];
} }
$title = ''; $title = '';
$appbox = appbox::get_instance(); $appbox = appbox::get_instance();
$session = $appbox->get_session(); $session = $appbox->get_session();
$fields = $this->get_databox()->get_meta_structure(); $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) if (count($fields_to_retrieve) > 0)
{ {
$retrieved_fields = $this->get_caption()->get_highlight_fields($highlight, $fields_to_retrieve, $searchEngine); $retrieved_fields = $this->get_caption()->get_highlight_fields($highlight, $fields_to_retrieve, $searchEngine);
$titles = array(); $titles = array();
foreach ($retrieved_fields as $key => $value) foreach ($retrieved_fields as $key => $value)
{ {
if (trim($value['value'] === '')) if (trim($value['value'] === ''))
continue; continue;
$titles[] = $value['value']; $titles[] = $value['value'];
} }
$title = trim(implode(' - ', $titles)); $title = trim(implode(' - ', $titles));
} }
if (trim($title) === '') if (trim($title) === '')
@@ -1004,7 +1012,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface
*/ */
protected function searchRegFields(databox_descriptionStructure $meta_struct) protected function searchRegFields(databox_descriptionStructure $meta_struct)
{ {
$fields = null; $fields = null;
$fields["regname"] = ""; $fields["regname"] = "";
$fields["regdesc"] = ""; $fields["regdesc"] = "";
$fields["regdate"] = ""; $fields["regdate"] = "";
@@ -1078,11 +1086,11 @@ class record_adapter implements record_Interface, cache_cacheableInterface
public function substitute_subdef($name, system_file $pathfile) public function substitute_subdef($name, system_file $pathfile)
{ {
$newfilename = $this->record_id . '_0_' . $name $newfilename = $this->record_id . '_0_' . $name
. '.' . $pathfile->get_extension(); . '.' . $pathfile->get_extension();
$base_url = ''; $base_url = '';
$original_file = $subdef_def = false; $original_file = $subdef_def = false;
if ($name == 'document') if ($name == 'document')
{ {
@@ -1132,7 +1140,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface
} }
catch (Exception $e) catch (Exception $e)
{ {
$path = databox::dispatch($subdef_def->get_path()); $path = databox::dispatch($subdef_def->get_path());
system_file::mkdir($path); system_file::mkdir($path);
$original_file = $path . $newfilename; $original_file = $path . $newfilename;
} }
@@ -1142,9 +1150,9 @@ class record_adapter implements record_Interface, cache_cacheableInterface
if (trim($subdef_def->get_baseurl()) !== '') if (trim($subdef_def->get_baseurl()) !== '')
{ {
$base_url = str_replace( $base_url = str_replace(
array((string) $subdef_def->get_path(), $newfilename) array((string) $subdef_def->get_path(), $newfilename)
, array((string) $subdef_def->get_baseurl(), '') , array((string) $subdef_def->get_baseurl(), '')
, $path_file_dest , $path_file_dest
); );
} }
@@ -1161,18 +1169,18 @@ class record_adapter implements record_Interface, cache_cacheableInterface
try try
{ {
$appbox = \appbox::get_instance(); $appbox = \appbox::get_instance();
$session = $appbox->get_session(); $session = $appbox->get_session();
$connbas = connection::getPDOConnection($this->get_sbas_id()); $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 = $connbas->prepare($sql);
$stmt->execute( $stmt->execute(
array( array(
':record_id' => $this->record_id ':record_id' => $this->record_id
, ':name' => $name , ':name' => $name
) )
); );
$image_size = $system_file->get_technical_datas(); $image_size = $system_file->get_technical_datas();
@@ -1187,18 +1195,18 @@ class record_adapter implements record_Interface, cache_cacheableInterface
$stmt = $connbas->prepare($sql); $stmt = $connbas->prepare($sql);
$stmt->execute(array( $stmt->execute(array(
':record_id' => $this->record_id, ':record_id' => $this->record_id,
':name' => $name, ':name' => $name,
':baseurl' => $base_url, ':baseurl' => $base_url,
':filename' => $system_file->getFilename(), ':filename' => $system_file->getFilename(),
':width' => $image_size[system_file::TC_DATAS_WIDTH], ':width' => $image_size[system_file::TC_DATAS_WIDTH],
':height' => $image_size[system_file::TC_DATAS_HEIGHT], ':height' => $image_size[system_file::TC_DATAS_HEIGHT],
':mime' => $system_file->get_mime(), ':mime' => $system_file->get_mime(),
':path' => $system_file->getPath(), ':path' => $system_file->getPath(),
':filesize' => $system_file->getSize() ':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 = $connbas->prepare($sql);
$stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->execute(array(':record_id' => $this->get_record_id()));
$stmt->closeCursor(); $stmt->closeCursor();
@@ -1217,7 +1225,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface
$type = $name == 'document' ? 'HD' : $name; $type = $name == 'document' ? 'HD' : $name;
$session->get_logger($this->get_databox()) $session->get_logger($this->get_databox())
->log($this, Session_Logger::EVENT_SUBSTITUTE, $type, ''); ->log($this, Session_Logger::EVENT_SUBSTITUTE, $type, '');
} }
catch (Exception $e) catch (Exception $e)
{ {
@@ -1235,13 +1243,13 @@ class record_adapter implements record_Interface, cache_cacheableInterface
protected function set_xml(DOMDocument $dom_doc) protected function set_xml(DOMDocument $dom_doc)
{ {
$connbas = $this->get_databox()->get_connection(); $connbas = $this->get_databox()->get_connection();
$sql = 'UPDATE record SET xml = :xml WHERE record_id= :record_id'; $sql = 'UPDATE record SET xml = :xml WHERE record_id= :record_id';
$stmt = $connbas->prepare($sql); $stmt = $connbas->prepare($sql);
$stmt->execute( $stmt->execute(
array( array(
':xml' => $dom_doc->saveXML(), ':xml' => $dom_doc->saveXML(),
':record_id' => $this->record_id ':record_id' => $this->record_id
) )
); );
$this->reindex(); $this->reindex();
@@ -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']);
@@ -1338,9 +1348,9 @@ class record_adapter implements record_Interface, cache_cacheableInterface
public function reindex() public function reindex()
{ {
$connbas = connection::getPDOConnection($this->get_sbas_id()); $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'; WHERE record_id= :record_id';
$stmt = $connbas->prepare($sql); $stmt = $connbas->prepare($sql);
$stmt->execute(array(':record_id' => $this->record_id)); $stmt->execute(array(':record_id' => $this->record_id));
$this->delete_data_from_cache(self::CACHE_STATUS); $this->delete_data_from_cache(self::CACHE_STATUS);
@@ -1354,8 +1364,8 @@ class record_adapter implements record_Interface, cache_cacheableInterface
public function rebuild_subdefs() public function rebuild_subdefs()
{ {
$connbas = connection::getPDOConnection($this->get_sbas_id()); $connbas = connection::getPDOConnection($this->get_sbas_id());
$sql = 'UPDATE record SET jeton=(jeton | ' . JETON_MAKE_SUBDEF . ') WHERE record_id = :record_id'; $sql = 'UPDATE record SET jeton=(jeton | ' . JETON_MAKE_SUBDEF . ') WHERE record_id = :record_id';
$stmt = $connbas->prepare($sql); $stmt = $connbas->prepare($sql);
$stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->execute(array(':record_id' => $this->get_record_id()));
return $this; return $this;
@@ -1368,10 +1378,10 @@ class record_adapter implements record_Interface, cache_cacheableInterface
public function write_metas() public function write_metas()
{ {
$connbas = connection::getPDOConnection($this->get_sbas_id()); $connbas = connection::getPDOConnection($this->get_sbas_id());
$sql = 'UPDATE record $sql = 'UPDATE record
SET jeton = ' . (JETON_WRITE_META_DOC | JETON_WRITE_META_SUBDEF) . ' SET jeton = ' . (JETON_WRITE_META_DOC | JETON_WRITE_META_SUBDEF) . '
WHERE record_id= :record_id'; WHERE record_id= :record_id';
$stmt = $connbas->prepare($sql); $stmt = $connbas->prepare($sql);
$stmt->execute(array(':record_id' => $this->record_id)); $stmt->execute(array(':record_id' => $this->record_id));
return $this; return $this;
@@ -1387,21 +1397,21 @@ class record_adapter implements record_Interface, cache_cacheableInterface
$connbas = connection::getPDOConnection($this->get_sbas_id()); $connbas = connection::getPDOConnection($this->get_sbas_id());
$registry = registry::get_instance(); $registry = registry::get_instance();
$sql = 'UPDATE record SET status = 0b' . $status . ' $sql = 'UPDATE record SET status = 0b' . $status . '
WHERE record_id= :record_id'; WHERE record_id= :record_id';
$stmt = $connbas->prepare($sql); $stmt = $connbas->prepare($sql);
$stmt->execute(array(':record_id' => $this->record_id)); $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); $stmt = $connbas->prepare($sql);
$status = strrev($status); $status = strrev($status);
for ($i = 4; $i < strlen($status); $i++) for ($i = 4; $i < strlen($status); $i++)
{ {
$stmt->execute(array( $stmt->execute(array(
':record_id' => $this->get_record_id(), ':record_id' => $this->get_record_id(),
':name' => $i, ':name' => $i,
':value' => $status[$i] ':value' => $status[$i]
)); ));
} }
$stmt->closeCursor(); $stmt->closeCursor();
@@ -1411,10 +1421,10 @@ class record_adapter implements record_Interface, cache_cacheableInterface
$sphinx = sphinxrt::get_instance($registry); $sphinx = sphinxrt::get_instance($registry);
$sbas_params = phrasea::sbas_params(); $sbas_params = phrasea::sbas_params();
$sbas_id = $this->get_sbas_id(); $sbas_id = $this->get_sbas_id();
if (isset($sbas_params[$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']))); $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)); $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 = ''; $regname = '';
if ($sxe = simplexml_load_string($this->get_xml())) if ($sxe = simplexml_load_string($this->get_xml()))
$regname = (string) $sxe->description->$balisename; $regname = (string) $sxe->description->$balisename;
return $regname; return $regname;
} }
@@ -1478,7 +1488,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface
if ($is_grouping) if ($is_grouping)
{ {
$uuid = uuid::generate_v4(); $uuid = uuid::generate_v4();
$sha256 = null; $sha256 = null;
} }
else else
@@ -1486,7 +1496,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface
$uuid = $system_file->read_uuid(); $uuid = $system_file->read_uuid();
if (!uuid::is_valid($uuid)) if (!uuid::is_valid($uuid))
{ {
$uuid = uuid::generate_v4(); $uuid = uuid::generate_v4();
} }
$sha256 = $system_file->get_sha256(); $sha256 = $system_file->get_sha256();
} }
@@ -1510,32 +1520,32 @@ class record_adapter implements record_Interface, cache_cacheableInterface
$stmt = $connbas->prepare($sql); $stmt = $connbas->prepare($sql);
$stmt->execute(array( $stmt->execute(array(
':coll_id' => $coll_id ':coll_id' => $coll_id
, ':parent_record_id' => ($is_grouping ? 1 : 0) , ':parent_record_id' => ($is_grouping ? 1 : 0)
, ':type' => $type , ':type' => $type
, ':sha256' => $sha256 , ':sha256' => $sha256
, ':uuid' => $uuid , ':uuid' => $uuid
, ':originalname' => $original_name , ':originalname' => $original_name
, ':mime' => $system_file->get_mime() , ':mime' => $system_file->get_mime()
)); ));
$record_id = $connbas->lastInsertId(); $record_id = $connbas->lastInsertId();
$record = new self($sbas_id, $record_id); $record = new self($sbas_id, $record_id);
try try
{ {
$appbox = appbox::get_instance(); $appbox = appbox::get_instance();
$session = $appbox->get_session(); $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(), VALUES (null, :log_id, now(),
:record_id, "add", :coll_id,"")'; :record_id, "add", :coll_id,"")';
$stmt = $connbas->prepare($sql); $stmt = $connbas->prepare($sql);
$stmt->execute(array( $stmt->execute(array(
':log_id' => $log_id, ':log_id' => $log_id,
':record_id' => $record_id, ':record_id' => $record_id,
':coll_id' => $coll_id ':coll_id' => $coll_id
)); ));
$stmt->closeCursor(); $stmt->closeCursor();
} }
@@ -1564,7 +1574,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface
$tc_datas = $system_file->get_technical_datas(); $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)'; VALUES (null, :record_id, :name, :value)';
$stmt = $connbas->prepare($sql); $stmt = $connbas->prepare($sql);
@@ -1574,9 +1584,9 @@ class record_adapter implements record_Interface, cache_cacheableInterface
continue; continue;
$stmt->execute(array( $stmt->execute(array(
':record_id' => $record_id ':record_id' => $record_id
, ':name' => $name , ':name' => $name
, ':value' => $value , ':value' => $value
)); ));
} }
$stmt->closeCursor(); $stmt->closeCursor();
@@ -1610,14 +1620,14 @@ class record_adapter implements record_Interface, cache_cacheableInterface
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
$records = array(); $records = array();
foreach ($rs as $row) foreach ($rs as $row)
{ {
$k = count($records); $k = count($records);
$records[$k] = new record_adapter($sbas_id, $row['record_id']); $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() public function delete()
{ {
$connbas = $this->get_databox()->get_connection(); $connbas = $this->get_databox()->get_connection();
$sbas_id = $this->get_databox()->get_sbas_id(); $sbas_id = $this->get_databox()->get_sbas_id();
$appbox = appbox::get_instance(); $appbox = appbox::get_instance();
$registry = $appbox->get_registry(); $registry = $appbox->get_registry();
$conn = $appbox->get_connection(); $conn = $appbox->get_connection();
$ftodel = array(); $ftodel = array();
foreach ($this->get_subdefs() as $subdef) foreach ($this->get_subdefs() as $subdef)
@@ -1654,30 +1664,30 @@ class record_adapter implements record_Interface, cache_cacheableInterface
if (!$subdef->is_physically_present()) if (!$subdef->is_physically_present())
continue; continue;
$ftodel[] = $subdef->get_pathfile(); $ftodel[] = $subdef->get_pathfile();
$watermark = $subdef->get_path() . 'watermark_' . $subdef->get_file(); $watermark = $subdef->get_path() . 'watermark_' . $subdef->get_file();
if (file_exists($watermark)) if (file_exists($watermark))
$ftodel[] = $watermark; $ftodel[] = $watermark;
$stamp = $subdef->get_path() . 'stamp_' . $subdef->get_file(); $stamp = $subdef->get_path() . 'stamp_' . $subdef->get_file();
if (file_exists($stamp)) if (file_exists($stamp))
$ftodel[] = $stamp; $ftodel[] = $stamp;
} }
$origcoll = phrasea::collFromBas($this->get_base_id()); $origcoll = phrasea::collFromBas($this->get_base_id());
$appbox->get_session()->get_logger($this->get_databox()) $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 = $connbas->prepare($sql);
$stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->execute(array(':record_id' => $this->get_record_id()));
$stmt->closeCursor(); $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 = $connbas->prepare($sql);
$stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->execute(array(':record_id' => $this->get_record_id()));
$rs = $stmt->fetchAll(); $rs = $stmt->fetchAll();
$stmt->closeCursor(); $stmt->closeCursor();
try try
@@ -1688,7 +1698,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface
if (isset($sbas_params[$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']))); $sbas_crc = crc32(str_replace(array('.', '%'), '_', sprintf('%s_%s_%s_%s', $params['host'], $params['port'], $params['user'], $params['dbname'])));
foreach ($rs as $row) foreach ($rs as $row)
{ {
@@ -1702,49 +1712,49 @@ class record_adapter implements record_Interface, cache_cacheableInterface
unset($e); 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 = $connbas->prepare($sql);
$stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->execute(array(':record_id' => $this->get_record_id()));
$stmt->closeCursor(); $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 = $connbas->prepare($sql);
$stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->execute(array(':record_id' => $this->get_record_id()));
$stmt->closeCursor(); $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 = $connbas->prepare($sql);
$stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->execute(array(':record_id' => $this->get_record_id()));
$stmt->closeCursor(); $stmt->closeCursor();
$sql = "DELETE FROM permalinks $sql = "DELETE FROM permalinks
WHERE subdef_id WHERE subdef_id
IN (SELECT subdef_id FROM subdef WHERE record_id=:record_id)"; IN (SELECT subdef_id FROM subdef WHERE record_id=:record_id)";
$stmt = $connbas->prepare($sql); $stmt = $connbas->prepare($sql);
$stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->execute(array(':record_id' => $this->get_record_id()));
$stmt->closeCursor(); $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 = $connbas->prepare($sql);
$stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->execute(array(':record_id' => $this->get_record_id()));
$stmt->closeCursor(); $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 = $connbas->prepare($sql);
$stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->execute(array(':record_id' => $this->get_record_id()));
$stmt->closeCursor(); $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 = $connbas->prepare($sql);
$stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->execute(array(':record_id' => $this->get_record_id()));
$stmt->closeCursor(); $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 = $connbas->prepare($sql);
$stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->execute(array(':record_id' => $this->get_record_id()));
$stmt->closeCursor(); $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 = $connbas->prepare($sql);
$stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->execute(array(':record_id' => $this->get_record_id()));
$stmt->closeCursor(); $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"; 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(); $record_subdefs = $this->get_subdefs();
foreach ($subdefs as $subdef) 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) protected function generate_subdef(databox_subdefInterface $subdef_class, $pathdest)
{ {
$registry = registry::get_instance(); $registry = registry::get_instance();
$generated = $subdef_class->generate($this, $pathdest, $registry); $generated = $subdef_class->generate($this, $pathdest, $registry);
return $this; return $this;
@@ -1918,12 +1928,12 @@ class record_adapter implements record_Interface, cache_cacheableInterface
(null, :log_id, now(), :rec, :referrer, :site)'; (null, :log_id, now(), :rec, :referrer, :site)';
$params = array( $params = array(
':log_id' => $log_id ':log_id' => $log_id
, ':rec' => $this->get_record_id() , ':rec' => $this->get_record_id()
, ':referrer' => $referrer , ':referrer' => $referrer
, ':site' => $gv_sit , ':site' => $gv_sit
); );
$stmt = $connbas->prepare($sql); $stmt = $connbas->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
$stmt->closeCursor(); $stmt->closeCursor();
@@ -1964,7 +1974,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface
public function get_container_baskets() public function get_container_baskets()
{ {
$Core = bootstrap::getCore(); $Core = bootstrap::getCore();
$em = $Core->getEntityManager(); $em = $Core->getEntityManager();
$repo = $em->getRepository('\Entities\Basket'); $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) 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); $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 $sql = sprintf('SELECT record_id FROM record
WHERE original_name = :original_name LIMIT %d, %d' WHERE original_name = :original_name LIMIT %d, %d'
, $offset_start, $how_many); , $offset_start, $how_many);
$stmt = $databox->get_connection()->prepare($sql); $stmt = $databox->get_connection()->prepare($sql);
$stmt->execute(array(':original_name' => $original_name)); $stmt->execute(array(':original_name' => $original_name));
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
$records = array(); $records = array();
@@ -2027,18 +2037,18 @@ class record_adapter implements record_Interface, cache_cacheableInterface
ORDER BY g.ord ASC, dateadd ASC, record_id ASC'; ORDER BY g.ord ASC, dateadd ASC, record_id ASC';
$params = array( $params = array(
':GV_site' => $appbox->get_registry()->get('GV_sit') ':GV_site' => $appbox->get_registry()->get('GV_sit')
, ':usr_id' => $appbox->get_session()->get_usr_id() , ':usr_id' => $appbox->get_session()->get_usr_id()
, ':record_id' => $this->get_record_id() , ':record_id' => $this->get_record_id()
); );
$stmt = $this->get_databox()->get_connection()->prepare($sql); $stmt = $this->get_databox()->get_connection()->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
$set = new set_selection(); $set = new set_selection();
$i = 1; $i = 1;
foreach ($rs as $row) foreach ($rs as $row)
{ {
$set->add_element(new record_adapter($this->get_sbas_id(), $row['record_id'], $i)); $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( $params = array(
':GV_site' => $appbox->get_registry()->get('GV_sit') ':GV_site' => $appbox->get_registry()->get('GV_sit')
, ':usr_id' => $appbox->get_session()->get_usr_id() , ':usr_id' => $appbox->get_session()->get_usr_id()
, ':record_id' => $this->get_record_id() , ':record_id' => $this->get_record_id()
); );
$stmt = $this->get_databox()->get_connection()->prepare($sql); $stmt = $this->get_databox()->get_connection()->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
$set = new set_selection(); $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)'; VALUES (null, :parent_record_id, :record_id, NOW(), :ord)';
$params = array( $params = array(
':parent_record_id' => $this->get_record_id() ':parent_record_id' => $this->get_record_id()
, ':record_id' => $record->get_record_id() , ':record_id' => $record->get_record_id()
, ':ord' => $ord , ':ord' => $ord
); );
$stmt = $connbas->prepare($sql); $stmt = $connbas->prepare($sql);
@@ -2134,7 +2144,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface
$stmt->closeCursor(); $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 = $connbas->prepare($sql);
$stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->execute(array(':record_id' => $this->get_record_id()));
$stmt->closeCursor(); $stmt->closeCursor();
@@ -2155,15 +2165,15 @@ class record_adapter implements record_Interface, cache_cacheableInterface
AND rid_child = :record_id"; AND rid_child = :record_id";
$params = array( $params = array(
':parent_record_id' => $this->get_record_id() ':parent_record_id' => $this->get_record_id()
, ':record_id' => $record->get_record_id() , ':record_id' => $record->get_record_id()
); );
$stmt = $connbas->prepare($sql); $stmt = $connbas->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
$stmt->closeCursor(); $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 = $connbas->prepare($sql);
$stmt->execute(array(':record_id' => $this->get_record_id())); $stmt->execute(array(':record_id' => $this->get_record_id()));
$stmt->closeCursor(); $stmt->closeCursor();

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');
} }
} }