/** * {@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(); }
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(); }