Merge branch 'master' into PHRAS-3988_feedback-report-same-record

This commit is contained in:
jygaulier
2023-12-14 21:02:04 +01:00
committed by GitHub
12 changed files with 210 additions and 66 deletions

View File

@@ -15,10 +15,11 @@ use Alchemy\Phrasea\Authentication\ACLProvider;
use Alchemy\Phrasea\Authentication\Authenticator;
use Alchemy\Phrasea\Controller\Controller;
use Alchemy\Phrasea\Core\Configuration\DisplaySettingService;
use Alchemy\Phrasea\Model\Manipulator\TaskManipulator;
use Alchemy\Phrasea\SearchEngine\Elastic\ElasticsearchOptions;
use Alchemy\Phrasea\WorkerManager\Event\PopulateIndexEvent;
use Alchemy\Phrasea\WorkerManager\Event\WorkerEvents;
use collection;
use Exception;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
@@ -103,7 +104,8 @@ class DataboxController extends Controller
$success = true;
$msg = $this->app->trans('Successful removal');
}
} catch (\Exception $e) {
}
catch (Exception $e) {
}
if (!$databox) {
@@ -150,7 +152,8 @@ class DataboxController extends Controller
$value = $labels[$code] ?: null;
$databox->set_label($code, $value);
}
} catch (\Exception $e) {
}
catch (Exception $e) {
$success = false;
}
@@ -190,7 +193,9 @@ class DataboxController extends Controller
try {
$this->getDispatcher()->dispatch(WorkerEvents::POPULATE_INDEX, new PopulateIndexEvent($populateInfo));
$success = true;
} catch (\Exception $e) {
}
catch (Exception $e) {
// no-op
}
if ('json' === $request->getRequestFormat()) {
@@ -222,8 +227,8 @@ class DataboxController extends Controller
$indexable = !!$request->request->get('indexable', false);
$this->getApplicationBox()->set_databox_indexable($databox, $indexable);
$success = true;
} catch (\Exception $e) {
} catch (Exception $e) {
// no-op
}
if ('json' === $request->getRequestFormat()) {
@@ -255,7 +260,8 @@ class DataboxController extends Controller
foreach ($request->request->get('TOU', []) as $loc => $terms) {
$databox->update_cgus($loc, $terms, !!$request->request->get('valid', false));
}
} catch (\Exception $e) {
}
catch (Exception $e) {
return $this->app->redirectPath('admin_database_display_cgus', [
'databox_id' => $databox_id,
'success' => 0,
@@ -283,7 +289,7 @@ class DataboxController extends Controller
try {
/** @var Authenticator $authenticator */
$authenticator = $this->app->getAuthenticator();
$baseId = \collection::mount_collection(
$baseId = collection::mount_collection(
$this->app,
$this->findDataboxById($databox_id),
$collection_id,
@@ -315,7 +321,8 @@ class DataboxController extends Controller
'databox_id' => $databox_id,
'mount' => 'ok',
]);
} catch (\Exception $e) {
}
catch (Exception $e) {
$connection->rollBack();
return $this->app->redirectPath('admin_database', [
@@ -366,7 +373,8 @@ class DataboxController extends Controller
'error' => 'file-invalid',
]);
}
} catch (\Exception $e) {
}
catch (Exception $e) {
return $this->app->redirectPath('admin_database', [
'databox_id' => $databox_id,
'success' => '0',
@@ -395,8 +403,9 @@ class DataboxController extends Controller
\databox::PIC_PDF
);
$success = true;
} catch (\Exception $e) {
}
catch (Exception $e) {
// no-op
}
if ('json' === $request->getRequestFormat()) {
@@ -428,8 +437,9 @@ class DataboxController extends Controller
try {
$this->findDataboxById($databox_id)->clear_logs();
$success = true;
} catch (\Exception $e) {
}
catch (Exception $e) {
// no-op
}
if ('json' === $request->getRequestFormat()) {
@@ -465,8 +475,9 @@ class DataboxController extends Controller
try {
$this->findDataboxById($databox_id)->set_viewname($viewName);
$success = true;
} catch (\Exception $e) {
}
catch (Exception $e) {
// no-op
}
if ('json' === $request->getRequestFormat()) {
@@ -500,8 +511,9 @@ class DataboxController extends Controller
$databox->unmount_databox();
$success = true;
} catch (\Exception $e) {
}
catch (Exception $e) {
// no-op
}
if ('json' === $request->getRequestFormat()) {
@@ -553,8 +565,9 @@ class DataboxController extends Controller
// if ($taskCreated) {
// $msg = $this->app->trans('A task has been created, please run it to complete empty collection');
// }
} catch (\Exception $e) {
}
catch (Exception $e) {
// no-op
}
if ('json' === $request->getRequestFormat()) {
@@ -612,8 +625,9 @@ class DataboxController extends Controller
$ret['success'] = true;
$ret['msg'] = $this->app->trans('Successful update');
} catch (\Exception $e) {
}
catch (Exception $e) {
// no-op
}
return $this->app->json($ret);
@@ -645,11 +659,12 @@ class DataboxController extends Controller
{
try {
foreach ($request->request->get('order', []) as $data) {
$collection = \collection::getByBaseId($this->app, $data['id']);
$collection = collection::getByBaseId($this->app, $data['id']);
$collection->set_ord($data['offset']);
}
$success = true;
} catch (\Exception $e) {
}
catch (Exception $e) {
$success = false;
}
@@ -680,11 +695,11 @@ class DataboxController extends Controller
/**
* Create a new collection
*
* @param Request $request The current HTTP request
* @param integer $databox_id The requested databox
* @param Request $request The current HTTP request
* @param integer $databox_id The requested databox
* @return Response
*/
public function createCollection(Request $request, $databox_id)
public function createCollection(Request $request, int $databox_id)
{
if (($name = trim($request->request->get('name', ''))) === '') {
return $this->app->redirectPath('admin_database_display_new_collection_form', [
@@ -695,7 +710,7 @@ class DataboxController extends Controller
try {
$databox = $this->findDataboxById($databox_id);
$collection = \collection::create(
$collection = collection::create(
$this->app, $databox,
$this->getApplicationBox(),
$name,
@@ -721,7 +736,8 @@ class DataboxController extends Controller
'success' => 1,
'reload-tree' => 1,
]);
} catch (\Exception $e) {
}
catch (Exception $e) {
return $this->app->redirectPath('admin_database_submit_collection', [
'databox_id' => $databox_id,
'error' => $e->getMessage(),

View File

@@ -22,6 +22,7 @@ use Alchemy\Phrasea\WorkerManager\Event\ExportFtpEvent;
use Alchemy\Phrasea\WorkerManager\Event\WorkerEvents;
use DOMDocument;
use DOMXPath;
use Exception;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@@ -61,8 +62,10 @@ class ExportController extends Controller
$removeable_stamp = false; // true if at least one coll is "unstampable"
$removeable_stamp_by_base = []; // unset: no stamp ; false: stamp not "unstampable" ; true: stamp "unstampable"
$colls_manageable = array_keys($this->getAclForConnectedUser()->get_granted_base([ACL::COLL_MANAGE]) ?? []);
$dbox_manageable = array_keys($this->getAclForConnectedUser()->get_granted_sbas([ACL::BAS_MANAGE]) ?? []);
$colls_manageable = array_keys($this->getAclForConnectedUser()->get_granted_base([ACL::COLL_MANAGE]) ?? []);
$colls_editable = array_keys($this->getAclForConnectedUser()->get_granted_base([ACL::CANMODIFRECORD]) ?? []);
$colls_imgtoolsable = array_keys($this->getAclForConnectedUser()->get_granted_base([ACL::IMGTOOLS]) ?? []);
$dbox_manageable = array_keys($this->getAclForConnectedUser()->get_granted_sbas([ACL::BAS_MANAGE]) ?? []);
foreach($download->get_elements() as $recordAdapter) {
// check collection only once
@@ -92,6 +95,16 @@ class ExportController extends Controller
$removeable_stamp_by_base[$bid] = $removeable_stamp = true;
}
break;
case 'record_edit':
if (in_array($bid, $colls_editable)) {
$removeable_stamp_by_base[$bid] = $removeable_stamp = true;
}
break;
case 'image_tools':
if (in_array($bid, $colls_imgtoolsable)) {
$removeable_stamp_by_base[$bid] = $removeable_stamp = true;
}
break;
case 'manage_databox':
if (in_array($recordAdapter->getDatabox()->get_sbas_id(), $dbox_manageable)) {
$removeable_stamp_by_base[$bid] = $removeable_stamp = true;
@@ -138,7 +151,9 @@ class ExportController extends Controller
$ftpClient->close();
$msg = $this->app->trans('Connection to FTP succeed');
$success = true;
} catch (\Exception $e) {
}
catch (Exception $e) {
// no-op
}
return $this->app->json([
@@ -184,7 +199,7 @@ class ExportController extends Controller
\set_export::STAMP_ASYNC,
$request->request->get('stamp_choice') === "REMOVE_STAMP",
false
);
);
$exportFtpId = $download->export_ftp(
$request->request->get('user_dest'),
@@ -206,7 +221,8 @@ class ExportController extends Controller
'success' => true,
'message' => $this->app->trans('Export saved in the waiting queue')
]);
} catch (\Exception $e) {
}
catch (Exception $e) {
return $this->app->json([
'success' => false,
'message' => $e->getMessage()//$this->app->trans('Something went wrong')
@@ -217,8 +233,9 @@ class ExportController extends Controller
/**
* Export document by mail
*
* @param Request $request
* @param Request $request
* @return JsonResponse
* @throws Exception
*/
public function exportMail(Request $request)
{

View File

@@ -72,6 +72,7 @@ class Databox implements ControllerProviderInterface, ServiceProviderInterface
->before([$this, 'requireManageRightOnSbas'])
->bind('admin_database_submit_collections_order');
/** @uses DataboxController::createCollection */
$controllers->post('/{databox_id}/collection/', 'controller.admin.databox:createCollection')
->before([$this, 'requireManageRightOnSbas'])
->bind('admin_database_submit_collection');
@@ -97,6 +98,7 @@ class Databox implements ControllerProviderInterface, ServiceProviderInterface
->before([$this, 'requireManageRightOnSbas'])
->bind('admin_database_display_document_details');
/** @uses DataboxController::mountCollection */
$controllers->post('/{databox_id}/collection/{collection_id}/mount/', 'controller.admin.databox:mountCollection')
->assert('collection_id', '\d+')
->before([$this, 'requireManageRightOnSbas'])

View File

@@ -95,6 +95,11 @@ class FtpExportElement
*/
private $updated;
/**
* @ORM\Column(type="boolean", options={"default" = 0})
*/
private $toStamp = false;
/**
* Get id
*
@@ -368,4 +373,20 @@ class FtpExportElement
{
return $this->export;
}
/**
* @return bool
*/
public function isToStamp(): bool
{
return $this->toStamp;
}
/**
* @param bool $toStamp
*/
public function setToStamp(bool $toStamp)
{
$this->toStamp = $toStamp;
}
}

View File

@@ -88,7 +88,7 @@ class ExportMailWorker implements WorkerInterface
foreach($list['files'] as $k_file => $v_file) {
foreach($v_file['subdefs'] as $k_subdef => $v_subdef) {
if($k_subdef === "document" && $v_subdef['to_stamp']) {
if($v_subdef['to_stamp']) {
// we must stamp this document
try {
$record = $this->app->getApplicationBox()->get_databox($v_file['databox_id'])->get_record($v_file['record_id']);

View File

@@ -15,6 +15,8 @@ use Alchemy\Phrasea\Notification\Mail\MailSuccessFTPReceiver;
use Alchemy\Phrasea\Notification\Mail\MailSuccessFTPSender;
use Alchemy\Phrasea\Notification\Receiver;
use Alchemy\Phrasea\WorkerManager\Queue\MessagePublisher;
use Exception;
use ftpClient;
use Psr\Log\LoggerInterface;
use Symfony\Component\Translation\TranslatorInterface;
@@ -83,7 +85,8 @@ class FtpWorker implements WorkerInterface
$em->flush();
$em->commit();
} catch (\Exception $e) {
}
catch (Exception $e) {
$em->rollback();
}
} else {
@@ -101,7 +104,8 @@ class FtpWorker implements WorkerInterface
$em->flush();
$em->commit();
} catch (\Exception $e) {
}
catch (Exception $e) {
$em->rollback();
}
}
@@ -146,7 +150,7 @@ class FtpWorker implements WorkerInterface
try {
$ssl = $export->isSsl();
/** @var \ftpClient $ftp_client */
/** @var ftpClient $ftp_client */
$ftp_client = $this->app['phraseanet.ftp.client'](
$ftp_server, 21, 300, $ssl, $proxy, $proxyport,
$proxyuser, $proxypwd
@@ -156,7 +160,8 @@ class FtpWorker implements WorkerInterface
if ($export->isPassif()) {
try {
$ftp_client->passive(true);
} catch (\Exception $e) {
}
catch (Exception $e) {
$this->logger->debug($e->getMessage());
}
}
@@ -165,7 +170,8 @@ class FtpWorker implements WorkerInterface
try {
$ftp_client->chdir($export->getDestFolder());
$export->setDestfolder('/' . $export->getDestfolder());
} catch (\Exception $e) {
}
catch (Exception $e) {
$this->logger->debug($e->getMessage());
}
} else {
@@ -175,14 +181,16 @@ class FtpWorker implements WorkerInterface
if (trim($export->getFoldertocreate()) != '') {
try {
$ftp_client->mkdir($export->getFoldertocreate());
} catch (\Exception $e) {
}
catch (Exception $e) {
$this->logger->debug($e->getMessage());
}
try {
$new_dir = $ftp_client->add_end_slash($export->getDestfolder())
. $export->getFoldertocreate();
$ftp_client->chdir($new_dir);
} catch (\Exception $e) {
}
catch (Exception $e) {
$this->logger->debug($e->getMessage());
}
}
@@ -223,25 +231,35 @@ class FtpWorker implements WorkerInterface
$localfile = sys_get_temp_dir().'/' . md5($desc . time() . mt_rand());
if (file_put_contents($localfile, $desc) === false) {
throw new \Exception('Impossible de creer un fichier temporaire');
throw new Exception('Impossible de creer un fichier temporaire');
}
} elseif ($subdef == 'caption-yaml') {
}
elseif ($subdef == 'caption-yaml') {
$desc = $this->app['serializer.caption']->serialize($record->get_caption(), CaptionSerializer::SERIALIZE_YAML, $exportElement->isBusinessfields());
$localfile = sys_get_temp_dir().'/' . md5($desc . time() . mt_rand());
if (file_put_contents($localfile, $desc) === false) {
throw new \Exception('Impossible de creer un fichier temporaire');
throw new Exception('Impossible de creer un fichier temporaire');
}
} else {
}
else {
try {
$sd = $record->get_subdef($subdef);
} catch (\Exception_Media_SubdefNotFound $notFount) {
$localfile = $sd->getRealPath();
if($exportElement->isToStamp()) {
if (!is_null($path = \recordutils_image::stamp($this->app, $sd))) {
// stamped !
$localfile = $path;
}
}
}
catch (\Exception_Media_SubdefNotFound $notFound) {
continue;
}
$localfile = $sd->getRealPath();
if (!file_exists($localfile)) {
throw new \Exception('Le fichier local n\'existe pas');
if (!$localfile || !file_exists($localfile)) {
throw new Exception('Le fichier local n\'existe pas');
}
}
@@ -250,7 +268,8 @@ class FtpWorker implements WorkerInterface
if ($ftp_client->pwd() != $current_folder) {
try {
$ftp_client->chdir($current_folder);
} catch (\Exception $e) {
}
catch (Exception $e) {
$this->logger->debug($e->getMessage());
}
}
@@ -272,7 +291,8 @@ class FtpWorker implements WorkerInterface
$this->app['orm.em']->persist($exportElement);
$this->app['orm.em']->flush();
$this->logexport($this->app, $record, $obj, $ftpLog);
} catch (\Exception $e) {
}
catch (Exception $e) {
$state .= $line = $this->translator->trans('task::ftp:File "%file%" (record %record_id%) de la base "%basename%" (Export du Document) : Transfert cancelled (le document n\'existe plus)', ['%file%' => basename($localfile), '%record_id%' => $record_id, '%basename%' => \phrasea::sbas_labels(\phrasea::sbasFromBas($this->app, $base_id), $this->app)]) . "\n<br/>";
$this->logger->debug($line);
@@ -317,7 +337,8 @@ class FtpWorker implements WorkerInterface
}
$ftp_client->close();
} catch (\Exception $e) {
}
catch (Exception $e) {
$state .= $line = $e . "\n";
$this->logger->debug($line);
@@ -342,7 +363,8 @@ class FtpWorker implements WorkerInterface
$em->persist($workerRunningJob);
$em->flush();
$em->commit();
} catch (\Exception $e) {
}
catch (Exception $e) {
$em->rollback();
}
} else {
@@ -360,7 +382,8 @@ class FtpWorker implements WorkerInterface
$em->persist($workerRunningJob);
$em->flush();
$em->commit();
} catch (\Exception $e) {
}
catch (Exception $e) {
$em->rollback();
}
@@ -472,7 +495,9 @@ class FtpWorker implements WorkerInterface
$mail = MailSuccessFTPSender::create($app, $receiver, null, $sender_message);
$mail->setServer($ftp_server);
$this->deliver($mail);
} catch (\Exception $e) {
}
catch (Exception $e) {
// no-op
}
try {
@@ -480,7 +505,8 @@ class FtpWorker implements WorkerInterface
$mail = MailSuccessFTPReceiver::create($app, $receiver, null, $receiver_message);
$mail->setServer($ftp_server);
$this->deliver($mail);
} catch (\Exception $e) {
}
catch (Exception $e) {
$this->logger->debug(sprintf('Unable to deliver success message : %s', $e->getMessage()));
}
}