mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 09:53:15 +00:00
Merge branch 'master' into PHRAS-1630-databox-unmount
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2016 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace Alchemy\Phrasea\Command\Collection;
|
||||
|
||||
use Alchemy\Phrasea\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class ListCollectionCommand extends Command
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct('collection:list');
|
||||
$this->setDescription('List all collection in Phraseanet')
|
||||
->addOption('databox_id', 'd', InputOption::VALUE_REQUIRED, 'The id of the databox to list collection')
|
||||
->addOption('jsonformat', null, InputOption::VALUE_NONE, 'Output in json format')
|
||||
->setHelp('');
|
||||
return $this;
|
||||
}
|
||||
protected function doExecute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
try {
|
||||
$jsonformat = $input->getOption('jsonformat');
|
||||
$databox = $this->container->findDataboxById($input->getOption('databox_id'));
|
||||
$collections = $this->listDataboxCollections($databox);
|
||||
|
||||
if ($jsonformat) {
|
||||
foreach ($collections as $collection) {
|
||||
$collectionList[] = array_combine(['id local for API', 'id distant', 'name','label','status','total records'], $collection);
|
||||
}
|
||||
echo json_encode($collectionList);
|
||||
} else {
|
||||
$table = $this->getHelperSet()->get('table');
|
||||
$table
|
||||
->setHeaders(['id local for API', 'id distant', 'name','label','status','total records'])
|
||||
->setRows($collections)
|
||||
->render($output);
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$output->writeln("<error>{$e->getMessage()}</error>");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private function listDataboxCollections(\databox $databox)
|
||||
{
|
||||
return array_map(function (\collection $collection) {
|
||||
return $this->listCollection($collection);
|
||||
}, array_merge($databox->get_collections(),$this->getUnabledCollection($databox->get_activable_colls())));
|
||||
}
|
||||
|
||||
private function getUnabledCollection($collections)
|
||||
{
|
||||
return array_map(function ($colId){
|
||||
return \collection::getByBaseId($this->container, $colId);
|
||||
},$collections);
|
||||
|
||||
}
|
||||
|
||||
private function listCollection(\collection $collection)
|
||||
{
|
||||
return [
|
||||
$collection->get_base_id(),
|
||||
$collection->get_coll_id(),
|
||||
$collection->get_name(),
|
||||
'en: ' . $collection->get_label('en') .
|
||||
', de: ' . $collection->get_label('de') .
|
||||
', fr: ' . $collection->get_label('fr') .
|
||||
', nl: ' . $collection->get_label('nl'),
|
||||
($collection->is_active()) ? 'enabled' : 'disabled',
|
||||
$collection->get_record_amount()
|
||||
];
|
||||
}
|
||||
}
|
72
lib/Alchemy/Phrasea/Command/Databox/ListDataboxCommand.php
Normal file
72
lib/Alchemy/Phrasea/Command/Databox/ListDataboxCommand.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2016 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Alchemy\Phrasea\Command\Databox;
|
||||
|
||||
use Alchemy\Phrasea\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class ListDataboxCommand extends Command
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct('databox:list');
|
||||
|
||||
$this->setDescription('List all databox in Phraseanet')
|
||||
->addOption('jsonformat', null, InputOption::VALUE_NONE, 'Output in json format')
|
||||
->setHelp('');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function doExecute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
try {
|
||||
$jsonformat = $input->getOption('jsonformat');
|
||||
$databoxes = array_map(function (\databox $databox) {
|
||||
return $this->listDatabox($databox);
|
||||
}, $this->container->getApplicationBox()->get_databoxes());
|
||||
|
||||
if ($jsonformat) {
|
||||
foreach ($databoxes as $databox) {
|
||||
$databoxList[] = array_combine(['id', 'name', 'alias'], $databox);
|
||||
}
|
||||
echo json_encode($databoxList);
|
||||
} else {
|
||||
$table = $this->getHelperSet()->get('table');
|
||||
$table
|
||||
->setHeaders(['id', 'name', 'alias'])
|
||||
->setRows($databoxes)
|
||||
->render($output);
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$output->writeln('<error>Listing databox failed : '.$e->getMessage().'</error>');
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private function listDatabox(\databox $databox)
|
||||
{
|
||||
return [
|
||||
$databox->get_sbas_id(),
|
||||
$databox->get_dbname(),
|
||||
$databox->get_viewname()
|
||||
];
|
||||
}
|
||||
|
||||
}
|
211
lib/Alchemy/Phrasea/Command/User/UserCreateCommand.php
Normal file
211
lib/Alchemy/Phrasea/Command/User/UserCreateCommand.php
Normal file
@@ -0,0 +1,211 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2016 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Alchemy\Phrasea\Command\User;
|
||||
|
||||
use Alchemy\Phrasea\Application\Helper\NotifierAware;
|
||||
use Alchemy\Phrasea\Command\Command;
|
||||
use Alchemy\Phrasea\Core\LazyLocator;
|
||||
use Alchemy\Phrasea\Model\Entities\User;
|
||||
use Alchemy\Phrasea\Notification\Mail\MailRequestPasswordSetup;
|
||||
use Alchemy\Phrasea\Notification\Mail\MailRequestEmailConfirmation;
|
||||
use Alchemy\Phrasea\Notification\Receiver;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
|
||||
class UserCreateCommand extends Command
|
||||
{
|
||||
use NotifierAware;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct('user:create');
|
||||
|
||||
$this->setDescription('Create user in Phraseanet')
|
||||
->addOption('user_login', null, InputOption::VALUE_REQUIRED, 'The desired login for created user.')
|
||||
->addOption('user_mail', null, InputOption::VALUE_OPTIONAL, 'The desired mail for created user.')
|
||||
->addOption('user_password', null, InputOption::VALUE_OPTIONAL, 'The desired password')
|
||||
->addOption('send_mail_confirm', null, InputOption::VALUE_NONE, 'Send an email to user, for validate email.')
|
||||
->addOption('send_mail_password', null, InputOption::VALUE_NONE, 'Send an email to user, for password definition, work only if user_password is not define')
|
||||
->addOption('model_number', null, InputOption::VALUE_OPTIONAL, 'Id of model')
|
||||
->addOption('user_gender', null, InputOption::VALUE_OPTIONAL, 'The gender for created user.')
|
||||
->addOption('user_firstname', null, InputOption::VALUE_OPTIONAL, 'The first name for created user.')
|
||||
->addOption('user_lastname', null, InputOption::VALUE_OPTIONAL, 'The last name for created user.')
|
||||
->addOption('user_compagny', null, InputOption::VALUE_OPTIONAL, 'The compagny for created user.')
|
||||
->addOption('user_job', null, InputOption::VALUE_OPTIONAL, 'The job for created user.')
|
||||
->addOption('user_activitie', null, InputOption::VALUE_OPTIONAL, 'The activitie for created user.')
|
||||
->addOption('user_phone', null, InputOption::VALUE_OPTIONAL, 'The phone number for created user.')
|
||||
->setHelp('');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function doExecute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
|
||||
$userLogin = $input->getOption('user_login');
|
||||
$userMail = $input->getOption('user_mail');
|
||||
$userPassword = $input->getOption('user_password');
|
||||
$sendMailConfirm = $input->getOption('send_mail_confirm');
|
||||
$sendMailPassword = $input->getOption('send_mail_password');
|
||||
$modelNumber = $input->getOption('model_number');
|
||||
$userGender = $input->getOption('user_gender');
|
||||
$userFirstName = $input->getOption('user_firstname');
|
||||
$userLastName = $input->getOption('user_lastname');
|
||||
$userCompagny = $input->getOption('user_compagny');
|
||||
$userJob = $input->getOption('user_job');
|
||||
$userActivity = $input->getOption('user_activitie');
|
||||
$userPhone = $input->getOption('user_phone');
|
||||
|
||||
$userRepository = $this->container['repo.users'];
|
||||
|
||||
if ($userMail) {
|
||||
if (!\Swift_Validate::email($userMail)) {
|
||||
$output->writeln('<error>Invalid mail address</error>');
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (null !== $userRepository->findByEmail($userMail)) {
|
||||
$output->writeln('<error>An user exist with this email.</error>');
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$password = (!is_null($userPassword)) ? $userPassword : $this->container['random.medium']->generateString(128);
|
||||
$userManipulator = $this->container['manipulator.user'];
|
||||
$user = $userManipulator->createUser($userLogin, $password, $userMail);
|
||||
|
||||
if ($userGender) {
|
||||
if (null === $gender = $this->verifyGender($userGender)) {
|
||||
$output->writeln('<bg=yellow;options=bold>Gender '.$userGender.' not exists.</>');
|
||||
}
|
||||
$user->setGender($gender);
|
||||
}
|
||||
|
||||
if($userFirstName) $user->setFirstName($userFirstName);
|
||||
if($userLastName) $user->setLastName($userLastName);
|
||||
if($userCompagny) $user->setCompany($userCompagny);
|
||||
if($userJob) $user->setJob($userJob);
|
||||
if($userActivity) $user->setActivity($userActivity);
|
||||
if($userPhone) $user->setPhone($userPhone);
|
||||
|
||||
if ($sendMailPassword and $userMail and is_null($userPassword)) {
|
||||
$this->sendPasswordSetupMail($user);
|
||||
}
|
||||
|
||||
if ($sendMailConfirm and $userMail) {
|
||||
$user->setMailLocked(true);
|
||||
$this->sendAccountUnlockEmail($user);
|
||||
}
|
||||
|
||||
if ($modelNumber) {
|
||||
$template = $userRepository->find($modelNumber);
|
||||
if (!$template) {
|
||||
$output->writeln('<bg=yellow;options=bold>Model '.$modelNumber.' not found.</>');
|
||||
} else {
|
||||
$base_ids = [];
|
||||
foreach ($this->container->getApplicationBox()->get_databoxes() as $databox) {
|
||||
foreach ($databox->get_collections() as $collection) {
|
||||
$base_ids[] = $collection->get_base_id();
|
||||
}
|
||||
}
|
||||
$this->container->getAclForUser($user)->apply_model($template, $base_ids);
|
||||
}
|
||||
}
|
||||
|
||||
$this->container['orm.em']->flush();
|
||||
|
||||
$output->writeln("<info>Create new user successful !</info>");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get gender for user
|
||||
* @param $type
|
||||
* @return int|null
|
||||
*/
|
||||
private function verifyGender($type)
|
||||
{
|
||||
switch (strtolower($type)) {
|
||||
case "mlle.":
|
||||
case "mlle":
|
||||
case "miss":
|
||||
case "mademoiselle":
|
||||
case "0":
|
||||
$gender = User::GENDER_MISS;
|
||||
break;
|
||||
case "mme":
|
||||
case "madame":
|
||||
case "ms":
|
||||
case "ms.":
|
||||
case "1":
|
||||
$gender = User::GENDER_MRS;
|
||||
break;
|
||||
case "m":
|
||||
case "m.":
|
||||
case "mr":
|
||||
case "mr.":
|
||||
case "monsieur":
|
||||
case "mister":
|
||||
case "2":
|
||||
$gender = User::GENDER_MR;
|
||||
break;
|
||||
default:
|
||||
$gender = null;
|
||||
}
|
||||
return $gender;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send mail for renew password
|
||||
* @param User $user
|
||||
*/
|
||||
public function sendPasswordSetupMail(User $user)
|
||||
{
|
||||
$this->setDelivererLocator(new LazyLocator($this->container, 'notification.deliverer'));
|
||||
$receiver = Receiver::fromUser($user);
|
||||
|
||||
$token = $this->container['manipulator.token']->createResetPasswordToken($user);
|
||||
|
||||
$mail = MailRequestPasswordSetup::create($this->container, $receiver);
|
||||
$servername = $this->container['conf']->get('servername');
|
||||
$mail->setButtonUrl('http://'.$servername.'/login/renew-password/?token='.$token->getValue());
|
||||
$mail->setLogin($user->getLogin());
|
||||
|
||||
$this->deliver($mail);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
public function sendAccountUnlockEmail(User $user)
|
||||
{
|
||||
$this->setDelivererLocator(new LazyLocator($this->container, 'notification.deliverer'));
|
||||
$receiver = Receiver::fromUser($user);
|
||||
|
||||
$token = $this->container['manipulator.token']->createAccountUnlockToken($user);
|
||||
|
||||
$mail = MailRequestEmailConfirmation::create($this->container, $receiver);
|
||||
$servername = $this->container['conf']->get('servername');
|
||||
$mail->setButtonUrl('http://'.$servername.'/login/register-confirm/?code='.$token->getValue());
|
||||
$mail->setExpiration($token->getExpiration());
|
||||
|
||||
$this->deliver($mail);
|
||||
}
|
||||
|
||||
}
|
287
lib/Alchemy/Phrasea/Command/User/UserListCommand.php
Normal file
287
lib/Alchemy/Phrasea/Command/User/UserListCommand.php
Normal file
@@ -0,0 +1,287 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2016 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Alchemy\Phrasea\Command\User;
|
||||
|
||||
use Alchemy\Phrasea\Command\Command;
|
||||
use Alchemy\Phrasea\Model\Entities\User;
|
||||
use Symfony\Component\Console\Helper\TableCell;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Alchemy\Phrasea\Utilities\NullableDateTime;
|
||||
|
||||
|
||||
class UserListCommand extends Command
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct('user:list');
|
||||
|
||||
$this->setDescription('List of all user (experimental)')
|
||||
->addOption('user_id', null, InputOption::VALUE_OPTIONAL, ' The id of user export only info this user ')
|
||||
->addOption('user_email', null, InputOption::VALUE_OPTIONAL, 'The mail of user export only info this user .')
|
||||
->addOption('database_id', null, InputOption::VALUE_OPTIONAL, 'Id of database.')
|
||||
->addOption('collection_id', null, InputOption::VALUE_OPTIONAL, 'Id of the collection.')
|
||||
->addOption('mail_lock_status', null, InputOption::VALUE_NONE, 'Status by mail locked')
|
||||
->addOption('guest', null, InputOption::VALUE_NONE, 'Only guest user')
|
||||
->addOption('created', null, InputOption::VALUE_OPTIONAL, 'Created at with operator,aaaa-mm-jj hh:mm:ss.')
|
||||
->addOption('updated', null, InputOption::VALUE_OPTIONAL, 'Update at with operator,aaaa-mm-jj hh:mm:ss.')
|
||||
->addOption('application', null, InputOption::VALUE_NONE, 'List application of user work only if --user_id is set')
|
||||
->addOption('right', null, InputOption::VALUE_NONE, 'Show right information')
|
||||
->addOption('adress', null, InputOption::VALUE_NONE, 'Show adress information')
|
||||
->addOption('models', null, InputOption::VALUE_NONE, "Show only defined models, if --user_id is set with --models it's the template owner")
|
||||
->addOption('jsonformat', null, InputOption::VALUE_NONE, 'Output in json format')
|
||||
->setHelp('');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function doExecute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
|
||||
$userId = $input->getOption('user_id');
|
||||
$userEmail = $input->getOption('user_email');
|
||||
$databaseId = $input->getOption('database_id');
|
||||
$collectionId = $input->getOption('collection_id');
|
||||
$lockStatus = $input->getOption('mail_lock_status');
|
||||
$guest = $input->getOption('guest');
|
||||
$application = $input->getOption('application');
|
||||
$withAdress = $input->getOption('adress');
|
||||
$created = $input->getOption('created');
|
||||
$updated = $input->getOption('updated');
|
||||
$withRight = $input->getOption('right');
|
||||
$models = $input->getOption('models');
|
||||
$jsonformat = $input->getOption('jsonformat');
|
||||
|
||||
$query = $this->container['phraseanet.user-query'];
|
||||
|
||||
if($databaseId) $query->on_base_ids([$databaseId]);
|
||||
if($collectionId) $query->on_sbas_ids([$collectionId]);
|
||||
if($created) $this->addFilterDate($created,'created',$query);
|
||||
if($updated) $this->addFilterDate($updated,'updated',$query);
|
||||
if($userId && !$models) $query->addSqlFilter('Users.id = ?' ,[$userId]);
|
||||
if($userEmail && !$models) $query->addSqlFilter('Users.email = ?' ,[$userEmail]);
|
||||
if($lockStatus && !$models) $query->addSqlFilter('Users.mail_locked = 1');
|
||||
if($guest && !$models) $query->include_invite(true)->addSqlFilter('Users.guest = 1');
|
||||
|
||||
if ($application and !$userId) {
|
||||
$output->writeln('<error>You must provide --user_id when using --application option</error>');
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** @var UserRepository $userRepository */
|
||||
$userRepository = $this->container['repo.users'];
|
||||
|
||||
if ($models && $userId) {
|
||||
$users = $userRepository->findBy(['templateOwner' => $userId]);
|
||||
} elseif ($models) {
|
||||
$users = $userRepository->findTemplate();
|
||||
} else {
|
||||
$users = $query->execute()->get_results();
|
||||
}
|
||||
|
||||
$userList = [];
|
||||
$showApplication = false;
|
||||
foreach ($users as $key => $user) {
|
||||
if ($userId and $application) {
|
||||
$showApplication = true;
|
||||
}
|
||||
$userList[] = $this->listUser($user, $withAdress, $withRight);
|
||||
|
||||
$userListRaw[] = array_combine($this->headerTable($withAdress, $withRight), $this->listUser($user, $withAdress, $withRight));
|
||||
}
|
||||
|
||||
if ($jsonformat) {
|
||||
echo json_encode($userListRaw);
|
||||
} else {
|
||||
$table = $this->getHelperSet()->get('table');
|
||||
$table
|
||||
->setHeaders($this->headerTable($withAdress, $withRight))
|
||||
->setRows($userList)
|
||||
->render($output);
|
||||
;
|
||||
|
||||
|
||||
if ($showApplication) {
|
||||
$applicationTable = $this->getHelperSet()->get('table');
|
||||
$applicationTable->setHeaders(array(
|
||||
array(new TableCell('Applications', array('colspan' => 5))),
|
||||
['name','callback','client_secret','client_id','token'],
|
||||
))->setRows($this->getApplicationOfUser($users[0]))->render($output);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $withAdress
|
||||
* @param $withRight
|
||||
* @return array
|
||||
*/
|
||||
private function headerTable($withAdress,$withRight)
|
||||
{
|
||||
$defaultHeader = ['id', 'login', 'email','last_model','first_name','last_name','gender','created','updated','status','locale'];
|
||||
$adressHeader = [ 'address', 'zip_code', 'city', 'country', 'phone', 'fax', 'job','position', 'company', 'geoname_id'];
|
||||
$rightHeader = [ 'admin', 'guest', 'mail_notification', 'ldap_created', 'mail_locked'];
|
||||
|
||||
return $this->createInformation($withAdress,$withRight,$defaultHeader,['adress' => $adressHeader,'right' =>$rightHeader]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param $withAdress
|
||||
* @param $withRight
|
||||
* @return array
|
||||
*/
|
||||
private function listUser(User $user,$withAdress,$withRight)
|
||||
{
|
||||
switch ($user->getGender()) {
|
||||
case User::GENDER_MRS:
|
||||
$gender = 'Mrs';
|
||||
break;
|
||||
case User::GENDER_MISS:
|
||||
$gender = 'Miss';
|
||||
break;
|
||||
case User::GENDER_MR:
|
||||
default:
|
||||
$gender = 'Mr';
|
||||
}
|
||||
|
||||
$defaultInfo = [
|
||||
$user->getId(),
|
||||
$user->getLogin() ?: '-',
|
||||
$user->getEmail() ?: '-',
|
||||
$user->getLastAppliedTemplate() ? $user->getLastAppliedTemplate()->getLogin() : '-',
|
||||
$user->getFirstName() ?: '-',
|
||||
$user->getLastName() ?: '-',
|
||||
$gender,
|
||||
NullableDateTime::format($user->getCreated(),'Y-m-d H:i:s'),
|
||||
NullableDateTime::format($user->getUpdated(),'Y-m-d H:i:s'),
|
||||
'status',
|
||||
$user->getLocale() ?: '-',
|
||||
];
|
||||
|
||||
return $this->createInformation($withAdress,$withRight,$defaultInfo,['adress' => $this->userAdress($user),'right' => $this->userRight($user)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @return array
|
||||
*/
|
||||
private function userAdress(User $user)
|
||||
{
|
||||
return [
|
||||
$user->getAddress() ?: '-',
|
||||
$user->getZipCode() ?: '-',
|
||||
$user->getCity() ?: '-',
|
||||
$user->getCountry() ?: '-',
|
||||
$user->getPhone() ?: '-',
|
||||
$user->getFax() ?: '-',
|
||||
$user->getJob() ?: '-',
|
||||
$user->getActivity() ?: '-',
|
||||
$user->getCompany() ?: '-',
|
||||
$user->getGeonameId() ?: '-',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @return array
|
||||
*/
|
||||
private function userRight(User $user)
|
||||
{
|
||||
return [
|
||||
$user->isAdmin() ?: false,
|
||||
$user->isGuest() ?: false,
|
||||
$user->hasMailNotificationsActivated() ?: false,
|
||||
$user->hasLdapCreated() ?: false,
|
||||
$user->isMailLocked() ?: false,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @return array
|
||||
*/
|
||||
private function getApplicationOfUser(User $user)
|
||||
{
|
||||
$apiRepository = $this->container['repo.api-applications'];
|
||||
$applications = $apiRepository->findByUser($user);
|
||||
|
||||
if (empty($applications)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$accountRepository = $this->container['repo.api-accounts'];
|
||||
$apiOauthRepository = $this->container['repo.api-oauth-tokens'];
|
||||
$usersApplication = [];
|
||||
foreach ($applications as $application) {
|
||||
$account = $accountRepository->findByUserAndApplication($user, $application);
|
||||
$token = $account ? $apiOauthRepository->findDeveloperToken($account) : null;
|
||||
$usersApplication[] = [
|
||||
$application->getName(),
|
||||
$application->getRedirectUri(),
|
||||
$application->getClientSecret(),
|
||||
$application->getClientId(),
|
||||
($token) ? $token->getOauthToken() : '-'
|
||||
];
|
||||
}
|
||||
|
||||
return $usersApplication;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $withAdress
|
||||
* @param $withRight
|
||||
* @param $default
|
||||
* @param $infoToMerge
|
||||
* @return array
|
||||
*/
|
||||
private function createInformation($withAdress,$withRight,$default,$infoToMerge)
|
||||
{
|
||||
if ($withAdress && $withRight) {
|
||||
$information = array_merge($default, $infoToMerge['adress'],$infoToMerge['right']);
|
||||
} elseif ($withAdress && !$withRight) {
|
||||
$information = array_merge($default, $infoToMerge['adress']);
|
||||
} elseif(!$withAdress && $withRight) {
|
||||
$information = array_merge($default, $infoToMerge['right']);
|
||||
} else {
|
||||
$information = $default;
|
||||
}
|
||||
|
||||
return $information;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $date
|
||||
* @param $type
|
||||
* @param $query
|
||||
*/
|
||||
private function addFilterDate($date,$type,$query){
|
||||
|
||||
list($operator,$dateAt) = explode(',', $date);
|
||||
|
||||
if (!in_array($operator,['=','>=','<=','>','<'])) {
|
||||
throw new \InvalidArgumentException(" '=' or '<=' or '>=' or '>' or '<'");
|
||||
}
|
||||
|
||||
$query->addSqlFilter($type.$operator.' ?' ,[$dateAt]);
|
||||
}
|
||||
|
||||
}
|
79
lib/Alchemy/Phrasea/Command/User/UserSetPasswordCommand.php
Normal file
79
lib/Alchemy/Phrasea/Command/User/UserSetPasswordCommand.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2016 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Alchemy\Phrasea\Command\User;
|
||||
|
||||
use Alchemy\Phrasea\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
|
||||
class UserSetPasswordCommand extends Command
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct('user:set-password');
|
||||
|
||||
$this->setDescription('Set user password in Phraseanet')
|
||||
->addOption('user_id', null, InputOption::VALUE_REQUIRED, 'The id of user.')
|
||||
->addOption('generate', null, InputOption::VALUE_NONE, 'Generate the password')
|
||||
->addOption('password', null, InputOption::VALUE_OPTIONAL, 'The password')
|
||||
->setHelp('');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function doExecute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
|
||||
$dialog = $this->getHelperSet()->get('dialog');
|
||||
$userRepository = $this->container['repo.users'];
|
||||
$userManipulator = $this->container['manipulator.user'];
|
||||
$user = $userRepository->find($input->getOption('user_id'));
|
||||
$password = $input->getOption('password');
|
||||
$generate = $input->getOption('generate');
|
||||
|
||||
if ($user === null) {
|
||||
$output->writeln('<info>Not found User.</info>');
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($generate) {
|
||||
$password = $this->container['random.medium']->generateString(64);
|
||||
} else {
|
||||
if (!$password) {
|
||||
$output->writeln('<error>--password option not specified</error>');
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
$continue = mb_strtolower($dialog->ask($output, '<question>Do you want really set password to this user? (y/N)</question>', 'N'));
|
||||
} while (!in_array($continue, ['y', 'n']));
|
||||
|
||||
if ($continue !== 'y') {
|
||||
$output->writeln('Aborting !');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$userManipulator->setPassword($user,$password);
|
||||
$output->writeln('New password: <info>' . $password . '</info>');
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
@@ -1573,9 +1573,9 @@ class V1Controller extends Controller
|
||||
$options->setFirstResult((int)($request->get('offset_start') ?: 0));
|
||||
$options->setMaxResults((int)$request->get('per_page') ?: 10);
|
||||
|
||||
$this->getSearchEngine()->resetCache();
|
||||
$searchEngine = $this->getSearchEngine();
|
||||
|
||||
$search_result = $this->getSearchEngine()->query((string)$request->get('query'), $options);
|
||||
$search_result = $searchEngine->query((string)$request->get('query'), $options);
|
||||
|
||||
$this->getUserManipulator()->logQuery($this->getAuthenticatedUser(), $search_result->getQueryText());
|
||||
|
||||
@@ -1583,12 +1583,12 @@ class V1Controller extends Controller
|
||||
$collectionsReferencesByDatabox = $options->getCollectionsReferencesByDatabox();
|
||||
foreach ($collectionsReferencesByDatabox as $sbid => $references) {
|
||||
$databox = $this->findDataboxById($sbid);
|
||||
$collectionsIds = array_map(function(CollectionReference $ref){return $ref->getCollectionId();}, $references);
|
||||
$collectionsIds = array_map(function (CollectionReference $ref) {
|
||||
return $ref->getCollectionId();
|
||||
}, $references);
|
||||
$this->getSearchEngineLogger()->log($databox, $search_result->getQueryText(), $search_result->getTotal(), $collectionsIds);
|
||||
}
|
||||
|
||||
$this->getSearchEngine()->clearCache();
|
||||
|
||||
return $search_result;
|
||||
}
|
||||
|
||||
|
@@ -20,6 +20,7 @@ class DisplaySettingService
|
||||
const ORDER_BY_ADMIN = "ORDER_BY_ADMIN";
|
||||
const ORDER_BY_BCT = "ORDER_BY_BCT";
|
||||
const ORDER_BY_HITS = "ORDER_BY_HITS";
|
||||
const ORDER_BY_HITS_ASC = "ORDER_BY_HITS_ASC";
|
||||
|
||||
/**
|
||||
* The default user settings.
|
||||
@@ -31,7 +32,7 @@ class DisplaySettingService
|
||||
'images_per_page' => '20',
|
||||
'images_size' => '120',
|
||||
'editing_images_size' => '134',
|
||||
'editing_top_box' => '180px',
|
||||
'editing_top_box' => '120px',
|
||||
'editing_right_box' => '400px',
|
||||
'editing_left_box' => '710px',
|
||||
'basket_sort_field' => 'name',
|
||||
|
@@ -84,10 +84,14 @@ class DatabaseMetaProvider implements ServiceProviderInterface
|
||||
$service = $app['phraseanet.cache-service'];
|
||||
|
||||
$config->setMetadataCacheImpl(
|
||||
$service->factory('ORM_metadata', $app['orm.cache.driver'], $app['orm.cache.options'])
|
||||
$app['orm.cache.factory.filesystem'](array(
|
||||
'path' => $app['cache.path'].'/doctrine/metadata',
|
||||
))
|
||||
);
|
||||
$config->setQueryCacheImpl(
|
||||
$service->factory('ORM_query', $app['orm.cache.driver'], $app['orm.cache.options'])
|
||||
$app['orm.cache.factory.filesystem'](array(
|
||||
'path' => $app['cache.path'].'/doctrine/query',
|
||||
))
|
||||
);
|
||||
$config->setResultCacheImpl(
|
||||
$service->factory('ORM_result', $app['orm.cache.driver'], $app['orm.cache.options'])
|
||||
|
@@ -9,6 +9,8 @@ use MediaVorus\MediaVorusServiceProvider;
|
||||
use MP4Box\MP4BoxServiceProvider;
|
||||
use Neutron\Silex\Provider\ImagineServiceProvider;
|
||||
use PHPExiftool\PHPExiftoolServiceProvider;
|
||||
use PHPExiftool\Reader;
|
||||
use PHPExiftool\Writer;
|
||||
use Silex\Application;
|
||||
use Silex\ServiceProviderInterface;
|
||||
|
||||
@@ -48,6 +50,21 @@ class MediaUtilitiesMetaServiceProvider implements ServiceProviderInterface
|
||||
|
||||
public function boot(Application $app)
|
||||
{
|
||||
// no-op
|
||||
if(isset($app['exiftool.reader']) && isset($app['conf'])) {
|
||||
try {
|
||||
$timeout = $app['conf']->get(['main', 'binaries', 'exiftool_timeout'], 60);
|
||||
|
||||
/** @var Reader $exiftoolReader */
|
||||
$exiftoolReader = $app['exiftool.reader'];
|
||||
$exiftoolReader->setTimeout($timeout);
|
||||
|
||||
/** @var Writer $exiftoolWriter */
|
||||
$exiftoolWriter = $app['exiftool.writer'];
|
||||
$exiftoolWriter->setTimeout($timeout);
|
||||
}
|
||||
catch(\Exception $e) {
|
||||
// no-nop
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -122,4 +122,15 @@ class UserRepository extends EntityRepository
|
||||
{
|
||||
return $this->findBy(['templateOwner' => $user->getId()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds all templates
|
||||
*/
|
||||
public function findTemplate()
|
||||
{
|
||||
$qb = $this->createQueryBuilder('u');
|
||||
$qb->where('u.templateOwner is NOT NULL');
|
||||
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user