mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-16 14:33:14 +00:00
WIP with cache
This commit is contained in:
@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Command\Developer;
|
|||||||
|
|
||||||
use Alchemy\Phrasea\Border\Manager;
|
use Alchemy\Phrasea\Border\Manager;
|
||||||
use Alchemy\Phrasea\Command\Command;
|
use Alchemy\Phrasea\Command\Command;
|
||||||
|
use Alchemy\Phrasea\Media\SubdefSubstituer;
|
||||||
use Alchemy\Phrasea\Model\Entities\ApiApplication;
|
use Alchemy\Phrasea\Model\Entities\ApiApplication;
|
||||||
use Alchemy\Phrasea\Model\Entities\AuthFailure;
|
use Alchemy\Phrasea\Model\Entities\AuthFailure;
|
||||||
use Alchemy\Phrasea\Model\Entities\AggregateToken;
|
use Alchemy\Phrasea\Model\Entities\AggregateToken;
|
||||||
@@ -280,7 +281,9 @@ class RegenerateSqliteDb extends Command
|
|||||||
$DI['lazaret_1'] = $element;
|
$DI['lazaret_1'] = $element;
|
||||||
};
|
};
|
||||||
|
|
||||||
$this->container['border-manager']->process($session, $file, $callback, Manager::FORCE_LAZARET);
|
/** @var Manager $borderManager */
|
||||||
|
$borderManager = $this->container['border-manager'];
|
||||||
|
$borderManager->process($session, $file, $callback, Manager::FORCE_LAZARET);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function generateUsers(EntityManager $em, \Pimple $DI)
|
private function generateUsers(EntityManager $em, \Pimple $DI)
|
||||||
@@ -368,7 +371,8 @@ class RegenerateSqliteDb extends Command
|
|||||||
|
|
||||||
private function generateCollection(\Pimple $DI)
|
private function generateCollection(\Pimple $DI)
|
||||||
{
|
{
|
||||||
$coll = $collection_no_acces = $collection_no_acces_by_status = $db = null;
|
$coll = $collection_no_acces = $collection_no_acces_by_status = null;
|
||||||
|
/** @var \databox[] $databoxes */
|
||||||
$databoxes = $this->container['phraseanet.appbox']->get_databoxes();
|
$databoxes = $this->container['phraseanet.appbox']->get_databoxes();
|
||||||
|
|
||||||
foreach ($databoxes as $databox) {
|
foreach ($databoxes as $databox) {
|
||||||
@@ -390,16 +394,15 @@ class RegenerateSqliteDb extends Command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$DI['databox'] = $coll->get_databox();
|
$DI['databox'] = $databox = $coll->get_databox();
|
||||||
$DI['coll'] = $coll;
|
$DI['coll'] = $coll;
|
||||||
|
if (!$collection_no_acces instanceof \collection) {
|
||||||
if (!$collection_no_acces instanceof collection) {
|
|
||||||
$collection_no_acces = \collection::create($this->container, $databox, $this->container['phraseanet.appbox'], 'COLL_TEST_NO_ACCESS', $DI['user']);
|
$collection_no_acces = \collection::create($this->container, $databox, $this->container['phraseanet.appbox'], 'COLL_TEST_NO_ACCESS', $DI['user']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$DI['coll_no_access'] = $collection_no_acces;
|
$DI['coll_no_access'] = $collection_no_acces;
|
||||||
|
|
||||||
if (!$collection_no_acces_by_status instanceof collection) {
|
if (!$collection_no_acces_by_status instanceof \collection) {
|
||||||
$collection_no_acces_by_status = \collection::create($this->container, $databox, $this->container['phraseanet.appbox'], 'COLL_TEST_NO_ACCESS_BY_STATUS', $DI['user']);
|
$collection_no_acces_by_status = \collection::create($this->container, $databox, $this->container['phraseanet.appbox'], 'COLL_TEST_NO_ACCESS_BY_STATUS', $DI['user']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -420,8 +423,10 @@ class RegenerateSqliteDb extends Command
|
|||||||
foreach (range(1, 3) as $i) {
|
foreach (range(1, 3) as $i) {
|
||||||
$story = \record_adapter::createStory($this->container, $DI['coll']);
|
$story = \record_adapter::createStory($this->container, $DI['coll']);
|
||||||
if ($i < 3) {
|
if ($i < 3) {
|
||||||
$this->container['subdef.substituer']->substitute($story, 'preview', $media);
|
/** @var SubdefSubstituer $substituer */
|
||||||
$this->container['subdef.substituer']->substitute($story, 'thumbnail', $media);
|
$substituer = $this->container['subdef.substituer'];
|
||||||
|
$substituer->substitute($story, 'preview', $media);
|
||||||
|
$substituer->substitute($story, 'thumbnail', $media);
|
||||||
}
|
}
|
||||||
$DI['record_story_' . $i] = $story;
|
$DI['record_story_' . $i] = $story;
|
||||||
}
|
}
|
||||||
|
@@ -14,6 +14,10 @@ class Structure
|
|||||||
private $facets = array();
|
private $facets = array();
|
||||||
private $aliases = array();
|
private $aliases = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \databox[] $databoxes
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
public static function createFromDataboxes(array $databoxes)
|
public static function createFromDataboxes(array $databoxes)
|
||||||
{
|
{
|
||||||
$structure = new self();
|
$structure = new self();
|
||||||
|
@@ -822,8 +822,17 @@ class ACL implements cache_cacheableInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->_global_rights = $this->get_data_from_cache(self::CACHE_GLOBAL_RIGHTS);
|
$global_rights = $this->get_data_from_cache(self::CACHE_GLOBAL_RIGHTS);
|
||||||
$this->_rights_sbas = $this->get_data_from_cache(self::CACHE_RIGHTS_SBAS);
|
if (!is_array($global_rights)) {
|
||||||
|
throw new Exception('global rights were not properly retrieved');
|
||||||
|
}
|
||||||
|
$sbas_rights = $this->get_data_from_cache(self::CACHE_RIGHTS_SBAS);
|
||||||
|
if (!is_array($sbas_rights)) {
|
||||||
|
throw new Exception('sbas rights were not properly retrieved');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->_global_rights = $global_rights;
|
||||||
|
$this->_rights_sbas = $sbas_rights;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@@ -880,9 +889,21 @@ class ACL implements cache_cacheableInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->_global_rights = $this->get_data_from_cache(self::CACHE_GLOBAL_RIGHTS);
|
$data = $this->get_data_from_cache(self::CACHE_GLOBAL_RIGHTS);
|
||||||
$this->_rights_bas = $this->get_data_from_cache(self::CACHE_RIGHTS_BAS);
|
if (!is_array($data)) {
|
||||||
$this->_limited = $this->get_data_from_cache(self::CACHE_LIMITS_BAS);
|
throw new Exception('Unable to retrieve global rights');
|
||||||
|
}
|
||||||
|
$this->_global_rights = $data;
|
||||||
|
$data = $this->get_data_from_cache(self::CACHE_RIGHTS_BAS);
|
||||||
|
if (!is_array($data)) {
|
||||||
|
throw new Exception('Unable to retrieve base rights');
|
||||||
|
}
|
||||||
|
$this->_rights_bas = $data;
|
||||||
|
$data = $this->get_data_from_cache(self::CACHE_LIMITS_BAS);
|
||||||
|
if (!is_array($data)) {
|
||||||
|
throw new Exception('Unable to retrieve limits rights');
|
||||||
|
}
|
||||||
|
$this->_limited = $data;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
@@ -371,7 +371,7 @@ class appbox extends base
|
|||||||
}
|
}
|
||||||
$ret[$sbas_id] = $databox;
|
$ret[$sbas_id] = $databox;
|
||||||
} catch (NotFoundHttpException $e) {
|
} catch (NotFoundHttpException $e) {
|
||||||
$this->app['monolog']->error(sprintf('Databox %s is not reliable.', $databox->get_sbas_id()));
|
$this->app['monolog']->error(sprintf('Databox %s is not reliable.', $sbas_id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -383,7 +383,10 @@ class appbox extends base
|
|||||||
protected function retrieve_sbas_ids()
|
protected function retrieve_sbas_ids()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return $this->get_data_from_cache(self::CACHE_SBAS_IDS);
|
$data = $this->get_data_from_cache(self::CACHE_SBAS_IDS);
|
||||||
|
if (is_array($data)) {
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -64,6 +64,9 @@ class collection implements cache_cacheableInterface
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$datas = $this->get_data_from_cache();
|
$datas = $this->get_data_from_cache();
|
||||||
|
if (!is_array($datas)) {
|
||||||
|
throw new \Exception('Collection could not be retrieved from cache');
|
||||||
|
}
|
||||||
$this->is_active = $datas['is_active'];
|
$this->is_active = $datas['is_active'];
|
||||||
$this->base_id = $datas['base_id'];
|
$this->base_id = $datas['base_id'];
|
||||||
$this->available = $datas['available'];
|
$this->available = $datas['available'];
|
||||||
|
@@ -230,7 +230,10 @@ class databox extends base
|
|||||||
protected function get_available_collections()
|
protected function get_available_collections()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return $this->get_data_from_cache(self::CACHE_COLLECTIONS);
|
$data = $this->get_data_from_cache(self::CACHE_COLLECTIONS);
|
||||||
|
if (is_array($data)) {
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -551,13 +554,15 @@ class databox extends base
|
|||||||
, ':password' => $password
|
, ':password' => $password
|
||||||
];
|
];
|
||||||
|
|
||||||
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
|
/** @var appbox $appbox */
|
||||||
|
$appbox = $app['phraseanet.appbox'];
|
||||||
|
$stmt = $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 $app['phraseanet.appbox']->get_databox((int) $row['sbas_id']);
|
return $appbox->get_databox((int) $row['sbas_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -576,7 +581,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 = $app['phraseanet.appbox']->get_connection()->prepare($sql);
|
$stmt = $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();
|
||||||
@@ -588,10 +593,10 @@ 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 = $app['phraseanet.appbox']->get_connection()->prepare($sql);
|
$stmt = $appbox->get_connection()->prepare($sql);
|
||||||
$stmt->execute($params);
|
$stmt->execute($params);
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
$sbas_id = (int) $app['phraseanet.appbox']->get_connection()->lastInsertId();
|
$sbas_id = (int) $appbox->get_connection()->lastInsertId();
|
||||||
|
|
||||||
$app['orm.add']([
|
$app['orm.add']([
|
||||||
'host' => $host,
|
'host' => $host,
|
||||||
@@ -601,9 +606,9 @@ class databox extends base
|
|||||||
'password' => $password
|
'password' => $password
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$app['phraseanet.appbox']->delete_data_from_cache(appbox::CACHE_LIST_BASES);
|
$appbox->delete_data_from_cache(appbox::CACHE_LIST_BASES);
|
||||||
|
|
||||||
$databox = $app['phraseanet.appbox']->get_databox($sbas_id);
|
$databox = $appbox->get_databox($sbas_id);
|
||||||
$databox->insert_datas();
|
$databox->insert_datas();
|
||||||
|
|
||||||
$databox->setNewStructure(
|
$databox->setNewStructure(
|
||||||
@@ -688,15 +693,18 @@ class databox extends base
|
|||||||
*/
|
*/
|
||||||
public function get_meta_structure()
|
public function get_meta_structure()
|
||||||
{
|
{
|
||||||
$metaStructData = array();
|
|
||||||
|
|
||||||
if ($this->meta_struct) {
|
if ($this->meta_struct) {
|
||||||
return $this->meta_struct;
|
return $this->meta_struct;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$metaStructData = $this->get_data_from_cache(self::CACHE_META_STRUCT);
|
$metaStructData = $this->get_data_from_cache(self::CACHE_META_STRUCT);
|
||||||
|
if (!is_array($metaStructData)) {
|
||||||
|
throw new Exception('Invalid metaStructData');
|
||||||
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
$metaStructData = array();
|
||||||
|
|
||||||
$sql = 'SELECT id, `name` FROM metadatas_structure ORDER BY sorter ASC';
|
$sql = 'SELECT id, `name` FROM metadatas_structure ORDER BY sorter ASC';
|
||||||
$stmt = $this->get_connection()->prepare($sql);
|
$stmt = $this->get_connection()->prepare($sql);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
@@ -711,7 +719,7 @@ class databox extends base
|
|||||||
|
|
||||||
$this->meta_struct = new databox_descriptionStructure();
|
$this->meta_struct = new databox_descriptionStructure();
|
||||||
|
|
||||||
foreach ((array) $metaStructData as $row) {
|
foreach ($metaStructData as $row) {
|
||||||
$this->meta_struct->add_element(databox_field::get_instance($this->app, $this, $row['id']));
|
$this->meta_struct->add_element(databox_field::get_instance($this->app, $this, $row['id']));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1219,7 +1227,10 @@ class databox extends base
|
|||||||
protected function retrieve_structure()
|
protected function retrieve_structure()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return $this->get_data_from_cache(self::CACHE_STRUCTURE);
|
$data = $this->get_data_from_cache(self::CACHE_STRUCTURE);
|
||||||
|
if (is_array($data)) {
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -79,7 +79,7 @@ class databox_subdefsStructure implements IteratorAggregate, Countable
|
|||||||
{
|
{
|
||||||
$sx_struct = $this->databox->get_sxml_structure();
|
$sx_struct = $this->databox->get_sxml_structure();
|
||||||
|
|
||||||
$this->AvSubdefs = [
|
$avSubdefs = [
|
||||||
'image' => [],
|
'image' => [],
|
||||||
'video' => [],
|
'video' => [],
|
||||||
'audio' => [],
|
'audio' => [],
|
||||||
@@ -96,13 +96,14 @@ class databox_subdefsStructure implements IteratorAggregate, Countable
|
|||||||
foreach ($subdefgroup as $k => $subdefs) {
|
foreach ($subdefgroup as $k => $subdefs) {
|
||||||
$subdefgroup_name = strtolower($subdefs->attributes()->name);
|
$subdefgroup_name = strtolower($subdefs->attributes()->name);
|
||||||
|
|
||||||
if ( ! isset($AvSubdefs[$subdefgroup_name])) {
|
if ( ! isset($avSubdefs[$subdefgroup_name])) {
|
||||||
$AvSubdefs[$subdefgroup_name] = [];
|
$avSubdefs[$subdefgroup_name] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($subdefs as $sd) {
|
foreach ($subdefs as $sd) {
|
||||||
$subdef_name = strtolower($sd->attributes()->name);
|
$subdef_name = strtolower($sd->attributes()->name);
|
||||||
|
|
||||||
|
$type = null;
|
||||||
switch ($subdefgroup_name) {
|
switch ($subdefgroup_name) {
|
||||||
case 'audio':
|
case 'audio':
|
||||||
$type = new \Alchemy\Phrasea\Media\Type\Audio();
|
$type = new \Alchemy\Phrasea\Media\Type\Audio();
|
||||||
@@ -121,13 +122,12 @@ class databox_subdefsStructure implements IteratorAggregate, Countable
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
continue;
|
continue;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$AvSubdefs[$subdefgroup_name][$subdef_name] = new databox_subdef($type, $sd, $this->translator);
|
$avSubdefs[$subdefgroup_name][$subdef_name] = new databox_subdef($type, $sd, $this->translator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->AvSubdefs = $AvSubdefs;
|
$this->AvSubdefs = $avSubdefs;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@@ -160,6 +160,9 @@ class media_subdef extends media_abstract implements cache_cacheableInterface
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$datas = $this->get_data_from_cache();
|
$datas = $this->get_data_from_cache();
|
||||||
|
if (!is_array($datas)) {
|
||||||
|
throw new \Exception('Could not retrieve data');
|
||||||
|
}
|
||||||
$this->mime = $datas['mime'];
|
$this->mime = $datas['mime'];
|
||||||
$this->width = $datas['width'];
|
$this->width = $datas['width'];
|
||||||
$this->height = $datas['height'];
|
$this->height = $datas['height'];
|
||||||
|
@@ -46,9 +46,12 @@ class phrasea
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
self::$_sbas_params = $app['phraseanet.appbox']->get_data_from_cache(self::CACHE_SBAS_PARAMS);
|
$params = $app['phraseanet.appbox']->get_data_from_cache(self::CACHE_SBAS_PARAMS);
|
||||||
|
if (is_array($params)) {
|
||||||
|
self::$_sbas_params = $params;
|
||||||
|
|
||||||
return self::$_sbas_params;
|
return $params;
|
||||||
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -93,6 +93,10 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
|||||||
try {
|
try {
|
||||||
$datas = $this->get_data_from_cache();
|
$datas = $this->get_data_from_cache();
|
||||||
|
|
||||||
|
if (!is_array($datas)) {
|
||||||
|
throw new Exception('Could not retrieve record data');
|
||||||
|
}
|
||||||
|
|
||||||
$this->mime = $datas['mime'];
|
$this->mime = $datas['mime'];
|
||||||
$this->sha256 = $datas['sha256'];
|
$this->sha256 = $datas['sha256'];
|
||||||
$this->original_name = $datas['original_name'];
|
$this->original_name = $datas['original_name'];
|
||||||
@@ -105,7 +109,6 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$connbas = $this->databox->get_connection();
|
$connbas = $this->databox->get_connection();
|
||||||
@@ -586,7 +589,10 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
|||||||
protected function get_available_subdefs()
|
protected function get_available_subdefs()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return $this->get_data_from_cache(self::CACHE_SUBDEFS);
|
$data = $this->get_data_from_cache(self::CACHE_SUBDEFS);
|
||||||
|
if (is_array($data)) {
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user