コード例 #1
0
ファイル: subdef.php プロジェクト: romainneutron/Phraseanet
 /**
  * Build Image Subdef object depending the SimpleXMLElement
  *
  * @param  SimpleXMLElement                    $sd
  * @return \Alchemy\Phrasea\Media\Subdef\Video
  */
 protected function buildImageSubdef(SimpleXMLElement $sd)
 {
     $image = new Image($this->translator);
     if ($sd->size) {
         $image->setOptionValue(Image::OPTION_SIZE, (int) $sd->size);
     }
     if ($sd->quality) {
         $image->setOptionValue(Image::OPTION_QUALITY, (int) $sd->quality);
     }
     if ($sd->strip) {
         $image->setOptionValue(Image::OPTION_STRIP, p4field::isyes($sd->strip));
     }
     if ($sd->dpi) {
         $image->setOptionValue(Image::OPTION_RESOLUTION, (int) $sd->dpi);
     }
     return $image;
 }
コード例 #2
0
 private function getCommandline($indexerPath, Application $app, Task $task)
 {
     $cmd = [$indexerPath, '-o'];
     $settings = simplexml_load_string($task->getSettings());
     $host = trim($settings->host);
     $port = (int) $settings->port;
     $base = trim($settings->base);
     $user = trim($settings->user);
     $password = trim($settings->password);
     $socket = (int) $settings->socket;
     $charset = trim($settings->charset);
     $stem = trim($settings->stem);
     $sortempty = trim($settings->sortempty);
     $debugmask = (int) $settings->debugmask;
     $nolog = \p4field::isyes(trim($settings->nolog));
     $winsvc_run = \p4field::isyes(trim($settings->winsvc_run));
     if ('' !== $host) {
         $cmd[] = '--host';
         $cmd[] = $host;
     }
     if (0 < $port) {
         $cmd[] = '--port';
         $cmd[] = $port;
     }
     if ('' !== $base) {
         $cmd[] = '--base';
         $cmd[] = $base;
     }
     if ('' !== $user) {
         $cmd[] = '--user';
         $cmd[] = $user;
     }
     if ('' !== $password) {
         $cmd[] = '--password';
         $cmd[] = $password;
     }
     if (0 < $socket) {
         $cmd[] = '--socket';
         $cmd[] = $socket;
     }
     if ('' !== $charset) {
         $cmd[] = '--default-character-set';
         $cmd[] = $charset;
     }
     if ('' !== $stem) {
         $cmd[] = '--stem';
         $cmd[] = $stem;
     }
     if ('' !== $sortempty) {
         $cmd[] = '--sort-empty';
         $cmd[] = $sortempty;
     }
     if (0 < $debugmask) {
         $cmd[] = '--debug';
         $cmd[] = $debugmask;
     }
     if ($nolog) {
         $cmd[] = '--nolog';
     }
     if ($winsvc_run) {
         $cmd[] = '--run';
     }
     return $cmd;
 }
コード例 #3
0
ファイル: ArchiveJob.php プロジェクト: luisbrito/Phraseanet
 /**
  * {@inheritdoc}
  */
 protected function doJob(JobData $data)
 {
     $app = $data->getApplication();
     $task = $data->getTask();
     $settings = simplexml_load_string($task->getSettings());
     $baseId = (string) $settings->base_id;
     $sbasId = \phrasea::sbasFromBas($app, $baseId);
     if (!$sbasId) {
         throw new RuntimeException('Invalid collection base_id.');
     }
     $databox = $app->findDataboxById($sbasId);
     $TColls = [];
     $collection = null;
     foreach ($databox->get_collections() as $coll) {
         $TColls['c' . $coll->get_coll_id()] = $coll->get_coll_id();
         if ($baseId == $coll->get_base_id()) {
             $collection = $coll;
         }
     }
     $server_coll_id = $collection->get_coll_id();
     // mask(s) of accepted files
     $tmask = [];
     $tmaskgrp = [];
     $cold = min(max((int) $settings->cold, self::MINCOLD), self::MAXCOLD);
     $stat0 = $stat1 = "0";
     if (false !== ($sxBasePrefs = simplexml_load_string($collection->get_prefs()))) {
         if ($sxBasePrefs->status) {
             $stat0 = (string) $sxBasePrefs->status;
         }
     }
     if ($settings->status) {
         $stat1 = (string) $settings->status;
     }
     if (!$stat0) {
         $stat0 = '0';
     }
     if (!$stat1) {
         $stat1 = '0';
     }
     // check the data-repository exists
     $pathhd = (string) $settings->path;
     if ($pathhd) {
         $app['filesystem']->mkdir($pathhd, 0750);
     }
     // load masks
     if ($settings->files && $settings->files->file) {
         foreach ($settings->files->file as $ft) {
             $tmask[] = ["mask" => (string) $ft["mask"], "caption" => (string) $ft["caption"], "accept" => (string) $ft["accept"]];
         }
     }
     if ($settings->files && $settings->files->grouping) {
         foreach ($settings->files->grouping as $ft) {
             $tmaskgrp[] = ["mask" => (string) $ft["mask"], "caption" => (string) $ft["caption"], "representation" => (string) $ft["representation"], "accept" => (string) $ft["accept"]];
         }
     }
     if (count($tmask) == 0) {
         // no mask defined : accept all kind of files
         $tmask[] = ["mask" => ".*", "caption" => "", "accept" => ""];
     }
     while ($this->isStarted()) {
         $path_in = (string) $settings->hotfolder;
         if (!@is_dir($path_in)) {
             throw new RuntimeException(sprintf('Error : missing hotfolder \'%s\', stopping.', $path_in));
         }
         // copy settings to task, so it's easier to get later
         $moveArchived = \p4field::isyes($settings->move_archived);
         $moveError = \p4field::isyes($settings->move_error);
         clearstatcache();
         if (false === $app['filesystem']->exists($path_in . "/.phrasea.xml")) {
             throw new RuntimeException(sprintf('NO .phrasea.xml AT ROOT \'%s\' !', $path_in));
         }
         $path_archived = $path_error = null;
         if ($moveArchived) {
             $path_archived = $path_in . '_archived';
             $app['filesystem']->mkdir($path_archived, 0755);
         }
         if ($moveError) {
             $path_error = $path_in . '_error';
             $app['filesystem']->mkdir($path_error, 0755);
         }
         $dom = new \DOMDocument();
         $dom->formatOutput = true;
         $root = $dom->appendChild($dom->createElement('root'));
         $nnew = $this->listFilesPhase1($app, $dom, $root, $path_in, $server_coll_id, 0, $TColls);
         if ($app['debug']) {
             $this->log('debug', "=========== listFilesPhase1 ========== (returned " . $nnew . ")\n" . $dom->saveXML());
         }
         if (!$this->isStarted()) {
             return;
         }
         // wait for files to be cold
         $this->pause($cold);
         if (!$this->isStarted()) {
             return;
         }
         $this->listFilesPhase2($app, $dom, $root, $path_in, 0);
         if ($app['debug']) {
             $this->log('debug', "=========== listFilesPhase2 ========== : \n" . $dom->saveXML());
         }
         if (!$this->isStarted()) {
             return;
         }
         $this->makePairs($dom, $root, $path_in, $path_archived, $path_error, false, 0, $tmask, $tmaskgrp);
         if ($app['debug']) {
             $this->log('debug', "=========== makePairs ========== : \n" . $dom->saveXML());
         }
         $r = $this->removeBadGroups($app, $dom, $root, $path_in, $path_archived, $path_error, 0, $moveError);
         if ($app['debug']) {
             $this->log('debug', "=========== removeBadGroups ========== (returned " . ((bool) $r ? 'true' : 'false') . ") : \n" . $dom->saveXML());
         }
         $this->archive($app, $databox, $dom, $root, $path_in, $path_archived, $path_error, 0, $moveError, $moveArchived, $stat0, $stat1);
         if ($app['debug']) {
             $this->log('debug', "=========== archive ========== : \n" . $dom->saveXML());
         }
         if (!$this->isStarted()) {
             return;
         }
         $this->bubbleResults($dom, $root, $path_in, 0, \p4field::isyes($settings->copy_spe));
         if ($app['debug']) {
             $this->log('debug', "=========== bubbleResults ========== : \n" . $dom->saveXML());
         }
         $moved = $this->moveFiles($app, $dom, $root, $path_in, $path_archived, $path_error, 0, $moveArchived, $moveError);
         if ($app['debug']) {
             $this->log('debug', "=========== moveFiles ========== (returned " . ($moved ? 'true' : 'false') . ") : \n" . $dom->saveXML());
         }
     }
 }
コード例 #4
0
ファイル: V1Controller.php プロジェクト: luisbrito/Phraseanet
 public function addRecordAction(Request $request)
 {
     if (count($request->files->get('file')) == 0) {
         return $this->getBadRequestAction($request, 'Missing file parameter');
     }
     $file = $request->files->get('file');
     if (!$file instanceof UploadedFile) {
         return $this->getBadRequestAction($request, 'You can upload one file at time');
     }
     if (!$file->isValid()) {
         return $this->getBadRequestAction($request, 'Data corrupted, please try again');
     }
     if (!$request->get('base_id')) {
         return $this->getBadRequestAction($request, 'Missing base_id parameter');
     }
     $collection = \collection::get_from_base_id($this->app, $request->get('base_id'));
     if (!$this->getAclForUser()->has_right_on_base($request->get('base_id'), 'canaddrecord')) {
         return Result::createError($request, 403, sprintf('You do not have access to collection %s', $collection->get_label($this->app['locale'])))->createResponse();
     }
     $media = $this->app->getMediaFromUri($file->getPathname());
     $Package = new File($this->app, $media, $collection, $file->getClientOriginalName());
     if ($request->get('status')) {
         $Package->addAttribute(new Status($this->app, $request->get('status')));
     }
     $session = new LazaretSession();
     $session->setUser($this->getAuthenticatedUser());
     $entityManager = $this->app['orm.em'];
     $entityManager->persist($session);
     $entityManager->flush();
     $reasons = $output = null;
     $translator = $this->app['translator'];
     $callback = function ($element, Visa $visa) use($translator, &$reasons, &$output) {
         if (!$visa->isValid()) {
             $reasons = array_map(function (CheckerResponse $response) use($translator) {
                 return $response->getMessage($translator);
             }, $visa->getResponses());
         }
         $output = $element;
     };
     switch ($request->get('forceBehavior')) {
         case '0':
             $behavior = Manager::FORCE_RECORD;
             break;
         case '1':
             $behavior = Manager::FORCE_LAZARET;
             break;
         case null:
             $behavior = null;
             break;
         default:
             return $this->getBadRequestAction($request, sprintf('Invalid forceBehavior value `%s`', $request->get('forceBehavior')));
     }
     $nosubdef = $request->get('nosubdefs') === '' || \p4field::isyes($request->get('nosubdefs'));
     $this->getBorderManager()->process($session, $Package, $callback, $behavior, $nosubdef);
     $ret = ['entity' => null];
     if ($output instanceof \record_adapter) {
         $ret['entity'] = '0';
         $ret['url'] = '/records/' . $output->getDataboxId() . '/' . $output->getRecordId() . '/';
         $this->dispatch(PhraseaEvents::RECORD_UPLOAD, new RecordEdit($output));
     }
     if ($output instanceof LazaretFile) {
         $ret['entity'] = '1';
         $ret['url'] = '/quarantine/item/' . $output->getId() . '/';
     }
     return Result::create($request, $ret)->createResponse();
 }