Merge branch 'master' into PHRAS-2184-list-manager-email-domain-filter

This commit is contained in:
Nicolas Maillat
2019-09-27 16:40:56 +02:00
committed by GitHub
130 changed files with 8605 additions and 733 deletions

View File

@@ -115,6 +115,7 @@ use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormTypeInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Process\ExecutableFinder;
use Unoconv\UnoconvServiceProvider;
use XPDF\PdfToText;
use XPDF\XPDFServiceProvider;
@@ -237,8 +238,19 @@ class Application extends SilexApplication
$this->register(new UnicodeServiceProvider());
$this->register(new ValidatorServiceProvider());
$this->register(new XPDFServiceProvider());
$this->setupXpdf();
if ($this['configuration.store']->isSetup()) {
$binariesConfig = $this['conf']->get(['main', 'binaries']);
$executableFinder = new ExecutableFinder();
$this->register(new XPDFServiceProvider(), [
'xpdf.configuration' => [
'pdftotext.binaries' => isset($binariesConfig['pdftotext_binary']) ? $binariesConfig['pdftotext_binary'] : $executableFinder->find('pdftotext'),
]
]);
$this->setupXpdf();
}
$this->register(new FileServeServiceProvider());
$this->register(new ManipulatorServiceProvider());
$this->register(new PluginServiceProvider());
@@ -653,7 +665,7 @@ class Application extends SilexApplication
private function setupGeonames()
{
$this['geonames.server-uri'] = $this->share(function (Application $app) {
return $app['conf']->get(['registry', 'webservices', 'geonames-server'], 'http://geonames.alchemyasp.com/');
return $app['conf']->get(['registry', 'webservices', 'geonames-server'], 'https://geonames.alchemyasp.com/');
});
}

View File

@@ -51,4 +51,41 @@ abstract class AbstractPluginCommand extends Command
$this->container['plugins.autoloader-generator']->write($manifests);
$output->writeln(" <comment>OK</comment>");
}
protected function doInstallPlugin($source, InputInterface $input, OutputInterface $output)
{
$temporaryDir = $this->container['temporary-filesystem']->createTemporaryDirectory();
$output->write("Importing <info>$source</info>...");
$this->container['plugins.importer']->import($source, $temporaryDir);
$output->writeln(" <comment>OK</comment>");
$output->write("Validating plugin...");
$manifest = $this->container['plugins.plugins-validator']->validatePlugin($temporaryDir);
$output->writeln(" <comment>OK</comment> found <info>".$manifest->getName()."</info>");
$targetDir = $this->container['plugin.path'] . DIRECTORY_SEPARATOR . $manifest->getName();
$output->write("Setting up composer...");
$this->container['plugins.composer-installer']->install($temporaryDir);
$output->writeln(" <comment>OK</comment>");
$output->write("Installing plugin <info>".$manifest->getName()."</info>...");
$this->container['filesystem']->mirror($temporaryDir, $targetDir);
$output->writeln(" <comment>OK</comment>");
$output->write("Copying public files <info>".$manifest->getName()."</info>...");
$this->container['plugins.assets-manager']->update($manifest);
$output->writeln(" <comment>OK</comment>");
$output->write("Removing temporary directory...");
$this->container['filesystem']->remove($temporaryDir);
$output->writeln(" <comment>OK</comment>");
$output->write("Activating plugin...");
$this->container['conf']->set(['plugins', $manifest->getName(), 'enabled'], true);
$output->writeln(" <comment>OK</comment>");
$this->updateConfigFiles($input, $output);
}
}

View File

@@ -14,6 +14,7 @@ namespace Alchemy\Phrasea\Command\Plugin;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\ArrayInput;
class AddPlugin extends AbstractPluginCommand
{
@@ -29,41 +30,36 @@ class AddPlugin extends AbstractPluginCommand
protected function doExecutePluginAction(InputInterface $input, OutputInterface $output)
{
$source = $input->getArgument('source');
$shouldDownload = $this->shouldDownloadPlugin($source);
$temporaryDir = $this->container['temporary-filesystem']->createTemporaryDirectory();
if ($shouldDownload){
$command = $this->getApplication()->find('plugins:download');
$arguments = [
'command' => 'plugins:download',
'source' => $source,
'shouldInstallPlugin' => true
];
$output->write("Importing <info>$source</info>...");
$this->container['plugins.importer']->import($source, $temporaryDir);
$output->writeln(" <comment>OK</comment>");
$downloadInput = new ArrayInput($arguments);
$command->run($downloadInput, $output);
$output->write("Validating plugin...");
$manifest = $this->container['plugins.plugins-validator']->validatePlugin($temporaryDir);
$output->writeln(" <comment>OK</comment> found <info>".$manifest->getName()."</info>");
} else {
$targetDir = $this->container['plugin.path'] . DIRECTORY_SEPARATOR . $manifest->getName();
$output->write("Setting up composer...");
$this->container['plugins.composer-installer']->install($temporaryDir);
$output->writeln(" <comment>OK</comment>");
$output->write("Installing plugin <info>".$manifest->getName()."</info>...");
$this->container['filesystem']->mirror($temporaryDir, $targetDir);
$output->writeln(" <comment>OK</comment>");
$output->write("Copying public files <info>".$manifest->getName()."</info>...");
$this->container['plugins.assets-manager']->update($manifest);
$output->writeln(" <comment>OK</comment>");
$output->write("Removing temporary directory...");
$this->container['filesystem']->remove($temporaryDir);
$output->writeln(" <comment>OK</comment>");
$output->write("Activating plugin...");
$this->container['conf']->set(['plugins', $manifest->getName(), 'enabled'], true);
$output->writeln(" <comment>OK</comment>");
$this->updateConfigFiles($input, $output);
$this->doInstallPlugin($source, $input, $output);
}
return 0;
}
protected function shouldDownloadPlugin($source)
{
$allowedScheme = array('https','ssh');
$scheme = parse_url($source, PHP_URL_SCHEME);
if (in_array($scheme, $allowedScheme)){
return true;
} else{
return false;
}
}
}

View File

@@ -0,0 +1,157 @@
<?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\Plugin;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\ArrayInput;
use Cz\Git\GitRepository as GitRepository;
class DownloadPlugin extends AbstractPluginCommand
{
public function __construct()
{
parent::__construct('plugins:download');
$this
->setDescription('Downloads a plugin to Phraseanet')
->addArgument('source', InputArgument::REQUIRED, 'The source is a remote url (.zip or .git)')
->addArgument('destination', InputArgument::OPTIONAL, 'Download destination')
->addArgument('shouldInstallPlugin', InputArgument::OPTIONAL, 'True or false, determines if plugin should be installed after download');
}
protected function doExecutePluginAction(InputInterface $input, OutputInterface $output)
{
$source = $input->getArgument('source');
$destination = $input->getArgument('destination');
$shouldInstallPlugin = false;
$shouldInstallPlugin = $input->getArgument('shouldInstallPlugin');
$destinationSubdir = '/plugin-'.md5($source);
if ($destination){
$destination = trim($destination);
$destination = rtrim($destination, '/');
$localDownloadPath = $destination;
} else {
$localDownloadPath = '/tmp/plugin-download' . $destinationSubdir;
}
if (!is_dir($localDownloadPath)) {
mkdir($localDownloadPath, 0755, true);
}
$extension = $this->getURIExtension($source);
if ($extension){
switch ($extension){
case 'zip':
$localUnpackPath = '/tmp/plugin-zip'. $destinationSubdir;
if (!is_dir($localUnpackPath)) {
mkdir($localUnpackPath, 0755, true);
}
$localArchiveFile = $localUnpackPath . '/plugin-downloaded.zip';
// download
$output->writeln("Downloading <info>$source</info>...");
set_time_limit(0);
$fp = fopen ($localArchiveFile, 'w+');
$ch = curl_init($source);;
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);
// unpack
$output->writeln("Unpacking <info>$source</info>...");
$zip = new \ZipArchive();
$errorUnpack = false;
if ($zip->open($localArchiveFile)) {
for ($i = 0; $i < $zip->numFiles; $i++) {
if (!($zip->extractTo($localDownloadPath, array($zip->getNameIndex($i))))) {
$errorUnpack = true;
}
}
$zip->close();
}
if ($errorUnpack){
$output->writeln("Failed unzipping <info>$source</info>");
} else {
$output->writeln("Plugin downloaded to <info>$localDownloadPath</info>");
if ($shouldInstallPlugin) $this->doInstallPlugin($localDownloadPath, $input, $output);
}
// remove zip archive
$this->delDirTree($localUnpackPath);
break;
case 'git':
$output->writeln("Downloading <info>$source</info>...");
$repo = GitRepository::cloneRepository($source, $localDownloadPath);
$output->writeln("Plugin downloaded to <info>$localDownloadPath</info>");
if ($shouldInstallPlugin) $this->doInstallPlugin($localDownloadPath, $input, $output);
break;
}
} else {
$output->writeln("The source <info>$source</info> is not supported. Only .zip and .git are supported.");
}
return 0;
}
protected function getURIExtension($source)
{
$validExtension = false;
$allowedExtension = array('zip','git');
$path = parse_url($source, PHP_URL_PATH);
if (strpos($path, '.') !== false) {
$pathParts = explode('.', $path);
$extension = $pathParts[1];
if (in_array($extension, $allowedExtension)){
$validExtension = true;
}
}
if ($validExtension){
return $extension;
} else {
return false;
}
}
protected static function delDirTree($dir) {
$files = array_diff(scandir($dir), array('.','..'));
foreach ($files as $file) {
(is_dir("$dir/$file")) ? self::delDirTree("$dir/$file") : unlink("$dir/$file");
}
return rmdir($dir);
}
}

View File

@@ -944,7 +944,7 @@ class V1Controller extends Controller
}
$originalName = $pi['filename'] . '.' . $pi['extension'];
$newPathname = $tempfile;
$uploadedFilename = $newPathname = $tempfile;
}
}
else {
@@ -956,8 +956,11 @@ class V1Controller extends Controller
if (!$file->isValid()) {
return $this->getBadRequestAction($request, 'Data corrupted, please try again');
}
$uploadedFilename = $file->getPathname();
$originalName = $file->getClientOriginalName();
$newPathname = $file->getPathname() . '.' . $file->getClientOriginalExtension();
if (false === rename($file->getPathname(), $newPathname)) {
return Result::createError($request, 403, 'Error while renaming file')->createResponse();
}
@@ -1010,6 +1013,11 @@ class V1Controller extends Controller
$nosubdef = $request->get('nosubdefs') === '' || \p4field::isyes($request->get('nosubdefs'));
$this->getBorderManager()->process($session, $Package, $callback, $behavior, $nosubdef);
// remove $newPathname on temporary directory
if ($newPathname !== $uploadedFilename) {
@rename($newPathname, $uploadedFilename);
}
$ret = ['entity' => null];
if ($output instanceof \record_adapter) {
@@ -1081,6 +1089,11 @@ class V1Controller extends Controller
}
}
// remove $newPathname on temporary directory
if ($renamedFilename !== $uploadedFilename) {
@rename($renamedFilename, $uploadedFilename);
}
return Result::create($request, $ret)->createResponse();
}
@@ -1984,7 +1997,7 @@ class V1Controller extends Controller
return $this->getBadRequestAction($request);
}
$datas = substr($datas, 0, ($n)) . $value . substr($datas, ($n + 2));
$datas = substr($datas, 0, ($n)) . $value . substr($datas, ($n + 1));
}
$record->setStatus(strrev($datas));
@@ -2588,8 +2601,18 @@ class V1Controller extends Controller
foreach ($recordsData as $data) {
$records[] = $this->addOrDelStoryRecord($story, $data, $action);
if($action === 'ADD' && !$cover_set && isset($data->{'use_as_cover'}) && $data->{'use_as_cover'} === true) {
$coverSource = [];
if (isset($data->{'thumbnail_cover_source'})) {
$coverSource['thumbnail_cover_source'] = $data->{'thumbnail_cover_source'};
}
if (isset($data->{'preview_cover_source'})) {
$coverSource['preview_cover_source'] = $data->{'preview_cover_source'};
}
// because we can try many records as cover source, we let it fail
$cover_set = ($this->setStoryCover($story, $data->{'record_id'}, true) !== false);
$cover_set = ($this->setStoryCover($story, $data->{'record_id'}, true, $coverSource) !== false);
}
}
@@ -2643,14 +2666,26 @@ class V1Controller extends Controller
$story = new \record_adapter($this->app, $databox_id, $story_id);
$coverSource = [];
if (isset($data->{'thumbnail_cover_source'})) {
$coverSource['thumbnail_cover_source'] = $data->{'thumbnail_cover_source'};
}
if (isset($data->{'preview_cover_source'})) {
$coverSource['preview_cover_source'] = $data->{'preview_cover_source'};
}
// we do NOT let "setStoryCover()" fail : pass false as last arg
$record_key = $this->setStoryCover($story, $data->{'record_id'}, false);
$record_key = $this->setStoryCover($story, $data->{'record_id'}, false, $coverSource);
return Result::create($request, array($record_key))->createResponse();
}
protected function setStoryCover(\record_adapter $story, $record_id, $can_fail=false)
protected function setStoryCover(\record_adapter $story, $record_id, $can_fail=false, $coverSource = [])
{
$coverSource = array_merge(['thumbnail_cover_source' => 'thumbnail', 'preview_cover_source' => 'preview'], $coverSource);
try {
$record = new \record_adapter($this->app, $story->getDataboxId(), $record_id);
} catch (\Exception_Record_AdapterNotFound $e) {
@@ -2662,18 +2697,22 @@ class V1Controller extends Controller
$this->app->abort(404, sprintf('Record identified by databox_id %s and record_id %s is not in the story', $story->getDataboxId(), $record_id));
}
if ($record->getType() !== 'image' && $record->getType() !== 'video') {
// this can fail so we can loop on many records during story creation...
if($can_fail) {
return false;
}
$this->app->abort(403, sprintf('Record identified by databox_id %s and record_id %s is not an image nor a video', $story->getDataboxId(), $record_id));
}
// taking account all record type as a cover
// if ($record->getType() !== 'image' && $record->getType() !== 'video') {
// // this can fail so we can loop on many records during story creation...
// if($can_fail) {
// return false;
// }
// $this->app->abort(403, sprintf('Record identified by databox_id %s and record_id %s is not an image nor a video', $story->getDataboxId(), $record_id));
// }
foreach ($record->get_subdefs() as $name => $value) {
if (!in_array($name, array('thumbnail', 'preview'))) {
if (!($key = array_search($name, $coverSource))) {
continue;
}
$name = ($key == 'thumbnail_cover_source') ? 'thumbnail': 'preview';
$media = $this->app->getMediaFromUri($value->getRealPath());
$this->getSubdefSubstituer()->substituteSubdef($story, $name, $media); // name = thumbnail | preview
$this->getDataboxLogger($story->getDatabox())->log(

View File

@@ -114,6 +114,7 @@ class MoveCollectionController extends Controller
$trashCollectionsBySbasId = [];
foreach ($records as $record) {
$oldCollectionId = $record->getCollection()->get_coll_id();
$record->move_to_collection($collection, $this->getApplicationBox());
if ($request->request->get("chg_coll_son") == "1") {
@@ -130,7 +131,7 @@ class MoveCollectionController extends Controller
$trashCollectionsBySbasId[$sbasId] = $record->getDatabox()->getTrashCollection();
}
if ($trashCollectionsBySbasId[$sbasId] !== null) {
if ($record->getCollection()->get_coll_id() == $trashCollectionsBySbasId[$sbasId]->get_coll_id() && $collection->get_coll_id() !== $trashCollectionsBySbasId[$sbasId]->get_coll_id()) {
if ($oldCollectionId == $trashCollectionsBySbasId[$sbasId]->get_coll_id() && $collection->get_coll_id() !== $trashCollectionsBySbasId[$sbasId]->get_coll_id()) {
// record is already in trash so active it
foreach ($record->get_subdefs() as $subdef) {
if (($pl = $subdef->get_permalink())) {

View File

@@ -463,6 +463,8 @@ class PushController extends Controller
}
try {
$manager = $this->getEntityManager();
$password = $this->getRandomGenerator()->generateString(128);
$user = $this->getUserManipulator()->createUser($email, $password, $email);
@@ -476,12 +478,15 @@ class PushController extends Controller
$user->setCompany($request->request->get('company'));
}
if ($request->request->get('job')) {
$user->setCompany($request->request->get('job'));
$user->setJob($request->request->get('job'));
}
if ($request->request->get('form_geonameid')) {
$this->getUserManipulator()->setGeonameId($user, $request->request->get('form_geonameid'));
if ($request->request->get('city')) {
$this->getUserManipulator()->setGeonameId($user, $request->request->get('city'));
}
$manager->persist($user);
$manager->flush();
$result['message'] = $this->app->trans('User successfully created');
$result['success'] = true;
$result['user'] = $this->formatUser($user);

View File

@@ -179,7 +179,6 @@ class QueryController extends Controller
};
$userManipulator->setUserSetting($user, 'last_jsonquery', (string)$request->request->get('jsQuery'));
$jsQuery = @json_decode((string)$request->request->get('jsQuery'), true);
if(($ft = $findFulltext($jsQuery['query'])) !== null) {
$userManipulator->setUserSetting($user, 'start_page_query', $ft);
@@ -215,7 +214,7 @@ class QueryController extends Controller
if (min($d2top, $d2bottom) < 4) {
if ($d2bottom < 4) {
if($page != 1){
$string .= "<a id='PREV_PAGE' class='btn btn-primary btn-mini'></a>";
$string .= "<a id='PREV_PAGE' class='btn btn-primary btn-mini icon-baseline-chevron_left-24px'></a>";
}
for ($i = 1; ($i <= 4 && (($i <= $npages) === true)); $i++) {
if ($i == $page)
@@ -224,13 +223,13 @@ class QueryController extends Controller
$string .= '<a class="btn btn-primary btn-mini search-navigate-action" data-page="'.$i.'">' . $i . '</a>';
}
if ($npages > 4)
$string .= "<a id='NEXT_PAGE' class='btn btn-primary btn-mini'></a>";
$string .= '<a href="#" class="btn btn-primary btn-mini search-navigate-action" data-page="' . $npages . '" id="last"></a>';
$string .= "<a id='NEXT_PAGE' class='btn btn-primary btn-mini icon icon-baseline-chevron_right-24px'></a>";
$string .= '<a href="#" class="btn btn-primary btn-mini search-navigate-action icon icon-double-arrows" data-page="' . $npages . '" id="last"></a>';
} else {
$start = $npages - 4;
if (($start) > 0){
$string .= '<a class="btn btn-primary btn-mini search-navigate-action" data-page="1" id="first"></a>';
$string .= '<a id="PREV_PAGE" class="btn btn-primary btn-mini"></a>';
$string .= '<a class="btn btn-primary btn-mini search-navigate-action" data-page="1" id="first"><span class="icon icon-double-arrows icon-inverse"></span></a>';
$string .= '<a id="PREV_PAGE" class="btn btn-primary btn-mini icon icon-baseline-chevron_left-24px"></a>';
}else
$start = 1;
for ($i = ($start); $i <= $npages; $i++) {
@@ -240,11 +239,11 @@ class QueryController extends Controller
$string .= '<a class="btn btn-primary btn-mini search-navigate-action" data-page="'.$i.'">' . $i . '</a>';
}
if($page < $npages){
$string .= "<a id='NEXT_PAGE' class='btn btn-primary btn-mini'></a>";
$string .= "<a id='NEXT_PAGE' class='btn btn-primary btn-mini icon icon-baseline-chevron_right-24px'></a>";
}
}
} else {
$string .= '<a class="btn btn-primary btn-mini btn-mini search-navigate-action" data-page="1" id="first"></a>';
$string .= '<a class="btn btn-primary btn-mini search-navigate-action" data-page="1" id="first"><span class="icon icon-double-arrows icon-inverse"></span></a>';
for ($i = ($page - 2); $i <= ($page + 2); $i++) {
if ($i == $page)
@@ -253,10 +252,10 @@ class QueryController extends Controller
$string .= '<a class="btn btn-primary btn-mini search-navigate-action" data-page="'.$i.'">' . $i . '</a>';
}
$string .= '<a href="#" class="btn btn-primary btn-mini search-navigate-action" data-page="' . $npages . '" id="last"></a>';
$string .= '<a href="#" class="btn btn-primary btn-mini search-navigate-action icon icon-double-arrows" data-page="' . $npages . '" id="last"></a>';
}
}
$string .= '<div style="display:none;"><div id="NEXT_PAGE"></div><div id="PREV_PAGE"></div></div>';
$string .= '<div style="display:none;"><div id="NEXT_PAGE" class="icon icon-baseline-chevron_right-24px"></div><div id="PREV_PAGE" class="icon icon-baseline-chevron_left-24px"></div></div>';
$explain = $this->render(
"prod/results/infos.html.twig",
@@ -317,7 +316,7 @@ class QueryController extends Controller
</tfoot>
</table></div></div>'
. '</div><a href="#" class="search-display-info" data-infos="' . str_replace('"', '&quot;', $explain) . '">'
. $this->app->trans('%total% reponses', ['%total%' => '<span>'.$result->getTotal().'</span>']) . '</a>';
. $this->app->trans('%total% reponses', ['%total%' => '<span>'.number_format($result->getTotal(),null, null, ' ').'</span>']) . '</a>';
$json['infos'] = $infoResult;
$json['navigationTpl'] = $string;
@@ -471,7 +470,6 @@ class QueryController extends Controller
$json['results'] = $this->render($template, ['results'=> $result]);
}
return $this->app->json($json);
}

View File

@@ -15,12 +15,11 @@ use Alchemy\Phrasea\Core\Configuration\DisplaySettingService;
use Alchemy\Phrasea\Exception\SessionNotFound;
use Alchemy\Phrasea\Feed\Aggregate;
use Alchemy\Phrasea\Helper;
use Alchemy\Phrasea\Model\Entities\UserSetting;
use Alchemy\Phrasea\Helper\WorkZone as WorkzoneHelper;
use Alchemy\Phrasea\Model\Repositories\FeedRepository;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
use Symfony\Component\HttpFoundation\Request;
class RootController extends Controller
{
use Application\Helper\FirewallAware;
@@ -41,12 +40,11 @@ class RootController extends Controller
public function indexAction(Request $request) {
try {
\Session_Logger::updateClientInfos($this->app, 1);
} catch (SessionNotFound $e) {
}
catch (SessionNotFound $e) {
return $this->app->redirectPath('logout');
}
$css = [];
$user = $this->getAuthenticatedUser();
$cssfile = $this->getSettings()->getUserSetting($user, 'css');
@@ -85,6 +83,22 @@ class RootController extends Controller
/** @var \Closure $filter */
$filter = $this->app['plugin.filter_by_authorization'];
/* prepare work to extend whole taskbar... later
$menus = [
'push' => ['native'=>true, 'n'=>0],
'tools' => ['native'=>true, 'n'=>0],
];
/ ** @var ActionBarPluginInterface $plugin * /
foreach($filter('actionbar') as $kplugin=>$plugin) {
foreach($plugin->getActionBar() as $kmenu=>$menu) {
if(!array_key_exists($kmenu, $menus)) {
$menus[$kmenu] = ['native'=>false, 'n'=>0];
}
$menus[$kmenu]['n']++;
}
}
*/
$plugins = [
'workzone' => $filter('workzone'),
'actionbar' => $filter('actionbar'),
@@ -92,7 +106,7 @@ class RootController extends Controller
return $this->render('prod/index.html.twig', [
'module_name' => 'Production',
'WorkZone' => new Helper\WorkZone($this->app, $request),
'WorkZone' => new WorkzoneHelper($this->app, $request),
'module_prod' => $helper,
'search_datas' => $helper->get_search_datas(),
'cssfile' => $cssfile,
@@ -105,7 +119,7 @@ class RootController extends Controller
'feeds' => $feeds,
'aggregate' => $aggregate,
'GV_google_api' => $conf->get(['registry', 'webservices', 'google-charts-enabled']),
'geocodingProviders' => $conf->get(['geocoding-providers']),
'geocodingProviders' => $conf->get(['geocoding-providers']),
'search_status' => \databox_status::getSearchStatus($this->app),
'thesau_js_list' => $thjslist,
'thesau_json_sbas' => json_encode($sbas),

View File

@@ -367,15 +367,17 @@ class UploadController extends Controller
$postMaxSize = PHP_INT_MAX;
}
$r = 0;
switch (strtolower(substr($postMaxSize, -1))) {
/** @noinspection PhpMissingBreakStatementInspection */
case 'g':
$postMaxSize *= 1024;
$r += 10;
/** @noinspection PhpMissingBreakStatementInspection */
case 'm':
$postMaxSize *= 1024;
$r += 10;
case 'k':
$postMaxSize *= 1024;
$r += 10;
$postMaxSize = ((int)($postMaxSize))<<$r;
}
return min(UploadedFile::getMaxFilesize(), (int) $postMaxSize);

View File

@@ -522,27 +522,35 @@ class AccountController extends Controller
$list = array_keys($this->app['repo.collections-registry']->getBaseIdMap());
$this->app->getAclForUser($user)->revoke_access_from_bases($list);
try {
$this->app->getAclForUser($user)->revoke_access_from_bases($list);
}
catch (\Exception $e) {
// one or more access could not be revoked ? the user will not be phantom
$this->app->addFlash('error', $this->app->trans('phraseanet::error: failed to revoke some user access'));
}
if ($this->app->getAclForUser($user)->is_phantom()) {
// send confirmation email: the account has been deleted
try {
$receiver = Receiver::fromUser($user);
} catch (InvalidArgumentException $e) {
$this->app->addFlash('error', $this->app->trans('phraseanet::erreur: echec du serveur de mail'));
$mail = MailSuccessAccountDelete::create($this->app, $receiver);
}
catch (InvalidArgumentException $e) {
$this->app->addFlash('error', $this->app->trans('phraseanet::erreur: echec du serveur de mail'));
$mail = null;
}
$mail = MailSuccessAccountDelete::create($this->app, $receiver);
$this->app['manipulator.user']->delete($user);
$this->deliver($mail);
if($mail) {
$this->deliver($mail);
}
$this->getAuthenticator()->closeAccount();
$this->app->addFlash('info', $this->app->trans('phraseanet::account The account has been deleted'));
}
$this->getAuthenticator()->closeAccount();
$this->app->addFlash('info', $this->app->trans('phraseanet::account The account has been deleted'));
}
/**

View File

@@ -265,7 +265,7 @@ class LoginController extends Controller
return $this->render('login/register-classic.html.twig', array_merge(
$this->getDefaultTemplateVariables($request),
[
'geonames_server_uri' => str_replace(sprintf('%s:', parse_url($url, PHP_URL_SCHEME)), '', $url),
'geonames_server_uri' => $url,
'form' => $form->createView()
]));
}

View File

@@ -94,10 +94,9 @@ class SessionController extends Controller
}
/**
* Check session state
*
* @param Request $request
* @param Request $request
* @return JsonResponse
* @throws \Exception in case "new \DateTime()" fails ?
*/
public function updateSession(Request $request)
{
@@ -120,7 +119,8 @@ class SessionController extends Controller
return $this->app->json($ret);
}
} else {
}
else {
$ret['status'] = 'disconnected';
return $this->app->json($ret);
@@ -128,7 +128,8 @@ class SessionController extends Controller
try {
$this->getApplicationBox()->get_connection();
} catch (\Exception $e) {
}
catch (\Exception $e) {
return $this->app->json($ret);
}
@@ -148,8 +149,9 @@ class SessionController extends Controller
$module->setModuleId($moduleId);
$module->setSession($session);
$manager->persist($module);
} else {
$manager->persist($session->getModuleById($moduleId)->setUpdated(new \DateTime()));
}
else {
$manager->persist($session->getModuleById($moduleId)->setUpdated($now));
}
$manager->persist($session);
@@ -231,7 +233,10 @@ class SessionController extends Controller
*/
private function getBasketRepository()
{
return $this->getEntityManager()->getRepository('Phraseanet:Basket');
/** @var BasketRepository $ret */
$ret = $this->getEntityManager()->getRepository('Phraseanet:Basket');
return $ret;
}
/**

View File

@@ -146,7 +146,7 @@ class RegistryFormManipulator
],
'webservices' => [
'google-charts-enabled' => true,
'geonames-server' => 'http://geonames.alchemyasp.com/',
'geonames-server' => 'https://geonames.alchemyasp.com/',
'captchas-enabled' => false,
'recaptcha-public-key' => '',
'recaptcha-private-key' => '',

View File

@@ -16,7 +16,7 @@ class Version
/**
* @var string
*/
private $number = '4.1.0-alpha.14a';
private $number = '4.1.0-alpha.15a';
/**
* @var string

View File

@@ -11,28 +11,29 @@
namespace Alchemy\Phrasea\Helper;
use Doctrine\Common\Collections\ArrayCollection;
use Alchemy\Phrasea\Model\Entities\Basket as BasketEntity;
use Alchemy\Phrasea\Model\Repositories\BasketRepository;
use Alchemy\Phrasea\Model\Repositories\StoryWZRepository;
use Doctrine\Common\Collections\ArrayCollection;
class WorkZone extends Helper
{
const BASKETS = 'baskets';
const STORIES = 'stories';
const BASKETS = 'baskets';
const STORIES = 'stories';
const VALIDATIONS = 'validations';
/**
*
* Returns an ArrayCollection containing three keys :
* - self::BASKETS : an ArrayCollection of the actives baskets
* (Non Archived)
* - self::BASKETS : an ArrayCollection of the actives baskets (Non Archived)
* - self::STORIES : an ArrayCollection of working stories
* - self::VALIDATIONS : the validation people are waiting from me
*
* @return \Doctrine\Common\Collections\ArrayCollection
* @param null|string $sort "date"|"name"
* @return ArrayCollection
*/
public function getContent($sort)
public function getContent($sort = null)
{
/* @var $repo_baskets Alchemy\Phrasea\Model\Repositories\BasketRepository */
/* @var $repo_baskets BasketRepository */
$repo_baskets = $this->app['repo.baskets'];
$sort = in_array($sort, ['date', 'name']) ? $sort : 'name';
@@ -42,7 +43,7 @@ class WorkZone extends Helper
$baskets = $repo_baskets->findActiveByUser($this->app->getAuthenticatedUser(), $sort);
// force creation of a default basket
if (0 === count($baskets)) {
if (count($baskets) === 0) {
$basket = new BasketEntity();
$basket->setName($this->app->trans('Default basket'));
@@ -55,7 +56,7 @@ class WorkZone extends Helper
$validations = $repo_baskets->findActiveValidationByUser($this->app->getAuthenticatedUser(), $sort);
/* @var $repo_stories Alchemy\Phrasea\Model\Repositories\StoryWZRepository */
/* @var $repo_stories StoryWZRepository */
$repo_stories = $this->app['repo.story-wz'];
$stories = $repo_stories->findByUser($this->app, $this->app->getAuthenticatedUser(), $sort);

View File

@@ -61,7 +61,7 @@ class SubdefGenerator
public function generateSubdefs(\record_adapter $record, array $wanted_subdefs = null)
{
if ($record->get_hd_file() !== null) {
if ($record->get_hd_file() !== null && $record->get_hd_file()->getMimeType() == "application/x-indesign") {
$mediaSource = $this->mediavorus->guess($record->get_hd_file()->getPathname());
$metadatas = $mediaSource->getMetadatas();
@@ -69,15 +69,27 @@ class SubdefGenerator
if(!isset($this->tmpFilesystem)){
$this->tmpFilesystem = Manager::create();
}
$tmpDir = $this->tmpFilesystem->createTemporaryDirectory();
$tmpDir = $this->tmpFilesystem->createTemporaryDirectory(0777, 500);
try {
$this->app['filesystem']->dumpFile($tmpDir.'/file.jpg', $metadatas->get('XMP-xmp:PageImage')->getValue()->asString());
$this->tmpFilePath = $tmpDir.'/file.jpg';
} catch (\Exception $e) {
$this->logger->error(sprintf('Unable to write temporary file : %s', $e->getMessage()));
$files = $this->app['exiftool.preview-extractor']->extract($record->get_hd_file()->getPathname(), $tmpDir);
$selected = null;
$size = null;
foreach ($files as $file) {
if ($file->isDir() || $file->isDot()) {
continue;
}
if (is_null($selected) || $file->getSize() > $size) {
$selected = $file->getPathname();
$size = $file->getSize();
}
}
if ($selected) {
$this->tmpFilePath = $selected;
}
}
}

View File

@@ -73,6 +73,9 @@ class SubdefSubstituer
$this->createMediaSubdef($record, 'document', $media);
$record->setMimeType($media->getFile()->getMimeType());
$record->setType($media->getType());
$record->write_metas();
if ($shouldSubdefsBeRebuilt) {

View File

@@ -14,6 +14,7 @@ namespace Alchemy\Phrasea\Metadata;
use Alchemy\Phrasea\Border\File;
use Alchemy\Phrasea\Databox\DataboxRepository;
use Alchemy\Phrasea\Metadata\Tag\NoSource;
use DateTime;
use PHPExiftool\Driver\Metadata\Metadata;
class PhraseanetMetadataSetter
@@ -66,8 +67,16 @@ class PhraseanetMetadataSetter
continue;
}
$data['value'] = $value;
if ($field->get_type() == 'date') {
try {
$dateTime = new DateTime($value);
$value = $dateTime->format('Y/m/d H:i:s');
} catch (\Exception $e) {
// $value unchanged
}
}
$data['value'] = $value;
$metadataInRecordFormat[] = $data;
}
}

View File

@@ -54,21 +54,24 @@ class BasketRepository extends EntityRepository
/**
* Returns all basket for a given user that are not marked as archived
*
* @param User $user
* @param User $user
* @param null|string $sort
* @return Basket[]
*/
public function findActiveByUser(User $user, $sort = null)
{
$dql = 'SELECT b
FROM Phraseanet:Basket b
LEFT JOIN b.elements e
WHERE b.user = :usr_id
AND b.archived = false';
// checked : 4 usages, "b.elements" is useless
$dql = "SELECT b\n"
. " FROM Phraseanet:Basket b\n"
// . " LEFT JOIN b.elements e\n" //
. " WHERE b.user = :usr_id\n"
. " AND b.archived = false";
if ($sort == 'date') {
$dql .= ' ORDER BY b.created DESC';
} elseif ($sort == 'name') {
$dql .= ' ORDER BY b.name ASC';
$dql .= "\n ORDER BY b.created DESC";
}
elseif ($sort == 'name') {
$dql .= "\n ORDER BY b.name ASC";
}
$query = $this->_em->createQuery($dql);
@@ -80,24 +83,27 @@ class BasketRepository extends EntityRepository
/**
* Returns all unread basket for a given user that are not marked as archived
*
* @param User $user
* @param User $user
* @return Basket[]
*/
public function findUnreadActiveByUser(User $user)
{
$dql = 'SELECT b
FROM Phraseanet:Basket b
JOIN b.elements e
LEFT JOIN b.validation s
LEFT JOIN s.participants p
WHERE b.archived = false
AND (
(b.user = :usr_id_owner AND b.isRead = false)
OR (b.user != :usr_id_ownertwo
AND p.user = :usr_id_participant
AND p.is_aware = false)
)
AND (s.expires IS NULL OR s.expires > CURRENT_TIMESTAMP())';
// checked : 2 usages, "b.elements" is useless
$dql = "SELECT b\n"
. " FROM Phraseanet:Basket b\n"
// . " JOIN b.elements e\n"
. " LEFT JOIN b.validation s\n"
. " LEFT JOIN s.participants p\n"
. " WHERE b.archived = false\n"
. " AND (\n"
. " (b.user = :usr_id_owner AND b.isRead = false)\n"
. " OR \n"
. " (b.user != :usr_id_ownertwo\n"
. " AND p.user = :usr_id_participant\n"
. " AND p.is_aware = false\n"
. " AND s.expires > CURRENT_TIMESTAMP()\n"
. " )\n"
. " )";
$params = [
'usr_id_owner' => $user->getId(),
@@ -115,11 +121,22 @@ class BasketRepository extends EntityRepository
* Returns all baskets that are in validation session not expired and
* where a specified user is participant (not owner)
*
* @param User $user
* @param User $user
* @param null|string $sort
* @return Basket[]
*/
public function findActiveValidationByUser(User $user, $sort = null)
{
// checked : 2 usages, "b.elements" seems useless.
$dql = "SELECT b\n"
. "FROM Phraseanet:Basket b\n"
// . " JOIN b.elements e\n"
// . " JOIN e.validation_datas v\n"
. " JOIN b.validation s\n"
. " JOIN s.participants p\n"
. "WHERE b.user != ?1 AND p.user = ?2\n"
. " AND (s.expires IS NULL OR s.expires > CURRENT_TIMESTAMP())";
$dql = 'SELECT b
FROM Phraseanet:Basket b
JOIN b.elements e
@@ -130,9 +147,9 @@ class BasketRepository extends EntityRepository
AND (s.expires IS NULL OR s.expires > CURRENT_TIMESTAMP()) ';
if ($sort == 'date') {
$dql .= ' ORDER BY b.created DESC';
$dql .= "\nORDER BY b.created DESC";
} elseif ($sort == 'name') {
$dql .= ' ORDER BY b.name ASC';
$dql .= "\nORDER BY b.name ASC";
}
$query = $this->_em->createQuery($dql);
@@ -152,10 +169,11 @@ class BasketRepository extends EntityRepository
*/
public function findUserBasket($basket_id, User $user, $requireOwner)
{
$dql = 'SELECT b
FROM Phraseanet:Basket b
LEFT JOIN b.elements e
WHERE b.id = :basket_id';
// checked : 3 usages, "b.elements e" seems useless
$dql = "SELECT b\n"
. " FROM Phraseanet:Basket b\n"
// . " LEFT JOIN b.elements e\n"
. " WHERE b.id = :basket_id";
$query = $this->_em->createQuery($dql);
$query->setParameters(['basket_id' => $basket_id]);
@@ -188,7 +206,7 @@ class BasketRepository extends EntityRepository
public function findContainingRecordForUser(\record_adapter $record, User $user)
{
// todo : check "e.sbas_id = e.sbas_id" ???
$dql = 'SELECT b
FROM Phraseanet:Basket b
JOIN b.elements e
@@ -210,30 +228,31 @@ class BasketRepository extends EntityRepository
{
switch ($type) {
case self::RECEIVED:
$dql = 'SELECT b
FROM Phraseanet:Basket b
JOIN b.elements e
WHERE b.user = :usr_id AND b.pusher_id IS NOT NULL';
// todo : check when called, and if "LEFT JOIN b.elements e" is usefull
$dql = "SELECT b\n"
. "FROM Phraseanet:Basket b\n"
. " JOIN b.elements e\n"
. "WHERE b.user = :usr_id AND b.pusher_id IS NOT NULL";
$params = [
'usr_id' => $user->getId()
];
break;
case self::VALIDATION_DONE:
$dql = 'SELECT b
FROM Phraseanet:Basket b
JOIN b.elements e
JOIN b.validation s
JOIN s.participants p
WHERE b.user != ?1 AND p.user = ?2';
// todo : check when called, and if "LEFT JOIN b.elements e" is usefull
$dql = "SELECT b\n"
. "FROM Phraseanet:Basket b\n"
. " JOIN b.elements e\n"
. " JOIN b.validation s\n"
. " JOIN s.participants p\n"
. "WHERE b.user != ?1 AND p.user = ?2";
$params = [
1 => $user->getId()
, 2 => $user->getId()
1 => $user->getId(),
2 => $user->getId()
];
break;
case self::VALIDATION_SENT:
$dql = 'SELECT b
FROM Phraseanet:Basket b
JOIN b.elements e
JOIN b.validation v
WHERE b.user = :usr_id';
$params = [
@@ -243,7 +262,6 @@ class BasketRepository extends EntityRepository
case self::MYBASKETS:
$dql = 'SELECT b
FROM Phraseanet:Basket b
LEFT JOIN b.elements e
LEFT JOIN b.validation s
LEFT JOIN s.participants p
WHERE (b.user = :usr_id)';
@@ -252,6 +270,7 @@ class BasketRepository extends EntityRepository
];
break;
default:
// todo : check when called, and if "LEFT JOIN b.elements e" is usefull
$dql = 'SELECT b
FROM Phraseanet:Basket b
LEFT JOIN b.elements e
@@ -297,6 +316,7 @@ class BasketRepository extends EntityRepository
*/
public function findActiveValidationAndBasketByUser(User $user, $sort = null)
{
// todo : check caller and if "LEFT JOIN b.elements e" is usefull
$dql = 'SELECT b
FROM Phraseanet:Basket b
LEFT JOIN b.elements e

View File

@@ -30,6 +30,11 @@ class FieldKey implements Key, QueryPostProcessor
return $this->getField($context)->getIndexField($raw);
}
public function getFieldType(QueryContext $context)
{
return $this->getField($context)->getType();
}
public function isValueCompatible($value, QueryContext $context)
{
return ValueChecker::isValueCompatible($this->getField($context), $value);

View File

@@ -6,6 +6,7 @@ use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryContext;
interface Key
{
public function getFieldType(QueryContext $context);
public function getIndexField(QueryContext $context, $raw = false);
public function isValueCompatible($value, QueryContext $context);
public function __toString();

View File

@@ -23,6 +23,11 @@ class MetadataKey implements Key
return $this->getTag($context)->getIndexField($raw);
}
public function getFieldType(QueryContext $context)
{
return $this->getTag($context)->getType();
}
public function isValueCompatible($value, QueryContext $context)
{
return ValueChecker::isValueCompatible($this->getTag($context), $value);

View File

@@ -52,6 +52,11 @@ class NativeKey implements Key
$this->key = $key;
}
public function getFieldType(QueryContext $context)
{
return $this->type;
}
public function getIndexField(QueryContext $context, $raw = false)
{
return $this->key;

View File

@@ -2,18 +2,20 @@
namespace Alchemy\Phrasea\SearchEngine\Elastic\AST\KeyValue;
use Alchemy\Phrasea\SearchEngine\Elastic\FieldMapping;
use Alchemy\Phrasea\SearchEngine\Elastic\RecordHelper;
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Field as StructureField;
use Assert\Assertion;
use Alchemy\Phrasea\SearchEngine\Elastic\AST\KeyValue\FieldKey;
use Alchemy\Phrasea\SearchEngine\Elastic\AST\KeyValue\Key;
use Alchemy\Phrasea\SearchEngine\Elastic\AST\Node;
use Alchemy\Phrasea\SearchEngine\Elastic\Exception\QueryException;
use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryContext;
use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryHelper;
use Alchemy\Phrasea\SearchEngine\Elastic\Search\QueryPostProcessor;
class RangeExpression extends Node
{
/** @var FieldKey */
private $key;
private $lower_bound;
private $lower_inclusive;
private $higher_bound;
@@ -55,20 +57,34 @@ class RangeExpression extends Node
public function buildQuery(QueryContext $context)
{
$params = array();
if ($this->lower_bound !== null) {
$this->assertValueCompatible($this->lower_bound, $context);
if ($this->lower_inclusive) {
$params['gte'] = $this->lower_bound;
} else {
$params['gt'] = $this->lower_bound;
/** @var StructureField $field */
// $field = $this->key->getField($context);
$lower_bound = $this->lower_bound;
$higher_bound = $this->higher_bound;
if($this->key->getFieldType($context) === FieldMapping::TYPE_DATE) {
if($lower_bound !== null) {
$lower_bound = RecordHelper::sanitizeDate($lower_bound);
}
if($higher_bound !== null) {
$higher_bound = RecordHelper::sanitizeDate($higher_bound);
}
}
if ($this->higher_bound !== null) {
$this->assertValueCompatible($this->higher_bound, $context);
if ($this->higher_inclusive) {
$params['lte'] = $this->higher_bound;
if ($lower_bound !== null) {
$this->assertValueCompatible($lower_bound, $context);
if ($this->lower_inclusive) {
$params['gte'] = $lower_bound;
} else {
$params['lt'] = $this->higher_bound;
$params['gt'] = $lower_bound;
}
}
if ($higher_bound !== null) {
$this->assertValueCompatible($higher_bound, $context);
if ($this->higher_inclusive) {
$params['lte'] = $higher_bound;
} else {
$params['lt'] = $higher_bound;
}
}

View File

@@ -34,6 +34,11 @@ class TimestampKey implements Key, Typed
return FieldMapping::TYPE_DATE;
}
public function getFieldType(QueryContext $context)
{
return FieldMapping::TYPE_DATE;
}
public function getIndexField(QueryContext $context, $raw = false)
{
return $this->index_field;

View File

@@ -396,10 +396,10 @@ class ElasticSearchEngine implements SearchEngineInterface
if ($options->getDateFields() && ($options->getMaxDate() || $options->getMinDate())) {
$range = [];
if ($options->getMaxDate()) {
$range['lte'] = $options->getMaxDate()->format(FieldMapping::DATE_FORMAT_CAPTION_PHP);
$range['lte'] = $options->getMaxDate()->format('Y-m-d');
}
if ($options->getMinDate()) {
$range['gte'] = $options->getMinDate()->format(FieldMapping::DATE_FORMAT_CAPTION_PHP);
$range['gte'] = $options->getMinDate()->format('Y-m-d');
}
foreach ($options->getDateFields() as $dateField) {

View File

@@ -16,8 +16,7 @@ class FieldMapping
const DATE_FORMAT_MYSQL = 'yyyy-MM-dd HH:mm:ss';
const DATE_FORMAT_CAPTION = 'yyyy/MM/dd'; // ES format
const DATE_FORMAT_MYSQL_OR_CAPTION = 'yyyy-MM-dd HH:mm:ss||yyyy/MM/dd';
const DATE_FORMAT_CAPTION_PHP = 'Y/m/d'; // PHP format
const DATE_FORMAT_MYSQL_OR_CAPTION = 'yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||yyyy-MM||yyyy';
// Core types
const TYPE_STRING = 'string';

View File

@@ -155,15 +155,16 @@ class BulkOperation
// nb: results (items) are returned IN THE SAME ORDER as commands were pushed in the stack
// so the items[X] match the operationIdentifiers[X]
foreach ($response['items'] as $key => $item) {
foreach($item as $command=>$result) { // command may be "index" or "delete"
if($response['errors'] && $result['status'] >= 400) { // 4xx or 5xx error
throw new Exception(sprintf('%d: %s', $key, var_export($result, true)));
foreach ($item as $command=>$result) { // command may be "index" or "delete"
if ($response['errors'] && $result['status'] >= 400) { // 4xx or 5xx
$err = array_key_exists('error', $result) ? var_export($result['error'], true) : ($command . " error " . $result['status']);
throw new Exception(sprintf('%d: %s', $key, $err));
}
}
$operationIdentifier = $this->operationIdentifiers[$key];
if(is_string($operationIdentifier) || is_int($operationIdentifier)) { // dont include null keys
if (is_string($operationIdentifier) || is_int($operationIdentifier)) { // dont include null keys
$callbackData[$operationIdentifier] = $response['items'][$key];
}
}

View File

@@ -39,18 +39,13 @@ class MetadataHydrator implements HydratorInterface
public function hydrateRecords(array &$records)
{
$sql = <<<SQL
(SELECT record_id, ms.name AS `key`, m.value AS value, 'caption' AS type, ms.business AS private
FROM metadatas AS m
INNER JOIN metadatas_structure AS ms ON (ms.id = m.meta_struct_id)
WHERE record_id IN (?))
UNION
(SELECT record_id, t.name AS `key`, t.value AS value, 'exif' AS type, 0 AS private
FROM technical_datas AS t
WHERE record_id IN (?))
SQL;
$sql = "(SELECT record_id, ms.name AS `key`, m.value AS value, 'caption' AS type, ms.business AS private\n"
. " FROM metadatas AS m INNER JOIN metadatas_structure AS ms ON (ms.id = m.meta_struct_id)\n"
. " WHERE record_id IN (?))\n"
. "UNION\n"
. "(SELECT record_id, t.name AS `key`, t.value AS value, 'exif' AS type, 0 AS private\n"
. " FROM technical_datas AS t\n"
. " WHERE record_id IN (?))\n";
$ids = array_keys($records);
$statement = $this->connection->executeQuery(
@@ -62,7 +57,7 @@ SQL;
while ($metadata = $statement->fetch()) {
// Store metadata value
$key = $metadata['key'];
$value = $metadata['value'];
$value = trim($metadata['value']);
// Do not keep empty values
if ($key === '' || $value === '') {
@@ -80,7 +75,7 @@ SQL;
case 'caption':
// Sanitize fields
$value = StringHelper::crlfNormalize($value);
$value = $this->sanitizeValue($value, $this->structure->typeOf($key));
$value = $this->helper->sanitizeValue($value, $this->structure->typeOf($key));
// Private caption fields are kept apart
$type = $metadata['private'] ? 'private_caption' : 'caption';
// Caption are multi-valued
@@ -103,7 +98,7 @@ SQL;
}
$tag = $this->structure->getMetadataTagByName($key);
if ($tag) {
$value = $this->sanitizeValue($value, $tag->getType());
$value = $this->helper->sanitizeValue($value, $tag->getType());
}
// EXIF data is single-valued
$record['metadata_tags'][$key] = $value;
@@ -118,33 +113,6 @@ SQL;
$this->clearGpsPositionBuffer();
}
private function sanitizeValue($value, $type)
{
switch ($type) {
case FieldMapping::TYPE_STRING:
return str_replace("\0", "", $value);
case FieldMapping::TYPE_DATE:
return $this->helper->sanitizeDate($value);
case FieldMapping::TYPE_FLOAT:
case FieldMapping::TYPE_DOUBLE:
return (float) $value;
case FieldMapping::TYPE_INTEGER:
case FieldMapping::TYPE_LONG:
case FieldMapping::TYPE_SHORT:
case FieldMapping::TYPE_BYTE:
return (int) $value;
case FieldMapping::TYPE_BOOLEAN:
return (bool) $value;
default:
return $value;
}
}
private function handleGpsPosition(&$records, $id, $tag_name, $value)
{
// Get position object

View File

@@ -11,6 +11,8 @@
namespace Alchemy\Phrasea\SearchEngine\Elastic\Indexer\Record\Hydrator;
use Alchemy\Phrasea\SearchEngine\Elastic\FieldMapping;
use Alchemy\Phrasea\SearchEngine\Elastic\RecordHelper;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\Connection as DriverConnection;
@@ -18,31 +20,34 @@ class TitleHydrator implements HydratorInterface
{
private $connection;
public function __construct(DriverConnection $connection)
/** @var RecordHelper */
private $helper;
public function __construct(DriverConnection $connection, RecordHelper $helper)
{
$this->connection = $connection;
$this->helper = $helper;
}
public function hydrateRecords(array &$records)
{
$sql = <<<SQL
SELECT
m.`record_id`,
CASE ms.`thumbtitle`
WHEN "1" THEN "default"
WHEN "0" THEN "default"
ELSE ms.`thumbtitle`
END AS locale,
CASE ms.`thumbtitle`
WHEN "0" THEN r.`originalname`
ELSE GROUP_CONCAT(m.`value` ORDER BY ms.`thumbtitle`, ms.`sorter` SEPARATOR " - ")
END AS title
FROM metadatas AS m FORCE INDEX(`record_id`)
STRAIGHT_JOIN metadatas_structure AS ms ON (ms.`id` = m.`meta_struct_id`)
STRAIGHT_JOIN record AS r ON (r.`record_id` = m.`record_id`)
WHERE m.`record_id` IN (?)
GROUP BY m.`record_id`, ms.`thumbtitle`
SQL;
$sql = "SELECT\n"
. "m.`record_id`,\n"
. " CASE ms.`thumbtitle`\n"
. " WHEN '1' THEN 'default'\n"
. " WHEN '0' THEN 'default'\n"
. " ELSE ms.`thumbtitle`\n"
. " END AS locale,\n"
. " CASE ms.`thumbtitle`\n"
. " WHEN '0' THEN r.`originalname`\n"
. " ELSE GROUP_CONCAT(m.`value` ORDER BY ms.`thumbtitle`, ms.`sorter` SEPARATOR ' - ')\n"
. " END AS title\n"
. "FROM metadatas AS m FORCE INDEX(`record_id`)\n"
. "STRAIGHT_JOIN metadatas_structure AS ms ON (ms.`id` = m.`meta_struct_id`)\n"
. "STRAIGHT_JOIN record AS r ON (r.`record_id` = m.`record_id`)\n"
. "WHERE m.`record_id` IN (?)\n"
. "GROUP BY m.`record_id`, ms.`thumbtitle`\n";
$statement = $this->connection->executeQuery(
$sql,
array(array_keys($records)),
@@ -50,7 +55,7 @@ SQL;
);
while ($row = $statement->fetch()) {
$records[$row['record_id']]['title'][$row['locale']] = $row['title'];
$records[$row['record_id']]['title'][$row['locale']] = $this->helper->sanitizeValue($row['title'], FieldMapping::TYPE_STRING);
}
}
}

View File

@@ -57,6 +57,9 @@ class DateFieldMapping extends ComplexFieldMapping
*/
protected function getProperties()
{
return array_merge([ 'format' => $this->format ], parent::getProperties());
return array_merge([
'format' => $this->format,
'ignore_malformed' => true
], parent::getProperties());
}
}

View File

@@ -89,31 +89,72 @@ class RecordHelper
return $this->collectionMap;
}
/**
* @param string $date
* @return bool
*/
public static function validateDate($date)
{
$d = DateTime::createFromFormat(FieldMapping::DATE_FORMAT_CAPTION_PHP, $date);
return $d && $d->format(FieldMapping::DATE_FORMAT_CAPTION_PHP) == $date;
}
/**
* @param string $value
* @return null|string
*/
public static function sanitizeDate($value)
{
// introduced in https://github.com/alchemy-fr/Phraseanet/commit/775ce804e0257d3a06e4e068bd17330a79eb8370#diff-bee690ed259e0cf73a31dee5295d2edcR286
// not sure if it's really needed
$v_fix = null;
try {
$date = new \DateTime($value);
return $date->format(FieldMapping::DATE_FORMAT_CAPTION_PHP);
$a = explode(';', preg_replace('/\D+/', ';', trim($value)));
switch (count($a)) {
case 1: // yyyy
$date = new \DateTime($a[0] . '-01-01'); // will throw if date is not valid
$v_fix = $date->format('Y');
break;
case 2: // yyyy;mm
$date = new \DateTime( $a[0] . '-' . $a[1] . '-01');
$v_fix = $date->format('Y-m');
break;
case 3: // yyyy;mm;dd
$date = new \DateTime($a[0] . '-' . $a[1] . '-' . $a[2]);
$v_fix = $date->format('Y-m-d');
break;
case 4:
$date = new \DateTime($a[0] . '-' . $a[1] . '-' . $a[2] . ' ' . $a[3] . ':00:00');
$v_fix = $date->format('Y-m-d H:i:s');
break;
case 5:
$date = new \DateTime($a[0] . '-' . $a[1] . '-' . $a[2] . ' ' . $a[3] . ':' . $a[4] . ':00');
$v_fix = $date->format('Y-m-d H:i:s');
break;
case 6:
$date = new \DateTime($a[0] . '-' . $a[1] . '-' . $a[2] . ' ' . $a[3] . ':' . $a[4] . ':' . $a[5]);
$v_fix = $date->format('Y-m-d H:i:s');
break;
}
} catch (\Exception $e) {
return null;
// no-op, v_fix = null
}
return $v_fix;
}
public function sanitizeValue($value, $type)
{
switch ($type) {
case FieldMapping::TYPE_DATE:
return self::sanitizeDate($value);
case FieldMapping::TYPE_FLOAT:
case FieldMapping::TYPE_DOUBLE:
return (float) $value;
case FieldMapping::TYPE_INTEGER:
case FieldMapping::TYPE_LONG:
case FieldMapping::TYPE_SHORT:
case FieldMapping::TYPE_BYTE:
return (int) $value;
case FieldMapping::TYPE_BOOLEAN:
return (bool) $value;
case FieldMapping::TYPE_STRING:
return str_replace("\0", '', $value);
default:
return $value;
}
}
}

View File

@@ -110,41 +110,50 @@ class QueryHelper
}
}
public static function getRangeFromDateString($string)
public static function getRangeFromDateString($value)
{
$formats = ['Y/m/d', 'Y/m', 'Y'];
$deltas = ['+1 day', '+1 month', '+1 year'];
$to = null;
while ($format = array_pop($formats)) {
$delta = array_pop($deltas);
$from = date_create_from_format($format, $string);
if ($from !== false) {
// Rewind to start of range
$month = 1;
$day = 1;
switch ($format) {
case 'Y/m/d':
$day = (int) $from->format('d');
case 'Y/m':
$month = (int) $from->format('m');
case 'Y':
$year = (int) $from->format('Y');
}
date_date_set($from, $year, $month, $day);
date_time_set($from, 0, 0, 0);
// Create end of the the range
$to = date_modify(clone $from, $delta);
break;
$date_from = null;
$date_to = null;
try {
$a = explode(';', preg_replace('/\D+/', ';', trim($value)));
switch (count($a)) {
case 1: // yyyy
$date_to = clone($date_from = new \DateTime($a[0] . '-01-01 00:00:00')); // will throw if date is not valid
$date_to->add(new \DateInterval('P1Y'));
break;
case 2: // yyyy;mm
$date_to = clone($date_from = new \DateTime($a[0] . '-' . $a[1] . '-01 00:00:00')); // will throw if date is not valid
$date_to->add(new \DateInterval('P1M'));
break;
case 3: // yyyy;mm;dd
$date_to = clone($date_from = new \DateTime($a[0] . '-' . $a[1] . '-' . $a[2] . ' 00:00:00')); // will throw if date is not valid
$date_to->add(new \DateInterval('P1D'));
break;
case 4:
$date_to = clone($date_from = new \DateTime($a[0] . '-' . $a[1] . '-' . $a[2] . ' ' . $a[3] . ':00:00'));
$date_to->add(new \DateInterval('PT1H'));
break;
case 5:
$date_to = clone($date_from = new \DateTime($a[0] . '-' . $a[1] . '-' . $a[2] . ' ' . $a[3] . ':' . $a[4] . ':00'));
$date_to->add(new \DateInterval('PT1M'));
break;
case 6:
$date_to = clone($date_from = new \DateTime($a[0] . '-' . $a[1] . '-' . $a[2] . ' ' . $a[3] . ':' . $a[4] . ':' . $a[5]));
// $date_to->add(new \DateInterval('PT1S')); // no need since precision is 1 sec, a "equal" will be generated when from==to
break;
}
}
catch (\Exception $e) {
// no-op
}
if (!$from || !$to) {
throw new \InvalidArgumentException(sprintf('Invalid date "%s".', $string));
if ($date_from === null || $date_to === null) {
throw new \InvalidArgumentException(sprintf('Invalid date "%s".', $value));
}
return [
'from' => $from->format(FieldMapping::DATE_FORMAT_CAPTION_PHP),
'to' => $to->format(FieldMapping::DATE_FORMAT_CAPTION_PHP)
'from' => $date_from->format('Y-m-d H:i:s'),
'to' => $date_to->format('Y-m-d H:i:s')
];
}
}

View File

@@ -5,7 +5,7 @@ namespace Alchemy\Phrasea\SearchEngine\Elastic\Search;
use Alchemy\Phrasea\SearchEngine\Elastic\AST;
use Alchemy\Phrasea\SearchEngine\Elastic\Exception\Exception;
use Alchemy\Phrasea\SearchEngine\Elastic\FieldMapping;
use Alchemy\Phrasea\SearchEngine\Elastic\Mapping;
use Alchemy\Phrasea\SearchEngine\Elastic\RecordHelper;
use Alchemy\Phrasea\SearchEngine\Elastic\Structure\Structure;
use Hoa\Compiler\Llk\TreeNode;
use Hoa\Visitor\Element;
@@ -166,6 +166,12 @@ class QueryVisitor implements Visit
$key = $node->getChild(0)->accept($this);
$boundary = $node->getChild(1)->accept($this);
if ($this->isDateKey($key)) {
if(($v = RecordHelper::sanitizeDate($boundary)) !== null) {
$boundary = $v;
}
}
switch ($node->getId()) {
case NodeTypes::LT_EXPR:
return AST\KeyValue\RangeExpression::lessThan($key, $boundary);
@@ -195,11 +201,15 @@ class QueryVisitor implements Visit
try {
// Try to create a range for incomplete dates
$range = QueryHelper::getRangeFromDateString($right);
return new AST\KeyValue\RangeExpression(
$left,
$range['from'], true,
$range['to'], false
);
if ($range['from'] === $range['to']) {
return new AST\KeyValue\EqualExpression($left, $range['from']);
} else {
return new AST\KeyValue\RangeExpression(
$left,
$range['from'], true,
$range['to'], false
);
}
} catch (\InvalidArgumentException $e) {
// Fall back to equal expression
}

View File

@@ -3,7 +3,6 @@
namespace Alchemy\Phrasea\SearchEngine\Elastic\Structure;
use Alchemy\Phrasea\SearchEngine\Elastic\FieldMapping;
use Alchemy\Phrasea\SearchEngine\Elastic\Mapping;
use Alchemy\Phrasea\SearchEngine\Elastic\RecordHelper;
use Assert\Assertion;
@@ -20,7 +19,7 @@ class ValueChecker
{
Assertion::allIsInstanceOf($list, Typed::class);
$is_numeric = is_numeric($value);
$is_valid_date = RecordHelper::validateDate($value);
$is_valid_date = (RecordHelper::sanitizeDate($value) !== null);
$filtered = [];
foreach ($list as $item) {
switch ($item->getType()) {

View File

@@ -121,13 +121,16 @@ class WriteMetadataJob extends AbstractJob
$fieldName = $fieldStructure->get_name();
// skip fields with no src
if($tagName == '') {
if($tagName == '' || $tagName == 'Phraseanet:no-source') {
continue;
}
// check exiftool known tags to skip Phraseanet:tf-*
try {
TagFactory::getFromRDFTagname($tagName);
$tag = TagFactory::getFromRDFTagname($tagName);
if(!$tag->isWritable()) {
continue;
}
} catch (TagUnknown $e) {
continue;
}
@@ -139,29 +142,42 @@ class WriteMetadataJob extends AbstractJob
if ($fieldStructure->is_multi()) {
$values = array();
foreach ($fieldValues as $value) {
$values[] = $value->getValue();
$values[] = $this->removeNulChar($value->getValue());
}
$value = new Value\Multi($values);
} else {
$fieldValue = array_pop($fieldValues);
$value = $fieldValue->getValue();
$value = $this->removeNulChar($fieldValue->getValue());
$value = new Value\Mono($value);
// fix the dates edited into phraseanet
if($fieldStructure->get_type() === $fieldStructure::TYPE_DATE) {
try {
$value = self::fixDate($value); // will return NULL if the date is not valid
}
catch (\Exception $e) {
$value = null; // do NOT write back to iptc
}
}
if($value !== null) { // do not write invalid dates
$value = new Value\Mono($value);
}
}
} catch(\Exception $e) {
} catch (\Exception $e) {
// the field is not set in the record, erase it
if ($fieldStructure->is_multi()) {
$value = new Value\Multi(array(''));
}
else {
} else {
$value = new Value\Mono('');
}
}
$metadata->add(
new Metadata\Metadata($fieldStructure->get_tag(), $value)
);
if($value !== null) { // do not write invalid data
$metadata->add(
new Metadata\Metadata($fieldStructure->get_tag(), $value)
);
}
}
$writer = $this->getMetadataWriter($jobData->getApplication());
@@ -215,4 +231,39 @@ class WriteMetadataJob extends AbstractJob
return false;
}
private function removeNulChar($value)
{
return str_replace("\0", "", $value);
}
/**
* re-format a phraseanet date for iptc writing
* return NULL if the date is not valid
*
* @param string $value
* @return string|null
*/
private static function fixDate($value)
{
$date = null;
try {
$a = explode(';', preg_replace('/\D+/', ';', trim($value)));
switch (count($a)) {
case 3: // yyyy;mm;dd
$date = new \DateTime($a[0] . '-' . $a[1] . '-' . $a[2]);
$date = $date->format('Y-m-d H:i:s');
break;
case 6: // yyyy;mm;dd;hh;mm;ss
$date = new \DateTime($a[0] . '-' . $a[1] . '-' . $a[2] . ' ' . $a[3] . ':' . $a[4] . ':' . $a[5]);
$date = $date->format('Y-m-d H:i:s');
break;
}
}
catch (\Exception $e) {
$date = null;
}
return $date;
}
}

View File

@@ -1115,7 +1115,6 @@ class ACL implements cache_cacheableInterface
/**
* @param array $base_ids
* @return $this
* @throws DBALException
* @throws Exception
*/
public function revoke_access_from_bases(Array $base_ids)
@@ -1125,24 +1124,30 @@ class ACL implements cache_cacheableInterface
$usr_id = $this->user->getId();
$errors = 0;
foreach ($base_ids as $base_id) {
if (!$stmt_del->execute([':base_id' => $base_id, ':usr_id' => $usr_id])) {
throw new Exception('Error while deleteing some rights');
}
$this->app['dispatcher']->dispatch(
AclEvents::ACCESS_TO_BASE_REVOKED,
new AccessToBaseRevokedEvent(
$this,
array(
'base_id'=>$base_id
if ($stmt_del->execute([':base_id' => $base_id, ':usr_id' => $usr_id])) {
$this->app['dispatcher']->dispatch(
AclEvents::ACCESS_TO_BASE_REVOKED,
new AccessToBaseRevokedEvent(
$this,
[
'base_id' => $base_id
]
)
)
);
);
}
else {
$errors++;
}
}
$stmt_del->closeCursor();
$this->delete_data_from_cache(self::CACHE_RIGHTS_BAS);
if($errors > 0) {
throw new Exception('Error while deleting some rights');
}
return $this;
}

View File

@@ -121,9 +121,9 @@ class cache_databox
$conn = $app->getApplicationBox()->get_connection();
$sql = 'UPDATE sitepreff SET memcached_update = :date';
$sql = 'UPDATE sitepreff SET memcached_update = current_timestamp()';
$stmt = $conn->prepare($sql);
$stmt->execute([':date' => $now]);
$stmt->execute();
$stmt->closeCursor();
self::$refreshing = false;

View File

@@ -11,6 +11,9 @@
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Model\Entities\User;
use Alchemy\Phrasea\Model\Repositories\BasketRepository;
use Alchemy\Phrasea\Model\Repositories\UserRepository;
class eventsmanager_notify_orderdeliver extends eventsmanager_notifyAbstract
{
@@ -31,9 +34,9 @@ class eventsmanager_notify_orderdeliver extends eventsmanager_notifyAbstract
/**
*
* @param Array $datas
* @param string[] $data
* @param boolean $unread
* @return string
* @return array
*/
public function datas(array $data, $unread)
{
@@ -41,24 +44,29 @@ class eventsmanager_notify_orderdeliver extends eventsmanager_notifyAbstract
$ssel_id = $data['ssel_id'];
$n = $data['n'];
if (null === $user= $this->app['repo.users']->find(($from))) {
/** @var UserRepository $userRepo */
$userRepo = $this->app['repo.users'];
if( ($user= $userRepo->find(($from))) === null ) {
return [];
}
$sender = $user->getDisplayName();
try {
/** @var BasketRepository $repository */
$repository = $this->app['repo.baskets'];
$basket = $repository->findUserBasket($ssel_id, $this->app->getAuthenticatedUser(), false);
} catch (\Exception $e) {
}
catch (\Exception $e) {
return [];
}
$ret = [
'text' => $this->app->trans('%user% vous a delivre %quantity% document(s) pour votre commande %title%', ['%user%' => $sender, '%quantity%' => $n, '%title%' => '<a href="/lightbox/compare/'
. $ssel_id . '/" target="_blank">'
. $basket->getName() . '</a>'])
, 'class' => ''
. $basket->getName() . '</a>']),
'class' => ''
];
return $ret;

View File

@@ -11,6 +11,9 @@
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Model\Entities\User;
use Alchemy\Phrasea\Model\Repositories\BasketRepository;
use Alchemy\Phrasea\Model\Repositories\UserRepository;
class eventsmanager_notify_validationdone extends eventsmanager_notifyAbstract
{
@@ -31,35 +34,38 @@ class eventsmanager_notify_validationdone extends eventsmanager_notifyAbstract
/**
*
* @param string $datas
* @param string[] $data
* @param boolean $unread
* @return Array
* @return array
*/
public function datas(array $data, $unread)
{
$from = $data['from'];
$ssel_id = $data['ssel_id'];
if (null === $registered_user = $this->app['repo.users']->find($from)) {
/** @var UserRepository $userRepo */
$userRepo = $this->app['repo.users'];
if ( ($registered_user = $userRepo->find($from)) === null ) {
return [];
}
$sender = $registered_user->getDisplayName();
try {
/** @var BasketRepository $repository */
$repository = $this->app['repo.baskets'];
$basket = $repository->findUserBasket($ssel_id, $this->app->getAuthenticatedUser(), false);
} catch (\Exception $e) {
}
catch (\Exception $e) {
return [];
}
$ret = [
'text' => $this->app->trans('%user% a envoye son rapport de validation de %title%', ['%user%' => $sender, '%title%' => '<a href="/lightbox/validate/'
. $ssel_id . '/" target="_blank">'
. $basket->getName() . '</a>'
])
, 'class' => ''
. $basket->getName() . '</a>']),
'class' => ''
];
return $ret;
@@ -84,12 +90,18 @@ class eventsmanager_notify_validationdone extends eventsmanager_notifyAbstract
}
/**
* @param integer $usr_id The id of the user to check
* @param User $user The id of the user to check
*
* @return boolean
*/
public function is_available(User $user)
{
return $this->app->getAclForUser($user)->has_right(\ACL::CANPUSH);
try {
return $this->app->getAclForUser($user)->has_right(\ACL::CANPUSH);
}
catch (\Exception $e) {
// has_right(unknow_right) ? will not happen !
return false;
}
}
}

View File

@@ -9,13 +9,16 @@
*/
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Model\Serializer\CaptionSerializer;
use Alchemy\Phrasea\Model\Entities\Token;
use Alchemy\Phrasea\Model\Entities\User;
use Alchemy\Phrasea\Model\Repositories\BasketRepository;
use Alchemy\Phrasea\Model\Repositories\StoryWZRepository;
use Alchemy\Phrasea\Model\Serializer\CaptionSerializer;
use Assert\Assertion;
use Doctrine\DBAL\Connection;
use Symfony\Component\Filesystem\Filesystem;
class set_export extends set_abstract
{
private static $maxFilenameLength = 256;
@@ -60,6 +63,7 @@ class set_export extends set_abstract
$remain_hd = [];
if ($storyWZid) {
/** @var StoryWZRepository $repository */
$repository = $app['repo.story-wz'];
$storyWZ = $repository->findByUserAndId($this->app, $app->getAuthenticatedUser(), $storyWZid);
@@ -68,6 +72,7 @@ class set_export extends set_abstract
}
if ($sstid != "") {
/** @var BasketRepository $repository */
$repository = $app['repo.baskets'];
$Basket = $repository->findUserBasket($sstid, $app->getAuthenticatedUser(), false);

View File

@@ -1278,6 +1278,27 @@
<field>id</field>
</fields>
</index>
<index>
<name>usr_id</name>
<type>INDEX</type>
<fields>
<field>usr_id</field>
</fields>
</index>
<index>
<name>unread</name>
<type>INDEX</type>
<fields>
<field>unread</field>
</fields>
</index>
<index>
<name>created_on</name>
<type>INDEX</type>
<fields>
<field>created_on</field>
</fields>
</index>
</indexes>
<engine>InnoDB</engine>
</table>

View File

@@ -44,7 +44,7 @@ main:
doctype_aggregate_limit: 0
camera_model_aggregate_limit: 0
iso_aggregate_limit: 0
aperture_aggregate_limit: 0
aperture_aggregate_limit: 0
shutterspeed_aggregate_limit: 0
flashfired_aggregate_limit: 0
framerate_aggregate_limit: 0
@@ -234,6 +234,7 @@ embed_bundle:
audio:
player: videojs
autoplay: false
cover_subdef: thumbnail
document:
#player: flexpaper
enable_pdfjs: true
@@ -297,6 +298,6 @@ rabbitmq:
user: ''
password: ''
vhost: /
Console_logger_enabled_environments: [test]