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

View File

@@ -9,6 +9,9 @@
* file that was distributed with this source code.
*/
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Core\Version;
abstract class base implements cache_cacheableInterface
{
protected $version;
@@ -136,19 +139,7 @@ abstract class base implements cache_cacheableInterface
*/
public function get_registry()
{
return $this->registry;
}
/**
*
* @param registryInterface $registry
* @return base
*/
public function set_registry(registryInterface $registry)
{
$this->registry = $registry;
return $this;
return $this->app['phraseanet.registry'];
}
/**
@@ -176,7 +167,7 @@ abstract class base implements cache_cacheableInterface
public function get_cache()
{
if ( ! $this->cache) {
$this->cache = $this->Core->getCache();
$this->cache = $this->app['cache'];
}
return $this->cache;
@@ -191,7 +182,7 @@ abstract class base implements cache_cacheableInterface
{
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));
@@ -204,12 +195,12 @@ abstract class base implements cache_cacheableInterface
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) {
$keys = array($this->get_cache_key(appbox::CACHE_LIST_BASES));
phrasea::reset_sbasDatas();
phrasea::reset_baseDatas();
phrasea::clear_sbas_params();
phrasea::reset_sbasDatas($appbox);
phrasea::reset_baseDatas($appbox);
phrasea::clear_sbas_params($this->app);
$keys[] = $this->get_cache_key(appbox::CACHE_SBAS_IDS);
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();
@@ -280,8 +271,9 @@ abstract class base implements cache_cacheableInterface
$schema = $this->get_schema();
foreach ($schema->tables->table as $table)
foreach ($schema->tables->table as $table) {
$allTables[(string) $table['name']] = $table;
}
$upgrader->add_steps(count($allTables) + 1);
@@ -309,7 +301,6 @@ abstract class base implements cache_cacheableInterface
foreach ($rs as $row) {
$tname = $row["Name"];
if (isset($allTables[$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();
$Core = bootstrap::getCore();
$upgrader->set_current_message(sprintf(_('Applying patches on %s'), $this->get_dbname()));
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);
return $recommends;
}
protected function setVersion($version)
protected function setVersion(Version $version)
{
try {
$sql = '';
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) {
$sql = 'DELETE FROM pref WHERE prop="version" AND locale IS NULL';
$this->get_connection()->query($sql);
@@ -373,15 +362,15 @@ abstract class base implements cache_cacheableInterface
}
if ($sql !== '') {
$stmt = $this->get_connection()->prepare($sql);
$stmt->execute(array(':version' => $version));
$stmt->execute(array(':version' => $version->getNumber()));
$stmt->closeCursor();
$this->version = $version;
$this->version = $version->getNumber();
return true;
}
} catch (Exception $e) {
throw new Exception('Unable to set the database version');
throw new Exception('Unable to set the database version : '.$e->getMessage());
}
return;
@@ -416,7 +405,7 @@ abstract class base implements cache_cacheableInterface
*
* @return base
*/
protected function insert_datas()
protected function insert_datas(Version $version)
{
$this->load_schema();
@@ -424,8 +413,7 @@ abstract class base implements cache_cacheableInterface
$this->createTable($table);
}
$Core = bootstrap::getCore();
$this->setVersion($Core->getVersion()->getNumber());
$this->setVersion($version);
return $this;
}
@@ -508,7 +496,7 @@ abstract class base implements cache_cacheableInterface
foreach ($default->data as $data) {
$k = trim($data['key']);
if ($k === 'usr_password')
$data = User_Adapter::salt_password($data, $nonce);
$data = User_Adapter::salt_password($this->app, $data, $nonce);
if ($k === 'nonce')
$data = $nonce;
$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());
$alter = $alter_pre = $return = array();
$registry = registry::get_instance();
$registry = $this->app['phraseanet.registry'];
foreach ($table->fields->field as $field) {
$expr = trim((string) $field->type);
@@ -786,7 +774,7 @@ abstract class base implements cache_cacheableInterface
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, '=')) {
return true;
@@ -794,7 +782,7 @@ abstract class base implements cache_cacheableInterface
$list_patches = array();
$registry = registry::get_instance();
$registry = $this->app['phraseanet.registry'];
$upgrader->add_steps(1)->set_current_message(_('Looking for patches'));
@@ -837,7 +825,7 @@ abstract class base implements cache_cacheableInterface
$success = true;
foreach ($list_patches as $patch) {
if ( ! $patch->apply($this))
if ( ! $patch->apply($this, $app))
$success = false;
$upgrader->add_steps_complete(1);
}

View File

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

View File

@@ -9,6 +9,9 @@
* 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;
class databox extends base
@@ -94,19 +97,18 @@ class databox extends base
protected $cache;
protected $connection;
protected $registry;
protected $app;
public function __construct($sbas_id)
public function __construct(Application $app, $sbas_id)
{
assert(is_int($sbas_id));
assert($sbas_id > 0);
$this->registry = registry::get_instance();
$this->connection = connection::getPDOConnection($sbas_id);
$this->Core = \bootstrap::getCore();
$this->app = $app;
$this->connection = connection::getPDOConnection($app, $sbas_id, null);
$this->id = $sbas_id;
$connection_params = phrasea::sbas_params();
$connection_params = phrasea::sbas_params($this->app);
if ( ! isset($connection_params[$sbas_id])) {
throw new Exception_DataboxNotFound(sprintf('databox %d not found', $sbas_id));
@@ -121,13 +123,18 @@ class databox extends base
return $this;
}
public function get_appbox()
{
return $this->app['phraseanet.appbox'];
}
public function get_collections()
{
$ret = array();
foreach ($this->get_available_collections() as $coll_id) {
try {
$ret[] = collection::get_from_coll_id($this, $coll_id);
$ret[] = collection::get_from_coll_id($this->app, $this, $coll_id);
} 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
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)
{
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()
{
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()
{
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)
{
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()))
->include_phantoms(false)
->include_special_users(true)
@@ -368,7 +375,7 @@ class databox extends base
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())) {
throw new \InvalidArgumentException($data_template->getRealPath() . " does not exist");
@@ -395,13 +402,13 @@ class databox extends base
, ':password' => $password
);
$stmt = $appbox->get_connection()->prepare($sql);
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute($params);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
if ($row) {
return $appbox->get_databox((int) $row['sbas_id']);
return $app['phraseanet.appbox']->get_databox((int) $row['sbas_id']);
}
try {
@@ -420,7 +427,7 @@ class databox extends base
$stmt->closeCursor();
$sql = 'SELECT MAX(ord) as ord FROM sbas';
$stmt = $appbox->get_connection()->prepare($sql);
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
@@ -429,7 +436,7 @@ class databox extends base
$sql = 'INSERT INTO sbas (sbas_id, ord, host, port, dbname, sqlengine, user, pwd)
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(
':ord' => $ord
, ':host' => $host
@@ -439,12 +446,12 @@ class databox extends base
, ':password' => $password
));
$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->insert_datas();
$databox = $app['phraseanet.appbox']->get_databox($sbas_id);
$databox->insert_datas($app['phraseanet.version']);
$databox->setNewStructure(
$data_template, $registry->get('GV_base_datapath_noweb')
);
@@ -462,11 +469,11 @@ class databox extends base
* @param registry $registry
* @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);
$conn = $appbox->get_connection();
$conn = $app['phraseanet.appbox']->get_connection();
$sql = 'SELECT MAX(ord) as ord FROM sbas';
$stmt = $conn->prepare($sql);
$stmt->execute();
@@ -490,16 +497,16 @@ class databox extends base
$stmt->closeCursor();
$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);
$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;
}
@@ -541,7 +548,7 @@ class databox extends base
$stmt->closeCursor();
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->set_data_to_cache($this->meta_struct, self::CACHE_META_STRUCT);
@@ -590,14 +597,12 @@ class databox extends base
public function delete()
{
$appbox = appbox::get_instance(\bootstrap::getCore());
$sql = 'DROP DATABASE `' . $this->get_dbname() . '`';
$stmt = $this->get_connection()->prepare($sql);
$stmt->execute();
$stmt->closeCursor();
$appbox->delete_data_from_cache(appbox::CACHE_LIST_BASES);
$this->app['phraseanet.appbox']->delete_data_from_cache(appbox::CACHE_LIST_BASES);
return;
}
@@ -643,7 +648,7 @@ class databox extends base
*/
public function get_mountable_colls()
{
$conn = connection::getPDOConnection();
$conn = connection::getPDOConnection($this->app);
$colls = array();
$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()
{
$conn = connection::getPDOConnection();
$conn = connection::getPDOConnection($this->app);
$base_ids = array();
$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;
$appbox = appbox::get_instance(\bootstrap::getCore());
$appbox->delete_data_from_cache(appbox::CACHE_LIST_BASES);
$this->app['phraseanet.appbox']->delete_data_from_cache(appbox::CACHE_LIST_BASES);
$this->delete_data_from_cache(self::CACHE_STRUCTURE);
$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;
}
@@ -828,7 +832,7 @@ class databox extends base
$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
->set_readonly(isset($field['readonly']) ? $field['readonly'] : 0)
->set_indexable(isset($field['index']) ? $field['index'] : '1')
@@ -858,8 +862,7 @@ class databox extends base
*/
public function registerAdmin(User_Interface $user)
{
$conn = connection::getPDOConnection();
$registry = registry::get_instance();
$conn = connection::getPDOConnection($this->app);
$user->ACL()
->give_access_to_sbas(array($this->get_sbas_id()))
@@ -888,7 +891,7 @@ class databox extends base
$base_ids[] = $base_id = $conn->lastInsertId();
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) {
unset($e);
@@ -919,10 +922,8 @@ class databox extends base
*/
public static function getPrintLogo($sbas_id)
{
$registry = registry::get_instance();
$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);
return $out;
@@ -1289,7 +1290,7 @@ class databox extends base
$missing_locale[] = $k;
$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)
VALUES (null, 'ToU', '', :locale, :date, NOW())";
$stmt = $this->get_connection()->prepare($sql);