PHRAS-3729 Uploader pull mode - make it compatible with PS-461 uploader multi-destinations and permissions (#4116)

* pull mode multi destination

* add patch
This commit is contained in:
Aina Sitraka
2022-09-07 12:49:35 +03:00
committed by GitHub
parent 507219f715
commit 54a96ee8df
29 changed files with 1330 additions and 887 deletions

View File

@@ -5,13 +5,18 @@ namespace Alchemy\Phrasea\PhraseanetService\Controller;
use Alchemy\Phrasea\Application as PhraseaApplication;
use Alchemy\Phrasea\Controller\Controller;
use Alchemy\Phrasea\PhraseanetService\Form\PSExposeConfigurationType;
use Alchemy\Phrasea\PhraseanetService\Form\PSUploaderConfigurationType;
use Alchemy\Phrasea\WorkerManager\Queue\AMQPConnection;
use Alchemy\Phrasea\WorkerManager\Queue\MessagePublisher;
use Symfony\Component\HttpFoundation\Request;
class PSAdminController extends Controller
{
public function indexAction(PhraseaApplication $app)
public function indexAction(PhraseaApplication $app, Request $request)
{
return $this->render('admin/phraseanet-service/index.html.twig');
return $this->render('admin/phraseanet-service/index.html.twig', [
'_fragment'=> $request->get('_fragment') ?? 'expose'
]);
}
public function authAction()
@@ -39,7 +44,7 @@ class PSAdminController extends Controller
$app['conf']->set(['phraseanet-service', 'phraseanet_local_id'], $phraseanetLocalId);
}
return $app->redirectPath('ps_admin');
return $app->redirectPath('ps_admin', ['_fragment'=>'expose']);
}
return $this->render('admin/phraseanet-service/expose.html.twig', [
@@ -57,8 +62,81 @@ class PSAdminController extends Controller
return $this->render('admin/phraseanet-service/report.html.twig');
}
public function uploaderAction()
public function uploaderAction(PhraseaApplication $app, Request $request)
{
return $this->render('admin/phraseanet-service/uploader.html.twig');
$uploaderConfiguration = $app['conf']->get(['phraseanet-service', 'uploader-service'], null);
// the "pullInterval" comes from the ttl_retry
$ttl_retry = $this->getConf()->get(['workers','queues', MessagePublisher::PULL_ASSETS_TYPE, 'ttl_retry'], null);
if(!is_null($ttl_retry)) {
$ttl_retry /= 1000; // form is in sec
}
$uploaderConfiguration['pullInterval'] = $ttl_retry;
$form = $app->form(new PSUploaderConfigurationType(), $uploaderConfiguration);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData();
switch($data['act']) {
case 'save' : // save the form content (settings) in 2 places
$ttl_retry = $data['pullInterval'];
unset($data['act'], $data['pullInterval']);
$this->getConf()->set(['phraseanet-service', 'uploader-service'], $data);
// save ttl in the q settings
if(!is_null($ttl_retry)) {
$this->getConf()->set(['workers','queues', MessagePublisher::PULL_ASSETS_TYPE, 'ttl_retry'], 1000 * (int)$ttl_retry);
}
$this->getAMQPConnection()->reinitializeQueue([MessagePublisher::PULL_ASSETS_TYPE]);
break;
case 'start':
$this->getAMQPConnection()->setQueue(MessagePublisher::PULL_ASSETS_TYPE);
$this->getAMQPConnection()->reinitializeQueue([MessagePublisher::PULL_ASSETS_TYPE]);
$this->getMessagePublisher()->initializeLoopQueue(MessagePublisher::PULL_ASSETS_TYPE);
break;
case 'stop':
$this->getAMQPConnection()->reinitializeQueue([MessagePublisher::PULL_ASSETS_TYPE]);
break;
}
return $app->redirectPath('ps_admin', ['_fragment'=>'uploader']);
}
// guess if the q is "running" = check if there are pending message on Q or loop-Q
$running = false;
$qStatuses = $this->getAMQPConnection()->getQueuesStatus();
foreach([
MessagePublisher::PULL_ASSETS_TYPE,
$this->getAMQPConnection()->getLoopQueueName(MessagePublisher::PULL_ASSETS_TYPE)
] as $qName) {
if(isset($qStatuses[$qName]) && $qStatuses[$qName]['messageCount'] > 0) {
$running = true;
}
}
return $this->render('admin/phraseanet-service/uploader.html.twig', [
'form' => $form->createView(),
'running' => $running
]);
}
/**
* @return AMQPConnection
*/
private function getAMQPConnection()
{
return $this->app['alchemy_worker.amqp.connection'];
}
/**
* @return MessagePublisher
*/
private function getMessagePublisher()
{
return $this->app['alchemy_worker.message.publisher'];
}
}