mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 18:03:17 +00:00
Avoid using getPartialReference
This commit is contained in:
@@ -35,6 +35,7 @@ before_script:
|
||||
- sudo mysql -e "GRANT ALL PRIVILEGES ON ab_unitTests.* TO 'phraseaUnitTests'@'localhost' IDENTIFIED BY 'iWvGxPE8' WITH GRANT OPTION"
|
||||
- sudo mysql -e "GRANT ALL PRIVILEGES ON db_unitTests.* TO 'phraseaUnitTests'@'localhost' IDENTIFIED BY 'iWvGxPE8' WITH GRANT OPTION"
|
||||
- mysql -e 'SET @@global.sql_mode= "";'
|
||||
- mysql -e 'SET @@global.max_allowed_packet= 33554432;'
|
||||
- mysql -e 'SET @@global.wait_timeout= 999999;'
|
||||
- git clone git://github.com/alchemy-fr/Phraseanet-Extension.git
|
||||
- sh -c "cd Phraseanet-Extension && phpize && ./configure --quiet && make -j --quiet && sudo make install"
|
||||
|
@@ -14,6 +14,7 @@ namespace Alchemy\Phrasea\Model\Repositories;
|
||||
use Alchemy\Phrasea\Model\Entities\UsrListOwner;
|
||||
use Alchemy\Phrasea\Model\Entities\UsrList;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\NoResultException;
|
||||
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
|
@@ -16,6 +16,7 @@ use Alchemy\Phrasea\Model\Entities\User;
|
||||
use Alchemy\Phrasea\Model\Entities\FtpCredential;
|
||||
use Doctrine\DBAL\Migrations\Configuration\Configuration;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\NoResultException;
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\ORM\Query\ResultSetMapping;
|
||||
|
||||
@@ -268,7 +269,7 @@ class Upgrade39Users implements PreSchemaUpgradeInterface
|
||||
}
|
||||
|
||||
$sql = sprintf('SELECT id FROM %s WHERE %s %s', $tableName, $field, $wrongIds);
|
||||
$rs = $em->getConnection()->fetchAll(\PDO::FETCH_COLUMN);
|
||||
$rs = $em->getConnection()->executeQuery($sql)->fetchAll(\PDO::FETCH_COLUMN);
|
||||
|
||||
if (count($rs) === 0) {
|
||||
return;
|
||||
@@ -379,9 +380,15 @@ class Upgrade39Users implements PreSchemaUpgradeInterface
|
||||
$rs = $em->getConnection()->fetchAll($sql);
|
||||
|
||||
foreach ($rs as $row) {
|
||||
if (null === $user = $em->getPartialReference('Phraseanet:User', $row['usr_id'])) {
|
||||
try {
|
||||
$user = $em->createQuery('SELECT PARTIAL u.{id} FROM Phraseanet:User u WHERE u.id = :id')
|
||||
->setParameters(['id' => $row['usr_id']])
|
||||
->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true)
|
||||
->getSingleResult();
|
||||
} catch (NoResultException $e) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$credential = new FtpCredential();
|
||||
$credential->setActive($row['activeFTP']);
|
||||
$credential->setAddress($row['addrFTP']);
|
||||
|
@@ -17,7 +17,7 @@ use Alchemy\Phrasea\Model\Entities\FeedPublisher;
|
||||
use Gedmo\Timestampable\TimestampableListener;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
class patch_320alpha4b implements patchInterface
|
||||
class patch_320alpha4b extends patchAbstract
|
||||
{
|
||||
/** @var string */
|
||||
private $release = '3.2.0-alpha.4';
|
||||
@@ -86,8 +86,9 @@ class patch_320alpha4b implements patchInterface
|
||||
|
||||
$app['EM']->getEventManager()->removeEventSubscriber(new TimestampableListener());
|
||||
foreach ($rs as $row) {
|
||||
$user = $app['EM']->getPartialReference('Phraseanet:User', $row['usr_id']);
|
||||
|
||||
if (null === $user = $this->loadUser($app['EM'], $row['usr_id'])) {
|
||||
continue;
|
||||
}
|
||||
$feed = $this->get_feed($appbox, $user, $row['pub_restrict'], $row['homelink'], $app);
|
||||
|
||||
if (! $feed instanceof Feed) {
|
||||
|
@@ -15,7 +15,7 @@ use Alchemy\Phrasea\Model\Entities\LazaretSession;
|
||||
use MediaAlchemyst\Exception\ExceptionInterface as MediaAlchemystException;
|
||||
use MediaAlchemyst\Specification\Image as ImageSpec;
|
||||
|
||||
class patch_370alpha7a implements patchInterface
|
||||
class patch_370alpha7a extends patchAbstract
|
||||
{
|
||||
/** @var string */
|
||||
private $release = '3.7.0-alpha.7';
|
||||
@@ -88,6 +88,9 @@ class patch_370alpha7a implements patchInterface
|
||||
|
||||
foreach ($rs as $row) {
|
||||
$filePath = $app['root.path'] . '/tmp/lazaret/' . $row['filepath'];
|
||||
if (null === $user = $this->loadUser($app['EM'], $row['usr_id'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (file_exists($filePath)) {
|
||||
$spec = new ImageSpec();
|
||||
@@ -109,8 +112,6 @@ class patch_370alpha7a implements patchInterface
|
||||
|
||||
$borderFile = new \Alchemy\Phrasea\Border\File($app, $media, $collection);
|
||||
|
||||
$user = $user = $app['EM']->getPartialReference('Phraseanet:User', $row['usr_id']);
|
||||
|
||||
$lazaretSession = new LazaretSession();
|
||||
$lazaretSession->setUser($user);
|
||||
|
||||
|
@@ -13,7 +13,7 @@ use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Model\Entities\Session;
|
||||
use Alchemy\Phrasea\Model\Entities\SessionModule;
|
||||
|
||||
class patch_380alpha11a implements patchInterface
|
||||
class patch_380alpha11a extends patchAbstract
|
||||
{
|
||||
/** @var string */
|
||||
private $release = '3.8.0-alpha.11';
|
||||
@@ -72,6 +72,10 @@ class patch_380alpha11a implements patchInterface
|
||||
}
|
||||
|
||||
foreach ($rs as $row) {
|
||||
if (null === $user = $this->loadUser($app['EM'], $row['usr_id'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$created = $updated = null;
|
||||
if ('0000-00-00 00:00:00' !== $row['created_on']) {
|
||||
$created = \DateTime::createFromFormat('Y-m-d H:i:s', $row['created_on']);
|
||||
@@ -80,8 +84,6 @@ class patch_380alpha11a implements patchInterface
|
||||
$updated = \DateTime::createFromFormat('Y-m-d H:i:s', $row['lastaccess']);
|
||||
}
|
||||
|
||||
$user = $app['EM']->getPartialReference('Phraseanet:User', $row['usr_id']);
|
||||
|
||||
$session = new Session();
|
||||
$session
|
||||
->setUser($user)
|
||||
|
@@ -10,8 +10,9 @@
|
||||
*/
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Doctrine\ORM\NoResultException;
|
||||
|
||||
class patch_383alpha2a implements patchInterface
|
||||
class patch_383alpha2a extends patchAbstract
|
||||
{
|
||||
/** @var string */
|
||||
private $release = '3.8.3-alpha.2';
|
||||
@@ -64,8 +65,14 @@ class patch_383alpha2a implements patchInterface
|
||||
$stmt->closeCursor();
|
||||
|
||||
foreach ($rows as $row) {
|
||||
if (null !== $vsession = $app['EM']->getPartialReference('Phraseanet:ValidationSession', $row['validation_session_id'])) {
|
||||
try {
|
||||
$vsession = $app['EM']->createQuery('SELECT PARTIAL s.{id} FROM Phraseanet:ValidationSession s WHERE s.id = :id')
|
||||
->setParameters(['id' => $row['validation_session_id']])
|
||||
->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true)
|
||||
->getSingleResult();
|
||||
$app['EM']->remove($vsession);
|
||||
} catch (NoResultException $e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -12,9 +12,10 @@
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Model\Entities\Order;
|
||||
use Alchemy\Phrasea\Model\Entities\OrderElement;
|
||||
use Doctrine\ORM\NoResultException;
|
||||
use Gedmo\Timestampable\TimestampableListener;
|
||||
|
||||
class patch_390alpha1a implements patchInterface
|
||||
class patch_390alpha1a extends patchAbstract
|
||||
{
|
||||
/** @var string */
|
||||
private $release = '3.9.0-alpha.1';
|
||||
@@ -91,7 +92,16 @@ class patch_390alpha1a implements patchInterface
|
||||
$todo = $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$user = $em->getPartialReference('Phraseanet:User', $row['usr_id']);
|
||||
$user = $this->loadUser($app['EM'], $row['usr_id']);
|
||||
|
||||
try {
|
||||
$basket = $app['EM']->createQuery('SELECT PARTIAL b.{id} FROM Phraseanet:Basket b WHERE b.id = :id')
|
||||
->setParameters(['id' => $row['ssel_id']])
|
||||
->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true)
|
||||
->getSingleResult();
|
||||
} catch (NoResultException $e) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$order = new Order();
|
||||
$order->setUser($user)
|
||||
@@ -99,7 +109,7 @@ class patch_390alpha1a implements patchInterface
|
||||
->setOrderUsage($row['usage'])
|
||||
->setDeadline(new \DateTime($row['deadline']))
|
||||
->setCreatedOn(new \DateTime($row['created_on']))
|
||||
->setBasket($em->getPartialReference('Phraseanet:Basket', $row['ssel_id']));
|
||||
->setBasket($basket);
|
||||
|
||||
$em->persist($order);
|
||||
|
||||
@@ -114,10 +124,11 @@ class patch_390alpha1a implements patchInterface
|
||||
|
||||
foreach ($elements as $element) {
|
||||
$orderElement = new OrderElement();
|
||||
$user = $this->loadUser($app['EM'], $row['usr_id']);
|
||||
$orderElement->setBaseId($element['base_id'])
|
||||
->setDeny($element['deny'] === null ? null : (Boolean) $element['deny'])
|
||||
->setOrder($order)
|
||||
->setOrderMaster($em->getPartialReference('Phraseanet:User',$element['order_master_id']))
|
||||
->setOrderMaster($user)
|
||||
->setRecordId($element['record_id']);
|
||||
|
||||
$order->addElement($orderElement);
|
||||
|
@@ -12,7 +12,7 @@
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Model\Entities\UserQuery;
|
||||
|
||||
class patch_390alpha3a implements patchInterface
|
||||
class patch_390alpha3a extends patchAbstract
|
||||
{
|
||||
/** @var string */
|
||||
private $release = '3.9.0-alpha.3';
|
||||
@@ -73,7 +73,9 @@ class patch_390alpha3a implements patchInterface
|
||||
$em = $app['EM'];
|
||||
|
||||
foreach ($rs as $row) {
|
||||
$user = $em->getPartialReference('Phraseanet:User', $row['usr_id']);
|
||||
if (null === $user = $this->loadUser($app['EM'], $row['usr_id'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$userQuery = new UserQuery();
|
||||
$userQuery->setQuery($row['query']);
|
||||
|
@@ -12,7 +12,7 @@
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Model\Entities\UserSetting;
|
||||
|
||||
class patch_390alpha4a implements patchInterface
|
||||
class patch_390alpha4a extends patchAbstract
|
||||
{
|
||||
/** @var string */
|
||||
private $release = '3.9.0-alpha.4';
|
||||
@@ -77,7 +77,9 @@ class patch_390alpha4a implements patchInterface
|
||||
continue;
|
||||
}
|
||||
|
||||
$user = $em->getPartialReference('Phraseanet:User', $row['usr_id']);
|
||||
if (null === $user = $this->loadUser($app['EM'], $row['usr_id'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$userSetting = new UserSetting();
|
||||
$userSetting->setName($row['prop']);
|
||||
|
@@ -12,7 +12,7 @@
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Model\Entities\UserNotificationSetting;
|
||||
|
||||
class patch_390alpha5a implements patchInterface
|
||||
class patch_390alpha5a extends patchAbstract
|
||||
{
|
||||
/** @var string */
|
||||
private $release = '3.9.0-alpha.5';
|
||||
@@ -74,7 +74,9 @@ class patch_390alpha5a implements patchInterface
|
||||
$em = $app['EM'];
|
||||
|
||||
foreach ($rs as $row) {
|
||||
$user = $em->getPartialReference('Phraseanet:User', $row['usr_id']);
|
||||
if (null === $user = $this->loadUser($app['EM'], $row['usr_id'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$userSetting = new UserNotificationSetting();
|
||||
$userSetting->setName($row['prop']);
|
||||
|
@@ -15,7 +15,7 @@ use Alchemy\Phrasea\Model\Entities\FtpExportElement;
|
||||
use Gedmo\Timestampable\TimestampableListener;
|
||||
use Doctrine\ORM\NoResultException;
|
||||
|
||||
class patch_390alpha6a implements patchInterface
|
||||
class patch_390alpha6a extends patchAbstract
|
||||
{
|
||||
/** @var string */
|
||||
private $release = '3.9.0-alpha.6';
|
||||
@@ -94,7 +94,7 @@ class patch_390alpha6a implements patchInterface
|
||||
$n = 0;
|
||||
|
||||
foreach ($rs as $row) {
|
||||
if (null === $user = $em->getPartialReference('Phraseanet:User', $row['usr_id'])) {
|
||||
if (null === $user = $this->loadUser($app['EM'], $row['usr_id'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@@ -18,7 +18,7 @@ use Alchemy\Phrasea\Model\Entities\FeedPublisher;
|
||||
use Alchemy\Phrasea\Model\Entities\FeedToken;
|
||||
use Doctrine\ORM\Query\ResultSetMapping;
|
||||
|
||||
class patch_390alpha7a implements patchInterface
|
||||
class patch_390alpha7a extends patchAbstract
|
||||
{
|
||||
/** @var string */
|
||||
private $release = '3.9.0-alpha.7';
|
||||
@@ -133,7 +133,9 @@ class patch_390alpha7a implements patchInterface
|
||||
$fpRes = $fpStmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
foreach ($fpRes as $fpRow) {
|
||||
$user = $em->getPartialReference('Phraseanet:User', $fpRow['usr_id']);
|
||||
if (null === $user = $this->loadUser($app['EM'], $fpRow['usr_id'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$feedPublisher = new FeedPublisher();
|
||||
$feedPublisher->setFeed($feed);
|
||||
@@ -179,7 +181,9 @@ class patch_390alpha7a implements patchInterface
|
||||
$ftRes = $ftStmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
foreach ($ftRes as $ftRow) {
|
||||
$user = $em->getPartialReference('Phraseanet:User', $ftRow['usr_id']);
|
||||
if (null === $user = $this->loadUser($app['EM'], $ftRow['usr_id'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$token = new FeedToken();
|
||||
$token->setFeed($feed);
|
||||
@@ -208,7 +212,9 @@ class patch_390alpha7a implements patchInterface
|
||||
$faRes = $faStmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
|
||||
foreach ($faRes as $faRow) {
|
||||
$user = $em->getPartialReference('Phraseanet:User', $faRow['usr_id']);
|
||||
if (null === $user = $this->loadUser($app['EM'], $faRow['usr_id'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$token = new AggregateToken();
|
||||
$token->setUser($user);
|
||||
|
28
lib/classes/patchAbstract.php
Normal file
28
lib/classes/patchAbstract.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2014 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Doctrine\ORM\NoResultException;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
|
||||
abstract class patchAbstract implements patchInterface
|
||||
{
|
||||
protected function loadUser(EntityManager $em, $usrId)
|
||||
{
|
||||
try {
|
||||
return $em->createQuery('SELECT PARTIAL u.{id} FROM Phraseanet:User u WHERE u.id = :id')
|
||||
->setParameters(['id' => $usrId])
|
||||
->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true)
|
||||
->getSingleResult();
|
||||
} catch (NoResultException $e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user