mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-10 03:23:19 +00:00
Refactor && Typo && Use plain objects as function parameters instead of ids
This commit is contained in:
@@ -1089,7 +1089,7 @@ class API_V1_adapter extends API_V1_Abstract
|
||||
}
|
||||
|
||||
$record->set_metadatas($metadatas);
|
||||
$result->set_datas(array("record_metadatas" => $this->list_record_caption($record->get_caption())));
|
||||
$result->set_datas(["record_metadatas" => $this->list_record_caption($record->get_caption())]);
|
||||
} catch (\Exception $e) {
|
||||
$result->set_error_message(API_V1_result::ERROR_BAD_REQUEST, _('An error occured'));
|
||||
}
|
||||
|
@@ -406,7 +406,7 @@ class collection implements cache_cacheableInterface
|
||||
$stmt->execute([':base_id' => $this->get_base_id()]);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->app['manipulator.registration']->deleteRegistrationsOnCollection($this->get_base_id());
|
||||
$this->app['manipulator.registration']->deleteRegistrationsOnCollection($this);
|
||||
|
||||
$this->get_databox()->delete_data_from_cache(databox::CACHE_COLLECTIONS);
|
||||
|
||||
@@ -534,7 +534,7 @@ class collection implements cache_cacheableInterface
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->app['manipulator.registration']->deleteRegistrationsOnCollection($this->get_base_id());
|
||||
$this->app['manipulator.registration']->deleteRegistrationsOnCollection($this);
|
||||
|
||||
phrasea::reset_baseDatas($app['phraseanet.appbox']);
|
||||
|
||||
@@ -748,17 +748,19 @@ class collection implements cache_cacheableInterface
|
||||
*/
|
||||
public function isRegistrationEnabled()
|
||||
{
|
||||
if ($xml = simplexml_load_string($this->get_prefs())) {
|
||||
$element = $xml->xpath('/baseprefs/caninscript');
|
||||
if (false === $xml = simplexml_load_string($this->get_prefs())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (count($element) === 0) {
|
||||
return $this->databox->isRegistrationEnabled();
|
||||
}
|
||||
$element = $xml->xpath('/baseprefs/caninscript');
|
||||
|
||||
foreach ($element as $caninscript) {
|
||||
if (false !== (Boolean) (string) $caninscript) {
|
||||
return true;
|
||||
}
|
||||
if (count($element) === 0) {
|
||||
return $this->databox->isRegistrationEnabled();
|
||||
}
|
||||
|
||||
foreach ($element as $caninscript) {
|
||||
if (false !== (Boolean) (string) $caninscript) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -774,12 +776,12 @@ class collection implements cache_cacheableInterface
|
||||
*/
|
||||
public function getTermsOfUse()
|
||||
{
|
||||
if ($xml = simplexml_load_string($this->get_prefs())) {
|
||||
foreach ($xml->xpath('/baseprefs/cgu') as $sbpcgu) {
|
||||
return $sbpcgu->saveXML();
|
||||
}
|
||||
if (false === $xml = simplexml_load_string($this->get_prefs())) {
|
||||
return;
|
||||
}
|
||||
|
||||
return null;
|
||||
foreach ($xml->xpath('/baseprefs/cgu') as $sbpcgu) {
|
||||
return $sbpcgu->saveXML();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -29,7 +29,7 @@ class databox_cgu
|
||||
if (trim($term['terms']) == '') {
|
||||
continue;
|
||||
}
|
||||
$out .= '<div style="display:none;" class="cgu-dialog" title="' . str_replace('"', '"', $app->trans('cgus:: CGUs de la base %s', $name)) . '">';
|
||||
$out .= '<div style="display:none;" class="cgu-dialog" title="' . str_replace('"', '"', $app->trans('cgus:: CGUs de la base %name%', ['%name%', $name])) . '">';
|
||||
|
||||
$out .= '<blockquote>' . $term['terms'] . '</blockquote>';
|
||||
$out .= '<div>' . $app->trans('cgus:: Pour continuer a utiliser lapplication, vous devez accepter les conditions precedentes') . '
|
||||
|
@@ -38,13 +38,10 @@ class eventsmanager_notify_register extends eventsmanager_notifyAbstract
|
||||
*/
|
||||
public function fire($event, $params, &$object)
|
||||
{
|
||||
$default = [
|
||||
'usr_id' => ''
|
||||
, 'demand' => []
|
||||
];
|
||||
$default = ['usr_id' => '', 'registrations' => []];
|
||||
|
||||
$params = array_merge($default, $params);
|
||||
$base_ids = $params['demand'];
|
||||
$base_ids = $params['registrations'];
|
||||
|
||||
if (count($base_ids) == 0) {
|
||||
return;
|
||||
@@ -79,7 +76,7 @@ class eventsmanager_notify_register extends eventsmanager_notifyAbstract
|
||||
|
||||
$usr_id->appendChild($dom_xml->createTextNode($params['usr_id']));
|
||||
|
||||
foreach ($params['demand'] as $base_id => $is_ok) {
|
||||
foreach ($params['registrations'] as $base_id => $is_ok) {
|
||||
$base_id_node = $dom_xml->createElement('base_id');
|
||||
$base_id_node->appendChild($dom_xml->createTextNode($base_id));
|
||||
$base_ids->appendChild($base_id_node);
|
||||
|
122
lib/classes/patch/390alpha13a.php
Normal file
122
lib/classes/patch/390alpha13a.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?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 Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Model\Entities\Registration;
|
||||
use Doctrine\ORM\NoResultException;
|
||||
use Doctrine\ORM\Query;
|
||||
use Doctrine\ORM\Query\ResultSetMapping;
|
||||
|
||||
class patch_390alpha13a implements patchInterface
|
||||
{
|
||||
/** @var string */
|
||||
private $release = '3.9.0-alpha.13';
|
||||
|
||||
/** @var array */
|
||||
private $concern = [base::APPLICATION_BOX];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_release()
|
||||
{
|
||||
return $this->release;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function require_all_upgrades()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function concern()
|
||||
{
|
||||
return $this->concern;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDoctrineMigrations()
|
||||
{
|
||||
return ['registration'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function apply(base $appbox, Application $app)
|
||||
{
|
||||
$em = $app['EM'];
|
||||
|
||||
$sql = "SELECT date_modif, usr_id, base_id, en_cours, refuser
|
||||
FROM demand";
|
||||
|
||||
$rsm = new ResultSetMapping();
|
||||
$rsm->addScalarResult('base_id','base_id');
|
||||
$rsm->addScalarResult('en_cours','en_cours');
|
||||
$rsm->addScalarResult('refuser','refuser');
|
||||
$rsm->addScalarResult('usr_id', 'usr_id');
|
||||
$rsm->addScalarResult('date_modif', 'date_modif');
|
||||
|
||||
$rs = $em->createNativeQuery($sql, $rsm)->getResult();
|
||||
$n = 0;
|
||||
|
||||
foreach ($rs as $row) {
|
||||
try {
|
||||
$user = $em->createQuery('SELECT PARTIAL u.{id} FROM Phraseanet:User s WHERE u.id = :id')
|
||||
->setParameters(['id' => $row['usr_id']])
|
||||
->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true)
|
||||
->getSingleResult();
|
||||
} catch (NoResultException $e) {
|
||||
$app['monolog']->addInfo(sprintf(
|
||||
'Patch %s : Registration for user (%s) could not be turn into doctrine entity as user could not be found.',
|
||||
$this->get_release(),
|
||||
$row['usr_id']
|
||||
));
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$collection = \collection::get_from_base_id($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.',
|
||||
$this->get_release(),
|
||||
$row['usr_id'],
|
||||
$row['base_id']
|
||||
));
|
||||
continue;
|
||||
}
|
||||
|
||||
$registration = new Registration();
|
||||
$registration->setCollection($collection);
|
||||
$registration->setUser($user);
|
||||
$registration->setPending($row['en_cours']);
|
||||
$registration->setCreated(new \DateTime($row['date_modif']));
|
||||
$registration->setRejected($row['refuser']);
|
||||
|
||||
if ($n % 100 === 0) {
|
||||
$em->flush();
|
||||
$em->clear();
|
||||
}
|
||||
$n++;
|
||||
}
|
||||
|
||||
$em->flush();
|
||||
$em->clear();
|
||||
}
|
||||
}
|
@@ -371,7 +371,7 @@ class record_preview extends record_adapter
|
||||
[
|
||||
'final' => []
|
||||
, 'comment' => []
|
||||
, 'user' => $this->app['manipulator.user']->getRepository()->find($row['usr_id'])
|
||||
, 'user' => $row['usr_id'] ? $this->app['manipulator.user']->getRepository()->find($row['usr_id']) : null
|
||||
];
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user