Example #1
0
 /**
  * Find a substitution file for a sibdef
  *
  * @return \media_subdef
  */
 protected function find_substitute_file()
 {
     if ($this->record->isStory()) {
         $this->mime = 'image/png';
         $this->width = 256;
         $this->height = 256;
         $this->path = $this->app['root.path'] . '/www/assets/common/images/icons/substitution/';
         $this->file = 'regroup_thumb.png';
         $this->url = Url::factory('/assets/common/images/icons/substitution/regroup_thumb.png');
     } else {
         $mime = $this->record->get_mime();
         $mime = trim($mime) != '' ? str_replace('/', '_', $mime) : 'application_octet-stream';
         $this->mime = 'image/png';
         $this->width = 256;
         $this->height = 256;
         $this->path = $this->app['root.path'] . '/www/assets/common/images/icons/substitution/';
         $this->file = str_replace('+', '%20', $mime) . '.png';
         $this->url = Url::factory('/assets/common/images/icons/substitution/' . $this->file);
     }
     $this->is_physically_present = false;
     if (!file_exists($this->path . $this->file)) {
         $this->path = $this->app['root.path'] . '/www/assets/common/images/icons/';
         $this->file = 'substitution.png';
         $this->url = Url::factory('/assets/common/images/icons/' . $this->file);
     }
     return $this;
 }
Example #2
0
 /**
  * {@inheritdoc}
  *
  * @return Story
  */
 public static function loadFromString(Application $app, $string)
 {
     $ids = explode('_', $string);
     try {
         $story = new \record_adapter($app, $ids[0], $ids[1]);
     } catch (NotFoundHttpException $e) {
         throw new \InvalidArgumentException('Unable to fetch a story from string');
     }
     if (!$story->isStory()) {
         throw new \InvalidArgumentException('Unable to fetch a story from string');
     }
     return new static($story);
 }
 public function attachStories(Request $request)
 {
     if (!$request->request->get('stories')) {
         throw new BadRequestHttpException('Missing parameters stories');
     }
     $storyWZRepo = $this->getStoryWZRepository();
     $alreadyFixed = $done = 0;
     $stories = $request->request->get('stories', []);
     $user = $this->getAuthenticatedUser();
     $acl = $this->getAclForUser($user);
     $manager = $this->getEntityManager();
     foreach ($stories as $element) {
         $element = explode('_', $element);
         $story = new \record_adapter($this->app, $element[0], $element[1]);
         if (!$story->isStory()) {
             throw new \Exception('You can only attach stories');
         }
         if (!$acl->has_access_to_base($story->get_base_id())) {
             throw new AccessDeniedHttpException('You do not have access to this Story');
         }
         if ($storyWZRepo->findUserStory($this->app, $user, $story)) {
             $alreadyFixed++;
             continue;
         }
         $storyWZ = new StoryWZ();
         $storyWZ->setUser($user);
         $storyWZ->setRecord($story);
         $manager->persist($storyWZ);
         $done++;
     }
     $manager->flush();
     if ($alreadyFixed === 0) {
         if ($done <= 1) {
             $message = $this->app->trans('%quantity% Story attached to the WorkZone', ['%quantity%' => $done]);
         } else {
             $message = $this->app->trans('%quantity% Stories attached to the WorkZone', ['%quantity%' => $done]);
         }
     } else {
         if ($done <= 1) {
             $message = $this->app->trans('%quantity% Story attached to the WorkZone, %quantity_already% already attached', ['%quantity%' => $done, '%quantity_already%' => $alreadyFixed]);
         } else {
             $message = $this->app->trans('%quantity% Stories attached to the WorkZone, %quantity_already% already attached', ['%quantity%' => $done, '%quantity_already%' => $alreadyFixed]);
         }
     }
     if ($request->getRequestFormat() == 'json') {
         return $this->app->json(['success' => true, 'message' => $message]);
     }
     return $this->app->redirectPath('prod_workzone_show');
 }
 public function substitute(\record_adapter $record, $name, MediaInterface $media)
 {
     $newfilename = $record->get_record_id() . '_0_' . $name . '.' . $media->getFile()->getExtension();
     $subdef_def = false;
     if ($name == 'document') {
         $baseprefs = $record->get_databox()->get_sxml_structure();
         $pathhd = \p4string::addEndSlash((string) $baseprefs->path);
         $filehd = $record->get_record_id() . "_document." . strtolower($media->getFile()->getExtension());
         $pathhd = \databox::dispatch($this->fs, $pathhd);
         $this->fs->copy($media->getFile()->getRealPath(), $pathhd . $filehd, true);
         $subdefFile = $pathhd . $filehd;
         $meta_writable = true;
     } else {
         $type = $record->isStory() ? 'image' : $record->get_type();
         $subdef_def = $record->get_databox()->get_subdef_structure()->get_subdef($type, $name);
         if ($record->has_subdef($name) && $record->get_subdef($name)->is_physically_present()) {
             $path_file_dest = $record->get_subdef($name)->get_pathfile();
             $record->get_subdef($name)->remove_file();
             $record->clearSubdefCache($name);
         } else {
             $path = \databox::dispatch($this->fs, $subdef_def->get_path());
             $this->fs->mkdir($path, 0750);
             $path_file_dest = $path . $newfilename;
         }
         try {
             $this->alchemyst->turnInto($media->getFile()->getRealPath(), $path_file_dest, $subdef_def->getSpecs());
         } catch (MediaAlchemystException $e) {
             return;
         }
         $subdefFile = $path_file_dest;
         $meta_writable = $subdef_def->meta_writeable();
     }
     $this->fs->chmod($subdefFile, 0760);
     $media = $this->mediavorus->guess($subdefFile);
     \media_subdef::create($this->app, $record, $name, $media);
     $record->delete_data_from_cache(\record_adapter::CACHE_SUBDEFS);
     if ($meta_writable) {
         $record->write_metas();
     }
     if ($name == 'document') {
         $record->rebuild_subdefs();
     }
     $this->dispatcher->dispatch(RecordEvents::MEDIA_SUBSTITUTED, new RecordMediaSubstitutedEvent($record));
 }
 public function serialize(\record_adapter $record)
 {
     $caption = $business = $status = [];
     $technicalInformation = $record->get_technical_infos()->getValues();
     foreach ($record->get_caption()->get_fields(null, true) as $field) {
         $isDate = $field->get_databox_field()->get_type() === \databox_field::TYPE_DATE;
         $isBusiness = $field->get_databox_field()->isBusiness();
         $vi = $field->get_values();
         if ($field->is_multi()) {
             $values = [];
             foreach ($vi as $value) {
                 $values[] = $this->sanitizeSerializedValue($value->getValue());
             }
             $value = implode(' ' . $field->get_databox_field()->get_separator(false) . ' ', $values);
         } else {
             $value = $this->sanitizeSerializedValue(array_pop($vi)->getValue());
         }
         if ($isDate) {
             try {
                 $date = new \DateTime($value);
                 $value = $date->format(DATE_ATOM);
             } catch (\Exception $e) {
                 continue;
             }
         }
         if ($isBusiness) {
             $business[$field->get_databox_field()->get_name()] = $value;
         }
         $caption[$field->get_databox_field()->get_name()] = $value;
     }
     $i = 0;
     foreach (preg_split('//', strrev($record->get_status()), -1, PREG_SPLIT_NO_EMPTY) as $val) {
         $status['status-' . $i] = (int) $val;
         $i++;
     }
     return ['databox_id' => $record->get_sbas_id(), 'record_id' => $record->get_record_id(), 'collection_id' => $record->get_collection()->get_coll_id(), 'base_id' => $record->get_base_id(), 'mime_type' => $record->get_mime(), 'title' => $record->get_title(), 'original_name' => $record->get_original_name(), 'updated_on' => $record->get_modification_date()->format(DATE_ATOM), 'created_on' => $record->get_creation_date()->format(DATE_ATOM), 'sha256' => $record->get_sha256(), 'technical_informations' => $technicalInformation, 'phrasea_type' => $record->get_type(), 'type' => $record->isStory() ? 'story' : 'record', 'uuid' => $record->getUuid(), 'caption' => $caption, 'status' => $status, 'caption-business' => $business];
 }
Example #6
0
 /**
  * @covers Alchemy\Phrasea\Controller\Prod\Upload::upload
  */
 public function testUploadRecordStatus()
 {
     self::$DI['app']['phraseanet.SE'] = $this->createSearchEngineMock();
     $params = ['base_id' => self::$DI['collection']->get_base_id(), 'forceAction' => Manager::FORCE_RECORD, 'status' => [self::$DI['collection']->get_base_id() => [4 => 1]]];
     $files = ['files' => [new UploadedFile($this->tmpFile, 'KIKOO.JPG')]];
     self::$DI['client']->request('POST', '/prod/upload/', $params, $files, ['HTTP_Accept' => 'application/json']);
     $response = self::$DI['client']->getResponse();
     $this->checkJsonResponse($response);
     $datas = json_decode($response->getContent(), true);
     $this->assertTrue($datas['success']);
     $this->assertEquals('record', $datas['element']);
     $this->assertEquals(Manager::RECORD_CREATED, $datas['code']);
     $id = explode('_', $datas['id']);
     $record = new \record_adapter(self::$DI['app'], $id[0], $id[1]);
     $this->assertFalse($record->isStory());
     $this->assertEquals(1, substr(strrev($record->get_status()), 4, 1));
     $this->assertEquals([], $datas['reasons']);
 }
Example #7
0
 /**
  *
  * @param array   $lst
  * @param Boolean $flatten_groupings
  *
  * @return set_selection
  */
 public function load_list(array $lst, $flatten_groupings = false)
 {
     foreach ($lst as $basrec) {
         $basrec = explode('_', $basrec);
         if (count($basrec) == 2) {
             try {
                 $record = new record_adapter($this->app, (int) $basrec[0], (int) $basrec[1], count($this->elements));
             } catch (\Exception $e) {
                 continue;
             }
             if ($record->isStory() && $flatten_groupings === true) {
                 foreach ($record->get_children() as $rec) {
                     $this->add_element($rec);
                 }
             } else {
                 $this->add_element($record);
             }
         }
     }
     return $this;
 }
Example #8
0
 /**
  * @param record_adapter $record
  */
 private function mirror(record_adapter $record)
 {
     $this->mime = $record->getMimeType();
     $this->sha256 = $record->getSha256();
     $this->original_name = $record->getOriginalName();
     $this->type = $record->getType();
     $this->isStory = $record->isStory();
     $this->uuid = $record->getUuid();
     $this->updated = $record->getUpdated();
     $this->created = $record->getCreated();
     $this->base_id = $record->getBaseId();
     $this->collection_id = $record->getCollectionId();
 }
Example #9
0
 /**
  *
  * @param  Application $app
  * @param  string      $lst
  * @param  integer     $sstid
  * @param  integer     $storyWZid
  * @return set_export
  */
 public function __construct(Application $app, $lst, $sstid, $storyWZid = null)
 {
     $this->app = $app;
     $download_list = [];
     $remain_hd = [];
     if ($storyWZid) {
         $repository = $app['repo.story-wz'];
         $storyWZ = $repository->findByUserAndId($this->app, $app->getAuthenticatedUser(), $storyWZid);
         $lst = $storyWZ->getRecord($this->app)->get_serialize_key();
     }
     if ($sstid != "") {
         $repository = $app['repo.baskets'];
         /* @var $repository Alchemy\Phrasea\Model\Repositories\BasketRepository */
         $Basket = $repository->findUserBasket($sstid, $app->getAuthenticatedUser(), false);
         $this->exportName = str_replace([' ', '\\', '/'], '_', $Basket->getName()) . "_" . date("Y-n-d");
         foreach ($Basket->getElements() as $basket_element) {
             $base_id = $basket_element->getRecord($this->app)->get_base_id();
             $record_id = $basket_element->getRecord($this->app)->get_record_id();
             if (!isset($remain_hd[$base_id])) {
                 if ($app->getAclForUser($app->getAuthenticatedUser())->is_restricted_download($base_id)) {
                     $remain_hd[$base_id] = $app->getAclForUser($app->getAuthenticatedUser())->remaining_download($base_id);
                 } else {
                     $remain_hd[$base_id] = false;
                 }
             }
             $current_element = $download_list[] = new record_exportElement($app, $basket_element->getRecord($this->app)->get_sbas_id(), $record_id, $Basket->getName(), $remain_hd[$base_id]);
             $remain_hd[$base_id] = $current_element->get_remain_hd();
         }
     } else {
         $this->exportName = "Export_" . date("Y-n-d") . '_' . mt_rand(100, 999);
         $tmp_lst = explode(';', $lst);
         $n = 1;
         foreach ($tmp_lst as $basrec) {
             $basrec = explode('_', $basrec);
             if (count($basrec) != 2) {
                 continue;
             }
             try {
                 $record = new record_adapter($this->app, $basrec[0], $basrec[1]);
             } catch (\Exception_Record_AdapterNotFound $e) {
                 continue;
             }
             if ($record->isStory()) {
                 foreach ($record->get_children() as $child_basrec) {
                     $base_id = $child_basrec->get_base_id();
                     $record_id = $child_basrec->get_record_id();
                     if (!isset($remain_hd[$base_id])) {
                         if ($app->getAclForUser($app->getAuthenticatedUser())->is_restricted_download($base_id)) {
                             $remain_hd[$base_id] = $app->getAclForUser($app->getAuthenticatedUser())->remaining_download($base_id);
                         } else {
                             $remain_hd[$base_id] = false;
                         }
                     }
                     $current_element = $download_list[] = new record_exportElement($app, $child_basrec->get_sbas_id(), $record_id, $record->get_title(null, null, true) . '_' . $n, $remain_hd[$base_id]);
                     $remain_hd[$base_id] = $current_element->get_remain_hd();
                 }
             } else {
                 $base_id = $record->get_base_id();
                 $record_id = $record->get_record_id();
                 if (!isset($remain_hd[$base_id])) {
                     if ($app->getAclForUser($app->getAuthenticatedUser())->is_restricted_download($base_id)) {
                         $remain_hd[$base_id] = $app->getAclForUser($app->getAuthenticatedUser())->remaining_download($base_id);
                     } else {
                         $remain_hd[$base_id] = false;
                     }
                 }
                 $current_element = $download_list[$basrec[0] . '_' . $basrec[1]] = new record_exportElement($app, $record->get_sbas_id(), $record_id, '', $remain_hd[$base_id]);
                 $remain_hd[$base_id] = $current_element->get_remain_hd();
             }
             $n++;
         }
     }
     $this->elements = $download_list;
     $display_download = [];
     $display_orderable = [];
     $this->total_download = 0;
     $this->total_order = 0;
     $this->total_ftp = 0;
     $this->businessFieldsAccess = false;
     foreach ($this->elements as $download_element) {
         if ($app->getAclForUser($app->getAuthenticatedUser())->has_right_on_base($download_element->get_base_id(), 'canmodifrecord')) {
             $this->businessFieldsAccess = true;
         }
         foreach ($download_element->get_downloadable() as $name => $properties) {
             if (!isset($display_download[$name])) {
                 $display_download[$name] = ['size' => 0, 'total' => 0, 'available' => 0, 'refused' => []];
             }
             $display_download[$name]['total']++;
             if ($properties !== false) {
                 $display_download[$name]['available']++;
                 $display_download[$name]['label'] = $properties['label'];
                 $display_download[$name]['class'] = $properties['class'];
                 $this->total_download++;
                 $display_download[$name]['size'] += $download_element->get_size($name);
             } else {
                 $display_download[$name]['refused'][] = $download_element->get_thumbnail();
             }
         }
         foreach ($download_element->get_orderable() as $name => $properties) {
             if (!isset($display_orderable[$name])) {
                 $display_orderable[$name] = ['total' => 0, 'available' => 0, 'refused' => []];
             }
             $display_orderable[$name]['total']++;
             if ($properties !== false) {
                 $display_orderable[$name]['available']++;
                 $this->total_order++;
             } else {
                 $display_orderable[$name]['refused'][] = $download_element->get_thumbnail();
             }
         }
     }
     foreach ($display_download as $name => $values) {
         $display_download[$name]['size'] = (int) $values['size'];
     }
     $display_ftp = [];
     $hasadminright = $app->getAclForUser($app->getAuthenticatedUser())->has_right('addrecord') || $app->getAclForUser($app->getAuthenticatedUser())->has_right('deleterecord') || $app->getAclForUser($app->getAuthenticatedUser())->has_right('modifyrecord') || $app->getAclForUser($app->getAuthenticatedUser())->has_right('coll_manage') || $app->getAclForUser($app->getAuthenticatedUser())->has_right('coll_modify_struct');
     $this->ftp_datas = [];
     if ($this->app['conf']->get(['registry', 'ftp', 'ftp-enabled']) && ($hasadminright || $this->app['conf']->get(['registry', 'ftp', 'ftp-user-access']))) {
         $display_ftp = $display_download;
         $this->total_ftp = $this->total_download;
         $lst_base_id = array_keys($app->getAclForUser($app->getAuthenticatedUser())->get_granted_base());
         if ($hasadminright) {
             $sql = "SELECT Users.id AS usr_id ,Users.login AS usr_login ,Users.email AS usr_mail, FtpCredential.*\n                  FROM (\n                    FtpCredential INNER JOIN Users ON (\n                        FtpCredential.active = 1 AND FtpCredential.user_id = Users.id\n                    ) INNER JOIN basusr ON (\n                        Users.id=basusr.usr_id\n                        AND (basusr.base_id=\n                        '" . implode("' OR basusr.base_id='", $lst_base_id) . "'\n                            )\n                         )\n                      )\n                  GROUP BY Users.id  ";
             $params = [];
         } elseif ($this->app['conf']->get(['registry', 'ftp', 'ftp-user-access'])) {
             $sql = "SELECT Users.id AS usr_id ,Users.login AS usr_login ,Users.email AS usr_mail, FtpCredential.*\n                  FROM (\n                    FtpCredential INNER JOIN Users ON (\n                        FtpCredential.active = 1 AND FtpCredential.id = Users.id\n                    ) INNER JOIN basusr ON (\n                        Users.id=basusr.usr_id\n                        AND Users.id = :usr_id\n                        AND (basusr.base_id=\n                        '" . implode("' OR basusr.base_id='", $lst_base_id) . "'\n                          )\n                        )\n                      )\n                  GROUP BY Users.id  ";
             $params = [':usr_id' => $app->getAuthenticatedUser()->getId()];
         }
         $datas[] = ['name' => $app->trans('export::ftp: reglages manuels'), 'usr_id' => '0', 'address' => '', 'login' => '', 'password' => '', 'ssl' => false, 'dest_folder' => '', 'prefix_folder' => 'Export_' . date("Y-m-d_H.i.s"), 'passive' => false, 'max_retry' => 5, 'sendermail' => $app->getAuthenticatedUser()->getEmail()];
         $stmt = $app->getApplicationBox()->get_connection()->prepare($sql);
         $stmt->execute($params);
         $rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
         $stmt->closeCursor();
         foreach ($rs as $row) {
             $datas[] = ['name' => $row["usr_login"], 'usr_id' => $row['usr_id'], 'address' => $row['address'], 'login' => $row['login'], 'password' => $row['password'], 'ssl' => !!$row['tls'], 'dest_folder' => $row['reception_folder'], 'prefix_folder' => strlen(trim($row['repository_prefix_name'])) > 0 ? trim($row['repository_prefix_name']) : 'Export_' . date("Y-m-d_H.i.s"), 'passive' => !!$row['passive'], 'max_retry' => $row['max_retry'], 'usr_mail' => $row['usr_mail'], 'sender_mail' => $app->getAuthenticatedUser()->getEmail()];
         }
         $this->ftp_datas = $datas;
     }
     $this->display_orderable = $display_orderable;
     $this->display_download = $display_download;
     $this->display_ftp = $display_ftp;
     return $this;
 }
Example #10
0
 /**
  * Retrieve detailed information about one story
  *
  * @param Request         $request
  * @param \record_adapter $story
  * @return array
  * @throws \Exception
  */
 public function listStory(Request $request, \record_adapter $story)
 {
     if (!$story->isStory()) {
         return Result::createError($request, 404, 'Story not found')->createResponse();
     }
     $records = array_map(function (\record_adapter $record) use($request) {
         return $this->listRecord($request, $record);
     }, array_values($story->get_children()->get_elements()));
     $caption = $story->get_caption();
     $format = function (\caption_record $caption, $dcField) {
         $field = $caption->get_dc_field($dcField);
         if (!$field) {
             return null;
         }
         return $field->get_serialized_values();
     };
     return ['@entity@' => self::OBJECT_TYPE_STORY, 'databox_id' => $story->getDataboxId(), 'story_id' => $story->getRecordId(), 'updated_on' => $story->getUpdated()->format(DATE_ATOM), 'created_on' => $story->getCreated()->format(DATE_ATOM), 'collection_id' => $story->getCollectionId(), 'base_id' => $story->getBaseId(), 'thumbnail' => $this->listEmbeddableMedia($request, $story, $story->get_thumbnail()), 'uuid' => $story->getUuid(), 'metadatas' => ['@entity@' => self::OBJECT_TYPE_STORY_METADATA_BAG, 'dc:contributor' => $format($caption, \databox_Field_DCESAbstract::Contributor), 'dc:coverage' => $format($caption, \databox_Field_DCESAbstract::Coverage), 'dc:creator' => $format($caption, \databox_Field_DCESAbstract::Creator), 'dc:date' => $format($caption, \databox_Field_DCESAbstract::Date), 'dc:description' => $format($caption, \databox_Field_DCESAbstract::Description), 'dc:format' => $format($caption, \databox_Field_DCESAbstract::Format), 'dc:identifier' => $format($caption, \databox_Field_DCESAbstract::Identifier), 'dc:language' => $format($caption, \databox_Field_DCESAbstract::Language), 'dc:publisher' => $format($caption, \databox_Field_DCESAbstract::Publisher), 'dc:relation' => $format($caption, \databox_Field_DCESAbstract::Relation), 'dc:rights' => $format($caption, \databox_Field_DCESAbstract::Rights), 'dc:source' => $format($caption, \databox_Field_DCESAbstract::Source), 'dc:subject' => $format($caption, \databox_Field_DCESAbstract::Subject), 'dc:title' => $format($caption, \databox_Field_DCESAbstract::Title), 'dc:type' => $format($caption, \databox_Field_DCESAbstract::Type)], 'records' => $records];
 }
Example #11
0
 public function reorderAction(Request $request, $sbas_id, $record_id)
 {
     try {
         $story = new \record_adapter($this->app, $sbas_id, $record_id);
         if (!$story->isStory()) {
             throw new \Exception('This is not a story');
         }
         if (!$this->getAclForUser()->has_right_on_base($story->get_base_id(), 'canmodifrecord')) {
             throw new ControllerException($this->app->trans('You can not edit this story'));
         }
         $sql = 'UPDATE regroup SET ord = :ord WHERE rid_parent = :parent_id AND rid_child = :children_id';
         $stmt = $story->get_databox()->get_connection()->prepare($sql);
         foreach ($request->request->get('element') as $record_id => $ord) {
             $params = [':ord' => $ord, ':parent_id' => $story->get_record_id(), ':children_id' => $record_id];
             $stmt->execute($params);
         }
         $stmt->closeCursor();
         $this->dispatch(PhraseaEvents::RECORD_EDIT, new RecordEdit($story));
         $ret = ['success' => true, 'message' => $this->app->trans('Story updated')];
     } catch (ControllerException $e) {
         $ret = ['success' => false, 'message' => $e->getMessage()];
     } catch (\Exception $e) {
         $ret = ['success' => false, 'message' => $this->app->trans('An error occured')];
     }
     return $this->app->json($ret);
 }