mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-15 22:13:13 +00:00
Merge branch 'clean-boxes' into merge-clean-boxes
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
*/
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Collection\CollectionRepositoryRegistry;
|
||||
use Alchemy\Phrasea\Core\Connection\ConnectionSettings;
|
||||
use Alchemy\Phrasea\Core\PhraseaTokens;
|
||||
use Alchemy\Phrasea\Core\Thumbnail\ThumbnailedElement;
|
||||
@@ -177,69 +178,35 @@ class databox extends base implements ThumbnailedElement
|
||||
*/
|
||||
public function get_collections()
|
||||
{
|
||||
$ret = [];
|
||||
static $collections;
|
||||
|
||||
foreach ($this->get_available_collections() as $coll_id) {
|
||||
$ret[] = collection::get_from_coll_id($this->app, $this, $coll_id);
|
||||
if ($collections === null) {
|
||||
/** @var CollectionRepositoryRegistry $repositoryRegistry */
|
||||
$repositoryRegistry = $this->app['repo.collections-registry'];
|
||||
$repository = $repositoryRegistry->getRepositoryByDatabox($this->get_sbas_id());
|
||||
|
||||
$collections = $repository->findAll();
|
||||
}
|
||||
|
||||
return $ret;
|
||||
return $collections;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int[]
|
||||
*/
|
||||
public function get_collection_unique_ids()
|
||||
{
|
||||
static $base_ids_cache = [];
|
||||
static $collectionsIds;
|
||||
|
||||
if (isset($base_ids_cache[$this->id])) {
|
||||
return $base_ids_cache[$this->id];
|
||||
}
|
||||
if ($collectionsIds === null) {
|
||||
$collectionsIds = [];
|
||||
|
||||
$conn = $this->get_appbox()->get_connection();
|
||||
$sql = "SELECT b.base_id FROM bas b WHERE b.sbas_id = :sbas_id AND b.active = '1' ORDER BY b.ord ASC";
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute([':sbas_id' => $this->id]);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$base_ids = [];
|
||||
foreach ($rs as $row) {
|
||||
$base_ids[] = (int) $row['base_id'];
|
||||
}
|
||||
|
||||
return $base_ids_cache[$this->id] = $base_ids;
|
||||
}
|
||||
|
||||
protected function get_available_collections()
|
||||
{
|
||||
try {
|
||||
$data = $this->get_data_from_cache(self::CACHE_COLLECTIONS);
|
||||
if (is_array($data)) {
|
||||
return $data;
|
||||
foreach ($this->get_collections() as $collection) {
|
||||
$collectionsIds[] = $collection->get_base_id();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
|
||||
}
|
||||
|
||||
$conn = $this->get_appbox()->get_connection();
|
||||
|
||||
$sql = "SELECT b.server_coll_id FROM sbas s, bas b
|
||||
WHERE s.sbas_id = b.sbas_id AND b.sbas_id = :sbas_id
|
||||
AND b.active = '1'
|
||||
ORDER BY s.ord ASC, b.ord,b.base_id ASC";
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute([':sbas_id' => $this->id]);
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$ret = [];
|
||||
|
||||
foreach ($rs as $row) {
|
||||
$ret[] = (int) $row['server_coll_id'];
|
||||
}
|
||||
|
||||
$this->set_data_to_cache($ret, self::CACHE_COLLECTIONS);
|
||||
|
||||
return $ret;
|
||||
return $collectionsIds;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -415,7 +382,7 @@ class databox extends base implements ThumbnailedElement
|
||||
$old_dbname = $this->get_dbname();
|
||||
|
||||
foreach ($this->get_collections() as $collection) {
|
||||
$collection->unmount_collection($this->app);
|
||||
$collection->unmount();
|
||||
}
|
||||
|
||||
$query = $this->app['phraseanet.user-query'];
|
||||
|
Reference in New Issue
Block a user