Update base and bootstrap

This commit is contained in:
Romain Neutron
2012-09-21 14:38:50 +02:00
parent 9cf8055d49
commit 3e13cb455c
4 changed files with 160 additions and 184 deletions

View File

@@ -9,6 +9,9 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Alchemy\Phrasea\Core\Configuration;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Core\Version;
use Alchemy\Phrasea\Cache\Manager as CacheManager; use Alchemy\Phrasea\Cache\Manager as CacheManager;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use MediaAlchemyst\Alchemyst; use MediaAlchemyst\Alchemyst;
@@ -45,11 +48,9 @@ class appbox extends base
* *
* @var <type> * @var <type>
*/ */
protected $session;
protected $cache; protected $cache;
protected $connection; protected $connection;
protected $registry; protected $app;
protected $Core;
const CACHE_LIST_BASES = 'list_bases'; const CACHE_LIST_BASES = 'list_bases';
const CACHE_SBAS_IDS = 'sbas_ids'; const CACHE_SBAS_IDS = 'sbas_ids';
@@ -59,10 +60,10 @@ class appbox extends base
* *
* @return appbox * @return appbox
*/ */
public static function get_instance(\Alchemy\Phrasea\Core $Core, registryInterface &$registry = null) public static function get_instance(Application $app, registryInterface &$registry = null)
{ {
if (!self::$_instance instanceof self) { if (!self::$_instance instanceof self) {
self::$_instance = new self($Core, $registry); self::$_instance = new static($app, $registry);
} }
return self::$_instance; return self::$_instance;
@@ -73,20 +74,13 @@ class appbox extends base
* *
* @return appbox * @return appbox
*/ */
public function __construct(\Alchemy\Phrasea\Core $Core, registryInterface $registry = null) public function __construct(Application $app, registryInterface $registry = null)
{ {
$this->Core = $Core; $this->app = $app;
if (!$registry) $this->connection = connection::getPDOConnection($app, null, $app['phraseanet.registry']);
$registry = registry::get_instance($Core); $choosenConnexion = $app['phraseanet.configuration']->getPhraseanet()->get('database');
$this->connection = connection::getPDOConnection(null, $registry);
$this->registry = $registry;
$this->session = Session_Handler::getInstance($this);
$configuration = $Core->getConfiguration(); $connexion = $app['phraseanet.configuration']->getConnexion($choosenConnexion);
$choosenConnexion = $configuration->getPhraseanet()->get('database');
$connexion = $configuration->getConnexion($choosenConnexion);
$this->host = $connexion->get('host'); $this->host = $connexion->get('host');
$this->port = $connexion->get('port'); $this->port = $connexion->get('port');
@@ -165,7 +159,7 @@ class appbox extends base
$collection->update_logo($pathfile); $collection->update_logo($pathfile);
} }
$registry = registry::get_instance(); $registry = $this->app['phraseanet.registry'];
$file = $registry->get('GV_RootPath') . 'config/' . $pic_type . '/' . $collection->get_base_id(); $file = $registry->get('GV_RootPath') . 'config/' . $pic_type . '/' . $collection->get_base_id();
$custom_path = $registry->get('GV_RootPath') . 'www/custom/' . $pic_type . '/' . $collection->get_base_id(); $custom_path = $registry->get('GV_RootPath') . 'www/custom/' . $pic_type . '/' . $collection->get_base_id();
@@ -322,8 +316,7 @@ class appbox extends base
$stmt->execute(array(':viewname' => $viewname, ':sbas_id' => $databox->get_sbas_id())); $stmt->execute(array(':viewname' => $viewname, ':sbas_id' => $databox->get_sbas_id()));
$stmt->closeCursor(); $stmt->closeCursor();
$appbox = appbox::get_instance(\bootstrap::getCore()); $this->delete_data_from_cache(appbox::CACHE_LIST_BASES);
$appbox->delete_data_from_cache(appbox::CACHE_LIST_BASES);
cache_databox::update($databox->get_sbas_id(), 'structure'); cache_databox::update($databox->get_sbas_id(), 'structure');
return $this; return $this;
@@ -338,7 +331,7 @@ class appbox extends base
return self::BASE_TYPE; return self::BASE_TYPE;
} }
public function forceUpgrade(Setup_Upgrade &$upgrader, CacheManager $cacheManager, $cacheservice,EntityManager $em, Filesystem $filesystem) public function forceUpgrade(Setup_Upgrade &$upgrader, Application $app)
{ {
$from_version = $this->get_version(); $from_version = $this->get_version();
@@ -351,16 +344,16 @@ class appbox extends base
*/ */
$upgrader->set_current_message(_('Flushing cache')); $upgrader->set_current_message(_('Flushing cache'));
$cacheManager->flushAll(); $app['phraseanet.cache-service']->flushAll();
$upgrader->add_steps_complete(1); $upgrader->add_steps_complete(1);
$upgrader->set_current_message(_('Creating new tables')); $upgrader->set_current_message(_('Creating new tables'));
//create schema //create schema
if ($em->getConnection()->getDatabasePlatform()->supportsAlterTable()) { if ($app['EM']->getConnection()->getDatabasePlatform()->supportsAlterTable()) {
$tool = new \Doctrine\ORM\Tools\SchemaTool($em); $tool = new \Doctrine\ORM\Tools\SchemaTool($app['EM']);
$metas = $em->getMetadataFactory()->getAllMetadata(); $metas = $app['EM']->getMetadataFactory()->getAllMetadata();
$tool->updateSchema($metas, true); $tool->updateSchema($metas, true);
} }
@@ -378,7 +371,7 @@ class appbox extends base
))->ignoreVCS(true)->ignoreDotFiles(true); ))->ignoreVCS(true)->ignoreDotFiles(true);
foreach ($finder as $file) { foreach ($finder as $file) {
$filesystem->remove($file); $app['filesystem']->remove($file);
} }
$upgrader->add_steps_complete(1); $upgrader->add_steps_complete(1);
@@ -388,8 +381,6 @@ class appbox extends base
*/ */
$upgrader->set_current_message(_('Copying files')); $upgrader->set_current_message(_('Copying files'));
$filesystem = $filesystem;
foreach (array( foreach (array(
'config/custom_files/' => 'www/custom/', 'config/custom_files/' => 'www/custom/',
'config/minilogos/' => 'www/custom/minilogos/', 'config/minilogos/' => 'www/custom/minilogos/',
@@ -397,7 +388,7 @@ class appbox extends base
'config/status/' => 'www/custom/status/', 'config/status/' => 'www/custom/status/',
'config/wm/' => 'www/custom/wm/', 'config/wm/' => 'www/custom/wm/',
) as $source => $target) { ) as $source => $target) {
$filesystem->mirror($registry->get('GV_RootPath') . $source, $registry->get('GV_RootPath') . $target); $app['filesystem']->mirror($registry->get('GV_RootPath') . $source, $registry->get('GV_RootPath') . $target);
} }
$upgrader->add_steps_complete(1); $upgrader->add_steps_complete(1);
@@ -408,7 +399,7 @@ class appbox extends base
* Step 6 * Step 6
*/ */
$upgrader->set_current_message(_('Upgrading appbox')); $upgrader->set_current_message(_('Upgrading appbox'));
$advices = $this->upgradeDB(true, $upgrader); $advices = $this->upgradeDB(true, $upgrader, $app);
$upgrader->add_steps_complete(1); $upgrader->add_steps_complete(1);
/** /**
@@ -416,7 +407,7 @@ class appbox extends base
*/ */
foreach ($this->get_databoxes() as $s) { foreach ($this->get_databoxes() as $s) {
$upgrader->set_current_message(sprintf(_('Upgrading %s'), $s->get_viewname())); $upgrader->set_current_message(sprintf(_('Upgrading %s'), $s->get_viewname()));
$advices = array_merge($advices, $s->upgradeDB(true, $upgrader)); $advices = array_merge($advices, $s->upgradeDB(true, $upgrader, $app));
$upgrader->add_steps_complete(1); $upgrader->add_steps_complete(1);
} }
@@ -424,7 +415,7 @@ class appbox extends base
* Step 8 * Step 8
*/ */
$upgrader->set_current_message(_('Post upgrade')); $upgrader->set_current_message(_('Post upgrade'));
$this->post_upgrade($upgrader); $this->post_upgrade($upgrader, $app);
$upgrader->add_steps_complete(1); $upgrader->add_steps_complete(1);
/** /**
@@ -432,7 +423,7 @@ class appbox extends base
*/ */
$upgrader->set_current_message(_('Flushing cache')); $upgrader->set_current_message(_('Flushing cache'));
$cacheManager->flushAll(); $app['phraseanet.cache-service']->flushAll();
$upgrader->add_steps_complete(1); $upgrader->add_steps_complete(1);
@@ -450,18 +441,16 @@ class appbox extends base
return $advices; return $advices;
} }
protected function post_upgrade(Setup_Upgrade &$upgrader) protected function post_upgrade(Setup_Upgrade &$upgrader, Application $app)
{ {
$Core = bootstrap::getCore();
$upgrader->add_steps(1 + count($this->get_databoxes())); $upgrader->add_steps(1 + count($this->get_databoxes()));
$this->apply_patches($this->get_version(), $Core->getVersion()->getNumber(), true, $upgrader); $this->apply_patches($this->get_version(), $app['phraseanet.version']->getNumber(), true, $upgrader, $app);
$this->setVersion($Core->getVersion()->getNumber()); $this->setVersion($app['phraseanet.version']);
$upgrader->add_steps_complete(1); $upgrader->add_steps_complete(1);
foreach ($this->get_databoxes() as $databox) { foreach ($this->get_databoxes() as $databox) {
$databox->apply_patches($databox->get_version(), $Core->getVersion()->getNumber(), true, $upgrader); $databox->apply_patches($databox->get_version(), $app['phraseanet.version']->getNumber(), true, $upgrader, $app);
$databox->setVersion($Core->getVersion()->getNumber()); $databox->setVersion($app['phraseanet.version']);
$upgrader->add_steps_complete(1); $upgrader->add_steps_complete(1);
} }
@@ -476,7 +465,7 @@ class appbox extends base
* @param type $write_file * @param type $write_file
* @return type * @return type
*/ */
public static function create(\Alchemy\Phrasea\Core $Core, registryInterface &$registry, connection_interface $conn, $dbname, $write_file = false) public static function create(Application $app, registryInterface &$registry, connection_interface $conn, $dbname, Version $version, $write_file = false)
{ {
$credentials = $conn->get_credentials(); $credentials = $conn->get_credentials();
@@ -494,7 +483,7 @@ class appbox extends base
$connexionINI[$key] = (string) $value; $connexionINI[$key] = (string) $value;
} }
$Core->getConfiguration()->initialize(); $app['phraseanet.configuration']->initialize();
$connexionINI['driver'] = 'pdo_mysql'; $connexionINI['driver'] = 'pdo_mysql';
$connexionINI['charset'] = 'UTF8'; $connexionINI['charset'] = 'UTF8';
@@ -512,9 +501,9 @@ class appbox extends base
$cacheService = "array_cache"; $cacheService = "array_cache";
$Core->getConfiguration()->setConnexions($connexion); $app['phraseanet.configuration']->setConnexions($connexion);
$services = $Core->getConfiguration()->getConfigurations(); $services = $app['phraseanet.configuration']->getConfigurations();
foreach ($services as $serviceName => $service) { foreach ($services as $serviceName => $service) {
if ($serviceName === "doctrine_prod") { if ($serviceName === "doctrine_prod") {
@@ -526,9 +515,9 @@ class appbox extends base
); );
} }
} }
$Core->getConfiguration()->setConfigurations($services); $app['phraseanet.configuration']->setConfigurations($services);
$arrayConf = $Core->getConfiguration()->getConfigurations(); $arrayConf = $app['phraseanet.configuration']->getConfigurations();
foreach ($arrayConf as $key => $value) { foreach ($arrayConf as $key => $value) {
if (is_array($value) && array_key_exists('phraseanet', $value)) { if (is_array($value) && array_key_exists('phraseanet', $value)) {
@@ -540,9 +529,8 @@ class appbox extends base
} }
} }
$Core->getConfiguration()->setConfigurations($arrayConf); $app['phraseanet.configuration']->setConfigurations($arrayConf);
$app['phraseanet.configuration']->setEnvironnement('prod');
$Core->getConfiguration()->setEnvironnement('prod');
} }
try { try {
if ($conn->is_multi_db()) { if ($conn->is_multi_db()) {
@@ -562,8 +550,8 @@ class appbox extends base
} }
try { try {
$appbox = self::get_instance($Core, $registry); $appbox = static::get_instance($app, $registry);
$appbox->insert_datas(); $appbox->insert_datas($version);
} catch (Exception $e) { } catch (Exception $e) {
throw new Exception('Error while installing ' . $e->getMessage()); throw new Exception('Error while installing ' . $e->getMessage());
} }
@@ -585,7 +573,7 @@ class appbox extends base
$ret = array(); $ret = array();
foreach ($this->retrieve_sbas_ids() as $sbas_id) { foreach ($this->retrieve_sbas_ids() as $sbas_id) {
try { try {
$ret[$sbas_id] = new \databox($sbas_id); $ret[$sbas_id] = new \databox($this->app, $sbas_id);
} catch (\Exception_DataboxNotFound $e) { } catch (\Exception_DataboxNotFound $e) {
} }
@@ -632,15 +620,6 @@ class appbox extends base
return $databoxes[$sbas_id]; return $databoxes[$sbas_id];
} }
/**
*
* @return Session_Handler
*/
public function get_session()
{
return $this->session;
}
public static function list_databox_templates() public static function list_databox_templates()
{ {
$files = array(); $files = array();

View File

@@ -9,6 +9,9 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Core\Version;
abstract class base implements cache_cacheableInterface abstract class base implements cache_cacheableInterface
{ {
protected $version; protected $version;
@@ -136,19 +139,7 @@ abstract class base implements cache_cacheableInterface
*/ */
public function get_registry() public function get_registry()
{ {
return $this->registry; return $this->app['phraseanet.registry'];
}
/**
*
* @param registryInterface $registry
* @return base
*/
public function set_registry(registryInterface $registry)
{
$this->registry = $registry;
return $this;
} }
/** /**
@@ -176,7 +167,7 @@ abstract class base implements cache_cacheableInterface
public function get_cache() public function get_cache()
{ {
if ( ! $this->cache) { if ( ! $this->cache) {
$this->cache = $this->Core->getCache(); $this->cache = $this->app['cache'];
} }
return $this->cache; return $this->cache;
@@ -191,7 +182,7 @@ abstract class base implements cache_cacheableInterface
{ {
if ($this->get_base_type() == self::DATA_BOX) { if ($this->get_base_type() == self::DATA_BOX) {
\cache_databox::refresh($this->id); \cache_databox::refresh($this->app, $this->id);
} }
return $this->get_cache()->get($this->get_cache_key($option)); return $this->get_cache()->get($this->get_cache_key($option));
@@ -204,12 +195,12 @@ abstract class base implements cache_cacheableInterface
public function delete_data_from_cache($option = null) public function delete_data_from_cache($option = null)
{ {
$appbox = $this->get_base_type() == self::APPLICATION_BOX ? $this : $this->get_appbox();
if ($option === appbox::CACHE_LIST_BASES) { if ($option === appbox::CACHE_LIST_BASES) {
$keys = array($this->get_cache_key(appbox::CACHE_LIST_BASES)); $keys = array($this->get_cache_key(appbox::CACHE_LIST_BASES));
phrasea::reset_sbasDatas(); phrasea::reset_sbasDatas($appbox);
phrasea::reset_baseDatas(); phrasea::reset_baseDatas($appbox);
phrasea::clear_sbas_params(); phrasea::clear_sbas_params($this->app);
$keys[] = $this->get_cache_key(appbox::CACHE_SBAS_IDS); $keys[] = $this->get_cache_key(appbox::CACHE_SBAS_IDS);
return $this->get_cache()->deleteMulti($keys); return $this->get_cache()->deleteMulti($keys);
@@ -272,7 +263,7 @@ abstract class base implements cache_cacheableInterface
} }
} }
protected function upgradeDb($apply_patches, Setup_Upgrade &$upgrader) protected function upgradeDb($apply_patches, Setup_Upgrade &$upgrader, Application $app)
{ {
$recommends = array(); $recommends = array();
@@ -280,8 +271,9 @@ abstract class base implements cache_cacheableInterface
$schema = $this->get_schema(); $schema = $this->get_schema();
foreach ($schema->tables->table as $table) foreach ($schema->tables->table as $table) {
$allTables[(string) $table['name']] = $table; $allTables[(string) $table['name']] = $table;
}
$upgrader->add_steps(count($allTables) + 1); $upgrader->add_steps(count($allTables) + 1);
@@ -309,7 +301,6 @@ abstract class base implements cache_cacheableInterface
foreach ($rs as $row) { foreach ($rs as $row) {
$tname = $row["Name"]; $tname = $row["Name"];
if (isset($allTables[$tname])) { if (isset($allTables[$tname])) {
$upgrader->set_current_message(sprintf(_('Updating table %s'), $tname)); $upgrader->set_current_message(sprintf(_('Updating table %s'), $tname));
@@ -349,23 +340,21 @@ abstract class base implements cache_cacheableInterface
} }
$current_version = $this->get_version(); $current_version = $this->get_version();
$Core = bootstrap::getCore();
$upgrader->set_current_message(sprintf(_('Applying patches on %s'), $this->get_dbname())); $upgrader->set_current_message(sprintf(_('Applying patches on %s'), $this->get_dbname()));
if ($apply_patches) { if ($apply_patches) {
$this->apply_patches($current_version, $Core->getVersion()->getNumber(), false, $upgrader); $this->apply_patches($current_version, $app['phraseanet.version']->getNumber(), false, $upgrader, $app);
} }
$upgrader->add_steps_complete(1); $upgrader->add_steps_complete(1);
return $recommends; return $recommends;
} }
protected function setVersion($version) protected function setVersion(Version $version)
{ {
try { try {
$sql = ''; $sql = '';
if ($this->get_base_type() === self::APPLICATION_BOX) if ($this->get_base_type() === self::APPLICATION_BOX)
$sql = 'UPDATE sitepreff SET version = "' . $version . '"'; $sql = 'UPDATE sitepreff SET version = "' . $version->getNumber() . '"';
if ($this->get_base_type() === self::DATA_BOX) { if ($this->get_base_type() === self::DATA_BOX) {
$sql = 'DELETE FROM pref WHERE prop="version" AND locale IS NULL'; $sql = 'DELETE FROM pref WHERE prop="version" AND locale IS NULL';
$this->get_connection()->query($sql); $this->get_connection()->query($sql);
@@ -373,15 +362,15 @@ abstract class base implements cache_cacheableInterface
} }
if ($sql !== '') { if ($sql !== '') {
$stmt = $this->get_connection()->prepare($sql); $stmt = $this->get_connection()->prepare($sql);
$stmt->execute(array(':version' => $version)); $stmt->execute(array(':version' => $version->getNumber()));
$stmt->closeCursor(); $stmt->closeCursor();
$this->version = $version; $this->version = $version->getNumber();
return true; return true;
} }
} catch (Exception $e) { } catch (Exception $e) {
throw new Exception('Unable to set the database version'); throw new Exception('Unable to set the database version : '.$e->getMessage());
} }
return; return;
@@ -416,7 +405,7 @@ abstract class base implements cache_cacheableInterface
* *
* @return base * @return base
*/ */
protected function insert_datas() protected function insert_datas(Version $version)
{ {
$this->load_schema(); $this->load_schema();
@@ -424,8 +413,7 @@ abstract class base implements cache_cacheableInterface
$this->createTable($table); $this->createTable($table);
} }
$Core = bootstrap::getCore(); $this->setVersion($version);
$this->setVersion($Core->getVersion()->getNumber());
return $this; return $this;
} }
@@ -508,7 +496,7 @@ abstract class base implements cache_cacheableInterface
foreach ($default->data as $data) { foreach ($default->data as $data) {
$k = trim($data['key']); $k = trim($data['key']);
if ($k === 'usr_password') if ($k === 'usr_password')
$data = User_Adapter::salt_password($data, $nonce); $data = User_Adapter::salt_password($this->app, $data, $nonce);
if ($k === 'nonce') if ($k === 'nonce')
$data = $nonce; $data = $nonce;
$v = trim(str_replace(array("\r\n", "\r", "\n", "\t"), '', $data)); $v = trim(str_replace(array("\r\n", "\r", "\n", "\t"), '', $data));
@@ -563,7 +551,7 @@ abstract class base implements cache_cacheableInterface
$correct_table = array('fields' => array(), 'indexes' => array(), 'collation' => array()); $correct_table = array('fields' => array(), 'indexes' => array(), 'collation' => array());
$alter = $alter_pre = $return = array(); $alter = $alter_pre = $return = array();
$registry = registry::get_instance(); $registry = $this->app['phraseanet.registry'];
foreach ($table->fields->field as $field) { foreach ($table->fields->field as $field) {
$expr = trim((string) $field->type); $expr = trim((string) $field->type);
@@ -786,7 +774,7 @@ abstract class base implements cache_cacheableInterface
return $return; return $return;
} }
protected function apply_patches($from, $to, $post_process, Setup_Upgrade &$upgrader) protected function apply_patches($from, $to, $post_process, Setup_Upgrade &$upgrader, Application $app)
{ {
if (version_compare($from, $to, '=')) { if (version_compare($from, $to, '=')) {
return true; return true;
@@ -794,7 +782,7 @@ abstract class base implements cache_cacheableInterface
$list_patches = array(); $list_patches = array();
$registry = registry::get_instance(); $registry = $this->app['phraseanet.registry'];
$upgrader->add_steps(1)->set_current_message(_('Looking for patches')); $upgrader->add_steps(1)->set_current_message(_('Looking for patches'));
@@ -837,7 +825,7 @@ abstract class base implements cache_cacheableInterface
$success = true; $success = true;
foreach ($list_patches as $patch) { foreach ($list_patches as $patch) {
if ( ! $patch->apply($this)) if ( ! $patch->apply($this, $app))
$success = false; $success = false;
$upgrader->add_steps_complete(1); $upgrader->add_steps_complete(1);
} }

View File

@@ -8,10 +8,9 @@
* For the full copyright and license information, please view the LICENSE * For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
require_once __DIR__ . '/../Alchemy/Phrasea/Core.php';
use Alchemy\Phrasea\Core; use Alchemy\Phrasea\Loader\Autoloader;
use Symfony\Component\HttpFoundation\Request; use Alchemy\Phrasea\Loader\CacheAutoloader;
/** /**
* *
@@ -20,53 +19,62 @@ use Symfony\Component\HttpFoundation\Request;
*/ */
class bootstrap class bootstrap
{ {
protected static $core; protected static $autoloader_initialized;
public static function set_php_configuration() public static function register_autoloads($cacheAutoload = false)
{ {
return Core::initPHPConf(); if (static::$autoloader_initialized) {
} return;
/**
*
* @param $env
* @return Alchemy\Phrasea\Core
*/
public static function execute($env = null)
{
if (static::$core) {
return static::$core;
} }
static::$core = new Core($env); require_once __DIR__ . '/../Alchemy/Phrasea/Loader/Autoloader.php';
require_once __DIR__ . '/../Alchemy/Phrasea/Loader/Autoloader.php';
$request = Request::createFromGlobals(); if ($cacheAutoload === true) {
try {
require_once __DIR__ . '/../Alchemy/Phrasea/Loader/CacheAutoloader.php';
if ( ! ! stripos($request->server->get('HTTP_USER_AGENT'), 'flash') && $request->getRequestUri() === '/prod/upload/') { $prefix = 'class_';
if (null !== $sessionId = $request->get('php_session_id')) { $namespace = md5(__DIR__);
session_id($sessionId);
$loader = new CacheAutoloader($prefix, $namespace);
} catch (\Exception $e) {
//no op code cache available
$loader = new Autoloader();
}
} else {
$loader = new Autoloader();
}
$getComposerNamespaces = function() {
return require realpath(__DIR__ . '/../../vendor/composer/autoload_namespaces.php');
};
foreach ($getComposerNamespaces() as $prefix => $path) {
if (substr($prefix, -1) === '_' || $prefix == 'Pimple') {
$loader->registerPrefix($prefix, $path);
} else {
$loader->registerNamespace($prefix, $path);
} }
} }
if (\setup::is_installed()) { $loader->registerNamespaces(array(
$gatekeeper = \gatekeeper::getInstance(static::$core); 'Entities' => realpath(__DIR__ . '/../Doctrine/'),
$gatekeeper->check_directory($request); 'Repositories' => realpath(__DIR__ . '/../Doctrine/'),
} 'Proxies' => realpath(__DIR__ . '/../Doctrine/'),
'Doctrine\\Logger' => realpath(__DIR__ . '/../'),
'Types' => realpath(__DIR__ . "/../Doctrine"),
'PhraseaFixture' => realpath(__DIR__ . "/../conf.d"),
));
return static::$core; $loader->register();
}
/** set_include_path(
* get_include_path() . PATH_SEPARATOR . realpath(__DIR__ . '/../../vendor/zend/gdata/library')
* @return Alchemy\Phrasea\Core );
*/
public static function getCore()
{
return static::$core;
}
public static function register_autoloads() static::$autoloader_initialized = true;
{
return Core::initAutoloads(); return;
} }
} }

View File

@@ -9,6 +9,9 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Core\Version;
use Alchemy\Phrasea\Core\Configuration;
use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Filesystem;
class databox extends base class databox extends base
@@ -94,19 +97,18 @@ class databox extends base
protected $cache; protected $cache;
protected $connection; protected $connection;
protected $registry; protected $app;
public function __construct($sbas_id) public function __construct(Application $app, $sbas_id)
{ {
assert(is_int($sbas_id)); assert(is_int($sbas_id));
assert($sbas_id > 0); assert($sbas_id > 0);
$this->registry = registry::get_instance(); $this->app = $app;
$this->connection = connection::getPDOConnection($sbas_id); $this->connection = connection::getPDOConnection($app, $sbas_id, null);
$this->Core = \bootstrap::getCore();
$this->id = $sbas_id; $this->id = $sbas_id;
$connection_params = phrasea::sbas_params(); $connection_params = phrasea::sbas_params($this->app);
if ( ! isset($connection_params[$sbas_id])) { if ( ! isset($connection_params[$sbas_id])) {
throw new Exception_DataboxNotFound(sprintf('databox %d not found', $sbas_id)); throw new Exception_DataboxNotFound(sprintf('databox %d not found', $sbas_id));
@@ -121,13 +123,18 @@ class databox extends base
return $this; return $this;
} }
public function get_appbox()
{
return $this->app['phraseanet.appbox'];
}
public function get_collections() public function get_collections()
{ {
$ret = array(); $ret = array();
foreach ($this->get_available_collections() as $coll_id) { foreach ($this->get_available_collections() as $coll_id) {
try { try {
$ret[] = collection::get_from_coll_id($this, $coll_id); $ret[] = collection::get_from_coll_id($this->app, $this, $coll_id);
} catch (Exception $e) { } catch (Exception $e) {
} }
@@ -144,7 +151,7 @@ class databox extends base
} }
$conn = connection::getPDOConnection(); $conn = connection::getPDOConnection($this->app);
$sql = "SELECT b.server_coll_id FROM sbas s, bas b $sql = "SELECT b.server_coll_id FROM sbas s, bas b
WHERE s.sbas_id = b.sbas_id AND b.sbas_id = :sbas_id WHERE s.sbas_id = b.sbas_id AND b.sbas_id = :sbas_id
@@ -173,12 +180,12 @@ class databox extends base
*/ */
public function get_record($record_id, $number = null) public function get_record($record_id, $number = null)
{ {
return new record_adapter($this->get_sbas_id(), $record_id, $number); return new record_adapter($this->app, $this->get_sbas_id(), $record_id, $number);
} }
public function get_viewname() public function get_viewname()
{ {
return phrasea::sbas_names($this->get_sbas_id()); return phrasea::sbas_names($this->get_sbas_id(), $this->app);
} }
/** /**
@@ -187,7 +194,7 @@ class databox extends base
*/ */
public function get_statusbits() public function get_statusbits()
{ {
return databox_status::getStatus($this->get_sbas_id()); return databox_status::getStatus($this->app, $this->get_sbas_id());
} }
/** /**
@@ -320,10 +327,10 @@ class databox extends base
public function unmount_databox(appbox $appbox) public function unmount_databox(appbox $appbox)
{ {
foreach ($this->get_collections() as $collection) { foreach ($this->get_collections() as $collection) {
$collection->unmount_collection($appbox); $collection->unmount_collection($this->app);
} }
$query = new User_Query($appbox); $query = new User_Query($this->app);
$total = $query->on_sbas_ids(array($this->get_sbas_id())) $total = $query->on_sbas_ids(array($this->get_sbas_id()))
->include_phantoms(false) ->include_phantoms(false)
->include_special_users(true) ->include_special_users(true)
@@ -368,7 +375,7 @@ class databox extends base
return; return;
} }
public static function create(appbox &$appbox, connection_pdo &$connection, \SplFileInfo $data_template, registryInterface $registry) public static function create(Application $app, connection_pdo &$connection, \SplFileInfo $data_template, registryInterface $registry)
{ {
if ( ! file_exists($data_template->getRealPath())) { if ( ! file_exists($data_template->getRealPath())) {
throw new \InvalidArgumentException($data_template->getRealPath() . " does not exist"); throw new \InvalidArgumentException($data_template->getRealPath() . " does not exist");
@@ -395,13 +402,13 @@ class databox extends base
, ':password' => $password , ':password' => $password
); );
$stmt = $appbox->get_connection()->prepare($sql); $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params); $stmt->execute($params);
$row = $stmt->fetch(PDO::FETCH_ASSOC); $row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
if ($row) { if ($row) {
return $appbox->get_databox((int) $row['sbas_id']); return $app['phraseanet.appbox']->get_databox((int) $row['sbas_id']);
} }
try { try {
@@ -420,7 +427,7 @@ class databox extends base
$stmt->closeCursor(); $stmt->closeCursor();
$sql = 'SELECT MAX(ord) as ord FROM sbas'; $sql = 'SELECT MAX(ord) as ord FROM sbas';
$stmt = $appbox->get_connection()->prepare($sql); $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute(); $stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC); $row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor(); $stmt->closeCursor();
@@ -429,7 +436,7 @@ class databox extends base
$sql = 'INSERT INTO sbas (sbas_id, ord, host, port, dbname, sqlengine, user, pwd) $sql = 'INSERT INTO sbas (sbas_id, ord, host, port, dbname, sqlengine, user, pwd)
VALUES (null, :ord, :host, :port, :dbname, "MYSQL", :user, :password)'; VALUES (null, :ord, :host, :port, :dbname, "MYSQL", :user, :password)';
$stmt = $appbox->get_connection()->prepare($sql); $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute(array( $stmt->execute(array(
':ord' => $ord ':ord' => $ord
, ':host' => $host , ':host' => $host
@@ -439,12 +446,12 @@ class databox extends base
, ':password' => $password , ':password' => $password
)); ));
$stmt->closeCursor(); $stmt->closeCursor();
$sbas_id = (int) $appbox->get_connection()->lastInsertId(); $sbas_id = (int) $app['phraseanet.appbox']->get_connection()->lastInsertId();
$appbox->delete_data_from_cache(appbox::CACHE_LIST_BASES); $app['phraseanet.appbox']->delete_data_from_cache(appbox::CACHE_LIST_BASES);
$databox = $appbox->get_databox($sbas_id); $databox = $app['phraseanet.appbox']->get_databox($sbas_id);
$databox->insert_datas(); $databox->insert_datas($app['phraseanet.version']);
$databox->setNewStructure( $databox->setNewStructure(
$data_template, $registry->get('GV_base_datapath_noweb') $data_template, $registry->get('GV_base_datapath_noweb')
); );
@@ -462,11 +469,11 @@ class databox extends base
* @param registry $registry * @param registry $registry
* @return databox * @return databox
*/ */
public static function mount(appbox $appbox, $host, $port, $user, $password, $dbname, registry $registry) public static function mount(Application $app, $host, $port, $user, $password, $dbname, registry $registry)
{ {
$connection = new connection_pdo('test', $host, $port, $user, $password, $dbname, array(), $registry); $connection = new connection_pdo('test', $host, $port, $user, $password, $dbname, array(), $registry);
$conn = $appbox->get_connection(); $conn = $app['phraseanet.appbox']->get_connection();
$sql = 'SELECT MAX(ord) as ord FROM sbas'; $sql = 'SELECT MAX(ord) as ord FROM sbas';
$stmt = $conn->prepare($sql); $stmt = $conn->prepare($sql);
$stmt->execute(); $stmt->execute();
@@ -490,16 +497,16 @@ class databox extends base
$stmt->closeCursor(); $stmt->closeCursor();
$sbas_id = (int) $conn->lastInsertId(); $sbas_id = (int) $conn->lastInsertId();
$appbox->delete_data_from_cache(appbox::CACHE_LIST_BASES); $app['phraseanet.appbox']->delete_data_from_cache(appbox::CACHE_LIST_BASES);
$databox = $appbox->get_databox($sbas_id); $databox = $app['phraseanet.appbox']->get_databox($sbas_id);
$databox->delete_data_from_cache(databox::CACHE_COLLECTIONS); $databox->delete_data_from_cache(databox::CACHE_COLLECTIONS);
$appbox->delete_data_from_cache(appbox::CACHE_SBAS_IDS); $app['phraseanet.appbox']->delete_data_from_cache(appbox::CACHE_SBAS_IDS);
phrasea::reset_sbasDatas(); phrasea::reset_sbasDatas($app['phraseanet.appbox']);
cache_databox::update($databox->get_sbas_id(), 'structure'); cache_databox::update($app, $databox->get_sbas_id(), 'structure');
return $databox; return $databox;
} }
@@ -541,7 +548,7 @@ class databox extends base
$stmt->closeCursor(); $stmt->closeCursor();
foreach ($rs as $row) { foreach ($rs as $row) {
$meta_struct->add_element(databox_field::get_instance($this, $row['id'])); $meta_struct->add_element(databox_field::get_instance($this->app, $this, $row['id']));
} }
$this->meta_struct = $meta_struct; $this->meta_struct = $meta_struct;
$this->set_data_to_cache($this->meta_struct, self::CACHE_META_STRUCT); $this->set_data_to_cache($this->meta_struct, self::CACHE_META_STRUCT);
@@ -590,14 +597,12 @@ class databox extends base
public function delete() public function delete()
{ {
$appbox = appbox::get_instance(\bootstrap::getCore());
$sql = 'DROP DATABASE `' . $this->get_dbname() . '`'; $sql = 'DROP DATABASE `' . $this->get_dbname() . '`';
$stmt = $this->get_connection()->prepare($sql); $stmt = $this->get_connection()->prepare($sql);
$stmt->execute(); $stmt->execute();
$stmt->closeCursor(); $stmt->closeCursor();
$appbox->delete_data_from_cache(appbox::CACHE_LIST_BASES); $this->app['phraseanet.appbox']->delete_data_from_cache(appbox::CACHE_LIST_BASES);
return; return;
} }
@@ -643,7 +648,7 @@ class databox extends base
*/ */
public function get_mountable_colls() public function get_mountable_colls()
{ {
$conn = connection::getPDOConnection(); $conn = connection::getPDOConnection($this->app);
$colls = array(); $colls = array();
$sql = 'SELECT server_coll_id FROM bas WHERE sbas_id = :sbas_id'; $sql = 'SELECT server_coll_id FROM bas WHERE sbas_id = :sbas_id';
@@ -678,7 +683,7 @@ class databox extends base
public function get_activable_colls() public function get_activable_colls()
{ {
$conn = connection::getPDOConnection(); $conn = connection::getPDOConnection($this->app);
$base_ids = array(); $base_ids = array();
$sql = 'SELECT base_id FROM bas WHERE sbas_id = :sbas_id AND active = "0"'; $sql = 'SELECT base_id FROM bas WHERE sbas_id = :sbas_id AND active = "0"';
@@ -726,12 +731,11 @@ class databox extends base
$this->meta_struct = null; $this->meta_struct = null;
$appbox = appbox::get_instance(\bootstrap::getCore()); $this->app['phraseanet.appbox']->delete_data_from_cache(appbox::CACHE_LIST_BASES);
$appbox->delete_data_from_cache(appbox::CACHE_LIST_BASES);
$this->delete_data_from_cache(self::CACHE_STRUCTURE); $this->delete_data_from_cache(self::CACHE_STRUCTURE);
$this->delete_data_from_cache(self::CACHE_META_STRUCT); $this->delete_data_from_cache(self::CACHE_META_STRUCT);
cache_databox::update($this->get_sbas_id(), 'structure'); cache_databox::update($this->app, $this->get_sbas_id(), 'structure');
return $this; return $this;
} }
@@ -828,7 +832,7 @@ class databox extends base
$multi = isset($field['multi']) ? (Boolean) $field['multi'] : false; $multi = isset($field['multi']) ? (Boolean) $field['multi'] : false;
$meta_struct_field = databox_field::create($this, $fname, $multi); $meta_struct_field = databox_field::create($this->app, $this, $fname, $multi);
$meta_struct_field $meta_struct_field
->set_readonly(isset($field['readonly']) ? $field['readonly'] : 0) ->set_readonly(isset($field['readonly']) ? $field['readonly'] : 0)
->set_indexable(isset($field['index']) ? $field['index'] : '1') ->set_indexable(isset($field['index']) ? $field['index'] : '1')
@@ -858,8 +862,7 @@ class databox extends base
*/ */
public function registerAdmin(User_Interface $user) public function registerAdmin(User_Interface $user)
{ {
$conn = connection::getPDOConnection(); $conn = connection::getPDOConnection($this->app);
$registry = registry::get_instance();
$user->ACL() $user->ACL()
->give_access_to_sbas(array($this->get_sbas_id())) ->give_access_to_sbas(array($this->get_sbas_id()))
@@ -888,7 +891,7 @@ class databox extends base
$base_ids[] = $base_id = $conn->lastInsertId(); $base_ids[] = $base_id = $conn->lastInsertId();
if ( ! empty($row['logo'])) { if ( ! empty($row['logo'])) {
file_put_contents($registry->get('GV_RootPath') . 'config/minilogos/' . $base_id, $row['logo']); file_put_contents($this->app['phraseanet.registry']->get('GV_RootPath') . 'config/minilogos/' . $base_id, $row['logo']);
} }
} catch (Exception $e) { } catch (Exception $e) {
unset($e); unset($e);
@@ -919,10 +922,8 @@ class databox extends base
*/ */
public static function getPrintLogo($sbas_id) public static function getPrintLogo($sbas_id)
{ {
$registry = registry::get_instance();
$out = ''; $out = '';
if (is_file(($filename = $registry->get('GV_RootPath') . 'config/minilogos/'.\databox::PIC_PDF.'_' . $sbas_id . '.jpg'))) if (is_file(($filename = __DIR__ . '/../../config/minilogos/'.\databox::PIC_PDF.'_' . $sbas_id . '.jpg')))
$out = file_get_contents($filename); $out = file_get_contents($filename);
return $out; return $out;
@@ -1289,7 +1290,7 @@ class databox extends base
$missing_locale[] = $k; $missing_locale[] = $k;
$date_obj = new DateTime(); $date_obj = new DateTime();
$date = phraseadate::format_mysql($date_obj); $date = $this->app['date-formatter']->format_mysql($date_obj);
$sql = "INSERT INTO pref (id, prop, value, locale, updated_on, created_on) $sql = "INSERT INTO pref (id, prop, value, locale, updated_on, created_on)
VALUES (null, 'ToU', '', :locale, :date, NOW())"; VALUES (null, 'ToU', '', :locale, :date, NOW())";
$stmt = $this->get_connection()->prepare($sql); $stmt = $this->get_connection()->prepare($sql);