Esempio n. 1
0
 /**
  * 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;
 }
Esempio n. 2
0
 /**
  * {@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());
         }
     }
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 protected function doJob(JobData $data)
 {
     $app = $data->getApplication();
     $settings = simplexml_load_string($data->getTask()->getSettings());
     $thumbnailExtraction = (bool) (string) $settings->embedded;
     Image2Image::$lookForEmbeddedPreview = $thumbnailExtraction;
     $sqlqmark = array();
     $sqlparms = array();
     foreach (array('image', 'video', 'audio', 'document', 'flash', 'unknown') as $type) {
         if (!isset($settings->{"type_" . $type}) || !\p4field::isno($settings->{"type_" . $type})) {
             $sqlqmark[] = '?';
             $sqlparms[] = $type;
         }
     }
     if (count($sqlqmark) == 0) {
         return;
     }
     foreach ($app->getDataboxes() as $databox) {
         if (!$this->isStarted()) {
             break;
         }
         if (count($settings->xpath("sbas[text()=" . $databox->get_sbas_id() . "]")) == 0) {
             continue;
         }
         $conn = $databox->get_connection();
         $sql = 'SELECT coll_id, record_id FROM record' . ' WHERE jeton & ' . PhraseaTokens::MAKE_SUBDEF . ' > 0' . ' AND type IN(' . implode(',', $sqlqmark) . ')' . ' ORDER BY record_id DESC LIMIT 0, 30';
         $stmt = $conn->prepare($sql);
         $stmt->execute($sqlparms);
         $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
         $stmt->closeCursor();
         $i = 0;
         foreach ($rs as $row) {
             if (!$this->isStarted()) {
                 break;
             }
             $this->log('info', sprintf("Generate subdefs for : sbasid=%s / databox=%s / recordid=%s ", $databox->get_sbas_id(), $databox->get_dbname(), $row['record_id']));
             try {
                 $record = $databox->get_record($row['record_id']);
                 /** @var SubdefGenerator $sg */
                 $sg = $app['subdef.generator'];
                 $sg->generateSubdefs($record);
             } catch (\Exception $e) {
                 $this->log('warning', sprintf("Generate subdefs failed for : sbasid=%s / databox=%s / recordid=%s : %s", $databox->get_sbas_id(), $databox->get_dbname(), $row['record_id'], $e->getMessage()));
             }
             $sql = 'UPDATE record' . ' SET jeton=(jeton & ~(:flag)), moddate=NOW()' . ' WHERE record_id=:record_id';
             $stmt = $conn->prepare($sql);
             $stmt->execute([':record_id' => $row['record_id'], ':flag' => PhraseaTokens::MAKE_SUBDEF]);
             $stmt->closeCursor();
             // rewrite metadata
             $sql = 'UPDATE record' . ' SET jeton=(jeton | :flag)' . ' WHERE record_id=:record_id';
             $stmt = $conn->prepare($sql);
             $stmt->execute([':record_id' => $row['record_id'], ':flag' => PhraseaTokens::WRITE_META_SUBDEF | PhraseaTokens::TO_INDEX]);
             $stmt->closeCursor();
             unset($record);
             $i++;
             if ($i % 5 === 0) {
                 $app['elasticsearch.indexer']->flushQueue();
             }
         }
     }
     $app['elasticsearch.indexer']->flushQueue();
 }
 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;
 }
Esempio n. 5
0
 public function substituteAction(Request $request)
 {
     $ret = array();
     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('databox_id')) {
         $this->getBadRequestAction($request, 'Missing databox_id parameter');
     }
     if (!$request->get('record_id')) {
         $this->getBadRequestAction($request, 'Missing record_id parameter');
     }
     if (!$request->get('name')) {
         return $this->getBadRequestAction($request, 'Missing name parameter');
     }
     $media = $this->app->getMediaFromUri($file->getPathname());
     $record = $this->findDataboxById($request->get('databox_id'))->get_record($request->get('record_id'));
     $base_id = $record->getBaseId();
     $collection = \collection::get_from_base_id($this->app, $base_id);
     if (!$this->getAclForUser()->has_right_on_base($base_id, 'canaddrecord')) {
         return Result::create($request, 403, sprintf('You do not have access to collection %s', $collection->get_label($this->app['locale.I18n'])));
     }
     $adapt = $request->get('adapt') === null || !\p4field::isno($request->get('adapt'));
     $ret['adapt'] = $adapt;
     $record->substitute_subdef($request->get('name'), $media, $this->app, $adapt);
     foreach ($record->get_embedable_medias() as $name => $media) {
         if ($name == $request->get('name') && null !== ($subdef = $this->listEmbeddableMedia($request, $record, $media))) {
             $ret[] = $subdef;
         }
     }
     return Result::create($request, $ret)->createResponse();
 }