mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-15 14:03:27 +00:00
Merge branch 'clean-boxes' into merge-clean-boxes
This commit is contained in:
12
circle.yml
12
circle.yml
@@ -36,12 +36,12 @@ database:
|
||||
override:
|
||||
- mysql -u ubuntu -e 'CREATE DATABASE update39_test;CREATE DATABASE ab_test;CREATE DATABASE db_test;SET @@global.sql_mode=STRICT_ALL_TABLES;SET @@global.max_allowed_packet=33554432;SET @@global.wait_timeout=999999;';
|
||||
post:
|
||||
- "./bin/developer system:uninstall"
|
||||
- "./bin/setup system:install --email=test@phraseanet.com --password=test --db-host=127.0.0.1 --db-user=ubuntu --db-template=fr --db-password= --databox=db_test --appbox=ab_test --server-name=http://127.0.0.1 -y;"
|
||||
- "./bin/developer ini:setup-tests-dbs"
|
||||
- "./bin/console searchengine:index:create"
|
||||
- "./bin/developer phraseanet:regenerate-sqlite"
|
||||
- "./bin/developer phraseanet:generate-js-fixtures"
|
||||
- "./bin/developer system:uninstall -v"
|
||||
- "./bin/setup system:install -v --email=test@phraseanet.com --password=test --db-host=127.0.0.1 --db-user=ubuntu --db-template=fr --db-password= --databox=db_test --appbox=ab_test --server-name=http://127.0.0.1 -y;"
|
||||
- "./bin/developer ini:setup-tests-dbs -v"
|
||||
- "./bin/console searchengine:index:create -v"
|
||||
- "./bin/developer phraseanet:regenerate-sqlite -v"
|
||||
- "./bin/developer phraseanet:generate-js-fixtures -v"
|
||||
|
||||
test:
|
||||
override:
|
||||
|
@@ -9,6 +9,8 @@
|
||||
*/
|
||||
namespace Alchemy\Phrasea\Application\Helper;
|
||||
|
||||
use Alchemy\Phrasea\Collection\CollectionService;
|
||||
|
||||
trait ApplicationBoxAware
|
||||
{
|
||||
/** @var \appbox|callable */
|
||||
@@ -61,6 +63,14 @@ trait ApplicationBoxAware
|
||||
return $this->applicationBox;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CollectionService
|
||||
*/
|
||||
public function getCollectionService()
|
||||
{
|
||||
return $this['services.collection'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a registered Databoxes.
|
||||
*
|
||||
|
250
lib/Alchemy/Phrasea/Collection/Collection.php
Normal file
250
lib/Alchemy/Phrasea/Collection/Collection.php
Normal file
@@ -0,0 +1,250 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Phrasea\Collection;
|
||||
|
||||
use Alchemy\Phrasea\Collection\Reference\CollectionReference;
|
||||
use PHPExiftool\Exception\LogicException;
|
||||
|
||||
class Collection
|
||||
{
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $databoxId;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $collectionId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $labels = [];
|
||||
|
||||
/**
|
||||
* @var string|int[] Binary representation of logo
|
||||
*/
|
||||
private $logo;
|
||||
|
||||
/**
|
||||
* @var \DateTimeInterface
|
||||
*/
|
||||
private $logoUpdatedAt;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $publicWatermark;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $preferences;
|
||||
|
||||
/**
|
||||
* @var CollectionReference
|
||||
*/
|
||||
private $collectionReference;
|
||||
|
||||
public function __construct($databoxId, $collectionId, $name)
|
||||
{
|
||||
$this->databoxId = (int) $databoxId;
|
||||
$this->collectionId = (int) $collectionId;
|
||||
$this->name = (string) $name;
|
||||
$this->preferences = <<<EOT
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<baseprefs>
|
||||
<status>0</status>
|
||||
<sugestedValues></sugestedValues>
|
||||
</baseprefs>
|
||||
EOT;
|
||||
$this->logo = '';
|
||||
$this->labels = array(
|
||||
'en' => '',
|
||||
'fr' => '',
|
||||
'de' => '',
|
||||
'nl' => ''
|
||||
);
|
||||
$this->publicWatermark = '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getDataboxId()
|
||||
{
|
||||
return $this->databoxId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getCollectionId()
|
||||
{
|
||||
return $this->collectionId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $collectionId
|
||||
*/
|
||||
public function setCollectionId($collectionId)
|
||||
{
|
||||
if ($this->collectionId > 0) {
|
||||
throw new LogicException('Cannot change the ID of an existing collection.');
|
||||
}
|
||||
|
||||
$this->collectionId = (int) $collectionId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$name = trim(strip_tags($name));
|
||||
|
||||
if ($name === '') {
|
||||
throw new \InvalidArgumentException();
|
||||
}
|
||||
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \string[]
|
||||
*/
|
||||
public function getLabels()
|
||||
{
|
||||
return $this->labels;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \string[] $labels
|
||||
*/
|
||||
public function setLabels($labels)
|
||||
{
|
||||
$this->labels = $labels;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $lang
|
||||
* @param bool $substitute
|
||||
* @return string
|
||||
*/
|
||||
public function getLabel($lang, $substitute = true)
|
||||
{
|
||||
if (!array_key_exists($lang, $this->labels)) {
|
||||
throw new \InvalidArgumentException(sprintf('Code %s is not defined', $lang));
|
||||
}
|
||||
|
||||
if ($substitute) {
|
||||
return isset($this->labels[$lang]) ? $this->labels[$lang] : $this->name;
|
||||
} else {
|
||||
return $this->labels[$lang];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $lang
|
||||
* @param $label
|
||||
*/
|
||||
public function setLabel($lang, $label)
|
||||
{
|
||||
if (!array_key_exists($lang, $this->labels)) {
|
||||
throw new \InvalidArgumentException(sprintf("Language '%s' is not defined.", $lang));
|
||||
}
|
||||
|
||||
$this->labels[$lang] = $label;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \int[]|string|null
|
||||
*/
|
||||
public function getLogo()
|
||||
{
|
||||
return $this->logo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \int[]|string $logo
|
||||
*/
|
||||
public function setLogo($logo)
|
||||
{
|
||||
$this->logo = $logo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTimeInterface
|
||||
*/
|
||||
public function getLogoUpdatedAt()
|
||||
{
|
||||
return $this->logoUpdatedAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPublicWatermark()
|
||||
{
|
||||
return $this->publicWatermark;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $publicWatermark
|
||||
*/
|
||||
public function setPublicWatermark($publicWatermark)
|
||||
{
|
||||
if (! in_array($publicWatermark, ['none', 'wm', 'stamp'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->publicWatermark = $publicWatermark;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPreferences()
|
||||
{
|
||||
return $this->preferences;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $preferences
|
||||
*/
|
||||
public function setPreferences($preferences)
|
||||
{
|
||||
$this->preferences = $preferences;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CollectionReference
|
||||
*/
|
||||
public function getCollectionReference()
|
||||
{
|
||||
return $this->collectionReference;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CollectionReference $collectionReference
|
||||
*/
|
||||
public function setCollectionReference($collectionReference)
|
||||
{
|
||||
$this->collectionReference = $collectionReference;
|
||||
}
|
||||
}
|
72
lib/Alchemy/Phrasea/Collection/CollectionFactory.php
Normal file
72
lib/Alchemy/Phrasea/Collection/CollectionFactory.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Phrasea\Collection;
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Collection\Reference\CollectionReference;
|
||||
use Assert\Assertion;
|
||||
|
||||
class CollectionFactory
|
||||
{
|
||||
/**
|
||||
* @var Application
|
||||
*/
|
||||
private $app;
|
||||
|
||||
/**
|
||||
* @param Application $application
|
||||
*/
|
||||
public function __construct(Application $application)
|
||||
{
|
||||
$this->app = $application;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $databoxId
|
||||
* @param CollectionReference $reference
|
||||
* @param array $row
|
||||
* @return \collection
|
||||
*/
|
||||
public function create($databoxId, CollectionReference $reference, array $row)
|
||||
{
|
||||
if ($databoxId != $reference->getDataboxId()) {
|
||||
throw new \InvalidArgumentException('Reference does not belong to given databoxId.');
|
||||
}
|
||||
|
||||
$collection = new Collection($databoxId, $row['coll_id'], $row['asciiname']);
|
||||
|
||||
$collection->setLabel('en', $row['label_en']);
|
||||
$collection->setLabel('fr', $row['label_fr']);
|
||||
$collection->setLabel('de', $row['label_de']);
|
||||
$collection->setLabel('nl', $row['label_nl']);
|
||||
$collection->setLogo($row['logo']);
|
||||
$collection->setPreferences($row['prefs']);
|
||||
$collection->setPublicWatermark($row['pub_wm']);
|
||||
|
||||
return new \collection($this->app, $collection, $reference, $row);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $databoxId
|
||||
* @param CollectionReference[] $collectionReferences
|
||||
* @param array $rows
|
||||
* @return array
|
||||
*/
|
||||
public function createMany($databoxId, $collectionReferences, array $rows)
|
||||
{
|
||||
Assertion::allIsInstanceOf($collectionReferences, CollectionReference::class);
|
||||
|
||||
$collections = [];
|
||||
$indexedReferences = [];
|
||||
|
||||
foreach ($collectionReferences as $reference) {
|
||||
$indexedReferences[$reference->getCollectionId()] = $reference;
|
||||
}
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$collections[$row['coll_id']] = $this->create($databoxId, $indexedReferences[$row['coll_id']], $row);
|
||||
}
|
||||
|
||||
return $collections;
|
||||
}
|
||||
}
|
30
lib/Alchemy/Phrasea/Collection/CollectionRepository.php
Normal file
30
lib/Alchemy/Phrasea/Collection/CollectionRepository.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Phrasea\Collection;
|
||||
|
||||
interface CollectionRepository
|
||||
{
|
||||
|
||||
/**
|
||||
* @return \collection[]
|
||||
*/
|
||||
public function findAll();
|
||||
|
||||
/**
|
||||
* @param int $collectionId
|
||||
* @return \collection|null
|
||||
*/
|
||||
public function find($collectionId);
|
||||
|
||||
/**
|
||||
* @param Collection $collection
|
||||
* @return void
|
||||
*/
|
||||
public function save(Collection $collection);
|
||||
|
||||
/**
|
||||
* @param Collection $collection
|
||||
* @return void
|
||||
*/
|
||||
public function delete(Collection $collection);
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Phrasea\Collection;
|
||||
|
||||
interface CollectionRepositoryFactory
|
||||
{
|
||||
/**
|
||||
* @param int $databoxId
|
||||
* @return CollectionRepository
|
||||
*/
|
||||
public function createRepositoryForDatabox($databoxId);
|
||||
}
|
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Phrasea\Collection;
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Collection\Reference\CollectionReferenceRepository;
|
||||
|
||||
class CollectionRepositoryRegistry
|
||||
{
|
||||
|
||||
private $baseIdMap = null;
|
||||
|
||||
/**
|
||||
* @var Application
|
||||
*/
|
||||
private $application;
|
||||
|
||||
/**
|
||||
* @var CollectionRepository[]
|
||||
*/
|
||||
private $repositories = array();
|
||||
|
||||
/**
|
||||
* @var CollectionReferenceRepository
|
||||
*/
|
||||
private $referenceRepository;
|
||||
|
||||
/**
|
||||
* @var CollectionRepositoryFactory
|
||||
*/
|
||||
private $repositoryFactory;
|
||||
|
||||
/**
|
||||
* @param Application $app
|
||||
* @param CollectionRepositoryFactory $collectionRepositoryFactory
|
||||
* @param CollectionReferenceRepository $referenceRepository
|
||||
*/
|
||||
public function __construct(
|
||||
Application $app,
|
||||
CollectionRepositoryFactory $collectionRepositoryFactory,
|
||||
CollectionReferenceRepository $referenceRepository
|
||||
) {
|
||||
$this->application = $app;
|
||||
$this->repositoryFactory = $collectionRepositoryFactory;
|
||||
$this->referenceRepository = $referenceRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $databoxId
|
||||
* @return CollectionRepository
|
||||
*/
|
||||
public function getRepositoryByDatabox($databoxId)
|
||||
{
|
||||
if (!isset($this->repositories[$databoxId])) {
|
||||
$this->repositories[$databoxId] = $this->repositoryFactory->createRepositoryForDatabox($databoxId);
|
||||
}
|
||||
|
||||
return $this->repositories[$databoxId];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $baseId
|
||||
* @return CollectionRepository
|
||||
* @throws \OutOfBoundsException if no repository was found for the given baseId.
|
||||
*/
|
||||
public function getRepositoryByBase($baseId)
|
||||
{
|
||||
if ($this->baseIdMap === null) {
|
||||
$this->loadBaseIdMap();
|
||||
}
|
||||
|
||||
if (isset($this->baseIdMap[$baseId])) {
|
||||
return $this->getRepositoryByDatabox($this->baseIdMap[$baseId]);
|
||||
}
|
||||
|
||||
throw new \OutOfBoundsException('No repository available for given base [baseId: ' . $baseId . ' ].');
|
||||
}
|
||||
|
||||
public function purgeRegistry()
|
||||
{
|
||||
$this->baseIdMap = null;
|
||||
|
||||
$appBox = $this->application->getApplicationBox();
|
||||
|
||||
\phrasea::reset_baseDatas($appBox);
|
||||
\phrasea::reset_sbasDatas($appBox);
|
||||
}
|
||||
|
||||
private function loadBaseIdMap()
|
||||
{
|
||||
$references = $this->referenceRepository->findAll();
|
||||
|
||||
$this->baseIdMap = [];
|
||||
|
||||
foreach ($references as $reference) {
|
||||
$this->baseIdMap[$reference->getBaseId()] = $reference->getDataboxId();
|
||||
}
|
||||
}
|
||||
}
|
266
lib/Alchemy/Phrasea/Collection/CollectionService.php
Normal file
266
lib/Alchemy/Phrasea/Collection/CollectionService.php
Normal file
@@ -0,0 +1,266 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Phrasea\Collection;
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Collection\Reference\CollectionReference;
|
||||
use Alchemy\Phrasea\Databox\DataboxConnectionProvider;
|
||||
use Alchemy\Phrasea\Model\Entities\User;
|
||||
use Doctrine\DBAL\Connection;
|
||||
|
||||
class CollectionService
|
||||
{
|
||||
/**
|
||||
* @var Application
|
||||
*/
|
||||
private $app;
|
||||
|
||||
private $connection;
|
||||
|
||||
private $connectionProvider;
|
||||
|
||||
public function __construct(Application $application, Connection $connection, DataboxConnectionProvider $connectionProvider)
|
||||
{
|
||||
$this->app = $application;
|
||||
$this->connection = $connection;
|
||||
$this->connectionProvider = $connectionProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $collection
|
||||
* @return int|null
|
||||
* @throws \Doctrine\DBAL\DBALException
|
||||
*/
|
||||
public function getRecordCount(Collection $collection)
|
||||
{
|
||||
$connection = $this->connectionProvider->getConnection($collection->getDataboxId());
|
||||
|
||||
$sql = "SELECT COALESCE(COUNT(record_id), 0) AS recordCount FROM record WHERE coll_id = :coll_id";
|
||||
$stmt = $connection->prepare($sql);
|
||||
$stmt->execute([':coll_id' => $collection->getCollectionId()]);
|
||||
$rowbas = $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$amount = $rowbas ? (int) $rowbas["recordCount"] : null;
|
||||
|
||||
return $amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $collection
|
||||
* @return array
|
||||
*/
|
||||
public function getRecordDetails(Collection $collection)
|
||||
{
|
||||
$sql = "SELECT record.coll_id,name,COALESCE(asciiname, CONCAT('_',record.coll_id)) AS asciiname,
|
||||
SUM(1) AS n, SUM(size) AS size
|
||||
FROM record NATURAL JOIN subdef
|
||||
INNER JOIN coll ON record.coll_id=coll.coll_id AND coll.coll_id = :coll_id
|
||||
GROUP BY record.coll_id, subdef.name";
|
||||
|
||||
$connection = $this->connectionProvider->getConnection($collection->getDataboxId());
|
||||
|
||||
$stmt = $connection->prepare($sql);
|
||||
$stmt->execute([':coll_id' => $collection->getCollectionId()]);
|
||||
$rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$ret = [];
|
||||
foreach ($rs as $row) {
|
||||
$ret[] = [
|
||||
"coll_id" => (int) $row["coll_id"],
|
||||
"name" => $row["name"],
|
||||
"amount" => (int) $row["n"],
|
||||
"size" => (int) $row["size"]];
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $collection
|
||||
* @return $this
|
||||
* @throws \Doctrine\DBAL\DBALException
|
||||
*/
|
||||
public function resetWatermark(Collection $collection)
|
||||
{
|
||||
$sql = 'SELECT path, file FROM record r INNER JOIN subdef s USING(record_id)
|
||||
WHERE r.coll_id = :coll_id AND r.type="image" AND s.name="preview"';
|
||||
|
||||
$connection = $this->connectionProvider->getConnection($collection->getDataboxId());
|
||||
|
||||
$stmt = $connection->prepare($sql);
|
||||
$stmt->execute([':coll_id' => $collection->getCollectionId()]);
|
||||
|
||||
while ($row2 = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
@unlink(\p4string::addEndSlash($row2['path']) . 'watermark_' . $row2['file']);
|
||||
}
|
||||
$stmt->closeCursor();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $collection
|
||||
* @param int|null $record_id
|
||||
* @return $this
|
||||
* @throws \Doctrine\DBAL\DBALException
|
||||
*/
|
||||
public function resetStamp(Collection $collection, $record_id = null)
|
||||
{
|
||||
$sql = 'SELECT path, file FROM record r INNER JOIN subdef s USING(record_id)
|
||||
WHERE r.coll_id = :coll_id
|
||||
AND r.type="image" AND s.name IN ("preview", "document")';
|
||||
|
||||
|
||||
$params = [':coll_id' => $collection->getCollectionId()];
|
||||
|
||||
if ($record_id) {
|
||||
$sql .= ' AND record_id = :record_id';
|
||||
$params[':record_id'] = $record_id;
|
||||
}
|
||||
|
||||
$connection = $this->connectionProvider->getConnection($collection->getDataboxId());
|
||||
|
||||
$stmt = $connection->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
|
||||
while ($row2 = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
@unlink(\p4string::addEndSlash($row2['path']) . 'stamp_' . $row2['file']);
|
||||
}
|
||||
$stmt->closeCursor();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \databox $databox
|
||||
* @param Collection $collection
|
||||
* @param CollectionReference $reference
|
||||
* @throws \Doctrine\DBAL\DBALException
|
||||
*/
|
||||
public function delete(\databox $databox, Collection $collection, CollectionReference $reference)
|
||||
{
|
||||
while ($this->getRecordCount($collection) > 0) {
|
||||
$this->emptyCollection($databox, $collection);
|
||||
}
|
||||
|
||||
$connection = $this->connectionProvider->getConnection($collection->getDataboxId());
|
||||
|
||||
$sql = "DELETE FROM coll WHERE coll_id = :coll_id";
|
||||
$stmt = $connection->prepare($sql);
|
||||
$stmt->execute([':coll_id' => $collection->getCollectionId()]);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$sql = "DELETE FROM bas WHERE base_id = :base_id";
|
||||
$stmt = $this->connection->prepare($sql);
|
||||
$stmt->execute([':base_id' => $reference->getBaseId()]);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$sql = "DELETE FROM basusr WHERE base_id = :base_id";
|
||||
$stmt = $this->connection->prepare($sql);
|
||||
$stmt->execute([':base_id' => $reference->getBaseId()]);
|
||||
$stmt->closeCursor();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \databox $databox
|
||||
* @param Collection $collection
|
||||
* @param int $pass_quantity
|
||||
* @return $this
|
||||
* @throws \Doctrine\DBAL\DBALException
|
||||
*/
|
||||
public function emptyCollection(\databox $databox, Collection $collection, $pass_quantity = 100)
|
||||
{
|
||||
$pass_quantity = (int) $pass_quantity > 200 ? 200 : (int) $pass_quantity;
|
||||
$pass_quantity = (int) $pass_quantity < 10 ? 10 : (int) $pass_quantity;
|
||||
|
||||
$sql = "SELECT record_id FROM record WHERE coll_id = :coll_id
|
||||
ORDER BY record_id DESC LIMIT 0, " . $pass_quantity;
|
||||
|
||||
$connection = $this->connectionProvider->getConnection($collection->getDataboxId());
|
||||
|
||||
$stmt = $connection->prepare($sql);
|
||||
$stmt->execute([':coll_id' => $collection->getCollectionId()]);
|
||||
$rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
foreach ($rs as $row) {
|
||||
$record = $databox->get_record($row['record_id']);
|
||||
$record->delete();
|
||||
unset($record);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CollectionReference $reference
|
||||
* @return $this
|
||||
* @throws \Doctrine\DBAL\DBALException
|
||||
*/
|
||||
public function unmountCollection(CollectionReference $reference)
|
||||
{
|
||||
$params = [':base_id' => $reference->getBaseId()];
|
||||
|
||||
$query = $this->app['phraseanet.user-query'];
|
||||
$total = $query->on_base_ids([$reference->getBaseId()])
|
||||
->include_phantoms(false)
|
||||
->include_special_users(true)
|
||||
->include_invite(true)
|
||||
->include_templates(true)->get_total();
|
||||
$n = 0;
|
||||
|
||||
while ($n < $total) {
|
||||
$results = $query->limit($n, 50)->execute()->get_results();
|
||||
|
||||
foreach ($results as $user) {
|
||||
$this->app->getAclForUser($user)->delete_data_from_cache(\ACL::CACHE_RIGHTS_SBAS);
|
||||
$this->app->getAclForUser($user)->delete_data_from_cache(\ACL::CACHE_RIGHTS_BAS);
|
||||
}
|
||||
|
||||
$n+=50;
|
||||
}
|
||||
|
||||
$sql = "DELETE FROM basusr WHERE base_id = :base_id";
|
||||
$stmt = $this->connection->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$sql = "DELETE FROM bas WHERE base_id = :base_id";
|
||||
$stmt = $this->connection->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CollectionReference $reference
|
||||
* @param User $user
|
||||
*/
|
||||
public function grantAdminRights(CollectionReference $reference, User $user)
|
||||
{
|
||||
$rights = [
|
||||
"canputinalbum" => "1",
|
||||
"candwnldhd" => "1",
|
||||
"nowatermark" => "1",
|
||||
"candwnldpreview" => "1",
|
||||
"cancmd" => "1",
|
||||
"canadmin" => "1",
|
||||
"actif" => "1",
|
||||
"canreport" => "1",
|
||||
"canpush" => "1",
|
||||
"basusr_infousr" => "",
|
||||
"canaddrecord" => "1",
|
||||
"canmodifrecord" => "1",
|
||||
"candeleterecord" => "1",
|
||||
"chgstatus" => "1",
|
||||
"imgtools" => "1",
|
||||
"manage" => "1",
|
||||
"modify_struct" => "1"
|
||||
];
|
||||
|
||||
$this->app->getAclForUser($user)->update_rights_to_base($reference->getBaseId(), $rights);
|
||||
}
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Phrasea\Collection\Factory;
|
||||
|
||||
use Alchemy\Phrasea\Collection\CollectionRepository;
|
||||
use Alchemy\Phrasea\Collection\CollectionRepositoryFactory;
|
||||
use Alchemy\Phrasea\Collection\Repository\ArrayCacheCollectionRepository;
|
||||
|
||||
class ArrayCachedCollectionRepositoryFactory implements CollectionRepositoryFactory
|
||||
{
|
||||
/**
|
||||
* @var CollectionRepositoryFactory
|
||||
*/
|
||||
private $collectionRepositoryFactory;
|
||||
|
||||
/**
|
||||
* @param CollectionRepositoryFactory $collectionRepositoryFactory
|
||||
*/
|
||||
public function __construct(CollectionRepositoryFactory $collectionRepositoryFactory)
|
||||
{
|
||||
$this->collectionRepositoryFactory = $collectionRepositoryFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $databoxId
|
||||
* @return CollectionRepository
|
||||
*/
|
||||
public function createRepositoryForDatabox($databoxId)
|
||||
{
|
||||
$repository = $this->collectionRepositoryFactory->createRepositoryForDatabox($databoxId);
|
||||
|
||||
return new ArrayCacheCollectionRepository($repository);
|
||||
}
|
||||
}
|
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Phrasea\Collection\Factory;
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Collection\CollectionRepository;
|
||||
use Alchemy\Phrasea\Collection\CollectionRepositoryFactory;
|
||||
use Alchemy\Phrasea\Collection\Repository\CachedCollectionRepository;
|
||||
use Doctrine\Common\Cache\Cache;
|
||||
|
||||
class CachedCollectionRepositoryFactory implements CollectionRepositoryFactory
|
||||
{
|
||||
/**
|
||||
* @var Application
|
||||
*/
|
||||
private $application;
|
||||
|
||||
/**
|
||||
* @var CollectionRepositoryFactory
|
||||
*/
|
||||
private $collectionRepositoryFactory;
|
||||
|
||||
/**
|
||||
* @var Cache
|
||||
*/
|
||||
private $cache;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $baseCacheKey;
|
||||
|
||||
/**
|
||||
* @param Application $application
|
||||
* @param CollectionRepositoryFactory $collectionRepositoryFactory
|
||||
* @param Cache $cache
|
||||
* @param string $baseCacheKey
|
||||
*/
|
||||
public function __construct(
|
||||
Application $application,
|
||||
CollectionRepositoryFactory $collectionRepositoryFactory,
|
||||
Cache $cache,
|
||||
$baseCacheKey
|
||||
) {
|
||||
$this->application = $application;
|
||||
$this->collectionRepositoryFactory = $collectionRepositoryFactory;
|
||||
$this->cache = $cache;
|
||||
$this->baseCacheKey = (string)$baseCacheKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $databoxId
|
||||
* @return CollectionRepository
|
||||
*/
|
||||
public function createRepositoryForDatabox($databoxId)
|
||||
{
|
||||
$repository = $this->collectionRepositoryFactory->createRepositoryForDatabox($databoxId);
|
||||
|
||||
return new CachedCollectionRepository(
|
||||
$this->application,
|
||||
$repository,
|
||||
$this->cache,
|
||||
$this->baseCacheKey . '.' . $databoxId
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Phrasea\Collection\Factory;
|
||||
|
||||
use Alchemy\Phrasea\Collection\CollectionFactory;
|
||||
use Alchemy\Phrasea\Collection\CollectionRepository;
|
||||
use Alchemy\Phrasea\Collection\CollectionRepositoryFactory;
|
||||
use Alchemy\Phrasea\Collection\Reference\CollectionReferenceRepository;
|
||||
use Alchemy\Phrasea\Collection\Repository\DbalCollectionRepository;
|
||||
use Alchemy\Phrasea\Databox\DataboxConnectionProvider;
|
||||
|
||||
class DbalCollectionRepositoryFactory implements CollectionRepositoryFactory
|
||||
{
|
||||
|
||||
/**
|
||||
* @var CollectionReferenceRepository
|
||||
*/
|
||||
private $collectionReferenceRepository;
|
||||
|
||||
/**
|
||||
* @var DataboxConnectionProvider
|
||||
*/
|
||||
private $databoxConnectionProvider;
|
||||
|
||||
/**
|
||||
* @var CollectionFactory
|
||||
*/
|
||||
private $collectionFactory;
|
||||
|
||||
/**
|
||||
* @param DataboxConnectionProvider $connectionProvider
|
||||
* @param CollectionFactory $collectionFactory
|
||||
* @param CollectionReferenceRepository $referenceRepository
|
||||
*/
|
||||
public function __construct(
|
||||
DataboxConnectionProvider $connectionProvider,
|
||||
CollectionFactory $collectionFactory,
|
||||
CollectionReferenceRepository $referenceRepository
|
||||
) {
|
||||
$this->databoxConnectionProvider = $connectionProvider;
|
||||
$this->collectionFactory = $collectionFactory;
|
||||
$this->collectionReferenceRepository = $referenceRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $databoxId
|
||||
* @return CollectionRepository
|
||||
*/
|
||||
public function createRepositoryForDatabox($databoxId)
|
||||
{
|
||||
$connection = $this->databoxConnectionProvider->getConnection($databoxId);
|
||||
|
||||
return new DbalCollectionRepository(
|
||||
$databoxId,
|
||||
$connection,
|
||||
$this->collectionReferenceRepository,
|
||||
$this->collectionFactory
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Phrasea\Collection\Reference;
|
||||
|
||||
class ArrayCacheCollectionReferenceRepository implements CollectionReferenceRepository
|
||||
{
|
||||
/**
|
||||
* @var CollectionReferenceRepository
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* @var null|array
|
||||
*/
|
||||
private $referenceCache = null;
|
||||
|
||||
public function __construct(CollectionReferenceRepository $referenceRepository)
|
||||
{
|
||||
$this->repository = $referenceRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CollectionReference[]
|
||||
*/
|
||||
public function findAll()
|
||||
{
|
||||
if ($this->referenceCache === null) {
|
||||
$this->referenceCache = $this->repository->findAll();
|
||||
}
|
||||
|
||||
return $this->referenceCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $databoxId
|
||||
* @return CollectionReference[]
|
||||
*/
|
||||
public function findAllByDatabox($databoxId)
|
||||
{
|
||||
$references = $this->findAll();
|
||||
$found = array();
|
||||
|
||||
foreach ($references as $reference) {
|
||||
if ($reference->getDataboxId() == $databoxId) {
|
||||
$found[$reference->getBaseId()] = $reference;
|
||||
}
|
||||
}
|
||||
|
||||
return $found;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $baseId
|
||||
* @return CollectionReference|null
|
||||
*/
|
||||
public function find($baseId)
|
||||
{
|
||||
$references = $this->findAll();
|
||||
|
||||
if (isset($references[$baseId])) {
|
||||
return $references[$baseId];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $databoxId
|
||||
* @param int $collectionId
|
||||
* @return CollectionReference|null
|
||||
*/
|
||||
public function findByCollectionId($databoxId, $collectionId)
|
||||
{
|
||||
$references = $this->findAll();
|
||||
|
||||
foreach ($references as $reference) {
|
||||
if ($reference->getCollectionId() == $collectionId) {
|
||||
return $reference;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CollectionReference $reference
|
||||
* @return void
|
||||
*/
|
||||
public function save(CollectionReference $reference)
|
||||
{
|
||||
$this->repository->save($reference);
|
||||
|
||||
if ($this->referenceCache !== null) {
|
||||
$this->referenceCache[$reference->getBaseId()] = $reference;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CollectionReference $reference
|
||||
* @return void
|
||||
*/
|
||||
public function delete(CollectionReference $reference)
|
||||
{
|
||||
$this->repository->delete($reference);
|
||||
|
||||
if ($this->referenceCache !== null) {
|
||||
unset($this->referenceCache[$reference->getBaseId()]);
|
||||
}
|
||||
}
|
||||
}
|
156
lib/Alchemy/Phrasea/Collection/Reference/CollectionReference.php
Normal file
156
lib/Alchemy/Phrasea/Collection/Reference/CollectionReference.php
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Phrasea\Collection\Reference;
|
||||
|
||||
class CollectionReference
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $baseId;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $databoxId;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $collectionId;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $displayIndex;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $isActive;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $alias;
|
||||
|
||||
/**
|
||||
* @param int $baseId
|
||||
* @param int $databoxId
|
||||
* @param int $collectionId
|
||||
* @param int $displayIndex
|
||||
* @param bool $isActive
|
||||
* @param string $alias
|
||||
*/
|
||||
public function __construct($baseId, $databoxId, $collectionId, $displayIndex, $isActive, $alias)
|
||||
{
|
||||
$this->baseId = (int) $baseId;
|
||||
$this->databoxId = (int) $databoxId;
|
||||
$this->collectionId = (int) $collectionId;
|
||||
$this->displayIndex = (int) $displayIndex;
|
||||
$this->isActive = (bool) $isActive;
|
||||
$this->alias = (string) $alias;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getDataboxId()
|
||||
{
|
||||
return $this->databoxId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getBaseId()
|
||||
{
|
||||
return $this->baseId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $baseId
|
||||
*/
|
||||
public function setBaseId($baseId)
|
||||
{
|
||||
if ($this->baseId > 0) {
|
||||
throw new \LogicException('Cannot change the baseId of an existing collection reference.');
|
||||
}
|
||||
|
||||
$this->baseId = $baseId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getCollectionId()
|
||||
{
|
||||
return $this->collectionId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getDisplayIndex()
|
||||
{
|
||||
return $this->displayIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $index
|
||||
* @return $this
|
||||
*/
|
||||
public function setDisplayIndex($index)
|
||||
{
|
||||
$this->displayIndex = (int) $index;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function isActive()
|
||||
{
|
||||
return $this->isActive;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function disable()
|
||||
{
|
||||
$this->isActive = false;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function enable()
|
||||
{
|
||||
$this->isActive = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAlias()
|
||||
{
|
||||
return $this->alias;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $alias
|
||||
* @return $this
|
||||
*/
|
||||
public function setAlias($alias)
|
||||
{
|
||||
$this->alias = (string) $alias;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Phrasea\Collection\Reference;
|
||||
|
||||
interface CollectionReferenceRepository
|
||||
{
|
||||
/**
|
||||
* @return CollectionReference[]
|
||||
*/
|
||||
public function findAll();
|
||||
|
||||
/**
|
||||
* @param int $databoxId
|
||||
* @return CollectionReference[]
|
||||
*/
|
||||
public function findAllByDatabox($databoxId);
|
||||
|
||||
/**
|
||||
* @param int $baseId
|
||||
* @return CollectionReference|null
|
||||
*/
|
||||
public function find($baseId);
|
||||
|
||||
/**
|
||||
* @param int $databoxId
|
||||
* @param int $collectionId
|
||||
* @return CollectionReference|null
|
||||
*/
|
||||
public function findByCollectionId($databoxId, $collectionId);
|
||||
|
||||
/**
|
||||
* @param CollectionReference $reference
|
||||
* @return void
|
||||
*/
|
||||
public function save(CollectionReference $reference);
|
||||
|
||||
/**
|
||||
* @param CollectionReference $reference
|
||||
* @return void
|
||||
*/
|
||||
public function delete(CollectionReference $reference);
|
||||
}
|
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Phrasea\Collection\Reference;
|
||||
|
||||
use Alchemy\Phrasea\Core\Database\QueryBuilder;
|
||||
use Doctrine\DBAL\Connection;
|
||||
|
||||
class DbalCollectionReferenceRepository implements CollectionReferenceRepository
|
||||
{
|
||||
|
||||
private static $table = 'bas';
|
||||
|
||||
private static $columns = [
|
||||
'base_id' => 'baseId',
|
||||
'sbas_id' => 'databoxId',
|
||||
'server_coll_id' => 'collectionId',
|
||||
'ord' => 'displayIndex',
|
||||
'active' => 'isActive',
|
||||
'aliases' => 'alias'
|
||||
];
|
||||
|
||||
private static $selectQuery = 'SELECT base_id AS baseId, sbas_id AS databoxId, server_coll_id AS collectionId,
|
||||
ord AS displayIndex, active AS isActive, aliases AS alias
|
||||
FROM bas';
|
||||
|
||||
private static $insertQuery = 'INSERT INTO bas (sbas_id, server_coll_id, ord, active, aliases)
|
||||
VALUES (:databoxId, :collectionId,
|
||||
(SELECT COALESCE(MAX(b.ord), 0) + 1 AS ord FROM bas b WHERE b.sbas_id = :databoxId),
|
||||
:isActive, :alias)';
|
||||
|
||||
private static $updateQuery = 'UPDATE bas SET ord = :displayIndex, active = :isActive, aliases = :alias
|
||||
WHERE base_id = :baseId';
|
||||
|
||||
private static $deleteQuery = 'DELETE FROM bas WHERE base_id = :baseId';
|
||||
|
||||
/**
|
||||
* @var Connection
|
||||
*/
|
||||
private $connection;
|
||||
|
||||
/**
|
||||
* @param Connection $connection
|
||||
*/
|
||||
public function __construct(Connection $connection)
|
||||
{
|
||||
$this->connection = $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CollectionReference[]
|
||||
*/
|
||||
public function findAll()
|
||||
{
|
||||
return $this->createManyReferences($this->connection->fetchAll(self::$selectQuery));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $databoxId
|
||||
* @return CollectionReference[]
|
||||
*/
|
||||
public function findAllByDatabox($databoxId)
|
||||
{
|
||||
$query = self::$selectQuery . ' WHERE sbas_id = :databoxId';
|
||||
$rows = $this->connection->fetchAll($query, [ ':databoxId' => $databoxId ]);
|
||||
|
||||
return $this->createManyReferences($rows);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $baseId
|
||||
* @return CollectionReference|null
|
||||
*/
|
||||
public function find($baseId)
|
||||
{
|
||||
$query = self::$selectQuery . ' WHERE base_id = :baseId';
|
||||
$row = $this->connection->fetchAssoc($query, [ ':baseId' => $baseId ]);
|
||||
|
||||
if ($row !== false) {
|
||||
return $this->createReference($row);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $databoxId
|
||||
* @param int $collectionId
|
||||
* @return CollectionReference|null
|
||||
*/
|
||||
public function findByCollectionId($databoxId, $collectionId)
|
||||
{
|
||||
$query = self::$selectQuery . ' WHERE sbas_id = :databoxId AND server_coll_id = :collectionId';
|
||||
$row = $this->connection->fetchAssoc($query, [ ':databoxId' => $databoxId, ':collectionId' => $collectionId ]);
|
||||
|
||||
if ($row !== false) {
|
||||
return $this->createReference($row);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function save(CollectionReference $collectionReference)
|
||||
{
|
||||
$query = self::$insertQuery;
|
||||
$isInsert = true;
|
||||
|
||||
$parameters = [
|
||||
'isActive' => $collectionReference->isActive(),
|
||||
'alias' => $collectionReference->getAlias()
|
||||
];
|
||||
|
||||
if ($collectionReference->getBaseId() > 0) {
|
||||
$query = self::$updateQuery;
|
||||
$isInsert = false;
|
||||
|
||||
$parameters['baseId'] = $collectionReference->getBaseId();
|
||||
$parameters['displayIndex'] = $collectionReference->getDisplayIndex();
|
||||
}
|
||||
else {
|
||||
$parameters['databoxId'] = $collectionReference->getDataboxId();
|
||||
$parameters['collectionId'] = $collectionReference->getCollectionId();
|
||||
}
|
||||
|
||||
$this->connection->executeQuery($query, $parameters);
|
||||
|
||||
if ($isInsert) {
|
||||
$collectionReference->setBaseId($this->connection->lastInsertId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CollectionReference $collectionReference
|
||||
* @throws \Doctrine\DBAL\DBALException
|
||||
*/
|
||||
public function delete(CollectionReference $collectionReference)
|
||||
{
|
||||
$parameters = [
|
||||
'baseId' => $collectionReference->getBaseId()
|
||||
];
|
||||
|
||||
$this->connection->executeQuery(self::$deleteQuery, $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $row
|
||||
* @return CollectionReference
|
||||
*/
|
||||
private function createReference(array $row)
|
||||
{
|
||||
return new CollectionReference(
|
||||
$row['baseId'],
|
||||
$row['databoxId'],
|
||||
$row['collectionId'],
|
||||
$row['displayIndex'],
|
||||
$row['isActive'],
|
||||
$row['alias']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $rows
|
||||
* @return array
|
||||
*/
|
||||
private function createManyReferences($rows)
|
||||
{
|
||||
$references = [];
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$references[$row['baseId']] = $this->createReference($row);
|
||||
}
|
||||
|
||||
return $references;
|
||||
}
|
||||
}
|
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Phrasea\Collection\Repository;
|
||||
|
||||
use Alchemy\Phrasea\Collection\Collection;
|
||||
use Alchemy\Phrasea\Collection\CollectionRepository;
|
||||
|
||||
class ArrayCacheCollectionRepository implements CollectionRepository
|
||||
{
|
||||
/**
|
||||
* @var CollectionRepository
|
||||
*/
|
||||
private $collectionRepository;
|
||||
|
||||
/**
|
||||
* @var \collection[]
|
||||
*/
|
||||
private $collectionCache = null;
|
||||
|
||||
public function __construct(CollectionRepository $collectionRepository)
|
||||
{
|
||||
$this->collectionRepository = $collectionRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \collection[]
|
||||
*/
|
||||
public function findAll()
|
||||
{
|
||||
if ($this->collectionCache === null) {
|
||||
$this->collectionCache = $this->collectionRepository->findAll();
|
||||
}
|
||||
|
||||
return $this->collectionCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $collectionId
|
||||
* @return \collection|null
|
||||
*/
|
||||
public function find($collectionId)
|
||||
{
|
||||
$collections = $this->findAll();
|
||||
|
||||
if (isset($collections[$collectionId])) {
|
||||
return $collections[$collectionId];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function save(Collection $collection)
|
||||
{
|
||||
$this->collectionRepository->save($collection);
|
||||
|
||||
if ($this->collectionCache !== null) {
|
||||
$this->collectionCache = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function delete(Collection $collection)
|
||||
{
|
||||
$this->collectionRepository->delete($collection);
|
||||
|
||||
if (isset($this->collectionCache[$collection->getCollectionId()])) {
|
||||
unset($this->collectionCache[$collection->getCollectionId()]);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2015 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace Alchemy\Phrasea\Collection\Repository;
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Collection\Collection;
|
||||
use Alchemy\Phrasea\Collection\CollectionRepository;
|
||||
use Doctrine\Common\Cache\Cache;
|
||||
|
||||
final class CachedCollectionRepository implements CollectionRepository
|
||||
{
|
||||
|
||||
/**
|
||||
* @var Application
|
||||
*/
|
||||
private $app;
|
||||
|
||||
/**
|
||||
* @var CollectionRepository
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* @var Cache
|
||||
*/
|
||||
private $cache;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $cacheKey;
|
||||
|
||||
/**
|
||||
* @param Application $application
|
||||
* @param CollectionRepository $repository
|
||||
* @param Cache $cache
|
||||
* @param $cacheKey
|
||||
*/
|
||||
public function __construct(Application $application, CollectionRepository $repository, Cache $cache, $cacheKey)
|
||||
{
|
||||
$this->app = $application;
|
||||
$this->repository = $repository;
|
||||
$this->cache = $cache;
|
||||
$this->cacheKey = $cacheKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \collection[]
|
||||
*/
|
||||
public function findAll()
|
||||
{
|
||||
$cacheKey = hash('sha256', $this->cacheKey);
|
||||
/** @var \collection[] $collections */
|
||||
$collections = $this->cache->fetch($cacheKey);
|
||||
|
||||
if ($collections === false) {
|
||||
$collections = $this->repository->findAll();
|
||||
$this->putInCache($cacheKey, $collections);
|
||||
} else {
|
||||
foreach ($collections as $collection) {
|
||||
$collection->hydrate($this->app);
|
||||
}
|
||||
}
|
||||
|
||||
return $collections;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $collectionId
|
||||
* @return \collection|null
|
||||
*/
|
||||
public function find($collectionId)
|
||||
{
|
||||
$collections = $this->findAll();
|
||||
|
||||
if (isset($collections[$collectionId])) {
|
||||
return $collections[$collectionId];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function save(Collection $collection)
|
||||
{
|
||||
$this->repository->save($collection);
|
||||
|
||||
$cacheKey = hash('sha256', $this->cacheKey);
|
||||
|
||||
$this->cache->delete($cacheKey);
|
||||
}
|
||||
|
||||
public function delete(Collection $collection)
|
||||
{
|
||||
$this->repository->delete($collection);
|
||||
|
||||
$cacheKey = hash('sha256', $this->cacheKey);
|
||||
|
||||
$this->cache->delete($cacheKey);
|
||||
}
|
||||
|
||||
private function putInCache($key, $value)
|
||||
{
|
||||
$this->cache->save($key, $value);
|
||||
}
|
||||
}
|
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Phrasea\Collection\Repository;
|
||||
|
||||
use Alchemy\Phrasea\Collection\Collection;
|
||||
use Alchemy\Phrasea\Collection\CollectionFactory;
|
||||
use Alchemy\Phrasea\Collection\CollectionRepository;
|
||||
use Alchemy\Phrasea\Collection\Reference\CollectionReferenceRepository;
|
||||
use Doctrine\DBAL\Connection;
|
||||
|
||||
class DbalCollectionRepository implements CollectionRepository
|
||||
{
|
||||
|
||||
private static $selectQuery = 'SELECT coll_id, asciiname, label_en, label_fr, label_de, label_nl, prefs, logo, majLogo, pub_wm
|
||||
FROM coll';
|
||||
|
||||
private static $insertQuery = 'INSERT INTO coll (asciiname, prefs, logo) VALUES (:name, :preferences, :logo)';
|
||||
|
||||
private static $updateQuery = 'UPDATE coll SET asciiname = :name, label_en = :labelEn, label_fr = :labelFr,
|
||||
label_de = :labelDe, label_nl = :labelNl, prefs = :preferences, logo = :logo,
|
||||
majLogo = :logoTimestamp, pub_wm = :publicWatermark WHERE coll_id = :collectionId';
|
||||
|
||||
private static $deleteQuery = 'DELETE FROM coll WHERE coll_id = :collectionId';
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $databoxId;
|
||||
|
||||
/**
|
||||
* @var CollectionReferenceRepository
|
||||
*/
|
||||
private $referenceRepository;
|
||||
|
||||
/**
|
||||
* @var Connection
|
||||
*/
|
||||
private $connection;
|
||||
|
||||
/**
|
||||
* @var CollectionFactory
|
||||
*/
|
||||
private $collectionFactory;
|
||||
|
||||
/**
|
||||
* @param $databoxId
|
||||
* @param Connection $connection
|
||||
* @param CollectionReferenceRepository $referenceRepository
|
||||
* @param CollectionFactory $collectionFactory
|
||||
*/
|
||||
public function __construct(
|
||||
$databoxId,
|
||||
Connection $connection,
|
||||
CollectionReferenceRepository $referenceRepository,
|
||||
CollectionFactory $collectionFactory
|
||||
) {
|
||||
$this->databoxId = (int) $databoxId;
|
||||
$this->connection = $connection;
|
||||
$this->referenceRepository = $referenceRepository;
|
||||
$this->collectionFactory = $collectionFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \collection[]
|
||||
*/
|
||||
public function findAll()
|
||||
{
|
||||
$references = $this->referenceRepository->findAllByDatabox($this->databoxId);
|
||||
$params = [];
|
||||
|
||||
foreach ($references as $reference) {
|
||||
$params[':id_' . $reference->getCollectionId()] = $reference->getCollectionId();
|
||||
}
|
||||
|
||||
$query = self::$selectQuery . sprintf(' WHERE coll_id IN (%s)', implode(', ', array_keys($params)));
|
||||
$rows = $this->connection->fetchAll($query, $params);
|
||||
|
||||
return $this->collectionFactory->createMany($this->databoxId, $references, $rows);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $baseId
|
||||
* @return \collection|null
|
||||
*/
|
||||
public function find($baseId)
|
||||
{
|
||||
$reference = $this->referenceRepository->find($baseId);
|
||||
|
||||
if ($reference === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$query = self::$selectQuery . ' WHERE coll_id = :collectionId';
|
||||
$row = $this->connection->fetchAssoc($query, [ ':collectionId' => $reference->getCollectionId() ]);
|
||||
|
||||
if ($row !== false) {
|
||||
return $this->collectionFactory->create($this->databoxId, $reference, $row);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $databoxId
|
||||
* @param int $collectionId
|
||||
* @return \collection|null
|
||||
*/
|
||||
public function findByCollectionId($databoxId, $collectionId)
|
||||
{
|
||||
$reference = $this->referenceRepository->findByCollectionId($databoxId, $collectionId);
|
||||
|
||||
if ($reference === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$query = self::$selectQuery . ' WHERE coll_id = :collectionId';
|
||||
$row = $this->connection->fetchAssoc($query, [ ':collectionId' => $reference->getCollectionId() ]);
|
||||
|
||||
if ($row !== false) {
|
||||
return $this->collectionFactory->create($this->databoxId, $reference, $row);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function save(Collection $collection)
|
||||
{
|
||||
$isInsert = true;
|
||||
$query = self::$insertQuery;
|
||||
$parameters = array(
|
||||
'name' => $collection->getName(),
|
||||
'preferences' => $collection->getPreferences(),
|
||||
'logo' => $collection->getLogo()
|
||||
);
|
||||
|
||||
if ($collection->getCollectionId() > 0) {
|
||||
$parameters['collectionId'] = $collection->getCollectionId();
|
||||
$parameters['labelEn'] = $collection->getLabel('en', false);
|
||||
$parameters['labelFr'] = $collection->getLabel('fr', false);
|
||||
$parameters['labelDe'] = $collection->getLabel('de', false);
|
||||
$parameters['labelNl'] = $collection->getLabel('nl', false);
|
||||
$parameters['logoTimestamp'] = $collection->getLogoUpdatedAt();
|
||||
$parameters['publicWatermark'] = $collection->getPublicWatermark();
|
||||
|
||||
$query = self::$updateQuery;
|
||||
$isInsert = false;
|
||||
}
|
||||
|
||||
$this->connection->executeQuery($query, $parameters);
|
||||
|
||||
if ($isInsert) {
|
||||
$collection->setCollectionId($this->connection->lastInsertId());
|
||||
}
|
||||
}
|
||||
|
||||
public function delete(Collection $collection)
|
||||
{
|
||||
$parameters = [
|
||||
'collectionId' => $collection->getCollectionId()
|
||||
];
|
||||
|
||||
$this->connection->executeQuery(self::$deleteQuery, $parameters);
|
||||
}
|
||||
}
|
@@ -43,7 +43,7 @@ class RecordAdd extends Command
|
||||
protected function doExecute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
try {
|
||||
$collection = \collection::get_from_base_id($this->container, $input->getArgument('base_id'));
|
||||
$collection = \collection::getByBaseId($this->container, $input->getArgument('base_id'));
|
||||
} catch (\Exception $e) {
|
||||
throw new \InvalidArgumentException(sprintf('Collection %s is invalid', $input->getArgument('base_id')));
|
||||
}
|
||||
|
@@ -125,7 +125,7 @@ class Step31 implements DatasUpgraderInterface
|
||||
$uuid = Uuid::uuid4();
|
||||
try {
|
||||
$media = $this->app->getMediaFromUri($pathfile);
|
||||
$collection = \collection::get_from_coll_id($this->$app, $databox, (int) $record['coll_id']);
|
||||
$collection = \collection::getByCollectionId($this->$app, $databox, (int) $record['coll_id']);
|
||||
|
||||
$file = new File($this->app, $media, $collection);
|
||||
$uuid = $file->getUUID(true, true);
|
||||
|
@@ -33,7 +33,7 @@ class CollectionController extends Controller
|
||||
*/
|
||||
public function getCollection(Request $request, $bas_id)
|
||||
{
|
||||
$collection = \collection::get_from_base_id($this->app, $bas_id);
|
||||
$collection = \collection::getByBaseId($this->app, $bas_id);
|
||||
|
||||
$admins = [];
|
||||
|
||||
@@ -144,7 +144,7 @@ class CollectionController extends Controller
|
||||
$success = false;
|
||||
$msg = $this->app->trans('An error occurred');
|
||||
|
||||
$collection = \collection::get_from_base_id($this->app, $bas_id);
|
||||
$collection = \collection::getByBaseId($this->app, $bas_id);
|
||||
try {
|
||||
if ($collection->get_record_amount() <= 500) {
|
||||
$collection->empty_collection(500);
|
||||
@@ -184,7 +184,7 @@ class CollectionController extends Controller
|
||||
{
|
||||
$success = false;
|
||||
|
||||
$collection = \collection::get_from_base_id($this->app, $bas_id);
|
||||
$collection = \collection::getByBaseId($this->app, $bas_id);
|
||||
|
||||
try {
|
||||
$this->app->getApplicationBox()->write_collection_pic(
|
||||
@@ -224,7 +224,7 @@ class CollectionController extends Controller
|
||||
{
|
||||
$success = false;
|
||||
|
||||
$collection = \collection::get_from_base_id($this->app, $bas_id);
|
||||
$collection = \collection::getByBaseId($this->app, $bas_id);
|
||||
|
||||
try {
|
||||
$this->app->getApplicationBox()->write_collection_pic(
|
||||
@@ -264,7 +264,7 @@ class CollectionController extends Controller
|
||||
{
|
||||
$success = false;
|
||||
|
||||
$collection = \collection::get_from_base_id($this->app, $bas_id);
|
||||
$collection = \collection::getByBaseId($this->app, $bas_id);
|
||||
|
||||
try {
|
||||
$collection->update_logo(null);
|
||||
@@ -323,7 +323,7 @@ class CollectionController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
$collection = \collection::get_from_base_id($this->app, $bas_id);
|
||||
$collection = \collection::getByBaseId($this->app, $bas_id);
|
||||
|
||||
try {
|
||||
$this->app->getApplicationBox()->write_collection_pic(
|
||||
@@ -378,7 +378,7 @@ class CollectionController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
$collection = \collection::get_from_base_id($this->app, $bas_id);
|
||||
$collection = \collection::getByBaseId($this->app, $bas_id);
|
||||
|
||||
try {
|
||||
$this->app->getApplicationBox()->write_collection_pic(
|
||||
@@ -432,7 +432,7 @@ class CollectionController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
$collection = \collection::get_from_base_id($this->app, $bas_id);
|
||||
$collection = \collection::getByBaseId($this->app, $bas_id);
|
||||
|
||||
try {
|
||||
$this->app->getApplicationBox()->write_collection_pic(
|
||||
@@ -468,13 +468,13 @@ class CollectionController extends Controller
|
||||
$success = false;
|
||||
$msg = $this->app->trans('An error occured');
|
||||
|
||||
$collection = \collection::get_from_base_id($this->app, $bas_id);
|
||||
$collection = \collection::getByBaseId($this->app, $bas_id);
|
||||
|
||||
try {
|
||||
if ($collection->get_record_amount() > 0) {
|
||||
$msg = $this->app->trans('Empty the collection before removing');
|
||||
} else {
|
||||
$collection->unmount_collection($this->app);
|
||||
$collection->unmount();
|
||||
$collection->delete();
|
||||
$success = true;
|
||||
$msg = $this->app->trans('Successful removal');
|
||||
@@ -522,10 +522,10 @@ class CollectionController extends Controller
|
||||
{
|
||||
$success = false;
|
||||
|
||||
$collection = \collection::get_from_base_id($this->app, $bas_id);
|
||||
$collection = \collection::getByBaseId($this->app, $bas_id);
|
||||
|
||||
try {
|
||||
$collection->unmount_collection($this->app);
|
||||
$collection->unmount();
|
||||
$success = true;
|
||||
} catch (\Exception $e) {
|
||||
|
||||
@@ -562,7 +562,7 @@ class CollectionController extends Controller
|
||||
|
||||
$success = false;
|
||||
|
||||
$collection = \collection::get_from_base_id($this->app, $bas_id);
|
||||
$collection = \collection::getByBaseId($this->app, $bas_id);
|
||||
|
||||
try {
|
||||
$collection->set_name($name);
|
||||
@@ -594,7 +594,7 @@ class CollectionController extends Controller
|
||||
$this->app->abort(400, $this->app->trans('Invalid labels parameter'));
|
||||
}
|
||||
|
||||
$collection = \collection::get_from_base_id($this->app, $bas_id);
|
||||
$collection = \collection::getByBaseId($this->app, $bas_id);
|
||||
$success = true;
|
||||
|
||||
try {
|
||||
@@ -638,7 +638,7 @@ class CollectionController extends Controller
|
||||
|
||||
$success = false;
|
||||
|
||||
$collection = \collection::get_from_base_id($this->app, $bas_id);
|
||||
$collection = \collection::getByBaseId($this->app, $bas_id);
|
||||
|
||||
try {
|
||||
$collection->set_public_presentation($watermark);
|
||||
@@ -671,7 +671,7 @@ class CollectionController extends Controller
|
||||
{
|
||||
$success = false;
|
||||
|
||||
$collection = \collection::get_from_base_id($this->app, $bas_id);
|
||||
$collection = \collection::getByBaseId($this->app, $bas_id);
|
||||
|
||||
try {
|
||||
$collection->enable($this->app->getApplicationBox());
|
||||
@@ -704,7 +704,7 @@ class CollectionController extends Controller
|
||||
{
|
||||
$success = false;
|
||||
|
||||
$collection = \collection::get_from_base_id($this->app, $bas_id);
|
||||
$collection = \collection::getByBaseId($this->app, $bas_id);
|
||||
|
||||
try {
|
||||
$collection->disable($this->app->getApplicationBox());
|
||||
@@ -736,7 +736,7 @@ class CollectionController extends Controller
|
||||
{
|
||||
/** @var \databox $databox */
|
||||
$databox = $this->app->findDataboxById(\phrasea::sbasFromBas($this->app, $bas_id));
|
||||
$collection = \collection::get_from_base_id($this->app, $bas_id);
|
||||
$collection = \collection::getByBaseId($this->app, $bas_id);
|
||||
$structFields = $suggestedValues = $basePrefs = [];
|
||||
|
||||
/** @var \databox_field $meta */
|
||||
@@ -806,7 +806,7 @@ class CollectionController extends Controller
|
||||
{
|
||||
$success = false;
|
||||
|
||||
$collection = \collection::get_from_base_id($this->app, $bas_id);
|
||||
$collection = \collection::getByBaseId($this->app, $bas_id);
|
||||
$prefs = $request->request->get('str');
|
||||
|
||||
try {
|
||||
@@ -843,7 +843,7 @@ class CollectionController extends Controller
|
||||
*/
|
||||
public function getDetails($bas_id)
|
||||
{
|
||||
$collection = \collection::get_from_base_id($this->app, $bas_id);
|
||||
$collection = \collection::getByBaseId($this->app, $bas_id);
|
||||
|
||||
$out = ['total' => ['totobj' => 0, 'totsiz' => 0, 'mega' => '0', 'giga' => '0'], 'result' => []];
|
||||
|
||||
|
@@ -633,7 +633,7 @@ class DataboxController extends Controller
|
||||
{
|
||||
try {
|
||||
foreach ($request->request->get('order', []) as $data) {
|
||||
$collection = \collection::get_from_base_id($this->app, $data['id']);
|
||||
$collection = \collection::getByBaseId($this->app, $data['id']);
|
||||
$collection->set_ord($data['offset']);
|
||||
}
|
||||
$success = true;
|
||||
@@ -712,7 +712,7 @@ class DataboxController extends Controller
|
||||
} catch (\Exception $e) {
|
||||
return $this->app->redirectPath('admin_database_submit_collection', [
|
||||
'databox_id' => $databox_id,
|
||||
'error' => 'error',
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@@ -56,7 +56,7 @@ class FeedController extends Controller
|
||||
if ($request->request->get('public') == '1') {
|
||||
$feed->setIsPublic(true);
|
||||
} elseif ($request->request->get('base_id')) {
|
||||
$feed->setCollection(\collection::get_from_base_id($this->app, $request->request->get('base_id')));
|
||||
$feed->setCollection(\collection::getByBaseId($this->app, $request->request->get('base_id')));
|
||||
}
|
||||
|
||||
$publisher->setFeed($feed);
|
||||
@@ -106,7 +106,7 @@ class FeedController extends Controller
|
||||
}
|
||||
|
||||
try {
|
||||
$collection = \collection::get_from_base_id($this->app, $request->request->get('base_id'));
|
||||
$collection = \collection::getByBaseId($this->app, $request->request->get('base_id'));
|
||||
} catch (\Exception $e) {
|
||||
$collection = null;
|
||||
}
|
||||
|
@@ -455,7 +455,7 @@ class UserController extends Controller
|
||||
$registrationRepository->getUserRegistrations(
|
||||
$user,
|
||||
array_map(function ($baseId) {
|
||||
return \collection::get_from_base_id($this->app, $baseId);
|
||||
return \collection::getByBaseId($this->app, $baseId);
|
||||
}, $bases)
|
||||
) as $registration) {
|
||||
$registrationManipulator->rejectRegistration($registration);
|
||||
@@ -473,7 +473,7 @@ class UserController extends Controller
|
||||
foreach ($registrationRepository->getUserRegistrations(
|
||||
$user,
|
||||
array_map(function ($baseId) {
|
||||
return \collection::get_from_base_id($this->app, $baseId);
|
||||
return \collection::getByBaseId($this->app, $baseId);
|
||||
}, $bases)
|
||||
) as $registration) {
|
||||
$done[$usr][$registration->getBaseId()] = true;
|
||||
@@ -503,7 +503,7 @@ class UserController extends Controller
|
||||
];
|
||||
|
||||
foreach ($bases as $bas => $isok) {
|
||||
$collection = \collection::get_from_base_id($this->app, $bas);
|
||||
$collection = \collection::getByBaseId($this->app, $bas);
|
||||
$label = $collection->get_label($this->app['locale']);
|
||||
|
||||
if ($isok) {
|
||||
|
@@ -837,7 +837,7 @@ class V1Controller extends Controller
|
||||
return $this->getBadRequestAction($request, 'Missing base_id parameter');
|
||||
}
|
||||
|
||||
$collection = \collection::get_from_base_id($this->app, $request->get('base_id'));
|
||||
$collection = \collection::getByBaseId($this->app, $request->get('base_id'));
|
||||
|
||||
if (!$this->getAclForUser()->has_right_on_base($request->get('base_id'), 'canaddrecord')) {
|
||||
return Result::createError($request, 403, sprintf(
|
||||
@@ -935,7 +935,7 @@ class V1Controller extends Controller
|
||||
$media = $this->app->getMediaFromUri($file->getPathname());
|
||||
$record = $this->findDataboxById($request->get('databox_id'))->get_record($request->get('record_id'));
|
||||
$base_id = $record->getBaseId();
|
||||
$collection = \collection::get_from_base_id($this->app, $base_id);
|
||||
$collection = \collection::getByBaseId($this->app, $base_id);
|
||||
if (!$this->getAclForUser()->has_right_on_base($base_id, 'canaddrecord')) {
|
||||
return Result::createError($request, 403, sprintf(
|
||||
'You do not have access to collection %s', $collection->get_label($this->app['locale.I18n'])
|
||||
@@ -1611,7 +1611,7 @@ class V1Controller extends Controller
|
||||
$record = $databox->get_record($record_id);
|
||||
|
||||
try {
|
||||
$collection = \collection::get_from_base_id($this->app, $request->get('base_id'));
|
||||
$collection = \collection::getByBaseId($this->app, $request->get('base_id'));
|
||||
$record->move_to_collection($collection, $this->getApplicationBox());
|
||||
|
||||
return Result::create($request, ["record" => $this->listRecord($request, $record)])->createResponse();
|
||||
@@ -2067,7 +2067,7 @@ class V1Controller extends Controller
|
||||
*/
|
||||
protected function createStory($data)
|
||||
{
|
||||
$collection = \collection::get_from_base_id($this->app, $data->{'base_id'});
|
||||
$collection = \collection::getByBaseId($this->app, $data->{'base_id'});
|
||||
|
||||
if (!$this->getAclForUser()->has_right_on_base($collection->get_base_id(), 'canaddrecord')) {
|
||||
$this->app->abort(403, sprintf('You can not create a story on this collection %s', $collection->get_base_id()));
|
||||
|
@@ -132,7 +132,7 @@ class PermalinkController extends AbstractDelivery
|
||||
return $this->deliverContentWithCaptionLink($request, $record, $subdef, $watermark, $stamp, $token);
|
||||
}
|
||||
|
||||
$collection = \collection::get_from_base_id($this->app, $record->get_base_id());
|
||||
$collection = \collection::getByBaseId($this->app, $record->get_base_id());
|
||||
switch ($collection->get_pub_wm()) {
|
||||
default:
|
||||
case 'none':
|
||||
|
@@ -58,7 +58,7 @@ class MoveCollectionController extends Controller
|
||||
}
|
||||
|
||||
try {
|
||||
$collection = \collection::get_from_base_id($this->app, $request->request->get('base_id'));
|
||||
$collection = \collection::getByBaseId($this->app, $request->request->get('base_id'));
|
||||
} catch (\Exception_Databox_CollectionNotFound $e) {
|
||||
$datas['message'] = $this->app->trans('Invalid target collection');
|
||||
|
||||
|
@@ -36,7 +36,7 @@ class PropertyController extends Controller
|
||||
]));
|
||||
}
|
||||
|
||||
$databox = current($records->databoxes());
|
||||
$databox = reset($records->databoxes());
|
||||
$statusStructure = $databox->getStatusStructure();
|
||||
$recordsStatuses = [];
|
||||
|
||||
|
@@ -33,7 +33,7 @@ class StoryController extends Controller
|
||||
|
||||
public function postCreateFormAction(Request $request)
|
||||
{
|
||||
$collection = \collection::get_from_base_id($this->app, $request->request->get('base_id'));
|
||||
$collection = \collection::getByBaseId($this->app, $request->request->get('base_id'));
|
||||
|
||||
if (!$this->getAclForUser()->has_right_on_base($collection->get_base_id(), 'canaddrecord')) {
|
||||
throw new AccessDeniedHttpException('You can not create a story on this collection');
|
||||
|
@@ -133,7 +133,7 @@ class UploadController extends Controller
|
||||
$this->getFilesystem()->rename($uploadedFilename, $renamedFilename);
|
||||
|
||||
$media = $this->app->getMediaFromUri($renamedFilename);
|
||||
$collection = \collection::get_from_base_id($this->app, $base_id);
|
||||
$collection = \collection::getByBaseId($this->app, $base_id);
|
||||
|
||||
$lazaretSession = new LazaretSession();
|
||||
$lazaretSession->setUser($this->getAuthenticatedUser());
|
||||
|
@@ -316,7 +316,7 @@ class AccountController extends Controller
|
||||
if (0 !== count($registrations)) {
|
||||
foreach ($registrations as $baseId) {
|
||||
$this->getRegistrationManipulator()
|
||||
->createRegistration($user, \collection::get_from_base_id($this->app, $baseId));
|
||||
->createRegistration($user, \collection::getByBaseId($this->app, $baseId));
|
||||
}
|
||||
$this->app->addFlash('success', $this->app->trans('Your registration requests have been taken into account.'));
|
||||
}
|
||||
|
@@ -70,7 +70,7 @@ class BorderManagerServiceProvider implements ServiceProviderInterface
|
||||
$collections = [];
|
||||
foreach ($checker['collections'] as $base_id) {
|
||||
try {
|
||||
$collections[] = \collection::get_from_base_id($app, $base_id);
|
||||
$collections[] = \collection::getByBaseId($app, $base_id);
|
||||
} catch (\Exception $e) {
|
||||
throw new \InvalidArgumentException('Invalid collection option');
|
||||
}
|
||||
|
@@ -12,7 +12,18 @@
|
||||
namespace Alchemy\Phrasea\Core\Provider;
|
||||
|
||||
use Alchemy\Phrasea\Application as PhraseaApplication;
|
||||
use Alchemy\Phrasea\Collection\CollectionFactory;
|
||||
use Alchemy\Phrasea\Collection\CollectionRepositoryRegistry;
|
||||
use Alchemy\Phrasea\Collection\Factory\ArrayCachedCollectionRepositoryFactory;
|
||||
use Alchemy\Phrasea\Collection\Factory\CachedCollectionRepositoryFactory;
|
||||
use Alchemy\Phrasea\Collection\Factory\DbalCollectionRepositoryFactory;
|
||||
use Alchemy\Phrasea\Collection\Reference\ArrayCacheCollectionReferenceRepository;
|
||||
use Alchemy\Phrasea\Collection\Reference\DbalCollectionReferenceRepository;
|
||||
use Alchemy\Phrasea\Collection\Repository\ArrayCacheCollectionRepository;
|
||||
use Alchemy\Phrasea\Collection\Repository\CachedCollectionRepository;
|
||||
use Alchemy\Phrasea\Collection\Repository\DbalCollectionRepository;
|
||||
use Alchemy\Phrasea\Databox\CachingDataboxRepositoryDecorator;
|
||||
use Alchemy\Phrasea\Databox\DataboxConnectionProvider;
|
||||
use Alchemy\Phrasea\Databox\DataboxFactory;
|
||||
use Alchemy\Phrasea\Databox\DbalDataboxRepository;
|
||||
use Alchemy\Phrasea\Databox\Field\DataboxFieldFactory;
|
||||
@@ -147,6 +158,33 @@ class RepositoriesServiceProvider implements ServiceProviderInterface
|
||||
$app['repo.records.factory'] = $app->protect(function (\databox $databox) use ($app) {
|
||||
return new LegacyRecordRepository($app, $databox);
|
||||
});
|
||||
|
||||
$app['repo.collection-references'] = $app->share(function (PhraseaApplication $app) {
|
||||
$repository = new DbalCollectionReferenceRepository($app->getApplicationBox()->get_connection());
|
||||
|
||||
return new ArrayCacheCollectionReferenceRepository($repository);
|
||||
});
|
||||
$app['repo.collections-registry'] = $app->share(function (PhraseaApplication $app) {
|
||||
$factory = new CollectionFactory($app);
|
||||
$connectionProvider = new DataboxConnectionProvider($app->getApplicationBox());
|
||||
|
||||
$repositoryFactory = new DbalCollectionRepositoryFactory(
|
||||
$connectionProvider,
|
||||
$factory,
|
||||
$app['repo.collection-references']
|
||||
);
|
||||
|
||||
$repositoryFactory = new CachedCollectionRepositoryFactory(
|
||||
$app,
|
||||
$repositoryFactory,
|
||||
$app['cache'],
|
||||
'phrasea.collections'
|
||||
);
|
||||
|
||||
$repositoryFactory = new ArrayCachedCollectionRepositoryFactory($repositoryFactory);
|
||||
|
||||
return new CollectionRepositoryRegistry($app, $repositoryFactory, $app['repo.collection-references']);
|
||||
});
|
||||
}
|
||||
|
||||
public function boot(Application $app)
|
||||
|
23
lib/Alchemy/Phrasea/Databox/DataboxConnectionProvider.php
Normal file
23
lib/Alchemy/Phrasea/Databox/DataboxConnectionProvider.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Alchemy\Phrasea\Databox;
|
||||
|
||||
class DataboxConnectionProvider
|
||||
{
|
||||
|
||||
private $applicationBox;
|
||||
|
||||
public function __construct(\appbox $applicationBox)
|
||||
{
|
||||
$this->applicationBox = $applicationBox;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $databoxId
|
||||
* @return \Doctrine\DBAL\Connection
|
||||
*/
|
||||
public function getConnection($databoxId)
|
||||
{
|
||||
return $this->applicationBox->get_databox($databoxId)->get_connection();
|
||||
}
|
||||
}
|
@@ -227,7 +227,7 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper
|
||||
'users' => $this->users,
|
||||
'users_serial' => implode(';', $this->users),
|
||||
'base_id' => $this->base_id,
|
||||
'collection' => \collection::get_from_base_id($this->app, $this->base_id),
|
||||
'collection' => \collection::getByBaseId($this->app, $this->base_id),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -331,7 +331,7 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper
|
||||
'users' => $this->users,
|
||||
'users_serial' => implode(';', $this->users),
|
||||
'base_id' => $this->base_id,
|
||||
'collection' => \collection::get_from_base_id($this->app, $this->base_id),
|
||||
'collection' => \collection::getByBaseId($this->app, $this->base_id),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -391,7 +391,7 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper
|
||||
'users' => $this->users,
|
||||
'users_serial' => implode(';', $this->users),
|
||||
'base_id' => $this->base_id,
|
||||
'collection' => \collection::get_from_base_id($this->app, $this->base_id),
|
||||
'collection' => \collection::getByBaseId($this->app, $this->base_id),
|
||||
];
|
||||
}
|
||||
|
||||
|
@@ -302,7 +302,7 @@ class Feed implements FeedInterface
|
||||
public function getCollection(Application $app)
|
||||
{
|
||||
if ($this->getBaseId() !== null) {
|
||||
return \collection::get_from_base_id($app, $this->getBaseId());
|
||||
return \collection::getByBaseId($app, $this->getBaseId());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -211,7 +211,7 @@ class LazaretFile
|
||||
*/
|
||||
public function getCollection(Application $app)
|
||||
{
|
||||
return \collection::get_from_base_id($app, $this->getBaseId());
|
||||
return \collection::getByBaseId($app, $this->getBaseId());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -141,7 +141,7 @@ class Registration
|
||||
*/
|
||||
public function getCollection(Application $app)
|
||||
{
|
||||
return \collection::get_from_base_id($app, $this->baseId);
|
||||
return \collection::getByBaseId($app, $this->baseId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -350,7 +350,7 @@ class PDF
|
||||
}
|
||||
}
|
||||
|
||||
$collection = \collection::get_from_base_id($this->app, $rec->get_base_id());
|
||||
$collection = \collection::getByBaseId($this->app, $rec->get_base_id());
|
||||
|
||||
$vn = "";
|
||||
if (false !== $str = simplexml_load_string($collection->get_prefs())) {
|
||||
|
@@ -481,7 +481,7 @@ class SearchEngineOptions
|
||||
break;
|
||||
case in_array($key, ['collections', 'business_fields']):
|
||||
$value = array_map(function ($base_id) use ($app) {
|
||||
return \collection::get_from_base_id($app, $base_id);
|
||||
return \collection::getByBaseId($app, $base_id);
|
||||
}, $value);
|
||||
break;
|
||||
}
|
||||
@@ -572,7 +572,7 @@ class SearchEngineOptions
|
||||
$bas = [];
|
||||
foreach ($selected_bases as $bas_id) {
|
||||
try {
|
||||
$bas[$bas_id] = \collection::get_from_base_id($app, $bas_id);
|
||||
$bas[$bas_id] = \collection::getByBaseId($app, $bas_id);
|
||||
} catch (\Exception_Databox_CollectionNotFound $e) {
|
||||
// Ignore
|
||||
}
|
||||
|
@@ -868,7 +868,7 @@ class ArchiveJob extends AbstractJob
|
||||
}
|
||||
|
||||
try {
|
||||
$collection = \collection::get_from_coll_id($app, $databox, (int) $cid);
|
||||
$collection = \collection::getByCollectionId($app, $databox, (int) $cid);
|
||||
if ($captionFileName === null) {
|
||||
$story = $this->createStory($app, $collection, $path . '/' . $representationFileName, null, $stat0, $stat1);
|
||||
} else {
|
||||
@@ -1203,7 +1203,7 @@ class ArchiveJob extends AbstractJob
|
||||
}
|
||||
|
||||
try {
|
||||
$collection = \collection::get_from_coll_id($app, $databox, (int) $cid);
|
||||
$collection = \collection::getByCollectionId($app, $databox, (int) $cid);
|
||||
|
||||
if ($captionFileName === null) {
|
||||
$this->createRecord($app, $collection, $path . '/' . $file, null, $grp_rid, null, $stat0, $stat1);
|
||||
|
@@ -61,7 +61,7 @@ class EmptyCollectionJob extends AbstractJob
|
||||
|
||||
$baseId = (string) $settings->base_id;
|
||||
|
||||
$collection = \collection::get_from_base_id($app, $baseId);
|
||||
$collection = \collection::getByBaseId($app, $baseId);
|
||||
$collection->empty_collection(200);
|
||||
|
||||
if (0 === $collection->get_record_amount()) {
|
||||
|
@@ -82,7 +82,7 @@ class RecordMoverJob extends AbstractJob
|
||||
case 'UPDATE':
|
||||
// change collection ?
|
||||
if (array_key_exists('coll', $row)) {
|
||||
$coll = \collection::get_from_coll_id($app, $databox, $row['coll']);
|
||||
$coll = \collection::getByCollectionId($app, $databox, $row['coll']);
|
||||
$rec->move_to_collection($coll, $app['phraseanet.appbox']);
|
||||
if ($logsql) {
|
||||
$this->log('debug', sprintf("on sbas %s move rid %s to coll %s \n", $row['sbas_id'], $row['record_id'], $coll->get_coll_id()));
|
||||
|
@@ -731,7 +731,7 @@ class ACL implements cache_cacheableInterface
|
||||
}
|
||||
|
||||
try {
|
||||
$ret[$base_id] = collection::get_from_base_id($this->app, $base_id);
|
||||
$ret[$base_id] = collection::getByBaseId($this->app, $base_id);
|
||||
} catch (\Exception $e) {
|
||||
|
||||
}
|
||||
@@ -1780,7 +1780,7 @@ class ACL implements cache_cacheableInterface
|
||||
$collections = [];
|
||||
|
||||
foreach ($rs as $row) {
|
||||
$collections[] = \collection::get_from_base_id($this->app, $row['base_id']);
|
||||
$collections[] = \collection::getByBaseId($this->app, $row['base_id']);
|
||||
}
|
||||
|
||||
return $collections;
|
||||
|
@@ -10,13 +10,14 @@
|
||||
*/
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Collection\CollectionService;
|
||||
use Alchemy\Phrasea\Core\Configuration\AccessRestriction;
|
||||
use Alchemy\Phrasea\Core\Connection\ConnectionSettings;
|
||||
use Alchemy\Phrasea\Core\Version\AppboxVersionRepository;
|
||||
use Alchemy\Phrasea\Databox\DataboxConnectionProvider;
|
||||
use Alchemy\Phrasea\Databox\DataboxRepository;
|
||||
use Doctrine\ORM\Tools\SchemaTool;
|
||||
use MediaAlchemyst\Alchemyst;
|
||||
use MediaAlchemyst\Specification\Image as ImageSpecification;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\HttpFoundation\File\File as SymfoFile;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
@@ -42,6 +43,10 @@ class appbox extends base
|
||||
* @var \databox[]
|
||||
*/
|
||||
protected $databoxes;
|
||||
/**
|
||||
* @var CollectionService
|
||||
*/
|
||||
protected $collectionService;
|
||||
|
||||
public function __construct(Application $app)
|
||||
{
|
||||
@@ -258,12 +263,12 @@ class appbox extends base
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $sbas_id
|
||||
* @param int $sbas_id
|
||||
* @return databox
|
||||
*/
|
||||
public function get_databox($sbas_id)
|
||||
{
|
||||
$databoxes = $this->get_databoxes();
|
||||
$databoxes = $this->getDataboxRepository()->findAll();
|
||||
|
||||
if (!isset($databoxes[$sbas_id]) && !array_key_exists($sbas_id, $databoxes)) {
|
||||
throw new NotFoundHttpException('Databox `' . $sbas_id . '` not found');
|
||||
@@ -314,6 +319,19 @@ class appbox extends base
|
||||
parent::delete_data_from_cache($option);
|
||||
}
|
||||
|
||||
public function getCollectionService()
|
||||
{
|
||||
if ($this->collectionService === null) {
|
||||
$this->collectionService = new CollectionService(
|
||||
$this->app,
|
||||
$this->connection,
|
||||
new DataboxConnectionProvider($this)
|
||||
);
|
||||
}
|
||||
|
||||
return $this->collectionService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return AccessRestriction
|
||||
*/
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -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'];
|
||||
|
@@ -110,7 +110,7 @@ class patch_370alpha7a extends patchAbstract
|
||||
|
||||
$media = $app->getMediaFromUri($filePath);
|
||||
|
||||
$collection = \collection::get_from_base_id($app, $row['base_id']);
|
||||
$collection = \collection::getByBaseId($app, $row['base_id']);
|
||||
|
||||
$borderFile = new \Alchemy\Phrasea\Border\File($app, $media, $collection);
|
||||
|
||||
|
@@ -91,7 +91,7 @@ class patch_390alpha13a implements patchInterface
|
||||
}
|
||||
|
||||
try {
|
||||
$collection = \collection::get_from_base_id($app, $row['base_id']);
|
||||
$collection = \collection::getByBaseId($app, $row['base_id']);
|
||||
} catch (\Exception $e) {
|
||||
$app['monolog']->addInfo(sprintf(
|
||||
'Patch %s : Registration for user (%s) could not be turn into doctrine entity as base with id (%s) could not be found.',
|
||||
|
@@ -10,6 +10,8 @@
|
||||
*/
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Collection\CollectionRepositoryRegistry;
|
||||
use Alchemy\Phrasea\Collection\Reference\CollectionReferenceRepository;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
|
||||
class phrasea
|
||||
@@ -98,49 +100,28 @@ class phrasea
|
||||
|
||||
public static function sbasFromBas(Application $app, $base_id)
|
||||
{
|
||||
if (!self::$_bas2sbas) {
|
||||
try {
|
||||
$data = $app->getApplicationBox()->get_data_from_cache(self::CACHE_SBAS_FROM_BAS);
|
||||
if (!$data) {
|
||||
throw new \Exception('Could not get sbas from cache');
|
||||
}
|
||||
self::$_bas2sbas = $data;
|
||||
} catch (\Exception $e) {
|
||||
$sql = 'SELECT base_id, sbas_id FROM bas';
|
||||
$stmt = $app->getApplicationBox()->get_connection()->prepare($sql);
|
||||
$stmt->execute();
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
/** @var CollectionReferenceRepository $repository */
|
||||
$repository = $app['repo.collection-references'];
|
||||
$reference = $repository->find($base_id);
|
||||
|
||||
foreach ($rs as $row) {
|
||||
self::$_bas2sbas[$row['base_id']] = (int) $row['sbas_id'];
|
||||
}
|
||||
|
||||
$app->getApplicationBox()->set_data_to_cache(self::$_bas2sbas, self::CACHE_SBAS_FROM_BAS);
|
||||
}
|
||||
if ($reference) {
|
||||
return $reference->getDataboxId();
|
||||
}
|
||||
|
||||
return isset(self::$_bas2sbas[$base_id]) ? self::$_bas2sbas[$base_id] : false;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function baseFromColl($sbas_id, $coll_id, Application $app)
|
||||
{
|
||||
if (!self::$_coll2bas) {
|
||||
$conn = $app->getApplicationBox()->get_connection();
|
||||
$sql = 'SELECT base_id, server_coll_id, sbas_id FROM bas';
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute();
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
/** @var CollectionReferenceRepository $repository */
|
||||
$repository = $app['repo.collection-references'];
|
||||
$reference = $repository->findByCollectionId($sbas_id, $coll_id);
|
||||
|
||||
foreach ($rs as $row) {
|
||||
if (!isset(self::$_coll2bas[$row['sbas_id']]))
|
||||
self::$_coll2bas[$row['sbas_id']] = [];
|
||||
self::$_coll2bas[$row['sbas_id']][$row['server_coll_id']] = (int) $row['base_id'];
|
||||
}
|
||||
if ($reference) {
|
||||
return $reference->getBaseId();
|
||||
}
|
||||
|
||||
return isset(self::$_coll2bas[$sbas_id][$coll_id]) ? self::$_coll2bas[$sbas_id][$coll_id] : false;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function reset_baseDatas(appbox $appbox)
|
||||
@@ -175,20 +156,15 @@ class phrasea
|
||||
|
||||
public static function collFromBas(Application $app, $base_id)
|
||||
{
|
||||
if (!self::$_bas2coll) {
|
||||
$conn = $app->getApplicationBox()->get_connection();
|
||||
$sql = 'SELECT base_id, server_coll_id FROM bas';
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute();
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
/** @var CollectionReferenceRepository $repository */
|
||||
$repository = $app['repo.collection-references'];
|
||||
$reference = $repository->find($base_id);
|
||||
|
||||
foreach ($rs as $row) {
|
||||
self::$_bas2coll[$row['base_id']] = (int) $row['server_coll_id'];
|
||||
}
|
||||
if ($reference) {
|
||||
return $reference->getCollectionId();
|
||||
}
|
||||
|
||||
return isset(self::$_bas2coll[$base_id]) ? self::$_bas2coll[$base_id] : false;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function sbas_names($sbas_id, Application $app)
|
||||
@@ -234,27 +210,28 @@ class phrasea
|
||||
|
||||
public static function bas_labels($base_id, Application $app)
|
||||
{
|
||||
if (!self::$_bas_labels) {
|
||||
try {
|
||||
self::$_bas_labels = $app->getApplicationBox()->get_data_from_cache(self::CACHE_BAS_LABELS);
|
||||
} catch (\Exception $e) {
|
||||
foreach ($app->getDataboxes() as $databox) {
|
||||
foreach ($databox->get_collections() as $collection) {
|
||||
self::$_bas_labels[$collection->get_base_id()] = [
|
||||
'fr' => $collection->get_label('fr'),
|
||||
'en' => $collection->get_label('en'),
|
||||
'de' => $collection->get_label('de'),
|
||||
'nl' => $collection->get_label('nl'),
|
||||
];
|
||||
}
|
||||
}
|
||||
/** @var CollectionReferenceRepository $repository */
|
||||
$referenceRepository = $app['repo.collection-references'];
|
||||
$reference = $referenceRepository->find($base_id);
|
||||
|
||||
$app->getApplicationBox()->set_data_to_cache(self::$_bas_labels, self::CACHE_BAS_LABELS);
|
||||
}
|
||||
if (! $reference) {
|
||||
return 'Unknown collection';
|
||||
}
|
||||
|
||||
if (isset(self::$_bas_labels[$base_id]) && isset(self::$_bas_labels[$base_id][$app['locale']])) {
|
||||
return self::$_bas_labels[$base_id][$app['locale']];
|
||||
/** @var CollectionRepositoryRegistry $collectionRepositoryRegistry */
|
||||
$collectionRepositoryRegistry = $app['repo.collections-registry'];
|
||||
$collectionRepository = $collectionRepositoryRegistry->getRepositoryByDatabox($reference->getDataboxId());
|
||||
|
||||
$collection = $collectionRepository->find($reference->getCollectionId());
|
||||
|
||||
if (! $collection) {
|
||||
throw new \RuntimeException('Missing collection ' . $base_id . '.');
|
||||
}
|
||||
|
||||
$labels = $collection->getCollection()->getLabels();
|
||||
|
||||
if (isset($labels[$app['locale']])) {
|
||||
return $labels[$app['locale']];
|
||||
}
|
||||
|
||||
return 'Unknown collection';
|
||||
|
@@ -346,7 +346,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
*/
|
||||
public function get_collection()
|
||||
{
|
||||
return \collection::get_from_coll_id($this->app, $this->databox, $this->collection_id);
|
||||
return \collection::getByCollectionId($this->app, $this->databox, $this->collection_id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -30,7 +30,7 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
self::$DI['app']['acl'] = new ACLProvider(self::$DI['app']);
|
||||
foreach (self::$createdCollections as $collection) {
|
||||
try {
|
||||
$collection->unmount_collection(self::$DI['app']);
|
||||
$collection->unmount();
|
||||
} catch (\Exception $e) {
|
||||
|
||||
}
|
||||
@@ -154,7 +154,7 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$json = $this->getJson(self::$DI['client']->getResponse());
|
||||
$this->assertTrue($json->success);
|
||||
|
||||
$collection = $collection = \collection::get_from_base_id(self::$DI['app'], self::$DI['collection']->get_base_id());
|
||||
$collection = $collection = \collection::getByBaseId(self::$DI['app'], self::$DI['collection']->get_base_id());
|
||||
$this->assertTrue( ! ! strrpos($collection->get_prefs(), 'my_new_value'));
|
||||
unset($collection);
|
||||
}
|
||||
@@ -212,7 +212,7 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$json = $this->getJson(self::$DI['client']->getResponse());
|
||||
$this->assertTrue($json->success);
|
||||
|
||||
$collection = \collection::get_from_base_id(self::$DI['app'], self::$DI['collection']->get_base_id());
|
||||
$collection = \collection::getByBaseId(self::$DI['app'], self::$DI['collection']->get_base_id());
|
||||
$this->assertTrue($collection->is_active());
|
||||
unset($collection);
|
||||
}
|
||||
@@ -252,7 +252,7 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
|
||||
$json = $this->getJson(self::$DI['client']->getResponse());
|
||||
$this->assertTrue($json->success);
|
||||
$collection = \collection::get_from_base_id(self::$DI['app'], self::$DI['collection']->get_base_id());
|
||||
$collection = \collection::getByBaseId(self::$DI['app'], self::$DI['collection']->get_base_id());
|
||||
$this->assertFalse($collection->is_active());
|
||||
unset($collection);
|
||||
}
|
||||
@@ -335,7 +335,7 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
|
||||
$json = $this->getJson(self::$DI['client']->getResponse());
|
||||
$this->assertTrue($json->success);
|
||||
$collection = \collection::get_from_base_id(self::$DI['app'], self::$DI['collection']->get_base_id());
|
||||
$collection = \collection::getByBaseId(self::$DI['app'], self::$DI['collection']->get_base_id());
|
||||
$this->assertNotNull($collection->get_pub_wm());
|
||||
unset($collection);
|
||||
}
|
||||
@@ -440,7 +440,7 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$json = $this->getJson(self::$DI['client']->getResponse());
|
||||
$this->assertTrue($json->success);
|
||||
$this->assertEquals($collection->get_name(), 'test_rename_coll');
|
||||
$collection->unmount_collection(self::$DI['app']);
|
||||
$collection->unmount();
|
||||
$collection->delete();
|
||||
}
|
||||
|
||||
@@ -469,7 +469,7 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$this->assertEquals($collection->get_label('nl'), 'netherlands label');
|
||||
$this->assertEquals($collection->get_label('fr'), 'label français');
|
||||
$this->assertEquals($collection->get_label('en'), 'label à l\'anglaise');
|
||||
$collection->unmount_collection(self::$DI['app']);
|
||||
$collection->unmount();
|
||||
$collection->delete();
|
||||
}
|
||||
|
||||
@@ -832,7 +832,7 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$json = $this->getJson(self::$DI['client']->getResponse());
|
||||
$this->assertTrue($json->success);
|
||||
try {
|
||||
\collection::get_from_base_id(self::$DI['app'], $collection->get_base_id());
|
||||
\collection::getByBaseId(self::$DI['app'], $collection->get_base_id());
|
||||
$this->fail('Collection not deleted');
|
||||
} catch (\Exception $e) {
|
||||
|
||||
@@ -902,7 +902,7 @@ class AdminCollectionTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$this->assertTrue($json->success);
|
||||
|
||||
try {
|
||||
\collection::get_from_base_id(self::$DI['app'], $collection->get_base_id());
|
||||
\collection::getByBaseId(self::$DI['app'], $collection->get_base_id());
|
||||
$this->fail('Collection not unmounted');
|
||||
} catch (\Exception_Databox_CollectionNotFound $e) {
|
||||
|
||||
|
@@ -34,7 +34,7 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
|
||||
foreach (self::$createdCollections as $collection) {
|
||||
try {
|
||||
$collection->unmount_collection(self::$DI['app']);
|
||||
$collection->unmount();
|
||||
} catch (\Exception $e) {
|
||||
|
||||
}
|
||||
@@ -513,7 +513,7 @@ class DataboxTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$this->setAdmin(true);
|
||||
|
||||
$collection = $this->createOneCollection();
|
||||
$collection->unmount_collection(self::$DI['app']);
|
||||
$collection->unmount();
|
||||
|
||||
self::$DI['client']->request('POST', '/admin/databox/' . $collection->get_sbas_id() . '/collection/' . $collection->get_coll_id() . '/mount/', [
|
||||
'othcollsel' => self::$DI['collection']->get_base_id()
|
||||
|
@@ -494,7 +494,7 @@ class ACLTest extends \PhraseanetTestCase
|
||||
|
||||
foreach ($bases as $base_id) {
|
||||
try {
|
||||
$collection = collection::get_from_base_id(self::$DI['app'], $base_id);
|
||||
$collection = collection::getByBaseId(self::$DI['app'], $base_id);
|
||||
$this->assertTrue($collection instanceof collection);
|
||||
$this->assertEquals($base_id, $collection->get_base_id());
|
||||
unset($collection);
|
||||
|
@@ -196,15 +196,15 @@ abstract class PhraseanetTestCase extends WebTestCase
|
||||
});
|
||||
|
||||
self::$DI['collection'] = self::$DI->share(function ($DI) {
|
||||
return collection::get_from_base_id($DI['app'], self::$fixtureIds['collection']['coll']);
|
||||
return collection::getByBaseId($DI['app'], self::$fixtureIds['collection']['coll']);
|
||||
});
|
||||
|
||||
self::$DI['collection_no_access'] = self::$DI->share(function ($DI) {
|
||||
return collection::get_from_base_id($DI['app'], self::$fixtureIds['collection']['coll_no_access']);
|
||||
return collection::getByBaseId($DI['app'], self::$fixtureIds['collection']['coll_no_access']);
|
||||
});
|
||||
|
||||
self::$DI['collection_no_access_by_status'] = self::$DI->share(function ($DI) {
|
||||
return collection::get_from_base_id($DI['app'], self::$fixtureIds['collection']['coll_no_status']);
|
||||
return collection::getByBaseId($DI['app'], self::$fixtureIds['collection']['coll_no_status']);
|
||||
});
|
||||
|
||||
self::$DI['lazaret_1'] = self::$DI->share(function ($DI) {
|
||||
|
@@ -175,7 +175,7 @@ class collectionTest extends \PhraseanetTestCase
|
||||
|
||||
public function testGet_from_coll_id()
|
||||
{
|
||||
$temp_coll = collection::get_from_coll_id(self::$DI['app'], self::$object->get_databox(), self::$object->get_coll_id());
|
||||
$temp_coll = collection::getByCollectionId(self::$DI['app'], self::$object->get_databox(), self::$object->get_coll_id());
|
||||
$this->assertEquals(self::$object->get_coll_id(), $temp_coll->get_coll_id());
|
||||
$this->assertEquals(self::$object->get_base_id(), $temp_coll->get_base_id());
|
||||
}
|
||||
|
Reference in New Issue
Block a user